Beispiel #1
0
def test_gfn1_xtb_3d():
    """Test ASE interface to GFN1-xTB"""
    thr = 5.0e-6

    atoms = Atoms(
        symbols="C4O8",
        positions=np.array([
            [0.9441259872, 0.9437851680, 0.9543505632],
            [3.7179966528, 0.9556570368, 3.7316862240],
            [3.7159517376, 3.7149292800, 0.9692330016],
            [0.9529872864, 3.7220864832, 3.7296981120],
            [1.6213905408, 1.6190616096, 1.6313879040],
            [0.2656685664, 0.2694175776, 0.2776540416],
            [4.3914553920, 1.6346256864, 3.0545920000],
            [3.0440834880, 0.2764611744, 4.4080419264],
            [4.3910577696, 3.0416409504, 0.2881058304],
            [3.0399936576, 4.3879335936, 1.6497353376],
            [0.2741322432, 4.4003734944, 3.0573754368],
            [1.6312174944, 3.0434586528, 4.4023048032],
        ]),
        cell=np.array([5.68032, 5.68032, 5.68032]),
        pbc=np.array([True, True, True]),
    )
    forces = np.array([
        [-0.08831700, -0.07001294, -0.07468651],
        [-0.03556765, -0.02242341, +0.03047788],
        [+0.03228896, -0.03948204, -0.02892694],
        [-0.02569098, +0.03373080, -0.03161988],
        [-1.90306812, -1.90236730, -1.90612450],
        [+1.98861177, +1.96958105, +1.97849378],
        [-1.88898997, -1.93509024, +1.91692369],
        [+1.92988257, +1.95061533, -1.94116843],
        [-1.93844982, +1.93069254, +1.96026641],
        [+1.91146115, -1.88620597, -1.93901862],
        [+1.94936349, -1.94760369, +1.92150003],
        [-1.93152440, +1.91856587, -1.88611692],
    ])
    stress = np.array([
        +4.49045792e-02,
        +4.49168887e-02,
        +4.49566951e-02,
        +3.38245641e-05,
        +1.52117499e-05,
        +1.13328271e-04,
    ])

    atoms.calc = TBLite(method="GFN1-xTB")
    assert atoms.pbc.all()

    assert approx(atoms.get_potential_energy(), abs=thr) == -1257.0801067985549
    assert approx(atoms.get_forces(), abs=thr) == forces
    assert approx(atoms.get_stress(), abs=thr) == stress
