Trees | Indices | Help |
|
---|
|
1 ############################################################################### 2 # # 3 # Copyright (C) 2003-2013 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 numpy import float64, zeros 24 from warnings import warn 25 26 # relax module imports. 27 from lib.physical_constants import return_atomic_mass 28 from lib.errors import RelaxError 29 from lib.warnings import RelaxWarning 30 31 3234 """Calculate and return the centre of mass for the given atomic coordinates. 35 36 @keyword pos: The list of atomic coordinates. 37 @type pos: list of lists of float 38 @keyword elements: The list of elements corresponding to the atoms. 39 @type elements: list of str 40 @keyword verbosity: The amount of text to print out. 0 results in no printouts, 1 the full amount. 41 @type verbosity: int 42 @return: The centre of mass vector and the mass. 43 @rtype: 3D list of floats, float 44 """ 45 46 # Print out. 47 if verbosity: 48 print("Calculating the centre of mass.") 49 50 # Initialise the centre of mass. 51 R = zeros(3, float64) 52 53 # Initialise the total mass. 54 M = 0.0 55 56 # Loop over all atoms. 57 for i in range(len(pos)): 58 # Atomic mass. 59 try: 60 mass = return_atomic_mass(elements[i]) 61 except RelaxError: 62 warn(RelaxWarning("Skipping the atom index %s as the element '%s' is unknown." % (i, elements[i]))) 63 64 # Total mass. 65 M = M + mass 66 67 # Sum of mass * position. 68 R = R + mass * pos[i] 69 70 # Normalise. 71 R = R / M 72 73 # Final printout. 74 if verbosity: 75 print(" Total mass: M = " + repr(M)) 76 print(" Centre of mass: R = " + repr(R)) 77 78 # Return the centre of mass and total mass 79 return R, M80
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Thu Jul 3 13:38:55 2014 | http://epydoc.sourceforge.net |