def test_forces_sign_far(dist): particles = cm.ParticleGroup.from_xyz(ar_path,('constant',0.)) particles.attach_potential(cm.LJPotential(A=A_ar,B=B_ar,rcut=cut)) particles.coords[1,:] = [dist,0.,0.] #forces for these coordinates should be, in magnitude: assert particles.get_forces()[0][0] > 0. and \ particles.get_forces()[1][0] < 0.
def test_forces_newton_third_pair(dist): particles = cm.ParticleGroup.from_xyz(ar_path,('constant',0.)) particles.attach_potential(cm.LJPotential(A=A_ar,B=B_ar,rcut=cut)) particles.coords[1,:] = [dist,0.,0.] #forces for these coordinates should be, in magnitude: assert isclose(abs(particles.get_forces()[0][0]), abs(particles.get_forces()[1][0]),rel_tol=1e-8,abs_tol=1e-8)
def test_forces_magnitude(dist): particles = cm.ParticleGroup.from_xyz(ar_path,('constant',0.)) particles.attach_potential(cm.LJPotential(A=A_ar,B=B_ar,rcut=cut)) particles.coords[1,:] = [dist,0.,0.] #forces for these coordinates should be, in magnitude: myforce = abs(12*A_ar/(dist**13)-6*B_ar/(dist**7)) assert isclose(abs(particles.get_forces()[0][0]), myforce,rel_tol=1e-8,abs_tol=1e-8)
def test_forces_eq(): particles = cm.ParticleGroup.from_xyz(ar_path,('constant',0.)) particles.attach_potential(cm.LJPotential(A=A_ar,B=B_ar,rcut=cut)) particles.coords[1,:] = [rmin_argon,0.,0.] #forces for these coordinates should be, in magnitude: assert isclose(particles.get_forces()[0][0],0., rel_tol=1e-8,abs_tol=1e-8) \ and isclose(particles.get_forces()[1][0],0., rel_tol=1e-8,abs_tol=1e-8)
def test_propagate_first_ts(): ts = 5. particles = cm.ParticleGroup.from_xyz(ar_path,('constant',0.)) particles.attach_potential(cm.LJPotential(A=A_ar,B=B_ar,rcut=cut)) particles.coords[1,:] = [4.,0.,0.] particles.attach_propagator(cm.VerletPropagator(ts)) myforce = 12*A_ar/(4.**13)-6*B_ar/(4.**7) upterm = (myforce/ar_mass)*ts**2 new_coord = 4. + 0.5*upterm particles.update_coords_velocs(0) assert isclose(new_coord,particles.coords[1][0],rel_tol=1e-8,abs_tol=1e-8)
#for j in range(10000): # particles.update_coords_velocs(j,'reflecting_fake') # with open("output_test.xyz","a") as myfile: # myfile.write('100\n') # myfile.write(f'timestep {j}\n') # for n in range(particles.coords.shape[0]): # x = particles.coords[n,0] # y = particles.coords[n,1] # z = particles.coords[n,2] # myfile.write(f'Ar {x} {y} {z} \n') ############################## particles = cm.ParticleGroup.from_xyz(reflecting_path,('constant',0.)) particles.coords = np.random.uniform(-9.,9.,(100,3)) particles.attach_potential(cm.LJPotential(A=A_ar,B=B_ar,rcut=cut)) particles.attach_box(-10.,10.,-10.,10.,-10.,10.) particles.attach_propagator(cm.SteepestDescentPropagator(5.)) for j in range(1000): particles.update_coords_velocs(j,'reflecting_velverlet') with open("output_velver.xyz","a") as myfile: myfile.write('100\n') myfile.write(f'timestep {j}\n') for n in range(particles.coords.shape[0]): x = particles.coords[n,0] y = particles.coords[n,1] z = particles.coords[n,2] myfile.write(f'Ar {x} {y} {z} \n')
import numpy as np import pycmech as cm import matplotlib.pyplot as plt water_path = './test_data/water.xyz' #sanity check for the lennard jones potential, this should look like the #argon lennard jones potential eps_argon = cm.joule2menergy(1.65e-21) sig_argon = 3.4 A_argon = 4 * eps_argon * sig_argon**12 B_argon = 4 * eps_argon * sig_argon**6 rmin_argon = 2**(1 / 6.) * sig_argon lj = cm.LJPotential(A=A_argon, B=B_argon, rcut=8.) #This plot should look like the argon lennard jones potential #with a minimum at the vertical line #and going towards 0 at the horizontal line dist = np.linspace(3.3, 8., 100) ljval = lj._lj_for_array(dist) plt.plot(dist, ljval) ylo, yhi = plt.gca().get_ylim() xlo, xhi = plt.gca().get_xlim() plt.vlines(rmin_argon, *plt.gca().get_ylim()) plt.hlines(0., *plt.gca().get_xlim(), linestyles='dashed') plt.gca().set_ylim(ylo, yhi) plt.gca().set_xlim(xlo, xhi) plt.show()