Apply the user's rotation in Python

Hi, If I open a protein structure, change the right mouse to rotate, select the structure, rotate it by the right mouse, and then execute the following script in the Python Shell, the structure will be moved; see the video ( https://i.gyazo.com/d72344f9c8610298f574c23e53224aac.mp4). I would expect it to be not moved as the mol.atoms.coords have not been changed. The mol.atoms.scene_coords have been changed instead. But this could be my misunderstanding of the design intent. I encounter some bugs in the downstream analysis using scene_coords only. from chimerax.atomic import Structure mol = session.models.list(type = Structure)[0] transformation = mol.scene_position mol.atoms.transform(transformation) However, if I open the same structure again and execute the following, it will go to the user's rotation. mol_2 = session.models.list(type = Structure)[1] mol_2.atoms.transform(transformation) So, I then applied the following code in my script. As a result, everything is as expected, and there is no bug. mol_path = mol.filename transformation = mol.scene_position mol.delete() mol = run(self.session, f"open {mol_path}")[0] mol.atoms.transform(transformation) I wonder if there is a way to bypass this re-opening of the file. I am with version 1.7.1 (2024-01-23) on Win 11. Many thanks, Roden -- This message and its contents, including attachments are intended solely for the original recipient. If you are not the intended recipient or have received this message in error, please notify me immediately and delete this message from your computer system. Any unauthorized use or distribution is prohibited. Please consider the environment before printing this email.

Hi Roden, mol.atoms.coords are the coordinates the atoms had in the original input file and most commands do not change those, though a few (like adjusting a torsion angle) will. mol.atoms.scene_coords is the coordinates of the structure in the scene, which in many cases are the same as mol.atom.coords because structures initially open with an identity matrix as their transformation matrix (and scene_coords is just coords multiplied by that transformation), and that matrix only changes if you move one structure relative to the other structures in the scene (such as superimposing structures with MatchMaker). The right-mouse rotation mode also moves a structure relative to others and can therefore change the scene_coords of that structure. When rotating an entire scene using the normal left-mouse mode, nether coords nor scene_coords are changed, just the direction that the camera is looking at the scene from. Your code is taking the transform that converts coords to scene_coords and is applying it to the coords themselves, effectively applying the transform twice, once to the coordinates themselves and then again when they get transformed into scene_coords. --Eric Eric Pettersen UCSF Computer Graphics Lab
On Sep 23, 2024, at 3:26 PM, Roden Deng Luo via ChimeraX-users <chimerax-users@cgl.ucsf.edu> wrote:
Hi,
If I open a protein structure, change the right mouse to rotate, select the structure, rotate it by the right mouse, and then execute the following script in the Python Shell, the structure will be moved; see the video (https://i.gyazo.com/d72344f9c8610298f574c23e53224aac.mp4). I would expect it to be not moved as the mol.atoms.coords have not been changed. The mol.atoms.scene_coords have been changed instead. But this could be my misunderstanding of the design intent. I encounter some bugs in the downstream analysis using scene_coords only.
from chimerax.atomic import Structure mol = session.models.list(type = Structure)[0] transformation = mol.scene_position mol.atoms.transform(transformation)
However, if I open the same structure again and execute the following, it will go to the user's rotation.
mol_2 = session.models.list(type = Structure)[1] mol_2.atoms.transform(transformation)
So, I then applied the following code in my script. As a result, everything is as expected, and there is no bug.
mol_path = mol.filename transformation = mol.scene_position mol.delete() mol = run(self.session, f"open {mol_path}")[0] mol.atoms.transform(transformation)
I wonder if there is a way to bypass this re-opening of the file. I am with version 1.7.1 (2024-01-23) on Win 11.
Many thanks, Roden
This message and its contents, including attachments are intended solely for the original recipient. If you are not the intended recipient or have received this message in error, please notify me immediately and delete this message from your computer system. Any unauthorized use or distribution is prohibited. Please consider the environment before printing this email._______________________________________________ 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/

Hi Eric, Many thanks! You reminded me that I could reset mol.position = Place(). With the following code, all bugs are gone! mol.atoms.transform(mol.position) from chimerax.geometry import Place mol.position = Place() Best, Roden On Tue, Sep 24, 2024 at 2:37 AM Eric Pettersen <pett@cgl.ucsf.edu> wrote:
Hi Roden, mol.atoms.coords are the coordinates the atoms had in the original input file and most commands do not change those, though a few (like adjusting a torsion angle) will. mol.atoms.scene_coords is the coordinates of the structure in the scene, which in many cases are the same as mol.atom.coords because structures initially open with an identity matrix as their transformation matrix (and scene_coords is just coords multiplied by that transformation), and that matrix only changes if you move one structure *relative* to the other structures in the scene (such as superimposing structures with MatchMaker). The right-mouse rotation mode also moves a structure relative to others and can therefore change the scene_coords of that structure. When rotating an entire scene using the normal left-mouse mode, nether coords nor scene_coords are changed, just the direction that the camera is looking at the scene from. Your code is taking the transform that converts coords to scene_coords and is applying it to the coords themselves, effectively applying the transform *twice*, once to the coordinates themselves and then again when they get transformed into scene_coords.
--Eric
Eric Pettersen UCSF Computer Graphics Lab
On Sep 23, 2024, at 3:26 PM, Roden Deng Luo via ChimeraX-users < chimerax-users@cgl.ucsf.edu> wrote:
Hi,
If I open a protein structure, change the right mouse to rotate, select the structure, rotate it by the right mouse, and then execute the following script in the Python Shell, the structure will be moved; see the video ( https://i.gyazo.com/d72344f9c8610298f574c23e53224aac.mp4 <https://urldefense.com/v3/__https://i.gyazo.com/d72344f9c8610298f574c23e5322...>). I would expect it to be not moved as the mol.atoms.coords have not been changed. The mol.atoms.scene_coords have been changed instead. But this could be my misunderstanding of the design intent. I encounter some bugs in the downstream analysis using scene_coords only.
from chimerax.atomic import Structure mol = session.models.list(type = Structure)[0] transformation = mol.scene_position mol.atoms.transform(transformation)
However, if I open the same structure again and execute the following, it will go to the user's rotation.
mol_2 = session.models.list(type = Structure)[1] mol_2.atoms.transform(transformation)
So, I then applied the following code in my script. As a result, everything is as expected, and there is no bug.
mol_path = mol.filename transformation = mol.scene_position mol.delete() mol = run(self.session, f"open {mol_path}")[0] mol.atoms.transform(transformation)
I wonder if there is a way to bypass this re-opening of the file. I am with version 1.7.1 (2024-01-23) on Win 11.
Many thanks, Roden
------------------------------ This message and its contents, including attachments are intended solely for the original recipient. If you are not the intended recipient or have received this message in error, please notify me immediately and delete this message from your computer system. Any unauthorized use or distribution is prohibited. Please consider the environment before printing this email._______________________________________________ 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/ <https://urldefense.com/v3/__https://mail.cgl.ucsf.edu/mailman/archives/list/...>
-- This message and its contents, including attachments are intended solely for the original recipient. If you are not the intended recipient or have received this message in error, please notify me immediately and delete this message from your computer system. Any unauthorized use or distribution is prohibited. Please consider the environment before printing this email.
participants (2)
-
Eric Pettersen
-
Roden Deng Luo