How to calculate the center of mass
2
0
Entering edit mode
2.3 years ago
M.O.L.S ▴ 40

Please can I have some ideas as I just don't get it. We usually come here, after countless Google searches, not as a first resort =)

What is the center of mass of an atomic coordinate of protein? I'd like to program it using biopython

Is there a formula for it? Why is this important? How is it related to the mean?

Center of Mass proteins physics python • 2.3k views
0
Entering edit mode

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:

from Bio.Struct.Geometry import center_of_mass

0
Entering edit mode

There is no guarantee that that function is correct...

0
Entering edit mode

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)

0
Entering edit mode

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.

0
Entering edit mode

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

1
Entering edit mode
23 months ago

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.

1
Entering edit mode
18 months ago

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())