root / ase / test / vasp_Al_volrelax.py @ 1
Historique | Voir | Annoter | Télécharger (2,23 ko)
1 |
#!/usr/bin/python
|
---|---|
2 |
|
3 |
"""
|
4 |
Run VASP tests to ensure that relaxation with the VASP calculator works.
|
5 |
This 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 |
import numpy as np |
19 |
from ase import io |
20 |
from ase.optimize import QuasiNewton |
21 |
from ase.constraints import StrainFilter |
22 |
from ase.structure import bulk |
23 |
from ase.calculators.vasp import Vasp |
24 |
|
25 |
# -- Perform Volume relaxation within Vasp
|
26 |
def vasp_vol_relax(): |
27 |
Al = bulk('Al', 'fcc', a=4.5, cubic=True) |
28 |
calc = Vasp(xc='LDA', isif=7, nsw=5, |
29 |
ibrion=1, ediffg=-1e-3, lwave=False, lcharg=False) |
30 |
calc.calculate(Al) |
31 |
|
32 |
# Explicitly parse atomic position output file from Vasp
|
33 |
CONTCAR_Al = io.read('CONTCAR', format='vasp') |
34 |
|
35 |
print 'Stress after relaxation:\n', calc.read_stress() |
36 |
|
37 |
print 'Al cell post relaxation from calc:\n', calc.get_atoms().get_cell() |
38 |
print 'Al cell post relaxation from atoms:\n', Al.get_cell() |
39 |
print 'Al cell post relaxation from CONTCAR:\n', CONTCAR_Al.get_cell() |
40 |
|
41 |
# All the cells should be the same.
|
42 |
assert (calc.get_atoms().get_cell() == CONTCAR_Al.get_cell()).all()
|
43 |
assert (Al.get_cell() == CONTCAR_Al.get_cell()).all()
|
44 |
|
45 |
return Al
|
46 |
|
47 |
# -- Perform Volume relaxation using ASE with Vasp as force/stress calculator
|
48 |
def ase_vol_relax(): |
49 |
Al = bulk('Al', 'fcc', a=4.5, cubic=True) |
50 |
calc = Vasp(xc='LDA')
|
51 |
Al.set_calculator(calc) |
52 |
|
53 |
from ase.constraints import StrainFilter |
54 |
sf = StrainFilter(Al) |
55 |
qn = QuasiNewton(sf, logfile='relaxation.log')
|
56 |
qn.run(fmax=0.1, steps=5) |
57 |
|
58 |
print 'Stress:\n', calc.read_stress() |
59 |
print 'Al post ASE volume relaxation\n', calc.get_atoms().get_cell() |
60 |
|
61 |
return Al
|
62 |
|
63 |
# Test function for comparing two cells
|
64 |
def cells_almost_equal(cellA, cellB, tol=0.01): |
65 |
return (np.abs(cellA - cellB) < tol).all()
|
66 |
|
67 |
# Correct LDA relaxed cell
|
68 |
a_rel = 4.18
|
69 |
LDA_cell = np.diag([a_rel, a_rel, a_rel]) |
70 |
|
71 |
Al_vasp = vasp_vol_relax() |
72 |
Al_ase = ase_vol_relax() |
73 |
|
74 |
assert cells_almost_equal(LDA_cell, Al_vasp.get_cell())
|
75 |
assert cells_almost_equal(LDA_cell, Al_ase.get_cell())
|