def test_gpos_vtens_dihed_cos_chebychev6_peroxide(): #Test for positive sign in polynomial system = get_system_peroxide() part = ForcePartValence(system) part.add_term(Chebychev6(1.5, DihedCos(0,1,2,3), sign=1)) check_gpos_part(system, part) check_vtens_part(system, part) #Test for negative sign in polynomial system = get_system_peroxide() part = ForcePartValence(system) part.add_term(Chebychev6(1.5, DihedCos(0,1,2,3), sign=-1)) check_gpos_part(system, part) check_vtens_part(system, part)
def test_vlist_peroxide_dihed_cos_chebychev6(): number_of_tests=50 for i in range(number_of_tests): system = get_system_peroxide() dlist = DeltaList(system) iclist = InternalCoordinateList(dlist) vlist = ValenceList(iclist) bonds=[] while len(bonds)<3: i0, i1 = [int(x) for x in np.random.uniform(low=0,high=4,size=2)] #pick 2 random atoms if i0==i1 or (i0,i1) in bonds or (i1,i0) in bonds: continue if (i0,i1) in system.bonds or (i1,i0) in system.bonds: iclist.add_ic(Bond(i0,i1)) bonds.append((i0,i1)) amp = np.random.normal(0, 1) sign = np.random.randint(2) if sign==0: sign = -1 vlist.add_term(Chebychev6(amp, DihedCos(0,1,2,3), sign=sign)) dlist.forward() iclist.forward() energy = vlist.forward() # calculate energy manually psi = dihed_angle(system.pos)[0] check_energy = 0.5*amp*(1.0+sign*np.cos(6*psi)) assert abs(energy - check_energy) < 1e-8
def test_vlist_peroxide_dihed_angle_cosine(): number_of_tests=50 for i in range(number_of_tests): system = get_system_peroxide() dlist = DeltaList(system) iclist = InternalCoordinateList(dlist) vlist = ValenceList(iclist) bonds=[] while len(bonds)<3: i0, i1 = [int(x) for x in np.random.uniform(low=0,high=4,size=2)] #pick 2 random atoms if i0==i1 or (i0,i1) in bonds or (i1,i0) in bonds: continue if (i0,i1) in system.bonds or (i1,i0) in system.bonds: iclist.add_ic(Bond(i0,i1)) bonds.append((i0,i1)) mult = np.random.randint(1, 4) amp = np.random.normal(0, 1) phi0 = np.random.uniform(0, 2*np.pi) vlist.add_term(Cosine(mult, amp, phi0, DihedAngle(0,1,2,3))) dlist.forward() iclist.forward() energy = vlist.forward() # calculate energy manually angle = dihed_angle(system.pos)[0] check_energy = 0.5*amp*(1-np.cos(mult*(angle-phi0))) assert abs(energy - check_energy) < 1e-8
def test_icgroup_cases(): sys = get_system_peroxide() assert (BondGroup(sys).cases == sys.bonds).all() assert BondGroup(sys, cases=[[1,2], [1,3]]).cases == [[1,2],[1,3]] assert BondGroup(sys, rules=['8', '8']).cases == [[0,1]] assert BondGroup(sys, rules=['1', '8']).cases == [[0,2],[1,3]] assert BendGroup(sys).cases == [[2, 0, 1], [3, 1, 0]] assert BendGroup(sys, cases=[[1,2,0], [0,1,3]]).cases == [[1,2,0],[0,1,3]]
def test_ic_list_dihedral_pernicious(): system = get_system_peroxide() dlist = DeltaList(system) iclist = InternalCoordinateList(dlist) iclist.add_ic(DihedAngle(0,1,2,3)) dlist.deltas[0] = (2.5645894177015855, -0.004063261303208772, 1.2798248429146284, 1, 2, 0.0, 0.0, 0.0) dlist.deltas[1] = (2.0394633015500796, -0.0032335148484117426, -1.98698089493469, 2, 3, 0.0, 0.0, 0.0) dlist.deltas[2] = (-1.8836397803889104, 0.0029844605526122576, -0.8613076025533011, 17, 3, 0.0, 0.0, 0.0) iclist.ictab[0] = (4, 0, -1, 1, 1, 2, -1, 0, 0, 0.0, 0.0) iclist.forward() assert abs(abs(iclist.ictab[0]['value']) - np.pi) < 1e-8
def test_ic_list_dihedral_pernicious(): system = get_system_peroxide() dlist = DeltaList(system) iclist = InternalCoordinateList(dlist) iclist.add_ic(DihedAngle(0, 1, 2, 3)) dlist.deltas[0] = (2.5645894177015855, -0.004063261303208772, 1.2798248429146284, 1, 2, 0.0, 0.0, 0.0) dlist.deltas[1] = (2.0394633015500796, -0.0032335148484117426, -1.98698089493469, 2, 3, 0.0, 0.0, 0.0) dlist.deltas[2] = (-1.8836397803889104, 0.0029844605526122576, -0.8613076025533011, 17, 3, 0.0, 0.0, 0.0) iclist.ictab[0] = (4, 0, -1, 1, 1, 2, -1, 0, 0, 0.0, 0.0) iclist.forward() assert abs(abs(iclist.ictab[0]['value']) - np.pi) < 1e-8
def test_plumed_peroxide_bond(): system = get_system_peroxide() # Linear restraint of the O-O bond m, a0 = 2.3 * kjmol / angstrom, 0.9 * angstrom # PLUMED input commands, remember that PLUMED starts counting atoms from 1 commands = "d: DISTANCE ATOMS=1,2\n" commands += "RESTRAINT ARG=d AT=%.20f SLOPE=%.20f LABEL=restraint\n"%\ (a0/nanometer, m/kjmol*nanometer) # Reference calculation: def reference(system): d = np.linalg.norm(system.pos[1] - system.pos[0]) return m * (d - a0) check_plumed(system, commands, reference)
def test_merge(): system1 = get_system_quartz() system2 = get_system_peroxide() system = system1.merge(system2) assert system1.natom + system2.natom == system.natom assert np.all(system.numbers[:system1.natom] == system1.numbers) assert np.all(system.numbers[system1.natom:] == system2.numbers) assert np.all(system.pos[:system1.natom] == system1.pos) assert np.all(system.pos[system1.natom:] == system2.pos) assert system.charges is None assert np.all( [system1.get_ffatype(iatom) for iatom in range(system1.natom) ] == system.ffatypes[system.ffatype_ids[:system1.natom]]) assert np.all( [system2.get_ffatype(iatom) for iatom in range(system2.natom) ] == system.ffatypes[system.ffatype_ids[system1.natom:]])
def test_iclist_peroxide_dihedral_angle(): number_of_tests=50 for i in xrange(number_of_tests): system = get_system_peroxide() dlist = DeltaList(system) iclist = InternalCoordinateList(dlist) # The bonds are added randomly to get different situations in the delta list bonds=[] while len(bonds)<3: i0, i1 = [int(x) for x in np.random.uniform(low=0,high=4,size=2)] #pick 2 random atoms if i0==i1 or (i0,i1) in bonds or (i1,i0) in bonds: continue if (i0,i1) in system.bonds or (i1,i0) in system.bonds: iclist.add_ic(Bond(i0,i1)) bonds.append((i0,i1)) iclist.add_ic(DihedAngle(0,1,2,3)) dlist.forward() iclist.forward() assert iclist.ictab[3]['kind']==4 #assert the third ic is DihedralAngle assert abs(iclist.ictab[3]['value'] - dihed_angle(system.pos)[0]) < 1e-5
def test_iclist_peroxide_dihedral_cos6(): number_of_tests=50 for i in range(number_of_tests): system = get_system_peroxide() system.pos += np.random.normal(0.0, 0.1, system.pos.shape)*angstrom dlist = DeltaList(system) iclist = InternalCoordinateList(dlist) # The bonds are added randomly to get different situations in the delta list bonds=[] while len(bonds)<3: i0, i1 = [int(x) for x in np.random.uniform(low=0,high=4,size=2)] #pick 2 random atoms if i0==i1 or (i0,i1) in bonds or (i1,i0) in bonds: continue if (i0,i1) in system.bonds or (i1,i0) in system.bonds: iclist.add_ic(Bond(i0,i1)) bonds.append((i0,i1)) iclist.add_ic(DihedCos6(0,1,2,3)) dlist.forward() iclist.forward() angle = dihed_angle(system.pos)[0] print('psi=%.3f deg: target=%.6f value=%.6f' %(angle/deg, np.cos(6*angle), iclist.ictab[3]['value'])) assert abs(iclist.ictab[3]['value'] - np.cos(6*angle)) < 1e-5
def test_iclist_peroxide_dihedral_cos(): number_of_tests = 50 for i in range(number_of_tests): system = get_system_peroxide() dlist = DeltaList(system) iclist = InternalCoordinateList(dlist) # The bonds are added randomly to get different situations in the delta list bonds = [] while len(bonds) < 3: i0, i1 = [ int(x) for x in np.random.uniform(low=0, high=4, size=2) ] #pick 2 random atoms if i0 == i1 or (i0, i1) in bonds or (i1, i0) in bonds: continue if (i0, i1) in system.bonds or (i1, i0) in system.bonds: iclist.add_ic(Bond(i0, i1)) bonds.append((i0, i1)) iclist.add_ic(DihedCos(0, 1, 2, 3)) dlist.forward() iclist.forward() assert iclist.ictab[3]['kind'] == 3 #assert the third ic is DihedralCos assert abs(iclist.ictab[3]['value'] - dihed_cos(system.pos)[0]) < 1e-5
def test_vlist_peroxide_dihed_angle(): number_of_tests=50 for i in range(number_of_tests): system = get_system_peroxide() dlist = DeltaList(system) iclist = InternalCoordinateList(dlist) vlist = ValenceList(iclist) bonds=[] while len(bonds)<3: i0, i1 = [int(x) for x in np.random.uniform(low=0,high=4,size=2)] #pick 2 random atoms if i0==i1 or (i0,i1) in bonds or (i1,i0) in bonds: continue if (i0,i1) in system.bonds or (i1,i0) in system.bonds: iclist.add_ic(Bond(i0,i1)) bonds.append((i0,i1)) vlist.add_term(Harmonic(1.5, 0.1 , DihedAngle(0,1,2,3))) dlist.forward() iclist.forward() energy = vlist.forward() # calculate energy manually angle = dihed_angle(system.pos)[0] check_energy = 0.5*1.5*(angle-0.1)**2 assert abs(energy - check_energy) < 1e-8
def test_iclist_peroxide_dihedral_cos6(): number_of_tests = 50 for i in range(number_of_tests): system = get_system_peroxide() system.pos += np.random.normal(0.0, 0.1, system.pos.shape) * angstrom dlist = DeltaList(system) iclist = InternalCoordinateList(dlist) # The bonds are added randomly to get different situations in the delta list bonds = [] while len(bonds) < 3: i0, i1 = [ int(x) for x in np.random.uniform(low=0, high=4, size=2) ] #pick 2 random atoms if i0 == i1 or (i0, i1) in bonds or (i1, i0) in bonds: continue if (i0, i1) in system.bonds or (i1, i0) in system.bonds: iclist.add_ic(Bond(i0, i1)) bonds.append((i0, i1)) iclist.add_ic(DihedCos6(0, 1, 2, 3)) dlist.forward() iclist.forward() angle = dihed_angle(system.pos)[0] print('psi=%.3f deg: target=%.6f value=%.6f' % (angle / deg, np.cos(6 * angle), iclist.ictab[3]['value'])) assert abs(iclist.ictab[3]['value'] - np.cos(6 * angle)) < 1e-5
def test_iter_matches_peroxide_graphene8(): system0 = get_system_graphene8() system1 = get_system_peroxide() assert len(list(system0.iter_matches(system1))) == 0
def test_gpos_vtens_dihed_angle_cosine_peroxide(): system = get_system_peroxide() part = ForcePartValence(system) part.add_term(Cosine(3, 1.5, 2 * np.pi / 3, DihedAngle(0, 1, 2, 3))) check_gpos_part(system, part) check_vtens_part(system, part)
def test_gpos_vtens_dihed_angle_peroxide(): system = get_system_peroxide() part = ForcePartValence(system) part.add_term(Harmonic(1.5, 1.0, DihedAngle(0, 1, 2, 3))) check_gpos_part(system, part) check_vtens_part(system, part)
def test_gpos_vtens_dihed_cos_peroxide(): system = get_system_peroxide() part = ForcePartValence(system) part.add_term(Harmonic(1.1, -0.2, DihedCos(0, 1, 2, 3))) check_gpos_part(system, part) check_vtens_part(system, part)
def test_gpos_vtens_dihed_angle_cosine_peroxide(): system = get_system_peroxide() part = ForcePartValence(system) part.add_term(Cosine(3, 1.5, 2*np.pi/3, DihedAngle(0,1,2,3))) check_gpos_part(system, part) check_vtens_part(system, part)
def test_gpos_vtens_dihed_angle_peroxide(): system = get_system_peroxide() part = ForcePartValence(system) part.add_term(Harmonic(1.5, 1.0, DihedAngle(0,1,2,3))) check_gpos_part(system, part) check_vtens_part(system, part)
def test_gpos_vtens_dihed_cos6_peroxide(): system = get_system_peroxide() part = ForcePartValence(system) part.add_term(Harmonic(1.1, -0.2, DihedCos6(0,1,2,3))) check_gpos_part(system, part) check_vtens_part(system, part)
def test_cut_bonds(): system = get_system_peroxide() system.cut_bonds([0, 2]) assert (system.bonds == [[0, 2], [1, 3]]).all()