def test_volume(): coordinates = mc_lj_potential.generate_initial_state(method='random', num_particles=100, box_length=5.0) mcs = mc_lj_potential.Box(coordinates=coordinates, box_length=5.0) assert mcs.volume == 125
def test_lennard_jones_potential(): """ Test the definition of lennard_jones_potential() function. It will pass when the calculated potential is equal to actual potential defined by lennard jones. """ coordinates = [np.array([0.0, 0.0, 0.0]), np.array([0.0, 0.0, 1.0])] box_length = 10.0 box = mc_lj_potential.Box(box_length=box_length, coordinates=coordinates) mcs = mc_lj_potential.MCState(box, cutoff=3.0) expected_vaule = 224.0 calculated_value = mcs.lennard_jones_potential(0.5) assert np.isclose(expected_vaule, calculated_value)
def test_get_particle_energy_equi(): """ Test the get_paricle_energy() function when it is at the equilibrated point. """ coordinates = [np.array([0.0, 0.0, 0.0]), np.array([0.0, 0.0, 1.0])] box_length = 10.0 box = mc_lj_potential.Box(box_length=box_length, coordinates=coordinates) mcs = mc_lj_potential.MCState(box, cutoff=3.0) expected_vaule = 0.0 calculated_value = mcs.get_particle_energy(0) assert np.isclose(expected_vaule, calculated_value)
def test_get_particle_energy_cutoff(): """ Test the get_particle_energy() function when the particle is exceed the cutoff. """ coordinates = [np.array([0.0, 0.0, 0.0]), np.array([0.0, 0.0, 4.0])] box_length = 10.0 box = mc_lj_potential.Box(box_length=box_length, coordinates=coordinates) mcs = mc_lj_potential.MCState(box, cutoff=3.0) expected_vaule = 0.0 calculated_value = mcs.get_particle_energy(0) assert np.isclose(expected_vaule, calculated_value)
def test_num_particles(): """ Test if the property of num_particles is true. """ coordinates = mc_lj_potential.generate_initial_state(method='random', num_particles=100, box_length=10.0) mcs = mc_lj_potential.Box(coordinates=coordinates, box_length=10.0) assert mcs.num_particles == 100
def mcs(): """ Set up the fixture to have a general MCState that can be callable for all tests of different energy functions. """ current_directory = os.path.dirname(os.path.abspath(__file__)) file_path = os.path.join(current_directory, "sample_config.xyz") coordinates = mc_lj_potential.generate_initial_state(method = "file", file_name=file_path) box_length = 10.0 cutoff = 3.0 box = mc_lj_potential.Box(box_length=box_length, coordinates=coordinates) mcs = mc_lj_potential.MCState(box, cutoff = cutoff) return mcs
def test_volume_2(): """Test the result of the volume function[property]- State 2 Parameters ---------- box_length : float One side of the cubic simulation box. coordinates : np.array A random set of coordinates in the box. Returns ------- volume : float Volume of the cubic simulation box. """ box_length = 12 mcs = mc_lj_potential.Box(coordinates=[[24, 36]], box_length=box_length) expected_volume = 1728 calculated_volume = mcs.volume assert expected_volume == calculated_volume
def test_wrap_2(): """Tests the result of the wrap function- State 2 Parameters ---------- coordinates : np.array(num_of_particles, 3) A numpy array with the s, y and z coordinates of each atom in the simulation box. box_length : float One side of the cubic simulation box. Returns ------- coordinates : np.array Determines whether the expected coordinates and calculated coordinates from the wrap function match. """ coordinates = np.array([-5, 12, 1.5]) box_length = 6.0 mcs = mc_lj_potential.Box(coordinates=coordinates, box_length=box_length) expected_coordinates = [1, 0, 1.5] mcs.wrap(coordinates=coordinates, box_length=box_length) assert np.array_equal(expected_coordinates, mcs.coordinates)
def test_minimum_image_distance_2(): """Test the result of the minimum_image_distance function- State 2 Parameters ---------- r_a : float Position of particle a r_b : float Position of particle b box_length : float One side of the cubic simulation box. Returns ------- rij2 : float Square of the minimum image distance between atom pair a and b. """ r_a = np.array([0, 0, 0]) r_b = np.array([5, 12, 2]) box_length = 5 mcs = mc_lj_potential.Box(coordinates=[r_a, r_b], box_length=box_length) expected_distance = 8.0 calculated_distance = mcs.minimum_image_distance(r_i=r_a, r_j=r_b, box_length=box_length) assert np.isclose(expected_distance, calculated_distance)
import mc_lj_potential as mc import numpy as np np.random.seed(123) num_particles = 100 box_length = 10.0 coordinates = mc.generate_initial_state(method='random', num_particles=num_particles, box_length=box_length) #print(coordinates) box = mc.Box(coordinates=coordinates, box_length=box_length) #print(box.coordinates) mcs = mc.MCState(box1=box, cutoff=3.0) total_pair_energy = mcs.calculate_total_pair_energy() #print(total_pair_energy) #print(mcs.calculate_tail_correction()) #print(mcs.calculate_unit_energy()) #print(mcs.get_particle_energy(0))