File: test_water.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 (36 lines) | stat: -rw-r--r-- 1,140 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
# fmt: off
from ase.atoms import Atoms
from ase.calculators.gaussian import Gaussian
from ase.io import read
from ase.optimize.lbfgs import LBFGS


def test_water(gaussian_factory):
    # First test to make sure Gaussian works
    calc = Gaussian(xc='pbe', chk='water.chk', label='water')
    calc.clean()

    water = Atoms('OHH',
                  positions=[(0, 0, 0), (1, 0, 0), (0, 1, 0)],
                  calculator=calc)

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

    forces = water.get_forces()
    energy = water.get_potential_energy()
    positions = water.get_positions()

    # Then test the IO routines
    water2 = read('water.log')
    forces2 = water2.get_forces()
    energy2 = water2.get_potential_energy()
    positions2 = water2.get_positions()
    # Compare distances since positions are different in standard orientation.
    dist = water.get_all_distances()
    dist2 = read('water.log', index=-1).get_all_distances()

    assert abs(energy - energy2) < 1e-7
    assert abs(forces - forces2).max() < 1e-9
    assert abs(positions - positions2).max() < 1e-6
    assert abs(dist - dist2).max() < 1e-6