frag_pele/Helpers/center_of_mass.py
def center_of_mass(pdbfile, include='ATOM,HETATM'):
  """
  Calculates center of mass of a protein and/or ligand structure.
  Returns:
      center (list): List of float coordinates [x,y,z] that represent the
      center of mass (precision 3).
  """

  center = [None, None, None]
  include = tuple(include.split(','))

  with open(pdbfile, 'r') as pdb:

    # extract coordinates [ [x1,y1,z1], [x2,y2,z2], ... ]
    coordinates = []
    masses = []
    for line in pdb:
      if line.startswith(include):
        coordinates.append([float(line[30:38]),    # x_coord
                            float(line[38:46]),    # y_coord
                            float(line[46:54])     # z_coord
                            ])
        element_name = line[76:].strip()
        if element_name not in ATOMIC_WEIGHTS:
          element_name = line.split()[2].strip()[0]
        masses.append(ATOMIC_WEIGHTS[element_name])

    assert len(coordinates) == len(masses)

    # calculate relative weight of every atomic mass
    total_mass = sum(masses)
    weights = [float(atom_mass / total_mass) for atom_mass in masses]

    # calculate center of mass
    center = [sum([coordinates[i][j] * weights[i]
                   for i in range(len(weights))]) for j in range(3)]
    center_rounded = [round(center[i], 3) for i in range(3)]
    return center_rounded

  Calculates center of mass of a protein and/or ligand structure.
  Returns:
      center (list): List of float coordinates [x,y,z] that represent the
      center of mass (precision 3).
  
Calculates center of mass of a protein and/or ligand structure.
Calculates center of mass of a protein and / or ligand structure .
def center_of_mass(pdbfile, include='ATOM,HETATM'):
  center = [None, None, None]
  include = tuple(include.split(','))
  with open(pdbfile, 'r') as pdb:
    coordinates = []
    masses = []
    for line in pdb:
      if line.startswith(include):
        coordinates.append([float(line[30:38]),    
                            float(line[38:46]),    
                            float(line[46:54])     
                            ])
        element_name = line[76:].strip()
        if element_name not in ATOMIC_WEIGHTS:
          element_name = line.split()[2].strip()[0]
        masses.append(ATOMIC_WEIGHTS[element_name])
    assert len(coordinates) == len(masses)
    total_mass = sum(masses)
    weights = [float(atom_mass / total_mass) for atom_mass in masses]
    center = [sum([coordinates[i][j] * weights[i]
                   for i in range(len(weights))]) for j in range(3)]
    center_rounded = [round(center[i], 3) for i in range(3)]
    return center_rounded
def center_of_mass ( pdbfile , include = 'ATOM,HETATM' ) : center = [ None , None , None ] include = tuple ( include . split ( ',' ) ) with open ( pdbfile , 'r' ) as pdb : coordinates = [ ] masses = [ ] for line in pdb : if line . startswith ( include ) : coordinates . append ( [ float ( line [ 30 : 38 ] ) , float ( line [ 38 : 46 ] ) , float ( line [ 46 : 54 ] ) ] ) element_name = line [ 76 : ] . strip ( ) if element_name not in ATOMIC_WEIGHTS : element_name = line . split ( ) [ 2 ] . strip ( ) [ 0 ] masses . append ( ATOMIC_WEIGHTS [ element_name ] ) assert len ( coordinates ) == len ( masses ) total_mass = sum ( masses ) weights = [ float ( atom_mass / total_mass ) for atom_mass in masses ] center = [ sum ( [ coordinates [ i ] [ j ] * weights [ i ] for i in range ( len ( weights ) ) ] ) for j in range ( 3 ) ] center_rounded = [ round ( center [ i ] , 3 ) for i in range ( 3 ) ] return center_rounded
Calculates center of mass of a protein and/or ligand structure.
Calculates center of mass of a protein and / or ligand structure .
"""
  Calculates center of mass of a protein and/or ligand structure.
  Returns:
      center (list): List of float coordinates [x,y,z] that represent the
      center of mass (precision 3).
  """ # extract coordinates [ [x1,y1,z1], [x2,y2,z2], ... ] # x_coord # y_coord # z_coord # calculate relative weight of every atomic mass # calculate center of mass
center (list): List of float coordinates [x,y,z] that represent the
center of mass (precision 3).
center ( list ) : List of float coordinates [ x y z ] that represent the center of mass ( precision 3 ) .
pdbfile
include