File: test_optimizer_irc.py

package info (click to toggle)
python-ase 3.21.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 13,936 kB
  • sloc: python: 122,428; xml: 946; makefile: 111; javascript: 47
file content (58 lines) | stat: -rw-r--r-- 1,892 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
import pytest
from ase import Atoms
from ase.io import read
from ase.calculators.gaussian import Gaussian, GaussianOptimizer, GaussianIRC
from ase.optimize import LBFGS


@pytest.fixture
def atoms():
    return Atoms('CHO',
                 [[0.0, 0.0, 0.0],
                  [0.0, 0.0, 1.35],
                  [1.178513, 0.0, -0.416662]],
                 magmoms=[0.5, 0.0, 0.5])


def get_calc(**kwargs):
    kwargs.update(mem='100MW', method='hf', basis='sto-3g')
    return Gaussian(**kwargs)


def test_optimizer(atoms):
    pos = atoms.positions.copy()
    atoms.calc = get_calc(label='opt', scf='qc')
    opt_gauss = GaussianOptimizer(atoms)
    opt_gauss.run(fmax='tight')
    e_gaussopt = read('opt.log', index=-1).get_potential_energy()

    atoms.positions[:] = pos
    atoms.calc.set_label('sp')
    opt_ase = LBFGS(atoms)
    opt_ase.run(fmax=1e-2)
    e_aseopt = atoms.get_potential_energy()
    assert e_gaussopt - e_aseopt == pytest.approx(0., abs=1e-3)


def test_irc(atoms):
    calc_ts = get_calc(label='ts', chk='ts.chk')
    ts = GaussianOptimizer(atoms, calc_ts)
    ts.run(opt='calcall,ts,noeigentest')
    tspos = atoms.positions.copy()

    atoms.calc = get_calc(label='sp', chk='sp.chk', freq='')
    e_ts = atoms.get_potential_energy()

    calc_irc_for = get_calc(label='irc_for', oldchk='sp', chk='irc_for.chk')
    irc_for = GaussianIRC(atoms, calc_irc_for)
    irc_for.run(direction='forward', irc='rcfc')
    e_for = read('irc_for.log', index=-1).get_potential_energy()

    atoms.positions[:] = tspos
    calc_irc_rev = get_calc(label='irc_rev', oldchk='sp', chk='irc_rev.chk')
    irc_rev = GaussianIRC(atoms, calc_irc_rev)
    irc_rev.run(direction='reverse', irc='rcfc')
    e_rev = read('irc_rev.log', index=-1).get_potential_energy()

    assert e_ts - e_for == pytest.approx(1.282, abs=1e-3)
    assert e_ts - e_rev == pytest.approx(0.201, abs=1e-3)