def center_of_mass(atomlist): total_mass=0.0 rcm=['CM', 0.0, 0.0, 0.0] for atom in atomlist: total_mass += atomic_data.mass(atom[0]) rcm[1] += atomic_data.mass(atom[0])*atom[1] rcm[2] += atomic_data.mass(atom[0])*atom[2] rcm[3] += atomic_data.mass(atom[0])*atom[3] for i in range(1,4): rcm[i] = rcm[i]/total_mass if rcm[i]<1e-10: rcm[i]=0.0 return rcm
def get_gaussian_results(filename): """Reads information from Gaussian formatted checkpoint files.""" input = open(filename,'r') s=input.readline() while s: if s.find('Number of atoms')!=-1: natoms=int(s.split()[4]) N=3*natoms if s.find('Atomic numbers')!=-1: atom_l=[] mass_l=[] nrows=int( (natoms+5)/6 ) for irow in range(nrows): for Z in input.readline().split(): atom_l.append(label(int(Z))) mass_l.append(mass(label(int(Z)))) if s.find('Current cartesian coordinates')!=-1: cart_l=[] nrows=int( (N+4)/5 ) for irow in range(nrows): cart_l+=map(float,input.readline().split()) cart_l=array(cart_l) if s.find('Cartesian Force Constants')!=-1: h=zeros((N,N)) r=0; c=0 nrows=int( (N*(N+1)/2+4)/5 ) for irow in range(nrows): hessian_elements=input.readline().split() for j in hessian_elements: if c<r: h[r,c]=float(j) h[c,r]=h[r,c] c+=1 elif c==r: h[r,r]=float(j) c=0;r+=1 s=input.readline() return h, atom_l, mass_l, cart_l