def test__generate_trial_position_redundancy(self): particle_type = ParticleType(name="Natrium", mass=2, charge=2, lj_epsilon=1.25, lj_sigma=0.5) particle_type = np.array([particle_type]) parameters = Parameters(temperature=0, box=np.array([12., 13., 14.]), es_sigma=0.5, update_radius=1, particle_types=particle_type, cutoff_radius=0.5, K_cutoff=1) particle_1 = Particle(position=np.array([1, 2, 3]), type_index=0) particle_2 = Particle(position=np.array([1, 2, 3]), type_index=0) trial_position1 = np.array( MetropolisMonteCarlo._generate_trial_position( particle_1.position, parameters)) trial_position2 = np.array( MetropolisMonteCarlo._generate_trial_position( particle_1.position, parameters)) x = 0 if np.array_equal(trial_position1, trial_position2): x = 1 else: x = 2 npt.assert_equal(x, 2, 'Failed', verbose=True)
def test_generate_trial_position_2(self): position = np.array([0.5, 0.5, 0.5]) # set test parameters charges = np.ones(10).astype(np.float32) lj_sigmas = np.ones(10).astype(np.float32) lj_epsilons = np.ones(10).astype(np.float32) para = Parameters(temperature=1, box=np.array([1, 1, 1]), es_sigma=1, update_radius=1, charges=charges, lj_sigmas=lj_sigmas, lj_epsilons=lj_epsilons, update_probability=0.5, accuracy=1) distances = [] for i in range(10000): trial_position = MetropolisMonteCarlo._generate_trial_position( position, para) distances.append(np.linalg.norm(position - trial_position)) distances = np.array(distances) npt.assert_approx_equal(distances.sum() / 10000, 0.5, significant=2)
def test_generate_trial_position_1(self): position = np.array([0.5, 0.5, 0.5]) # set test parameters charges = np.ones(10).astype(np.float32) lj_sigmas = np.ones(10).astype(np.float32) lj_epsilons = np.ones(10).astype(np.float32) para = Parameters(temperature=1, box=np.array([1, 1, 1]), es_sigma=1, update_radius=1, charges=charges, lj_sigmas=lj_sigmas, lj_epsilons=lj_epsilons, update_probability=0.5, accuracy=1) for i in range(1000): trial_position = MetropolisMonteCarlo._generate_trial_position( position, para) distance = np.linalg.norm(position - trial_position) if distance > para.update_radius: raise AssertionError("Distance greater than update radius")
def test__generate_trial_position_3(self): particle_type = ParticleType(name="Hydrogen", mass=1.008, charge=1.602, lj_epsilon=0.21, lj_sigma=2.5) particle_type = np.array([particle_type]) parameters = Parameters(temperature=0, box=np.array([12., 13., 13.]), es_sigma=0.5, update_radius=1, particle_types=particle_type, cutoff_radius=0.5) particle_1 = Particle(position=np.array([1, 2, 4]), type_index=1) trial_position1 = np.array( MetropolisMonteCarlo._generate_trial_position( particle_1.position, parameters))