This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to calculate the center of mass

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

How is this related to bioinformatics?

As posed, the question is not related to bioinformatics.

A simple Google search returns plenty of info, especially when the interest appears to be general.

Yes, the interest is general, but I don't think the knowledge is. I could be wrong.

Just out of interest: how is something involving "atomic coordinate of protein" not related to bioinformatics? This is only the case if you ignore the whole field of structural bioinformatics. Even if its golden era is over [or maybe it isn't, I have not worked in it for a while], it is still a valid and somewhat active field. Not everything is genomics/transcriptomics.

Had OP written "center of mass of atomic coordinate", i.e. without explicitly mentioning protein, it could be a cheminformatics question, but I'd still have given that the benefit of the doubt...

The original question has been edited.

Hm, ok. What I don't like, though, is it just says modified, which might be anything really. Maybe there should be a way to see the original pre-modified version or editing should not be possible or ... I mean, right now it looks as if someone posed a perfectly legit question only to be jumped on by a power user/mod. [It looks like this, not saying this is how it is.]

Edit: added missing "if" to "as if"

I think it is the set up for the Kabsch Algorithm or the orthogonal Procrustes problem. Is the centroid and the center of mass the same thing?

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

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.

2 answers

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

Log in to answer this question.