def test_get_atomic_mass(self): """Test of the periodic_table.atomic_mass() method.""" # Check the proton weight. weight = periodic_table.atomic_mass(id='H') self.assertEqual(weight, 1.007975) # Check the 1H weight. weight = periodic_table.atomic_mass(id='1H') self.assertEqual(weight, 1.0078250322) # Check the 2H weight. weight = periodic_table.atomic_mass(id='2H') self.assertEqual(weight, 2.0141017781)
def test_get_atomic_mass(self): """Test of the periodic_table.atomic_mass() method.""" # Check the proton weight. weight = periodic_table.atomic_mass(id="H") self.assertEqual(weight, 1.007975) # Check the 1H weight. weight = periodic_table.atomic_mass(id="1H") self.assertEqual(weight, 1.0078250322) # Check the 2H weight. weight = periodic_table.atomic_mass(id="2H") self.assertEqual(weight, 2.0141017781)
def centre_of_mass(pos=None, elements=None, verbosity=1): """Calculate and return the centre of mass for the given atomic coordinates. @keyword pos: The list of atomic coordinates. @type pos: list of lists of float @keyword elements: The list of elements corresponding to the atoms. @type elements: list of str @keyword verbosity: The amount of text to print out. 0 results in no printouts, 1 the full amount. @type verbosity: int @return: The centre of mass vector and the mass. @rtype: 3D list of floats, float """ # Print out. if verbosity: print("Calculating the centre of mass.") # Initialise the centre of mass. R = zeros(3, float64) # Initialise the total mass. M = 0.0 # Loop over all atoms. for i in range(len(pos)): # Atomic mass. try: mass = periodic_table.atomic_mass(elements[i]) except RelaxError: warn( RelaxWarning( "Skipping the atom index %s as the element '%s' is unknown." % (i, elements[i]))) # Total mass. M = M + mass # Sum of mass * position. R = R + mass * pos[i] # Normalise. R = R / M # Final printout. if verbosity: print(" Total mass: M = " + repr(M)) print(" Centre of mass: R = " + repr(R)) # Return the centre of mass and total mass return R, M
def centre_of_mass(pos=None, elements=None, verbosity=1): """Calculate and return the centre of mass for the given atomic coordinates. @keyword pos: The list of atomic coordinates. @type pos: list of lists of float @keyword elements: The list of elements corresponding to the atoms. @type elements: list of str @keyword verbosity: The amount of text to print out. 0 results in no printouts, 1 the full amount. @type verbosity: int @return: The centre of mass vector and the mass. @rtype: 3D list of floats, float """ # Print out. if verbosity: print("Calculating the centre of mass.") # Initialise the centre of mass. R = zeros(3, float64) # Initialise the total mass. M = 0.0 # Loop over all atoms. for i in range(len(pos)): # Atomic mass. try: mass = periodic_table.atomic_mass(elements[i]) except RelaxError: warn(RelaxWarning("Skipping the atom index %s as the element '%s' is unknown." % (i, elements[i]))) # Total mass. M = M + mass # Sum of mass * position. R = R + mass * pos[i] # Normalise. R = R / M # Final printout. if verbosity: print(" Total mass: M = " + repr(M)) print(" Centre of mass: R = " + repr(R)) # Return the centre of mass and total mass return R, M