Package pipe_control :: Package structure :: Module mass
[hide private]
[frames] | no frames]

Source Code for Module pipe_control.structure.mass

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2003-2014 Edward d'Auvergne                                   # 
  4  #                                                                             # 
  5  # This file is part of the program relax (http://www.nmr-relax.com).          # 
  6  #                                                                             # 
  7  # This program is free software: you can redistribute it and/or modify        # 
  8  # it under the terms of the GNU General Public License as published by        # 
  9  # the Free Software Foundation, either version 3 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # This program is distributed in the hope that it will be useful,             # 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 15  # GNU General Public License for more details.                                # 
 16  #                                                                             # 
 17  # You should have received a copy of the GNU General Public License           # 
 18  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
 19  #                                                                             # 
 20  ############################################################################### 
 21   
 22  # Python module imports. 
 23  from warnings import warn 
 24   
 25  # relax module imports. 
 26  from lib.errors import RelaxNoPdbError 
 27  from lib.structure.mass import centre_of_mass 
 28  from lib.warnings import RelaxWarning 
 29  from pipe_control.mol_res_spin import return_molecule, return_residue, return_spin 
 30   
 31   
 32   
33 -def pipe_centre_of_mass(atom_id=None, model=None, return_mass=False, verbosity=1):
34 """Calculate and return the centre of mass of the structures in the current data pipe. 35 36 @keyword atom_id: The molecule, residue, and atom identifier string. Only atoms matching this selection will be used. 37 @type atom_id: str or None 38 @keyword model: Only use a specific model. 39 @type model: int or None 40 @keyword return_mass: A flag which if False will cause only the centre of mass to be returned, but if True will cause the centre of mass and the mass itself to be returned as a tuple. 41 @type return_mass: bool 42 @keyword verbosity: The amount of text to print out. 0 results in no printouts, 1 the full amount. 43 @type verbosity: int 44 @return: The centre of mass vector, and additionally the mass. 45 @rtype: list of 3 floats (or tuple of a list of 3 floats and one float) 46 """ 47 48 # Test if a structure has been loaded. 49 if not hasattr(cdp, 'structure'): 50 raise RelaxNoPdbError 51 52 # Loop over all atoms. 53 coord = [] 54 element_list = [] 55 for mol_name, res_num, res_name, atom_num, atom_name, element, pos in cdp.structure.atom_loop(atom_id=atom_id, model_num=model, mol_name_flag=True, res_num_flag=True, res_name_flag=True, atom_num_flag=True, atom_name_flag=True, element_flag=True, pos_flag=True, ave=True): 56 # Initialise the spin id string. 57 id = '' 58 59 # Get the corresponding molecule container. 60 if mol_name == None: 61 mol_cont = cdp.mol[0] 62 else: 63 id = id + '#' + mol_name 64 mol_cont = return_molecule(id) 65 66 # Get the corresponding residue container. 67 if res_name == None and res_num == None: 68 res_cont = mol_cont.res[0] 69 else: 70 id = id + ':' + repr(res_num) 71 res_cont = return_residue(id) 72 73 # Get the corresponding spin container. 74 if atom_name == None and atom_num == None: 75 spin_cont = res_cont.spin[0] 76 else: 77 id = id + '@' + repr(atom_num) 78 spin_cont = return_spin(id) 79 80 # Deselected spins. 81 if spin_cont and not spin_cont.select: 82 continue 83 84 # No element? 85 if element == None: 86 warn(RelaxWarning("Skipping the atom '%s' as the element type cannot be determined." % id)) 87 continue 88 89 # Store the position and element. 90 coord.append(pos) 91 element_list.append(element) 92 93 # Calculate the CoM. 94 com, mass = centre_of_mass(pos=coord, elements=element_list, verbosity=verbosity) 95 96 # Return the centre of mass. 97 if return_mass: 98 return com, mass 99 else: 100 return com
101