Beispiel #1
0
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 deriv_(self,order,wfn):
     qm_mod=self.create_child_from_option("QM_METHOD_KEY")
     mm_mod=self.create_child_from_option("MM_METHOD_KEY")
     mm_chg=self.create_child_from_option("MM_CHARGES_KEY")
     partition=self.create_child_from_option("SYSTEM_FRAGMENTER_KEY")
     qm_key=str(self.options().get("QM_REGION_KEY"))+' '
     mm_key=str(self.options().get("MM_REGION_KEY"))+' '
     systems=partition.fragmentize(wfn.system)
     qm_u = systems[qm_key].nmer.as_universe()
     mm_sys = psr.System(systems[mm_key].nmer)
     wfn.system=mm_sys
     mm_wfn,mm_egy = mm_mod.deriv(order,wfn)
     qs=mm_chg.calculate(0,wfn)
     for q,a in zip(qs,mm_sys):
         qm_u.insert(psr.make_point_charge(a,q))
     wfn.system=psr.System(qm_u,True)
     qm_wfn,qm_egy = qm_mod.deriv(order,wfn)
     wfn.system=psr.System(mm_wfn.system.as_universe()+qm_wfn.system.as_universe(),True)
     return wfn,[mm_egy[i]+qm_egy[i] for i in range(len(qm_egy))]
Beispiel #3
0
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()