Hi Maik,

  In ChimeraX model positionining (rotation and translation) is done with a Place object defined in Python described in the programmer documentation here

https://www.cgl.ucsf.edu/chimerax/docs/devel/modules/geometry/geometry.html#chimerax.geometry.place.Place

These Place objects internally have a 3x4 numpy matrix of float64 values.  But the Place objects are read-only -- you can't change their matrix.  If you need a new position you make a new Place object.  So you should use

from chimerax.geometry import Place
pos = Place(matrix = my_numpy_3x4_matrix)
model.scene_position = pos

The Place objects can be multiplied (thinking of them as a coordinate transformation, and composing the transforms).  They have an inverse method to perform the inverse coordinate transformation, and many other operations.  So almost no ChimeraX code does coordinate transforms and positioning directly in numpy -- instead almost everything uses Place and other methods of the ChimeraX geometry module.

 Tom



On Apr 19, 2024, at 9:26 AM, Engeholm, Maik via ChimeraX-users <chimerax-users@cgl.ucsf.edu> wrote:

Hi Tom, hi Eric,

thanks a lot for answering my previous question so comprehensively! Hope it's OK to bother you again. This is about something completely unrelated.

I would like to apply a transformation (rotation plus translation) to an atomic model. I need to change the coordinates of the model relative to the overall coordinate system. Changing the scene or camera coordinates is not an option, since in the end I want to place multiple copies of my model (in this case a nucleosome) in a specific orientation relative to each other (i.e. within the same coordinate system) to model an array of nucleosomes.

If I remember correctly, back in Chimera this could be achieved with "model.openState.global/localXform(transformation)" where transformation was an chimera.Xform object. But as far as I can see this is not supported in chimeraX.

Here is a reproducible example of the simplest case, in which I define the center and two (roughly) orthogonal axes of my atomic model (i.e. the normal of the DNA superhelix and the dyad axis) and try to map those onto the origin of the coordinate system and two unit vectors.

"""
from chimerax.core.commands import run
import numpy as np 
from numpy import cross, dot

np.set_printoptions(suppress = True)

run    (session, 'close session')
run    (session, 'windowsize 360 360')

target_centre         =     np.array((0, 0, 0))
target_normal        =    np.array((0, 1, 0))
target_dyad            =    np.array((0, 0, 1))
target_3rd_axis        =    cross(target_normal, target_dyad)

run    (session, 'open 3lz0 name 3lz0')

pdb3lz0_DNA_plane        =    run    (session, 'define plane #1/I,J:-56-56')
pdb3lz0_DNA_centre        =    run    (session, 'define centroid #1/I,J:-56-56')
pdb3lz0_dyad_base_pair    =    run    (session, 'define centroid #1/I,J:0')
pdb3lz0_dyad_axis        =    run    (session, 'define axis #1.4 #1.5')


pdb3lz0_centre            =    session.models[3].xform_center
pdb3lz0_normal            =    session.models[3].xform_normal
pdb3lz0_dyad            =    session.models[6].xform_direction
pdb3lz0_3rd_axis        =    cross(pdb3lz0_normal, pdb3lz0_dyad)

rotation_inverse        =    np.c_[pdb3lz0_3rd_axis, pdb3lz0_normal, pdb3lz0_dyad]
rotation                =    np.linalg.inv(rotation_inverse)
translation                =    -pdb3lz0_centre        
transformation            =    np.c_[rotation, translation]

print(session.models[0].position.matrix)
"""

At this point I have tried to modify the position.matrix with

"session.models[0].position.matrix = transformation"

but this gives me an "AttributeError: property 'matrix' of 'Place' object has no setter".

I'm sure there must be a way to transform an atomic model in this way and would be really grateful for your help.

Thanks a lot in advance,

Maik

_______________________________________________
ChimeraX-users mailing list -- chimerax-users@cgl.ucsf.edu
To unsubscribe send an email to chimerax-users-leave@cgl.ucsf.edu
Archives: https://mail.cgl.ucsf.edu/mailman/archives/list/chimerax-users@cgl.ucsf.edu/