File: test_eos.py

package info (click to toggle)
python-ase 3.22.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 14,344 kB
  • sloc: python: 126,379; xml: 946; makefile: 111; javascript: 47
file content (34 lines) | stat: -rw-r--r-- 1,072 bytes parent folder | download | duplicates (2)
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
def test_eos():
    import numpy as np
    import scipy  # skip test early if no scipy
    from ase.build import bulk
    from ase.calculators.emt import EMT
    from ase.eos import EquationOfState as EOS, eos_names
    scipy  # silence pyflakes

    b = bulk('Al', 'fcc', a=4.0, orthorhombic=True)
    b.calc = EMT()
    cell = b.get_cell()

    volumes = []
    energies = []
    for x in np.linspace(0.98, 1.01, 5):
        b.set_cell(cell * x, scale_atoms=True)
        volumes.append(b.get_volume())
        energies.append(b.get_potential_energy())

    results = []
    for name in eos_names:
        if name == 'antonschmidt':
            # Someone should fix this!
            continue
        eos = EOS(volumes, energies, name)
        v, e, b = eos.fit()
        print('{0:20} {1:.8f} {2:.8f} {3:.8f} '.format(name, v, e, b))
        assert abs(v - 3.18658700e+01) < 4e-4
        assert abs(e - -9.76187802e-03) < 5e-7
        assert abs(b - 2.46812688e-01) < 2e-4
        results.append((v, e, b))

    print(np.ptp(results, 0))
    print(np.mean(results, 0))