Beispiel #2
0
class TestCalculator_SW_Potential(quippytest.QuippyTestCase):
    def setUp(self):
        self.xml = """
      <SW_params n_types="2" label="PRB_31_plus_H">
      <comment> Stillinger and Weber, Phys. Rev. B  31 p 5262 (1984), extended for other elements </comment>
      <per_type_data type="1" atomic_num="1" />
      <per_type_data type="2" atomic_num="14" />
      <per_pair_data atnum_i="1" atnum_j="1" AA="0.0" BB="0.0"
      p="0" q="0" a="1.0" sigma="1.0" eps="0.0" />
      <per_pair_data atnum_i="1" atnum_j="14" AA="8.581214" BB="0.0327827"
      p="4" q="0" a="1.25" sigma="2.537884" eps="2.1672" />
      <per_pair_data atnum_i="14" atnum_j="14" AA="7.049556277" BB="0.6022245584"
      p="4" q="0" a="1.80" sigma="2.0951" eps="2.1675" />

      <!-- triplet terms: atnum_c is the center atom, neighbours j and k -->
      <per_triplet_data atnum_c="1"  atnum_j="1"  atnum_k="1"
      lambda="21.0" gamma="1.20" eps="2.1675" />
      <per_triplet_data atnum_c="1"  atnum_j="1"  atnum_k="14"
      lambda="21.0" gamma="1.20" eps="2.1675" />
      <per_triplet_data atnum_c="1"  atnum_j="14" atnum_k="14"
      lambda="21.0" gamma="1.20" eps="2.1675" />

      <per_triplet_data atnum_c="14" atnum_j="1"  atnum_k="1"
      lambda="21.0" gamma="1.20" eps="2.1675" />
      <per_triplet_data atnum_c="14" atnum_j="1"  atnum_k="14"
      lambda="21.0" gamma="1.20" eps="2.1675" />
      <per_triplet_data atnum_c="14" atnum_j="14" atnum_k="14"
      lambda="21.0" gamma="1.20" eps="2.1675" />
      </SW_params>
      """

        quippy.system_module.system_reseed_rng(2065775975)
        self.pot_calculator = Potential('IP SW', param_str=self.xml)

        self.at = Atoms('Si8',
                        positions=diamond_pos,
                        pbc=True,
                        cell=[5.44, 5.44, 5.44])

        self.f = np.zeros((3, len(self.at)), order='F')
        self.df = np.zeros((3, len(self.at)), order='F')
        self.v = np.zeros((3, 3), order='F')

        self.energy_ref = -34.5038375509

        self.forces_ref = np.array([[0.89920374, -0.38025157, -0.38727027],
                                    [0.36623356, -0.52403757, 0.7200206],
                                    [-0.36952654, 0.12899529, 0.00458111],
                                    [-0.19912365, -0.1632057, 1.08509495],
                                    [-0.67565314, -0.59410498, -0.47921521],
                                    [0.17097454, 0.5847822, -0.31088749],
                                    [0.43613712, 0.90811269, 0.1600328],
                                    [-0.62824563, 0.03970963, -0.79235649]])

        self.virial_ref = np.array([[-0.34103601, 0.60925144, -0.02138795],
                                    [0.60925144, -0.36145702, -0.19375487],
                                    [-0.02138795, -0.19375487, -0.34640615]]).T

        # Voigt notation by hand from virial
        self.stress_ref = -np.array([
            -0.34103601, -0.36145702, -0.34640615, -0.19375487, -0.02138795,
            0.60925144
        ]) / self.at.get_volume()

        self.at.set_calculator(self.pot_calculator)

    def test_energy(self):
        self.assertAlmostEqual(self.at.get_potential_energy(), self.energy_ref)

    def test_forces(self):
        self.assertArrayAlmostEqual(self.at.get_forces(),
                                    self.forces_ref,
                                    tol=1E-06)

    def test_stress(self):
        self.assertArrayAlmostEqual(self.at.get_stress(), self.stress_ref)

    def test_virial(self):
        self.assertArrayAlmostEqual(self.pot_calculator.get_virial(self.at),
                                    self.virial_ref,
                                    tol=1E-06)

    def test_calc_args_1(self):
        self.pot_calculator.calculate(self.at,
                                      propertes=["forces"],
                                      calc_args="do_rescale_E E_scale=1.01")
        f = self.pot_calculator.results['forces']
        self.assertArrayAlmostEqual(f, self.forces_ref * 1.01, tol=1E-06)

    def test_calc_args_2(self):
        self.pot_calculator.calculate(self.at,
                                      properties=["forces"],
                                      do_rescale_E=True,
                                      E_scale=1.01)
        f = self.pot_calculator.results['forces']
        self.assertArrayAlmostEqual(f, self.forces_ref * 1.01, tol=1E-06)

    def test_calc_args_3(self):
        pot2 = Potential('IP SW',
                         param_str=self.xml,
                         calc_args="do_rescale_E E_scale=1.01")
        f = pot2.get_forces(self.at)
        self.assertArrayAlmostEqual(f, self.forces_ref * 1.01, tol=1E-06)

    def test_calc_args_4(self):
        pot2 = Potential('IP SW',
                         param_str=self.xml,
                         calc_args={
                             'do_rescale_E': True,
                             'E_scale': 1.01
                         })
        f = pot2.get_forces(self.at)
        self.assertArrayAlmostEqual(f, self.forces_ref * 1.01, tol=1E-06)