File: test_orca.py

package info (click to toggle)
python-ase 3.26.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,484 kB
  • sloc: python: 148,112; xml: 2,728; makefile: 110; javascript: 47
file content (101 lines) | stat: -rw-r--r-- 2,800 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# fmt: off
import re

import numpy as np
import pytest

from ase.atoms import Atoms
from ase.calculators.orca import get_version_from_orca_header
from ase.optimize import BFGS
from ase.units import Hartree

calc = pytest.mark.calculator


@pytest.fixture()
def txt1():
    return '               Program Version 4.1.2  - RELEASE  -'


@pytest.fixture()
def ref1():
    return '4.1.2'


def test_orca_version_from_string(txt1, ref1):
    version = get_version_from_orca_header(txt1)
    assert version == ref1


# @calc('orca') #somehow this test only works with static factory fixture
def test_orca_version_from_executable(orca_factory):
    # only check the format to be compatible with future versions
    version_regexp = re.compile(r'\d+.\d+.\d+')
    version = orca_factory.version()

    assert version_regexp.match(version)


@calc('orca')
def test_ohh(factory):
    atoms = Atoms('OHH',
                  positions=[(0, 0, 0), (1, 0, 0), (0, 1, 0)])

    atoms.calc = factory.calc(orcasimpleinput='BLYP def2-SVP')


@pytest.fixture()
def water():
    return Atoms('OHH', positions=[(0, 0, 0), (1, 0, 0), (0, 1, 0)])


@calc('orca')
def test_orca(water, factory):
    water.calc = factory.calc(label='water',
                              orcasimpleinput='BLYP def2-SVP Engrad')

    with BFGS(water) as opt:
        opt.run(fmax=0.05)

    final_energy = water.get_potential_energy()
    final_dipole = water.get_dipole_moment()

    np.testing.assert_almost_equal(final_energy, -2077.24420, decimal=0)
    np.testing.assert_almost_equal(
        final_dipole, [0.28669234, 0.28669234, 0.], decimal=6)


@pytest.mark.parametrize('charge', [-2, 0])
@calc('orca')
def test_orca_charged_dipole(water, factory, charge):
    # Make sure that dipole obeys the correct translation symmetry
    water.calc = factory.calc(label='water',
                              charge=charge,
                              orcasimpleinput='BLYP def2-SVP Engrad')

    displacement = np.array([0.2, 1.5, -4.2])
    dipole = water.get_dipole_moment()
    water.translate(displacement)
    new_dipole = water.get_dipole_moment()

    np.testing.assert_almost_equal(
        dipole + charge * displacement, new_dipole, decimal=4)


@calc('orca')
def test_orca_sp(water, factory):
    water.calc = factory.calc(label='water', orcasimpleinput='BLYP def2-SVP',
                              task="SP")

    final_energy = water.get_potential_energy()
    np.testing.assert_almost_equal(final_energy, -2077.24420, decimal=0)


@calc('orca')
def test_orca_use_last_energy(water, factory):
    water.calc = factory.calc(
        label='water',
        orcasimpleinput='PBE def2-SVP Opt TightOpt')
    energy = water.get_potential_energy() / Hartree

    np.testing.assert_almost_equal(energy, -76.272686944630, decimal=6)