1
$\begingroup$

I trying to write a pythonic PyMol script that loads a PDB, cmd.iterates through the PDB and stores the residues (three letter code) into an array. I then want to loop through this array and calculate the center of masses (COM) of each aa's sidechains (except gly) and add it into a second array. I am able to calculate the COM of a residue as a whole, i.e. including backbone atoms. But what I want to calculate is the COM of the sidechain. Please point me in the right direction.

path = 'Path to PDB dir'
for filename in glob.glob(os.path.join(path, '*.PDB')):
    cmd.load(filename)  
    stored_residues = []
    cmd.iterate('name ca', 'stored_residues.append(resn)')

    stored_residues_COM = []

    for i in stored_residues:
         stored_residues_sidechain_COM.append(centerOfMass('resn %s' % i))
$\endgroup$

1 Answer 1

1
$\begingroup$

I am guessing you used the command pymol.cmd.centerofmass? If so the selector is the ticket to doing it by selecting everything of the residue bar the backbone atoms, e.g. f'resi {r} not name N+CA+C+O+H'

Parenthetically, the cmd.iterate command is really ugly and counter-intuitive —it's heavily used because it is older. The command get_model(selection) in pymol2 module is so much nicer.

for atom in pymol.cmd.get_model('name CA').atom:
     atom.resi #note it is type str due to insertion codes!
     atom.resn
     atom.coords # List[float]

Second parenthesis. A and not element H is not needed or beneficial to pymol.cmd.centerofmass as this takes account of mass and occupancy. There is no need to select only heavy atoms as a proton weighs nothing. The barycentre and centroid are the same in geometry where there is no mass to the points, but here mass is present.

$\endgroup$
3
  • 1
    $\begingroup$ That is good advice. Thank you. I am also looking at Thomas Holder's code (pymolwiki.org/index.php/Sidechaincenters) as a comparative approach. $\endgroup$
    – gwot
    Commented Dec 9, 2021 at 14:09
  • 1
    $\begingroup$ @gwot Upvoting and checking 'answer resolved' is a good way to say thanks $\endgroup$
    – M__
    Commented Jan 7, 2022 at 14:59
  • $\begingroup$ Hi Matteo, sorry for the breach of etiquette. I have accepted you helpful answer, but do not yet have the rep to upvote. $\endgroup$
    – gwot
    Commented Jan 8, 2022 at 15:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.