schrodinger / pymol-open-source

Open-source foundation of the user-sponsored PyMOL molecular visualization system.
https://pymol.org/
Other
1.15k stars 275 forks source link

Transforming vertices to match original pdb reference frame using `transform_selection` #278

Open OliviaViessmann opened 1 year ago

OliviaViessmann commented 1 year ago

Hi,

I am using pymol to generate surface meshes from pdb source files. I would like to have the vertices in the same reference frame as the original pdb coordinates. However, when I save the obj file the object is centered at [0,0,0]. I tried to use the following code snippet to transform the surface, but it didn't do anything to the coordinates. What am I doing wrong, or is the command not behaving how supposed to?

pymol.load(pdb_file)
view = list(pymol.get_view())
M = view[0:3] + [-view[12]] + view[3:6] + [-view[13]] + view[6:9] + [-view[14]] + view[12:15] + [1.0]
pymol.transform_selection("(all)", M, 0, 0, 0, 1)
pymol.set_view([1, 0, 0, 0, 1, 0, 0, 0, 1] + view[9:])

Any help would be greatly appreciated. If there is a way to avoid the centering at the loading stage, that would be awesome too. Thanks Olivia