def test_gpos_vtens_quartz(): system = get_system_quartz() rv_table = { ('Si', 'O'): 3.24970, ('O', 'Si', 'O'): 2.06457, ('Si', 'O', 'Si'): 1.80173, } fc_table = { ('Si', 'O'): 0.30978, ('O', 'Si', 'O'): 0.19282, ('Si', 'O', 'Si'): 0.00751, } part = ForcePartValence(system) for i, j in system.bonds: key = system.get_ffatype(i), system.get_ffatype(j) part.add_term(Harmonic(fc_table[key], rv_table[key], Bond(i, j))) for i1 in xrange(system.natom): for i0 in system.neighs1[i1]: for i2 in system.neighs1[i1]: key = system.get_ffatype(i0), system.get_ffatype( i1), system.get_ffatype(i2) if i0 > i2: part.add_term( Harmonic(fc_table[key], rv_table[key], BendAngle(i0, i1, i2))) check_gpos_part(system, part) check_vtens_part(system, part)
def test_gpos_vtens_mm3quartic_water32(): system = get_system_water32() part = ForcePartValence(system) for i, j in system.bonds: part.add_term(MM3Quartic(1.5, 2.0 + 0.01 * i, Bond(i, j))) check_gpos_part(system, part) check_vtens_part(system, part)
def test_bias_gaussianhills_quartz(): system = get_system_quartz() # Volume cv0 = CVVolume(system) q0 = system.cell.volume # Distance between 2 and 8 cv1 = CVInternalCoordinate(system, Bond(2, 8)) delta = system.pos[2] - system.pos[8] system.cell.mic(delta) q1 = np.linalg.norm(delta) # Widths of the Gaussians sigmas = np.array([10.0 * angstrom**3, 0.2 * angstrom]) bias = GaussianHills([cv0, cv1], sigmas) # No hills added, energy should be zero e = bias.compute() assert e == 0.0 # Add one hill K0 = 5 * kjmol bias.add_hill(np.array([q0 + sigmas[0], q1 - 2 * sigmas[1]]), K0) e = bias.compute() assert np.abs(e - K0 * np.exp(-2.5)) < 1e-10 # Add another hill K1 = 2 * kjmol bias.add_hill(np.array([q0 - 3 * sigmas[0], q1 - 1 * sigmas[1]]), K1) e = bias.compute() assert np.abs(e - K0 * np.exp(-2.5) - K1 * np.exp(-5.0)) < 1e-10 # Test derivatives bias.add_hill(np.array([q0 - 3 * sigmas[0], q1 - 1 * sigmas[1]]), K1) part = ForcePartBias(system) part.add_term(bias) check_gpos_part(system, part) check_vtens_part(system, part)
def test_bks_vtens_gpos_parts(): system = get_system_quartz() fn_pars = context.get_fn('test/parameters_bks.txt') ff = ForceField.generate(system, fn_pars, smooth_ei=True, reci_ei='ignore') for part in ff.parts: check_vtens_part(system, part, ff.nlist) check_gpos_part(system, part, ff.nlist)
def test_gpos_vtens_oopdist_formaldehyde(): system = get_system_formaldehyde() system.pos[0,0] += 0.0*angstrom part = ForcePartValence(system) part.add_term(Harmonic(0.0,0.0*angstrom,OopDist(2,3,1,0))) check_gpos_part(system, part) check_vtens_part(system, part)
def test_bias_multiple_terms(): system = get_system_quartz() part = ForcePartBias(system) # Harmonic volume bias cv0 = CVVolume(system) K, q0 = 0.4, 0.9 * system.cell.volume bias0 = HarmonicBias(K, q0, cv0) part.add_term(bias0) # Cosine of bending angle cv1 = BendAngle(0, 1, 2) m, a, phi0 = 1, 2.0, np.pi / 4.0 bias1 = Cosine(m, a, phi0, cv1) part.add_term(bias1) # Check energy e = part.compute() contributions = part.get_term_energies() assert np.abs(e - np.sum(contributions)) < 1e-5 assert contributions[0] == bias0.compute() # Check derivatives check_gpos_part(system, part) check_vtens_part(system, part) # Check collective variable values cv_values0 = part.get_term_cv_values(0) assert cv_values0.shape[0] == 1 assert cv_values0[0] == cv0.compute() cv_values1 = part.get_term_cv_values(1) assert cv_values1.shape[0] == 1 delta0 = system.pos[1] - system.pos[0] system.cell.mic(delta0) delta2 = system.pos[1] - system.pos[2] system.cell.mic(delta2) phi = bend_angle([delta0, np.zeros(3, float), delta2])[0] assert np.abs(cv_values1[0] - phi) < 1e-5
def test_gpos_vtens_polyfour_water32(): system = get_system_water32() part = ForcePartValence(system) for i, j in system.bonds: part.add_term(PolyFour([-0.5, 0.3, -0.16, 0.09], Bond(i, j))) check_gpos_part(system, part) check_vtens_part(system, part)
def test_ewald_vtens_neut_water32(): # fake water model, negative oxygens and neutral hydrogens system = get_system_water32() system.charges -= 0.1 for alpha in 0.05, 0.1, 0.2: part_ewald_neut = ForcePartEwaldNeutralizing(system, alpha) check_vtens_part(system, part_ewald_neut)
def test_ewald_gpos_vtens_reci_water32(): system = get_system_water32() dielectric = 1.4 for alpha in 0.05, 0.1, 0.2: part_ewald_reci = ForcePartEwaldReciprocal(system, alpha, gcut=alpha / 0.75, dielectric=dielectric) check_gpos_part(system, part_ewald_reci) check_vtens_part(system, part_ewald_reci)
def test_gpos_vtens_morse_water32(): system = get_system_water32() part = ForcePartValence(system) for i, j in system.bonds: part.add_term(Morse(0.3, 1.7, 2.0, Bond(i, j))) check_gpos_part(system, part) check_vtens_part(system, part)
def test_gpos_vtens_bond_fues_water32(): system = get_system_water32() part = ForcePartValence(system) for i, j in system.bonds: part.add_term(Fues(0.3, 1.7, Bond(i, j))) check_gpos_part(system, part) check_vtens_part(system, part)
def test_gpos_vtens_pointlinedist_water32(): system = get_system_water32() part = ForcePartValence(system) for i, j, k in system.iter_angles(): part.add_term(Harmonic(0.3, 1.7, PointLineDistance(i, j, k))) check_gpos_part(system, part) check_vtens_part(system, part)
def test_gpos_vtens_dihedral_cos_mil53(): system = get_system_mil53() forbidden_dihedrals = [ ["O_HY","AL","O_HY","AL"], ["O_HY","AL","O_HY","H_HY"], ["O_CA","AL","O_CA","C_CA"], ["O_CA","AL","O_HY","H_HY"], ["H_PH","C_PH","C_PC","C_PH"], ["H_PH","C_PH","C_PC","C_CA"], ["C_PH","C_PH","C_PC","C_PH"], ["C_PH","C_PH","C_PC","C_CA"], ["C_PC","C_PH","C_PH","H_PH"], ["C_PC","C_PH","C_PH","C_PC"], ["H_PH","C_PH","C_PH","H_PH"], ["C_PH","C_PC","C_CA","O_CA"], ] idih = -1 for i1, i2 in system.bonds: for i0 in system.neighs1[i1]: if i0==i2: continue for i3 in system.neighs1[i2]: if i3==i1: continue types = [system.get_ffatype(i0), system.get_ffatype(i1), system.get_ffatype(i2), system.get_ffatype(i3)] if types in forbidden_dihedrals or types[::-1] in forbidden_dihedrals: continue idih += 1 fc = 2.1 + 0.01*(0.3*i1 + 0.7*i2) part = ForcePartValence(system) part.add_term(PolyFour([-2.0*fc,0.0001,0.0,0.0],DihedCos(i0,i1,i2,i3))) check_gpos_part(system, part) check_vtens_part(system, part)
def test_ewald_gpos_vtens_corr_water32(): system = get_system_water32() scalings = Scalings(system, 0.0, 0.0, 0.5) for alpha in 0.05, 0.1, 0.2: part_ewald_corr = ForcePartEwaldCorrection(system, alpha, scalings, dielectric=0.8) check_gpos_part(system, part_ewald_corr) check_vtens_part(system, part_ewald_corr)
def test_gpos_vtens_quartz(): system = get_system_quartz() rv_table = { ('Si', 'O'): 3.24970, ('O', 'Si', 'O'): 2.06457, ('Si', 'O', 'Si'): 1.80173, } fc_table = { ('Si', 'O'): 0.30978, ('O', 'Si', 'O'): 0.19282, ('Si', 'O', 'Si'): 0.00751, } part = ForcePartValence(system) for i, j in system.bonds: key = system.get_ffatype(i), system.get_ffatype(j) part.add_term(Harmonic(fc_table[key], rv_table[key], Bond(i, j))) for i1 in range(system.natom): for i0 in system.neighs1[i1]: for i2 in system.neighs1[i1]: key = system.get_ffatype(i0), system.get_ffatype(i1), system.get_ffatype(i2) if i0 > i2: part.add_term(Harmonic(fc_table[key], rv_table[key], BendAngle(i0, i1, i2))) 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))) print(dihed_angle(system.pos)[0] / np.pi) check_gpos_part(system, part) check_vtens_part(system, part)
def test_gpos_vtens_mm3quartic_water32(): system = get_system_water32() part = ForcePartValence(system) for i, j in system.bonds: part.add_term(MM3Quartic(1.5, 2.0+0.01*i, Bond(i, j))) check_gpos_part(system, part) check_vtens_part(system, part)
def test_gpos_vtens_oopdist_formaldehyde(): system = get_system_formaldehyde() system.pos[0, 0] += 0.0 * angstrom part = ForcePartValence(system) part.add_term(Harmonic(0.0, 0.0 * angstrom, OopDist(2, 3, 1, 0))) check_gpos_part(system, part) check_vtens_part(system, part)
def test_gpos_vtens_poly4_water32(): system = get_system_water32() part = ForcePartValence(system) for i, j in system.bonds: part.add_term(Poly4(0.001, 0.002, 0.271, -0.32793, 0.23151, 1.78, Bond(i, j))) check_gpos_part(system, part) check_vtens_part(system, part)
def test_ewald_gpos_vtens_corr_quartz(): system = get_system_quartz().supercell(2, 2, 2) scalings = Scalings(system, np.random.uniform(0.1, 0.9), np.random.uniform(0.1, 0.9), np.random.uniform(0.1, 0.9)) for alpha in 0.1, 0.2, 0.5: part_ewald_corr = ForcePartEwaldCorrection(system, alpha, scalings) check_gpos_part(system, part_ewald_corr) check_vtens_part(system, part_ewald_corr)
def test_ewald_gpos_vtens_reci_quartz(): system = get_system_quartz() for alpha in 0.1, 0.2, 0.5: part_ewald_reci = ForcePartEwaldReciprocal(system, alpha, gcut=alpha / 0.5) check_gpos_part(system, part_ewald_reci) check_vtens_part(system, part_ewald_reci)
def test_gpos_vtens_2T(): system = get_system_2T() rv_table = { ('H', 'Si', 'H'): 1.80861, ('Si', 'O'): 3.24970, ('H', 'O'): 1.96022, ('O', 'Si', 'O'): 2.06457, ('O', 'Si'): 3.24970, ('O', 'Si', 'H'): 1.85401, ('Si', 'O', 'Si'): 1.80173, ('Si', 'O', 'H'): 1.55702, ('H', 'O', 'Si'): 1.55702, ('Si', 'H'): 2.87853, ('H', 'Si'): 2.87853, ('H', 'Si', 'O'): 1.85401, ('O', 'H'): 1.96022, } fc_table = { ('H', 'Si', 'H'): 0.09376, ('Si', 'O'): 0.30978, ('H', 'O'): 0.60322, ('O', 'Si', 'O'): 0.19282, ('O', 'Si'): 0.30978, ('O', 'Si', 'H'): 0.11852, ('Si', 'O', 'Si'): 0.00751, ('Si', 'O', 'H'): 0.04271, ('H', 'O', 'Si'): 0.04271, ('Si', 'H'): 0.18044, ('H', 'Si'): 0.18044, ('H', 'Si', 'O'): 0.11852, ('O', 'H'): 0.60322, } part = ForcePartValence(system) for i, j in system.bonds: key = system.get_ffatype(i), system.get_ffatype(j) part.add_term(Harmonic(fc_table[key], rv_table[key], Bond(i, j))) for i1 in range(system.natom): for i0 in system.neighs1[i1]: for i2 in system.neighs1[i1]: key = system.get_ffatype(i0), system.get_ffatype(i1), system.get_ffatype(i2) if i0 > i2: part.add_term(Harmonic(fc_table[key], rv_table[key], BendAngle(i0, i1, i2))) check_gpos_part(system, part) check_vtens_part(system, part) # same test but with Fues bonds instead of Harmonic bonds part = ForcePartValence(system) for i, j in system.bonds: key = system.get_ffatype(i), system.get_ffatype(j) part.add_term(Fues(fc_table[key], rv_table[key], Bond(i, j))) for i1 in range(system.natom): for i0 in system.neighs1[i1]: for i2 in system.neighs1[i1]: key = system.get_ffatype(i0), system.get_ffatype(i1), system.get_ffatype(i2) if i0 > i2: part.add_term(Harmonic(fc_table[key], rv_table[key], BendAngle(i0, i1, i2))) check_gpos_part(system, part) check_vtens_part(system, part)
def test_gpos_vtens_sqpointlinedist_water32(): system = get_system_water32() part = ForcePartValence(system) for i, j, k in system.iter_angles(): # Add this term so no all signs of deltas are 1 part.add_term(Harmonic(0.4, 1.0, Bond(j, i))) part.add_term(Harmonic(0.3, 1.7, SqPointLineDistance(i, j, k))) check_gpos_part(system, part) check_vtens_part(system, part)
def test_gpos_vtens_ub_water(): system = get_system_water32() part = ForcePartValence(system) for i1 in range(system.natom): for i0 in system.neighs1[i1]: for i2 in system.neighs1[i1]: if i0 > i2: part.add_term(Harmonic(2.1,2.0*angstrom,UreyBradley(i0, i1, i2))) check_gpos_part(system, part) check_vtens_part(system, part)
def test_gpos_vtens_bend_cos_water32(): system = get_system_water32() part = ForcePartValence(system) for i1 in range(system.natom): for i0 in system.neighs1[i1]: for i2 in system.neighs1[i1]: if i0 > i2: part.add_term(Harmonic(1.1+0.01*i0, -0.2, BendCos(i0, i1, i2))) check_gpos_part(system, part) check_vtens_part(system, part)
def test_gpos_vtens_mm3benda_water32(): system = get_system_water32() part = ForcePartValence(system) for i1 in range(system.natom): for i0 in system.neighs1[i1]: for i2 in system.neighs1[i1]: if i0 > i2: part.add_term(MM3Bend(1.5, 2.0+0.01*i2, BendAngle(i0, i1, i2))) check_gpos_part(system, part) check_vtens_part(system, part)
def test_bias_harmonicvolume_quartz(): system = get_system_quartz() cv = CVVolume(system) K, q0 = 0.4, 0.9 * system.cell.volume bias = HarmonicBias(K, q0, cv) part = ForcePartBias(system) part.add_term(bias) e = part.compute() echeck = 0.5 * K * (system.cell.volume - q0)**2 assert np.abs(e - echeck) < 1e-8 check_gpos_part(system, part) check_vtens_part(system, part)
def test_quartz_vtens(): system = get_system_quartz() groups = [ (np.array([0, 2, 8, 1]), np.array([0.3, 0.2, 0.4, 0.3])), (np.array([1, 3, 4, 5]), np.array([0.3, 0.4, 0.1, 0.2])), ] comlist = COMList(system, groups) part = ForcePartValence(system, comlist) part.add_term(Harmonic(2.1, 0.5, Bond(0, 1))) check_gpos_part(system, part) check_vtens_part(system, part)
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_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 check_plumed(system, commands, reference): with tmpdir(__name__, 'check_plumed') as dirname: # Write PLUMED commands to file fn = os.path.join(dirname, 'plumed.dat') with open(fn, 'w') as f: f.write(commands) # Setup Plumed plumed = ForcePartPlumed(system, fn=fn) # Compare with direct calculation e = plumed.compute() eref = reference(system) check_gpos_part(system, plumed) check_vtens_part(system, plumed) assert np.abs(e - eref) < 1e-3 * kjmol
def test_gpos_vtens_cross_water32(): system = get_system_water32() part = ForcePartValence(system) for j in xrange(system.natom): if len(system.neighs1[j]) == 2: i, k = system.neighs1[j] part.add_term(Cross( 1.2, 1.7, 1.9, Bond(i, j), Bond(j, k), )) check_gpos_part(system, part) check_vtens_part(system, part)
def test_gpos_vtens_cross_water32(): system = get_system_water32() part = ForcePartValence(system) for j in range(system.natom): if len(system.neighs1[j])==2: i, k = system.neighs1[j] part.add_term(Cross( 1.2, 1.7, 1.9, Bond(i, j), Bond(j, k), )) check_gpos_part(system, part) check_vtens_part(system, part)
def test_pair_pot_eidip_water(): #Setup system and force part system, nlist, scalings, part_pair, pair_pot, pair_fn = get_part_water_eidip() #Check energy from Yaff with manually computed energy check_pair_pot_water(system, nlist, scalings, part_pair, pair_pot, pair_fn, 1.0e-12) check_gpos_part(system, part_pair, nlist) check_vtens_part(system, part_pair, nlist, symm_vtens=False) #Again, but with a truncation scheme (truncation scheme settings are ridiculous, #but this is needed to see an effect for water) #Setup system and force part system, nlist, scalings, part_pair, pair_pot, pair_fn = get_part_water_eidip(rcut=2.0*angstrom,switch_width=1.5*angstrom) #Check energy from Yaff with manually computed energy check_pair_pot_water(system, nlist, scalings, part_pair, pair_pot, pair_fn, 1.0e-12) check_gpos_part(system, part_pair, nlist) check_vtens_part(system, part_pair, nlist, symm_vtens=False)
def test_bias_gaussianhills_alanine(): ff = get_alaninedipeptide_amber99ff() cv = CVInternalCoordinate(ff.system, DihedAngle(4, 6, 8, 14)) sigma = 0.35 * rad bias = GaussianHills(cv, sigma) e = bias.compute() assert e == 0.0 K, phi0 = 3 * kjmol, -2.5 * rad bias.add_hill(phi0, K) e = bias.compute() phi = cv.compute() eref = K * np.exp(-(phi - phi0)**2 / 2 / sigma**2) assert np.abs(e - eref) < 1e-10 * kjmol part = ForcePartBias(ff.system) part.add_term(bias) check_gpos_part(ff.system, part) check_vtens_part(ff.system, part)
def test_bias_lowerwallvolume_quartz(): system = get_system_quartz() cv = CVVolume(system) K, q0 = 0.4, system.cell.volume bias = LowerWallBias(K, q0, cv) rvecs_orig = system.cell.rvecs.copy() part = ForcePartBias(system) part.add_term(bias) for scale in [0.5, 2.0]: rvecs = rvecs_orig * scale system.cell.update_rvecs(rvecs) e = bias.compute() if system.cell.volume < q0: eref = 0.5 * K * (system.cell.volume - q0)**2 else: eref = 0.0 assert np.abs(e - eref) < 1e-8 check_gpos_part(system, part) check_vtens_part(system, part)
def test_bias_gaussianhills_alanine_periodic(): ff = get_alaninedipeptide_amber99ff() cv = CVInternalCoordinate(ff.system, DihedAngle(4, 6, 8, 14)) sigma = 0.35 * rad bias = GaussianHills(cv, sigma, periodicities=2.0 * np.pi) e = bias.compute() assert e == 0.0 K, phi0 = 3 * kjmol, -2.5 * rad bias.add_hill(phi0, K) e = bias.compute() phi = cv.compute() eref = K * np.exp(-(phi - phi0)**2 / 2 / sigma**2) assert np.abs(e - eref) < 1e-10 * kjmol # Another hill, two periods away, so should give the same energy # once more bias.add_hill(phi0 - 4.0 * np.pi, K) e = bias.compute() assert np.abs(e - 2 * eref) < 1e-10 * kjmol part = ForcePartBias(ff.system) part.add_term(bias) check_gpos_part(ff.system, part) check_vtens_part(ff.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_oopcos_formaldehyde(): system = get_system_formaldehyde() part = ForcePartValence(system) part.add_term(Harmonic(2.1,0.0*angstrom,OopCos(2,3,1,0))) check_gpos_part(system, part) check_vtens_part(system, part)
def test_gpos_vtens_pair_pot_caffeine_exprep_5A_case2(): system, nlist, scalings, part_pair, pair_fn = get_part_caffeine_exprep_5A(1, 2.385e-2, 1, 7.897e-3) check_gpos_part(system, part_pair, nlist) check_vtens_part(system, part_pair, nlist)
def test_gpos_vtens_pair_pot_caffeine_dampdisp_9A(): system, nlist, scalings, part_pair, pair_fn = get_part_caffeine_dampdisp_9A() check_gpos_part(system, part_pair, nlist) check_vtens_part(system, part_pair, nlist)
def test_gpos_vtens_pair_pot_caffeine_ei2_10A(): system, nlist, scalings, part_pair, pair_fn = get_part_caffeine_ei3_10A() check_gpos_part(system, part_pair, nlist) check_vtens_part(system, part_pair, nlist)
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_vtens_pext_1(): system = get_system_polyethylene4() part = ForcePartPressure(system, 1.0) check_vtens_part(system, part)
def test_vtens_pext_2(): system = get_system_graphene8() part = ForcePartPressure(system, 1.0) check_vtens_part(system, part)
def test_vtens_pext_3(): system = get_system_water32() part = ForcePartPressure(system, 1.0) 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)