a-r-j / graphein

Protein Graph Library
https://graphein.ai/
MIT License
1.01k stars 126 forks source link

How to transform a surface to match original pdb reference frame #265

Closed OliviaViessmann closed 1 year ago

OliviaViessmann commented 1 year ago

Describe the bug I am using create_mesh() to generate surfaces. The background pymol commands generates an .obj which contains the vertices and faces, but it centers the protein, so the original pdb coordinates and the mesh do not align. How can I transform the surface vertices to match the original pdb reference frame? After reading about the specific order of rotations and translations in pymol I adapted the get_obj_file() in graphein using a transformation command from the pymol Q&A before the .obj file is saved, but it doesn't do anything. I call the lines below after pymol.load(pdb_file) and before pymol.save

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:])

Expected behavior Does anyone have any ideas how I can align the pdb residue coordinates and the graphein vertex coordinates?

a-r-j commented 1 year ago

It appears you need to reset the camera view. Can you try this config? It works for me.


import graphein.protein as gp

config = gp.ProteinMeshConfig(pymol_commands=["show surface", "set_view (1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, -50.0, 0.0, 0.0, 0.0, 40.0, 100.0, -20.0)"])```
OliviaViessmann commented 1 year ago

Cool, this indeed resets it! A question -- how did you chose the values for the matrix? Are these the defaults for the original view? Thanks a again for the help!

a-r-j commented 1 year ago

They came to me in a dream :)