With all due respect, I am not convinced that you have done countless Google searches. A single Google search with "center of mass protein biopython" returned this as a first hit. There is a section "Coarse Grain Structure" towards the end that shows a simple Biopython solution:
what version of biopython are u using ? I am using 1.78 and i get: 'Structure' object has no attribute 'center_of_mass'. Also I cannot find anything in the documentation of biopython.
I had the same issue with biopython in finding the centre of mass. Although as Mensurj Dlakic suggested, there is a Struct class within Bio, this is an experimental class from JoaoRodrigues which does not appear to be implemented in any of the current versions of biopython: you can't simply "conda/pip install biopython" to access this module, but rather define it within your directory to use it.
The file which will enable you to call center_of_mass is here. Once you download this file in your directory, you can write a separate file which calls:
from Geometry import *
and proceed to call center_of_mass on any "structural object" such as the model/chain/residue of interest.
Although you can read through how Geometry does the center-of-mass calculation yourself, a summary is:
Find all the atoms of the structure, create a list of the atom masses, define the center of mass=(sum each set of xyz coordinate * respective atom mass)/(sum of each atomic mass), just as you would expect per a center of mass calculation in three dimensions.
My GSOC branch was never fully merged in the main branch.
As of September 2020, Biopython has a native center of mass function. You can use it on any Entity (Structure, Chain, Residue, DisorderedAtom) and it returns either the center of mass or of geometry:
from Bio.PDB import PDBParser
parser = PDBParser()
structure = parser.get_structure('foo', '1abc.pdb')
com = structure.center_of_mass()
# For each chain
for chain in structure.get_chains():
print(chain.center_of_mass())
With all due respect, I am not convinced that you have done
countless Google searches
. A single Google search with "center of mass protein biopython" returned this as a first hit. There is a section "Coarse Grain Structure" towards the end that shows a simple Biopython solution:There is no guarantee that that function is correct...
Biopython is quite a mature library at this point, why would you assume that it is incorrect? (I haven't looked at the source myself)
what version of biopython are u using ? I am using 1.78 and i get: 'Structure' object has no attribute 'center_of_mass'. Also I cannot find anything in the documentation of biopython.
If you take a look here: https://biopython.org/wiki/Struct
the
centre_of_mass
function is currently not in the main development branch of the biopython repository. You would need to clone and use Joao's fork of the repo where you can see the code here: https://github.com/JoaoRodrigues/biopython/blob/GSOC2010/Bio/Struct/Geometry.py#L13