forked from abacusmodeling/abacus-develop
-
Notifications
You must be signed in to change notification settings - Fork 224
Expand file tree
/
Copy pathcellrelax.py
More file actions
76 lines (67 loc) · 2.19 KB
/
cellrelax.py
File metadata and controls
76 lines (67 loc) · 2.19 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
'''
This example shows how to perform a cell-ion joint relaxation with ABACUS
of Si diamond structure.
'''
import shutil
from pathlib import Path # a more Pythonic alternative to the os.path
here = Path(__file__).parent
# to the directory where the pseudopotential and orbital files are stored
# In your case you change to the appropriate one
pporb = here.parent.parent.parent / 'tests' / 'PP_ORB'
from ase.build import bulk
from ase.filters import FrechetCellFilter
from ase.optimize import BFGS
from abacuslite import Abacus, AbacusProfile
# AbacusProfile: the interface connecting the Abacus calculator instance
# with the file system and the enviroment
aprof = AbacusProfile(
command='mpirun -np 4 abacus',
pseudo_dir=pporb,
orbital_dir=pporb,
omp_num_threads=1,
)
# Abacus: the calculator instance
jobdir = here / 'scf'
abacus = Abacus(
profile=aprof,
directory=str(jobdir),
pseudopotentials={'Si': 'Si_ONCV_PBE-1.0.upf'},
basissets={'Si': 'Si_gga_8au_100Ry_2s2p1d.orb'},
inp={
'calculation': 'scf',
'nspin': 1,
'basis_type': 'lcao',
'ks_solver': 'genelpa',
'ecutwfc': 100,
'symmetry': 1,
'kspacing': 0.1,
'cal_force': 1, # let ABACUS calculate the forces
'cal_stress': 1 # let ABACUS calculate the stress
}
)
# get the structure, can also from the
# ```
# from ase.io import read
# atoms = read(...)
# ```
atoms = bulk('Si', 'diamond', a=5.43)
# bind the atoms with the abacus
atoms.calc = abacus
# print the energy before relaxation
print(f'Before: {atoms.get_potential_energy()}')
print(f'Cell: {atoms.get_cell()}')
# perform the relaxation calculation
dyn = BFGS(FrechetCellFilter(atoms), logfile='-')
# or a fixed alpha, beta, gamma relaxation, if you needed
# dyn = BFGS(FrechetCellFilter(
# atoms,
# mask=[True, True, True, False, False, False]
# ), logfile='-')
# the first three mask elements are for the strain,
# the last three are for the shear
dyn.run(fmax=0.05)
# print the energy after relaxation
print(f'After: {atoms.get_potential_energy()}')
print(f'Cell: {atoms.get_cell()}')
# remove the temporary job directory (including all files inside)
shutil.rmtree(jobdir)