Exemplo n.º 1
0
    def test_fene(self):
        fene_k = 23.15
        fene_d_r_max = 3.355
        fene_r_0 = 1.1

        fene = espressomd.interactions.FeneBond(
            k=fene_k, d_r_max=fene_d_r_max, r_0=fene_r_0)
        self.run_test(fene,
                      lambda r: tests_common.fene_force(
                          scalar_r=r, k=fene_k, d_r_max=fene_d_r_max, r_0=fene_r_0),
                      lambda r: tests_common.fene_potential(
                          scalar_r=r, k=fene_k, d_r_max=fene_d_r_max, r_0=fene_r_0),
                      0.01, fene_r_0 + fene_d_r_max, True)
Exemplo n.º 2
0
    def test_fene(self):
        fene_k = 23.15
        fene_d_r_max = 3.355
        fene_r_0 = 1.1

        fene = espressomd.interactions.FeneBond(k=fene_k,
                                                d_r_max=fene_d_r_max,
                                                r_0=fene_r_0)
        self.system.bonded_inter.add(fene)
        self.system.part[0].add_bond((fene, 1))

        for i in range(445):
            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.fene_potential(scalar_r=(i + 1) *
                                                self.step_width,
                                                k=fene_k,
                                                d_r_max=fene_d_r_max,
                                                r_0=fene_r_0)

            # Calculate forces
            f0_sim = self.system.part[0].f
            f1_sim = self.system.part[1].f
            f1_ref = self.axis * \
                tests_common.fene_force(scalar_r=(i + 1) * self.step_width,
                                        k=fene_k, d_r_max=fene_d_r_max, r_0=fene_r_0)

            # 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, decimal=5)

        # 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)