def format_coords(geo): """ format the coords section """ # Get the number of atoms natoms = len(geo) # Get the geometry information symbols = geom.symbols(geo) coordinates = geom.coordinates(geo) masses = geom.masses(geo) print(masses) # Build a string with the formatted coordinates string if geom.is_atom(geo): geo_str = '{0:<4s}{1:<6d}'.format(symbols[0], masses[0]) else: geo_str = '{0} \n'.format(str(natoms)) for symbol, mass, coords in zip(symbols, masses, coordinates): coords = [coord * phycon.BOHR2ANG for coord in coords] coords_str = '{0:>14.8f}{1:>14.8f}{2:>14.8f}'.format( coords[0], coords[1], coords[2]) geo_str += '{0:<4s}{1:<6.0f}{2}\n'.format(symbol, mass, coords_str) # Remove final newline character from the string geo_str = geo_str.rstrip() return natoms, geo_str
def format_coords(geo): """ format the coords section """ # Get the number of atoms natoms = len(geo) # Get the geometry information symbs = geom.symbols(geo) coords = geom.coordinates(geo) masses = tuple(round(mass) for mass in geom.masses(geo)) # Build a string with the formatted coordinates string if geom.is_atom(geo): geo_str = f'{symbs[0]:<4s}{masses[0]:<6d}' else: geo_str = f'{str(natoms)} \n' for symb, mass, xyzs in zip(symbs, masses, coords): _xyzs = [x * phycon.BOHR2ANG for x in xyzs] xyzs_str = f'{_xyzs[0]:>14.8f}{_xyzs[1]:>14.8f}{_xyzs[2]:>14.8f}' geo_str += f'{symb:<4s}{mass:<6.0f}{xyzs_str}\n' # Remove final newline character from the string geo_str = geo_str.rstrip() return natoms, geo_str
def test__mass(): """ test geom.masses test geom.center_of_mass() test geom.mass_centered() """ ref_masses = (1.00782503223, 15.99491461957, 1.00782503223) assert numpy.allclose(geom.masses(H2O_GEO, amu=True), ref_masses) ref_masses2 = (1837.1526464817923, 29156.94568388855, 1837.1526464817923) assert numpy.allclose(geom.masses(H2O_GEO, amu=False), ref_masses2) ref_red_mass = 0.9544182343494726 assert numpy.isclose(geom.reduced_mass(H2O_GEO, H_GEO), ref_red_mass) # make sure the COM for an uncentered geometry is non-zero cm_xyz = automol.geom.center_of_mass(C2H2CLF_GEO) assert not numpy.allclose(cm_xyz, 0.) # now make sure centering it yields a COM at the origin geo = automol.geom.mass_centered(C2H2CLF_GEO) cm_xyz = automol.geom.center_of_mass(geo) assert numpy.allclose(cm_xyz, 0.)