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


    # 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)

    opt = LBFGS(water)
    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