-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathase_test.py
340 lines (267 loc) · 11.6 KB
/
ase_test.py
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
import os
import sys
import numpy as np
# import writekp
import ase.io
from ase.optimize import BFGS, LBFGS, BFGSLineSearch, QuasiNewton, FIRE
from ase.optimize.sciopt import SciPyFminBFGS, SciPyFminCG
from ase.constraints import StrainFilter, UnitCellFilter
from ase.io.trajectory import Trajectory
atoms = ase.io.read('.'+'/'+'POSCAR')
# atoms = ase.io.read('.'+'/'+'fp_opt.vasp')
ase.io.vasp.write_vasp('input.vasp', atoms, direct = True)
# ase.io.vasp.write_vasp('fp_input.vasp', atoms, direct = True)
trajfile = 'opt.traj'
print("Number of atoms:", len(atoms))
'''
from ase.calculators.vasp import Vasp
import kp_finder
kpoints = kp_finder.get_kpoints(kgrid=0.07)
calc1 = Vasp( command = 'mpirun -n 16 /home/lz432/apps/vasp.6.3.0_intel/bin/vasp_std',
xc = 'PBE',
setups = 'recommended',
txt = 'vasp.out',
prec = 'Normal',
# ediff = 1.0e-8,
# ediffg = -1.0e-5,
encut = 400.0,
ibrion = -1, # No VASP relaxation
nsw = 0, # Max. no of relaxation steps
isif = 3,
ismear = 0,
sigma = 0.05,
potim = 0.2,
# lwave = False,
# lcharge = False,
# lplane = False,
isym = 0,
symprec = 1.0e-7,
npar = 4,
kpts = kpoints,
gamma = True
)
atoms.calc = calc1
print ("VASP_energy:\n", atoms.get_potential_energy())
print ("VASP_forces:\n", atoms.get_forces())
print ("VASP_stress:\n", atoms.get_stress())
###################################################################################################
from ase.calculators.espresso import Espresso
import kp_finder
kpoints = kp_finder.get_kpoints(kgrid=0.07)
pseudopotentials = {'Si': 'Si.pbe-n-rrkjus_psl.1.0.0.UPF'}
path_to_pseudopotentials="$HOME/apps/SSSP_1.3.0_PBE_efficiency"
command = 'mpirun -np 16 $HOME/apps/qe-7.2/bin pw.x -in PREFIX.pwi > PREFIX.pwo'
input_data = {
'control': {
'calculation': 'scf',
'prefix': 'silicon',
'outdir': './',
'etot_conv_thr': 1.0e-5,
'forc_conv_thr': 1.0e-3,
'tstress': True,
'tprnfor': True },
'system': {
'ecutwfc': 50,
'ecutrho': 400,
'occupations': 'smearing',
'smearing': 'gauss',
'degauss': 0.004,
'nosym': True },
'electrons': {
'electron_maxstep': 800,
'diagonalization': 'rmm-davidson',
'mixing_mode': 'local-TF',
'mixing_beta': 0.5,
'conv_thr': 1.0e-6 }
}
calc1 = Espresso(input_data = input_data,
pseudopotentials = pseudopotentials,
kpts = tuple(kpoints))
atoms.calc = calc1
print ("QE_energy:\n", atoms.get_potential_energy())
print ("QE_forces:\n", atoms.get_forces())
print ("QE_stress:\n", atoms.get_stress())
###################################################################################################
from ase.calculators.lj import LennardJones
calc1 = LennardJones()
calc1.parameters.epsilon = 1.0
calc1.parameters.sigma = 1.0
calc1.parameters.rc = 2.5
calc1.parameters.smooth = True
atoms.calc = calc1
print ("LJ_energy:\n", atoms.get_potential_energy())
print ("LJ_forces:\n", atoms.get_forces())
print ("LJ_stress:\n", atoms.get_stress())
##################################################################################################
Sigma gives a measurement of how close two nonbonding particles can get and is thus referred to as the van der Waals radius. It is equal to one-half of the internuclear distance between nonbonding particles.
Ideally, r_min == 2**(1/6) * sigma == 2.0 * r_cov, which means van der Waals radius is approximately two times larger than covalent radius.
Reference:
https://en.wikipedia.org/wiki/Lennard-Jones_potential
https://en.wikipedia.org/wiki/Van_der_Waals_radius
https://en.wikipedia.org/wiki/Covalent_radius
##################################################################################################
##################################################################################################
# OpenKim support for emperical potential access
from ase.calculators.kim.kim import KIM
model = "SW_StillingerWeber_1985_Si__MO_405512056662_006"
calc1 = KIM(model)
atoms.calc = calc1
print ("SW_energy:\n", atoms.get_potential_energy())
print ("SW_forces:\n", atoms.get_forces())
print ("SW_stress:\n", atoms.get_stress())
##################################################################################################
'''
from SF_LJ_api4ase import ShiftedForceLennardJones
calc1 = ShiftedForceLennardJones()
calc1.parameters.epsilon = np.array([1.00, 1.50, 0.50])
calc1.parameters.sigma = np.array([1.00, 0.80, 0.88])
calc1.parameters.rc = 2.5 * np.array([1.00, 0.80, 0.88])
atoms.calc = calc1
print ("SFLJ_energy:\n", atoms.get_potential_energy())
print ("SFLJ_forces:\n", atoms.get_forces())
print ("SFLJ_stress:\n", atoms.get_stress())
'''
########################################## For MgAl_2O_4 ##########################################
from Buck_api4ase import Buckingham
calc1 = Buckingham()
calc1.parameters.ZZ = { 'Mg': 2, 'Al': 3, 'O': -2 }
calc1.parameters.A = np.array([1279.69, 1361.29, 9547.96])
calc1.parameters.rho = np.array([0.2997, 0.3013, 0.2240])
calc1.parameters.C = np.array([0.00, 0.00, 32.0])
calc1.parameters.rc = 10.0
calc1.parameters.smooth = False
atoms.calc = calc1
print ("Buckingham_energy:\n", atoms.get_potential_energy())
print ("Buckingham_forces:\n", atoms.get_forces())
print ("Buckingham_stress:\n", atoms.get_stress())
###################################################################################################
from gulp_api4ase import GULP, Conditions
c = Conditions(atoms)
c.min_distance_rule('O',
'H',
ifcloselabel1='O_OH',
ifcloselabel2='H_OH',
elselabel1='O_O2-')
calc1 = GULP(keywords = 'conp gradient stress_out',
library = 'MgAlSiO.lib',
shel=['O'])
calc1 = GULP(keywords = 'conp gradient stress_out',
library = 'MgAlO.lib')
atoms.calc = calc1
print ("GULP_energy:\n", atoms.get_potential_energy())
print ("GULP_forces:\n", atoms.get_forces())
print ("GULP_stress:\n", atoms.get_stress())
###################################################################################################
from ase.calculators.lammpslib import LAMMPSlib
cmds = ["mass 1 24.305",
"mass 2 26.982",
"mass 3 15.999",
"pair_style buck 10.0",
"pair_coeff * * 0.0 1.0 0.0",
"pair_coeff 1 3 1428.5 0.2945 0.0",
"pair_coeff 2 3 1114.9 0.3118 0.0",
"pair_coeff 3 3 2023.8 0.2674 0.0",
"compute p_eng all pe pair bond",
"compute k_eng all ke",
"compute tmp all temp",
"compute prs all pressure tmp",
"compute strs all stress/atom NULL pair bond",
"fix 1 all box/relax iso 1.0e+5 vmax 0.001",
"thermo 10",
"thermo_style custom step lx ly lz enthalpy etotal",
"dump coord all custom 10 lammps.dump id element x y z",
"dump_modify coord element Mg Al O",
"min_style cg",
"minimize 1e-25 1e-25 5000 10000"]
calc1 = LAMMPSlib(lmpcmds = cmds, log_file = 'lammps.log')
atoms.calc = calc1
print ("lmp_energy:\n", atoms.get_potential_energy())
print ("lmp_forces:\n", atoms.get_forces())
print ("lmp_stress:\n", atoms.get_stress())
###################################################################################################
from quippy.potential import Potential
calc1 = Potential(param_filename='./gp_iter6_sparse9k.xml')
atoms.calc = calc1
print ("GAP_energy:\n", atoms.get_potential_energy())
print ("GAP_forces:\n", atoms.get_forces())
print ("GAP_stress:\n", atoms.get_stress())
# fmax_1 = np.amax(np.absolute(atoms.get_forces()))
###################################################################################################
from ase.calculators.dftb import Dftb
import kp_finder
kpoints = kp_finder.get_kpoints(kgrid=0.07)
calc1 = Dftb(atoms = atoms,
kpts = tuple(kpoints),
label = 'dftb')
atoms.calc = calc1
print ("DFTB_energy:\n", atoms.get_potential_energy())
print ("DFTB_forces:\n", atoms.get_forces())
print ("DFTB_stress:\n", atoms.get_stress())
# fmax_1 = np.amax(np.absolute(atoms.get_forces()))
###################################################################################################
from m3gnet.models._base import Potential
from m3gnet.models._m3gnet import M3GNet
from M3GNet_api4ase import M3GNet_Calculator
calc1 = M3GNet_Calculator(Potential(M3GNet.load()),
compute_stress = True,
stress_weight = 1.0)
atoms.calc = calc1
print ("M3GNet_energy:\n", atoms.get_potential_energy())
print ("M3GNet_forces:\n", atoms.get_forces())
print ("M3GNet_stress:\n", atoms.get_stress())
###################################################################################################
from fplib3_api4ase import fp_GD_Calculator
from functools import reduce
chem_nums = list(atoms.numbers)
znucl_list = reduce(lambda re, x: re+[x] if x not in re else re, chem_nums, [])
ntyp = len(znucl_list)
znucl = np.array(znucl_list, int)
calc1 = fp_GD_Calculator(
cutoff = 6.0,
contract = False,
znucl = znucl,
lmax = 0,
nx = 300,
ntyp = ntyp
)
atoms.calc = calc1
# calc1.test_energy_consistency(atoms = atoms)
# calc1.test_force_consistency(atoms = atoms)
print ("fp_energy:\n", atoms.get_potential_energy())
print ("fp_forces:\n", atoms.get_forces())
print ("fp_stress:\n", atoms.get_stress())
'''
############################## Relaxation type ##############################
# https ://wiki.fysik.dtu.dk/ase/ase/optimize.html#module-optimize #
# https ://wiki.fysik.dtu.dk/ase/ase/constraints.html #
#############################################################################
# af = atoms
# af = StrainFilter(atoms)
# mask = np.ones((3,3), dtype = int) - np.eye(3, dtype = int)
mask = np.eye(3, dtype = int)
af = UnitCellFilter(atoms, mask = mask, constant_volume = True, scalar_pressure = 0.0)
############################## Relaxation method ##############################\
# opt = BFGS(af, maxstep = 1.e-1, trajectory = trajfile)
opt = FIRE(af, maxstep = 1.e-1, trajectory = trajfile)
# opt = LBFGS(af, maxstep = 1.e-1, trajectory = trajfile, memory = 10, use_line_search = True)
# opt = LBFGS(af, maxstep = 1.e-1, trajectory = trajfile, memory = 10, use_line_search = False)
# opt = SciPyFminCG(af, maxstep = 1.e-1, trajectory = trajfile)
# opt = SciPyFminBFGS(af, maxstep = 1.e-1, trajectory = trajfile)
opt.run(fmax = 1.e-3, steps = 5000)
traj = Trajectory(trajfile)
atoms_final = traj[-1]
ase.io.write('opt.vasp', atoms_final, direct = True, long_format=True, vasp5 = True)
final_cell = atoms.get_cell()
final_cell_par = atoms.cell.cellpar()
final_structure = atoms.get_scaled_positions()
final_energy_per_atom = float( atoms.get_potential_energy() / len(atoms_final) )
final_stress = atoms.get_stress()
print("Relaxed lattice vectors are \n{0:s}".\
format(np.array_str(final_cell, precision=6, suppress_small=False)))
print("Relaxed cell parameters are \n{0:s}".\
format(np.array_str(final_cell_par, precision=6, suppress_small=False)))
print("Relaxed structure in fractional coordinates is \n{0:s}".\
format(np.array_str(final_structure, precision=6, suppress_small=False)))
print("Final energy per atom is \n{0:.6f}".format(final_energy_per_atom))
print("Final stress is \n{0:s}".\
format(np.array_str(final_stress, precision=6, suppress_small=False)))