Esempio n. 1
0
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)
Esempio n. 2
0
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)
Esempio n. 3
0
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)
Esempio n. 4
0
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
Esempio n. 5
0
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))