def test_harmonic(self): hb_k = 5 hb_r_0 = 1.5 hb_r_cut = 3.355 hb = espressomd.interactions.HarmonicBond(k=hb_k, r_0=hb_r_0, r_cut=hb_r_cut) self.run_test( hb, lambda r: tests_common.harmonic_force( scalar_r=r, k=hb_k, r_0=hb_r_0), lambda r: tests_common.harmonic_potential( scalar_r=r, k=hb_k, r_0=hb_r_0), 0.01, hb_r_cut, True)
def test_harmonic(self): hb_k = 5 hb_r_0 = 1.5 hb_r_cut = 3.355 hb = espressomd.interactions.HarmonicBond(k=hb_k, r_0=hb_r_0, r_cut=hb_r_cut) self.system.bonded_inter.add(hb) self.system.part[0].add_bond((hb, 1)) for i in range(335): self.system.part[1].pos = self.system.part[1].pos + self.step self.system.integrator.run(recalc_forces=True, steps=0) # Calculate energies E_sim = self.system.analysis.energy()["bonded"] E_ref = tests_common.harmonic_potential(scalar_r=(i + 1) * self.step_width, k=hb_k, r_0=hb_r_0, r_cut=hb_r_cut) # Calculate forces f0_sim = self.system.part[0].f f1_sim = self.system.part[1].f f1_ref = self.axis * \ tests_common.harmonic_force(scalar_r=(i + 1) * self.step_width, k=hb_k, r_0=hb_r_0, r_cut=hb_r_cut) # Check that energies match, ... np.testing.assert_almost_equal(E_sim, E_ref) # force equals minus the counter-force ... self.assertTrue((f0_sim == -f1_sim).all()) # and has correct value. f1_sim_copy = np.copy(f1_sim) np.testing.assert_almost_equal(f1_sim_copy, f1_ref) # Check that bond breaks when distance > r_cut self.system.part[1].pos = self.system.part[1].pos + self.step with self.assertRaisesRegexp(Exception, "Encoutered errors during integrate"): self.system.integrator.run(recalc_forces=True, steps=0)