Statistiques
| Révision :

root / ase / test / vasp_co.py @ 1

Historique | Voir | Annoter | Télécharger (1,74 ko)

1
#!/usr/bin/python
2

    
3
"""
4
Run some VASP tests to ensure that the VASP calculator works. This
5
is conditional on the existence of the VASP_COMMAND or VASP_SCRIPT
6
environment variables
7

8
"""
9

    
10
from ase.test import NotAvailable
11
import os
12

    
13
vcmd = os.getenv('VASP_COMMAND')
14
vscr = os.getenv('VASP_SCRIPT')
15
if vcmd == None and vscr == None:
16
    raise NotAvailable('Neither VASP_COMMAND nor VASP_SCRIPT defined')
17

    
18
from ase import Atoms
19
from ase.calculators.vasp import Vasp
20
import numpy as np
21

    
22
def array_almost_equal(a1, a2, tol=np.finfo(type(1.0)).eps):
23
    """Replacement for old numpy.testing.utils.array_almost_equal."""
24
    return (np.abs(a1 - a2) < tol).all()
25

    
26
d = 1.14
27
co = Atoms('CO', positions=[(0, 0, 0), (0, 0, d)],
28
              pbc=True)
29
co.center(vacuum=5.)
30

    
31
calc = Vasp(
32
            xc = 'PBE',
33
            prec = 'Low',
34
            algo = 'Fast',
35
            ismear= 0,
36
            sigma = 1.,
37
            lwave = False,
38
            lcharg = False)
39

    
40
co.set_calculator(calc)
41
en = co.get_potential_energy()
42
assert abs(en + 14.918933) < 1e-4
43

    
44
# Secondly, check that restart from the previously created VASP output works
45

    
46
calc2 = Vasp(restart=True)
47
co2 = calc2.get_atoms()
48

    
49
# Need tolerance of 1e-14 because VASP itself changes coordinates
50
# slightly between reading POSCAR and writing CONTCAR even if no ionic
51
# steps are made.
52
assert array_almost_equal(co.positions, co2.positions, 1e-14)
53

    
54
assert en - co2.get_potential_energy() == 0.
55
assert array_almost_equal(calc.get_stress(co), calc2.get_stress(co2))
56
assert array_almost_equal(calc.get_forces(co), calc2.get_forces(co2))
57
assert array_almost_equal(calc.get_eigenvalues(), calc2.get_eigenvalues())
58
assert calc.get_number_of_bands() == calc2.get_number_of_bands()
59
assert calc.get_xc_functional() == calc2.get_xc_functional()