def run_test(): tester=psr.PyTester("Testing NMerInfo Python Bindings") MyU=psr.AtomSetUniverse() H,H1=psr.create_atom([0.0,0.0,0.0],1),psr.create_atom([0.0,0.0,0.89],1) MyU.insert(H) MyU.insert(H1) H2=psr.System(MyU,True) SN={1,2,3} NI1,NI3=psr.NMerInfo(),psr.NMerInfo() NI1.sn=SN NI1.nmer=H2 NI1.weight=2.0 tester.test_equal("Serial number set",NI1.sn,SN) tester.test_equal("System is set",NI1.nmer,H2) tester.test_double("Weight is set",NI1.weight,2.0) NI2=psr.NMerInfo(NI1) tester.test_equal("Serial number is copied",NI2.sn,SN) tester.test_equal("System is copied",NI2.nmer,H2) tester.test_double("Weight is copied",NI2.weight,2.0) tester.test_equal("Equality works",NI1,NI2) tester.test_not_equal("Inequlaity works",NI1,NI3) tester.print_results() return tester.nfailed()
def run(mm): tester=psr.PyTester("Testing the MBEHelper Analysis Module") ang2au=1/0.52917721067 carts=[[-2.0449536949999998,-1.6898322539999999,0.0354707364500000], [-2.3427132454308994,-2.1474611062791298,0.8216939386571565], [-1.1344686596866658,-1.9649570182333860,-0.0720244010028244], [2.4859145229999999,-0.9260656876000000,0.0354704040100000], [2.2689370278862486,-0.0000001286725659,-0.0720246525395077], [3.0311125996609807,-0.9551186438629339,0.8216935421441762], [-2.4859145329999999,0.9260657306000000,-0.0354704090300000], [-3.0311126049484312,0.9551186852913661,-0.8216935504901171], [-2.2689370387823162,0.0000001718485472,0.0720246508442851] ] for i in carts: for j in range(3):i[j]*=ang2au atoms=[ psr.create_atom(carts[0],8), psr.create_atom(carts[1],1), psr.create_atom(carts[2],1), psr.create_atom(carts[3],8), psr.create_atom(carts[4],1), psr.create_atom(carts[5],1), psr.create_atom(carts[6],8), psr.create_atom(carts[7],1), psr.create_atom(carts[8],1) ] asu=psr.AtomSetUniverse() for ai in atoms:asu.insert(ai) water3=psr.System(asu,True) mm.load_supermodule("pulsar_modules") mm.load_module("testmodules","Fake SCF","Fake SCF") mm.change_option("PSR_NMER_FRAG","TRUNCATION_ORDER",2) mm.change_option("PSR_MBE","METHOD_KEY","Fake SCF") my_mod=mm.get_module("PSR_MBE",0) wfn=psr.Wavefunction() wfn.system=water3 egy=mbe_wrapper(mm,wfn,2,my_mod,"PSR_NMER_FRAG",['Fake SCF']) corr_egys={1:-228.1242232726998,2:-228.1287815638595} for meth,test_egy in egy.items(): for order,egy_i in test_egy.items(): msg=meth+" "+str(order)+" -body energy" tester.test_double(msg,egy_i,corr_egys[order]) corr_ints={'1 ': [-76.04140775809373], '0 1 ': [-0.0014981983144224387], '0 2 ': [-0.002230289885289949], '0 ': [-76.0414077582649], '1 2 ': [-0.0008298029599842494], '2 ': [-76.04140775634117]} ints=mbe_interactions(mm,wfn,2,my_mod,"PSR_NMER_FRAG",['Fake SCF']) for meth,test_int in ints.items(): for inti,egyi in test_int.items(): msg=meth+" "+str(inti)+" "+str(len(inti.split()))+"-body interaction" tester.test_double(msg,egyi,corr_ints[inti]) return tester.nfailed()
def run(mm): tester=psr.PyTester("Testing the MBE") ang2au=1/0.52917721067 carts=[[-2.0449536949999998,-1.6898322539999999,0.0354707364500000], [-2.3427132454308994,-2.1474611062791298,0.8216939386571565], [-1.1344686596866658,-1.9649570182333860,-0.0720244010028244], [2.4859145229999999,-0.9260656876000000,0.0354704040100000], [2.2689370278862486,-0.0000001286725659,-0.0720246525395077], [3.0311125996609807,-0.9551186438629339,0.8216935421441762], [-2.4859145329999999,0.9260657306000000,-0.0354704090300000], [-3.0311126049484312,0.9551186852913661,-0.8216935504901171], [-2.2689370387823162,0.0000001718485472,0.0720246508442851] ] for i in carts: for j in range(3):i[j]*=ang2au atoms=[ psr.create_atom(carts[0],8), psr.create_atom(carts[1],1), psr.create_atom(carts[2],1), psr.create_atom(carts[3],8), psr.create_atom(carts[4],1), psr.create_atom(carts[5],1), psr.create_atom(carts[6],8), psr.create_atom(carts[7],1), psr.create_atom(carts[8],1) ] asu=psr.AtomSetUniverse() for ai in atoms:asu.insert(ai) water3=psr.System(asu,True) mm.load_supermodule("pulsar_modules") mm.load_module("testmodules","Fake SCF","Fake SCF") mm.change_option("PSR_NMER_FRAG","TRUNCATION_ORDER",2) mm.change_option("PSR_MBE","SYSTEM_FRAGMENTER_KEY","PSR_BOND_FRAG") mm.change_option("PSR_MBE","METHOD_KEY","Fake SCF") my_mod=mm.get_module("PSR_MBE",0) wfn=psr.Wavefunction() wfn.system=water3 NewWfn,egy=my_mod.deriv(0,wfn) tester.test_double("One-Body energy",egy[0],-228.1242232726998) my_mod.options().change("SYSTEM_FRAGMENTER_KEY","PSR_NMER_FRAG") NewWfn,egy=my_mod.deriv(0,wfn) tester.test_double("Two-Body energy",egy[0],-228.12878156385943) return tester.nfailed()
def run_test(): tester = psr.PyTester("Testing the Atom class") H, H2 = psr.create_atom([0.0, 0.0, 0.0], 1), psr.create_atom([0.0, 0.0, 0.0], 1, 1) tester.test_return("create_atom works", True, True, H.__eq__, H2) tester.test_equal("correct Z", 1, H.Z) tester.test_equal("correct isotope", 1, H.isotope) tester.test_equal("correct mass", 1.007975, H.mass) tester.test_equal("correct isotope mass", 1.0078250322, H.isotope_mass) tester.test_equal("correct charge", 0, H.charge) tester.test_equal("correct multiplicity", 2, H.multiplicity) tester.test_equal("correct nelectrons", 1, H.nelectrons) tester.test_equal("correct covalent radius", 0.5858150988919267, H.cov_radius) tester.test_equal("correct vDW radius", 2.267671350549394, H.vdw_radius) H3 = psr.Atom(H2) tester.test_return("copy constructor works", True, True, H.__eq__, H3) D = psr.create_atom([0.0, 0.0, 0.0], 1, 2) tester.test_equal("Isotopes work", 2, D.isotope) tester.test_return("Isotopes are different", True, True, D.__ne__, H) tester.test_return("hash works", True, H.my_hash(), H2.my_hash) tester.test_return("hash works 1", True, H.my_hash(), H3.my_hash) GH = psr.make_ghost_atom(H2) tester.test_return("ghost works", True, True, psr.is_ghost_atom, GH) q = psr.make_point_charge(H2, 3.3) q2 = psr.make_point_charge(H2.get_coords(), 3.3) tester.test_return("point charges work", True, True, psr.is_point_charge, q) tester.test_return("point charges work 2", True, True, psr.is_point_charge, q2) tester.test_return("is same point charge", True, True, q.__eq__, q2) Dm = psr.make_dummy_atom(H) Dm2 = psr.make_dummy_atom(H.get_coords()) tester.test_return("is dummy atom", True, True, psr.is_dummy_atom, Dm) tester.test_return("is dummy atom 2", True, True, psr.is_dummy_atom, Dm2) tester.test_return("is same dummy atom", True, True, Dm.__eq__, Dm2) tester.print_results() return tester.nfailed()
def make_system(SomeString): """This function turns a string into a system object, which it then returns Special thanks to Lori A. Burns for the original version of this function ================================= Rules For Structuring Your String ================================= * An entire line may be commented out by prepending a '#' character * To specify the units of your system: * Add the line: 'units X' or 'units=X' * 'X' may be: * 'bohr', 'au', or 'a.u.' for atomic units * 'ang'or angstrom for Angstroms * Unit cells of crystals may be used as input. This is done by providing the fractional coordinates of your atoms and the cell's dimensions * sides are specified by 'sides a b c' * Units can be specified by units keyword * angles are specified by 'angles alpha beta gamma' * Units are in degrees """ #For the below comments, "any number" includes 0 comment = re.compile(r'^\s*#')#Comment line blank = re.compile(r'^\s*$')#Blank aside from white-space bohr = re.compile(r'^\s*units?[\s=]+(bohr|au|a.u.)\s*$', re.IGNORECASE)#a.u. ang = re.compile(r'^\s*units?[\s=]+(ang|angstrom)\s*$', re.IGNORECASE)#Ang #Ghosts and atoms? atom = re.compile(r'^(?:(?P<gh1>@)|(?P<gh2>Gh\())?(?P<label>(?P<symbol>[A-Z]{1,3})(?:(_\w+)|(\d+))?)(?(gh2)\))(?:@(?P<mass>\d+\.\d+))?$', re.IGNORECASE) cgmp = re.compile(r'^\s*(-?\d+)\s+(\d+)\s*$')#Charge/Mult frag = re.compile(r'^\s*--\s*$')#Fragment sperator #Matches something equals a number variable = re.compile(r'^\s*(\w+)\s*=\s*(-?\d+\.\d+|-?\d+\.|-?\.\d+|-?\d+|tda)\s*$', re.IGNORECASE) ghost = re.compile(r'@(.*)|Gh\((.*)\)', re.IGNORECASE)#Matches ghosts #Mathches a line that starts with 'sides' and has three numbers UCsides = re.compile(r'^\s*sides\s*(\d+|\d+\.\d+)\s*(\d+|\d+\.\d+)\s*(\d+|\d+\.\d+)\s*$',re.IGNORECASE) #Mathches a line that starts with 'angles' and has three numbers UCangles = re.compile(r'^\s*angles\s*(\d+|\d+\.\d+)\s*(\d+|\d+\.\d+)\s*(\d+|\d+\.\d+)\s*$',re.IGNORECASE) Systems=[0] #Atoms per fragment Zs=[] #Atomic number of each atom ToAU=1/0.52917721067 Charge=[0] #Charges, 0-th element is full system, i-th (i>0) is i-th frag Mult=[1] #Multiplicities, same as charges Sides=[] Angles=[] Carts=[] def NFrags(): return len(Systems)-1 lines = re.split('\n', SomeString) for line in lines: if comment.match(line) or blank.match(line) or ang.match(line): continue elif bohr.match(line): ToAU=1.0 elif cgmp.match(line): Charge[NFrags()] = int(cgmp.match(line).group(1)) Mult[NFrags()] = int(cgmp.match(line).group(2)) # handle fragment markers and default fragment cgmp elif frag.match(line): Systems.append(0) Charge.append(0) Mult.append(1) DaAtoms[len(DaAtoms)]=[] elif UCsides.match(line): for i in range(1,4): Sides.append(float(UCsides.match(line).group(i))) elif UCangles.match(line): for i in range(1,4): Angles.append(float(UCangles.match(line).group(i))) # handle atoms elif atom.match(line.split()[0].strip()): entries = re.split(r'\s+|\s*,\s*', line.strip()) atomm = atom.match(line.split()[0].strip().upper()) atomLabel = atomm.group('label') atomSym = atomm.group('symbol') # We don't know whether the @C or Gh(C) notation matched. Do a quick check. ghostAtom = False if (atomm.group('gh1') is None and atomm.group('gh2') is None) else True # handle cartesians if len(entries) == 4: for i in range(1,4): Carts.append(float(entries[i])) Zs.append(psr.atomic_z_from_symbol(atomSym)) Systems[NFrags()]+=1 else: raise PulsarException('make_system: Unidentifiable line in geometry specification: %s' % (line)) DaSpace=psr.Space() Periodic=(len(Sides)==3 and len(Angles)==3) NewSides=[ToAU*i for i in Sides] if Periodic: DaSpace=psr.Space(Angles,NewSides) ToAU=1.0 molu=psr.AtomSetUniverse() for i in range(0,len(Zs)): TempCarts=[ToAU*Carts[3*i+j] for j in range(0,3)] molu.insert(psr.create_atom(TempCarts,Zs[i])) DaSys=psr.System(molu,True) if Periodic: Newu=psr.system.Frac2Cart(molu,DaSpace) UC=psr.CarveUC( psr.MakeSuperCell(Newu,[3,3,3],DaSpace.LatticeSides), DaSpace.LatticeSides) molu=psr.CleanUC(UC,DaSpace.LatticeSides) DaSys=psr.System(molu,True) DaSys.space=DaSpace DaSys.charge=Charge[0] DaSys.multiplicity=Mult[0] return DaSys
def run_test(): tester=psr.PyTester("Testing the System class") MyU, MyU2=psr.AtomSetUniverse(), psr.AtomSetUniverse() H, H1 = psr.create_atom([0.0,0.0,0.0],1), psr.create_atom([0.0,0.0,0.89],1) MyU.insert(H) MyU.insert(H1) #Constructors and assignment Empty=psr.System(MyU,False) H2=psr.System(MyU,True) tester.test_return("System is empty",True,0,Empty.size) tester.test_return("System is full",True,2,H2.size) Empty2=psr.System(MyU,False) tester.test_return("Different universes!=different systems",True,True,Empty.__eq__,Empty2) H22=psr.System(H2) tester.test_return("Copy constructor works",True,True,H2.__eq__,H22) H99=psr.System(H22,True) tester.test_return("Copy and fill works",True,True,H99.__eq__,H22) #At this point H2==H22={H,H1} #Properties q=psr.make_point_charge([0.0,0.0,-0.89],-1.0) MyU.insert(q) ChargedH2=psr.System(MyU,True) tester.test_return("size works",True,2,H2.size) tester.test_return("sum of mass works",True,2.01595,H22.get_sum_mass) tester.test_equal("mass is set correct",2.01595,H22.mass) tester.test_return("sum of charge works (non-charged)",True,0,H2.get_sum_charge) tester.test_equal("charge is set correctly (non-charged)",0,H2.charge) tester.test_return("sum charges works (charged)",True,-1.0,ChargedH2.get_sum_charge) tester.test_equal("charge is set correctly (charged)",-1.0,ChargedH2.charge) tester.test_equal("multiplicity is correct",1,H2.multiplicity) tester.test_return("sum of n electrons is correct",True,2,H22.get_sum_n_electrons) tester.test_equal("n electrons is set correctly",2,H22.nelectrons) tester.test_equal("spaces are the same",psr.Space(),H22.space) tester.test_return("count works",True,True,H22.count,H1) tester.test_return("compare info works",True,True,H22.compare_info,H2) #Access and filling HAtoms=[i for i in H22] corr_atoms=[H,H1] tester.test_equal("Iterators work",HAtoms,corr_atoms) H26, H27 =psr.System(MyU,False), psr.System(MyU,False) H26.insert(H) H26.insert(H1) H27.insert(q) tester.test_equal("Single element inserts work",H26,H22) H28=psr.System(ChargedH2) #At this point H2=H22={H,H1} | H28==ChargedH2={H,H1,q} H26={H,H1} H27={q} #Set operations tester.test_return("intersection works",True,H2,ChargedH2.intersection,H26) tester.test_return("intersection assignment",True,H2,ChargedH2.intersection_assign,H26) tester.test_return("union works",True,H28,ChargedH2.set_union,H27) tester.test_return("union assignment works",True,H28,ChargedH2.union_assign,H27) tester.test_return("difference works",True,H26,ChargedH2.difference,H27) tester.test_return("difference assign works",True,H26,ChargedH2.difference_assign,H27) tester.test_return("complement works",True,H26,H27.complement) #At this point H2=H22={H,H1}| ChargedH2==H26={H,H1} H27={q} H28={H,H1,q} tester.test_return("subset equal",True,True,H2.is_subset_of,H22) tester.test_return("subset true",True,True,H27.is_subset_of,H28) tester.test_return("subset false",True,False,H28.is_subset_of,H27) tester.test_return("superset equal",True,True,H2.is_superset_of,H22) tester.test_return("superset true",True,True,H28.is_superset_of,H27) tester.test_return("superset false",True,False,H27.is_superset_of,H28) tester.test_return("proper subset equal",True,False,H2.is_proper_subset_of,H22) tester.test_return("proper subset true",True,True,H27.is_proper_subset_of,H28) tester.test_return("proper subset false",True,False,H28.is_proper_subset_of,H27) tester.test_return("proper superset equal",True,False,H2.is_proper_superset_of,H22) tester.test_return("proper superset true",True,True,H28.is_proper_superset_of,H27) tester.test_return("proper superset false",True,False,H27.is_proper_superset_of,H28) tester.test_return("inequality works",True,True,H26.__ne__,H28) def part_fxn(atomi): return psr.is_point_charge(atomi) tester.test_return("partition",True,H27,H28.partition,part_fxn) MyU3=psr.AtomSetUniverse([psr.create_atom([1.0,0.0,0.0],1), psr.create_atom([1.0,0.0,0.89],1)]) def translate_by_1(atomi): temp=psr.Atom(atomi) temp[0]=1.0 return temp tester.test_return("transform",True,psr.System(MyU3,True),H22.transform,translate_by_1) tester.test_return("get universe works",True,MyU,H27.get_universe) tester.test_return("as universe works",True,MyU,H28.as_universe) #Despite the manipulations and different universes, the following sets are equal tester.test_return("Hash is correct 1",True,H2.my_hash(),H22.my_hash) tester.test_return("Hash is correct 2",True,H2.my_hash(),ChargedH2.my_hash) tester.test_return("Hash is correct 3",True,H2.my_hash(),H26.my_hash) H28.clear() tester.test_return("Clear works",True,0,H28.size) tester.print_results() return tester.nfailed()
ang2au=1/0.52917721067 carts=[[-2.0449536949999998,-1.6898322539999999,0.0354707364500000], [-2.3427132454308994,-2.1474611062791298,0.8216939386571565], [-1.1344686596866658,-1.9649570182333860,-0.0720244010028244], [2.4859145229999999,-0.9260656876000000,0.0354704040100000], [2.2689370278862486,-0.0000001286725659,-0.0720246525395077], [3.0311125996609807,-0.9551186438629339,0.8216935421441762], [-2.4859145329999999,0.9260657306000000,-0.0354704090300000], [-3.0311126049484312,0.9551186852913661,-0.8216935504901171], [-2.2689370387823162,0.0000001718485472,0.0720246508442851] ] for i in carts: for j in range(3):i[j]*=ang2au atoms=[ psr.create_atom(carts[0],8), psr.create_atom(carts[1],1), psr.create_atom(carts[2],1), psr.create_atom(carts[3],8), psr.create_atom(carts[4],1), psr.create_atom(carts[5],1), psr.create_atom(carts[6],8), psr.create_atom(carts[7],1), psr.create_atom(carts[8],1) ] asu=psr.AtomSetUniverse() for ai in atoms:asu.insert(ai) water3=psr.System(asu,True) waters=[psr.System(water3,False) for i in range(6)] for i in range(3):
def run_test(): tester=psr.PyTester("Testing Make System Python Function") carts=[ -2.0449536949999998, -1.6898322539999999, 0.0354707364500000, -2.3427132454308994, -2.1474611062791298, 0.8216939386571565, -1.1344686596866658, -1.9649570182333860, -0.0720244010028244, 2.4859145229999999, -0.9260656876000000, 0.0354704040100000, 2.2689370278862486, -0.0000001286725659, -0.0720246525395077, 3.0311125996609807, -0.9551186438629339, 0.8216935421441762 ] ToAu=1/0.52917721067 all_atoms=[ psr.create_atom([carts[i]*ToAu for i in range(0,3)],8), psr.create_atom([carts[i]*ToAu for i in range(3,6)],1), psr.create_atom([carts[i]*ToAu for i in range(6,9)],1), psr.create_atom([carts[i]*ToAu for i in range(9,12)],8), psr.create_atom([carts[i]*ToAu for i in range(12,15)],1), psr.create_atom([carts[i]*ToAu for i in range(15,18)],1) ] unv=psr.AtomSetUniverse(all_atoms) for i in all_atoms: unv.insert(psr.make_ghost_atom(i)) corr_mol1=psr.System(unv,False) corr_mol2=psr.System(corr_mol1) for i in all_atoms: corr_mol2.insert(i) corr_mol3=psr.System(corr_mol1) for i in all_atoms[0:3]: corr_mol3.insert(psr.make_ghost_atom(i)) for i in all_atoms[3:6]: corr_mol3.insert(i) mol1=""" #0 1 #O -2.0449536949999998 -1.6898322539999999 0.0354707364500000 #H -2.3427132454308994 -2.1474611062791298 0.8216939386571565 #H -1.1344686596866658 -1.9649570182333860 -0.0720244010028244 #O 2.4859145229999999 -0.9260656876000000 0.0354704040100000 #H 2.2689370278862486 -0.0000001286725659 -0.0720246525395077 #H 3.0311125996609807 -0.9551186438629339 0.8216935421441762 """ tester.test_return("Comments work",True,corr_mol1,psr.make_system,mol1) mol2=""" 0 1 O -2.0449536949999998 -1.6898322539999999 0.0354707364500000 H -2.3427132454308994 -2.1474611062791298 0.8216939386571565 H -1.1344686596866658 -1.9649570182333860 -0.0720244010028244 O 2.4859145229999999 -0.9260656876000000 0.0354704040100000 H 2.2689370278862486 -0.0000001286725659 -0.0720246525395077 H 3.0311125996609807 -0.9551186438629339 0.8216935421441762 """ tester.test_return("Normal molecule works",True,corr_mol2,psr.make_system,mol2) mol3=""" 0 1 @O -2.0449536949999998 -1.6898322539999999 0.0354707364500000 @H -2.3427132454308994 -2.1474611062791298 0.8216939386571565 @H -1.1344686596866658 -1.9649570182333860 -0.0720244010028244 O 2.4859145229999999 -0.9260656876000000 0.0354704040100000 H 2.2689370278862486 -0.0000001286725659 -0.0720246525395077 H 3.0311125996609807 -0.9551186438629339 0.8216935421441762 """ #tester.test_return("@ for ghost works",True,corr_mol3,psr.make_system,mol3) mol4=""" 0 1 Gh(O) -2.0449536949999998 -1.6898322539999999 0.0354707364500000 Gh(H) -2.3427132454308994 -2.1474611062791298 0.8216939386571565 Gh(H) -1.1344686596866658 -1.9649570182333860 -0.0720244010028244 O 2.4859145229999999 -0.9260656876000000 0.0354704040100000 H 2.2689370278862486 -0.0000001286725659 -0.0720246525395077 H 3.0311125996609807 -0.9551186438629339 0.8216935421441762 """ #tester.test_return("Gh(X) for ghosts works",True,corr_mol3,psr.make_system,mol4) tester.print_results() return tester.nfailed()