Exemplo n.º 1
0
    def test_CH(self):
        vac = 4
        dist_min = 0.8
        dist_max = 1.9

        a = Atoms('CH', positions=[[0, 0, 0], [dist_min, 0, 0]])
        a.center(vacuum=vac)
        distances = np.linspace(dist_min, dist_max, 1000)

        for potential in [Rebo2(), Rebo2Scr()]:
            a.set_calculator(potential)
            energies = []
            forces = []
            for dist in distances:
                a[1].position[0] = dist + vac
                forces += [a.get_forces()[0][0]]
                energies += [a.get_potential_energy()]

            forces = np.array(forces)
            energies = np.array(energies)
            en_differences = np.abs(energies[1:] - energies[:-1])
            self.assertTrue(np.max(en_differences) < 0.03)
            self.assertTrue(np.max(np.abs(forces[1:] - forces[:-1])) < 0.3)
Exemplo n.º 2
0
    def test_energy(self):
        vac = 8
        dist_min = 1.2

        atoms = Atoms('CC', positions=[[0, 0, 0], [dist_min, 0, 0]])
        atoms.center(vacuum=vac)

        for calc in [Rebo2(), Rebo2Scr()]:
            atoms.calc = calc
            energy = atoms.get_potential_energy()
            forces_ac = atoms.get_forces()
            stress = atoms.get_stress()

            fname = 'structure.traj'
            atoms.write(fname)
            atoms = io.read(fname)

            self.assertTrue(
                np.abs(energy - atoms.get_potential_energy()) < 1e-10)
            self.assertTrue(
                (np.abs(forces_ac - atoms.get_forces()) < 1e-10).all())
            self.assertTrue(
                (np.abs(stress - atoms.get_stress()) < 1e-10).all())