Skip to content

Commit 33b6364

Browse files
author
root
committed
support to read coord/cell from STRU_ION*_D in abacus/relax
1 parent 26171f2 commit 33b6364

18 files changed

Lines changed: 2559 additions & 4 deletions

File tree

dpdata/abacus/relax.py

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
import os
3+
import os, glob
44

55
import numpy as np
66

@@ -30,8 +30,22 @@ def get_log_file(fname, inlines):
3030
logf = os.path.join(fname, f"OUT.{suffix}/running_{calculation}.log")
3131
return logf
3232

33+
def get_relax_stru_files(output_dir):
34+
"""Find the STRU files in the output directory.
35+
36+
Args:
37+
output_dir (str): output directory
38+
39+
returns:
40+
strus: list of STRU files
41+
42+
example:
43+
["STRU_ION1_D", "STRU_ION2_D"]
44+
"""
45+
return glob.glob(os.path.join(output_dir, "STRU_ION*_D"))
46+
3347

34-
def get_coords_from_log(loglines, natoms):
48+
def get_coords_from_log(loglines, natoms, stru_files=[]):
3549
"""NOTICE: unit of coords and cells is Angstrom
3650
order:
3751
coordinate
@@ -101,6 +115,24 @@ def get_coords_from_log(loglines, natoms):
101115
# get the energy of current structure
102116
energy.append(float(line.split()[-2]))
103117

118+
# in some relax method (like: bfgs_trad), the coordinate is not outputed in running_relax.log
119+
# but if out_stru is true, then STRU_ION*_D will be outputed in OUT.ABACUS
120+
# we should read cell and coord from STRU_ION*_D files
121+
if len(energy) > 1 and len(coords) == 1:
122+
# the energies of all structrues are collected, but coords have only the first structure
123+
if len(stru_files) > 1: # if stru_files are not only STRU_ION_D
124+
stru_file_name = [os.path.basename(i) for i in stru_files]
125+
coords = coords[:1] + [np.nan for i in range(len(energy)-1)]
126+
coord_direct = coord_direct[:1] + [False for i in range(len(energy)-1)]
127+
cells = cells[:1] + [np.nan for i in range(len(energy)-1)]
128+
for iframe in range(1, len(energy)):
129+
if f"STRU_ION{iframe}_D" in stru_file_name:
130+
# read the structure from STRU_ION*_D
131+
stru_data = get_frame_from_stru(stru_files[stru_file_name.index(f"STRU_ION{iframe}_D")])
132+
coords[iframe] = stru_data["coords"][0]
133+
cells[iframe] = stru_data["cells"][0]
134+
135+
104136
force = collect_force(loglines)
105137
stress = collect_stress(loglines)
106138

@@ -133,7 +165,7 @@ def get_coords_from_log(loglines, natoms):
133165

134166
# delete structures whose energy is np.nan
135167
for i in range(minl):
136-
if np.isnan(energy[i - minl]):
168+
if np.isnan(energy[i - minl]) or np.any(np.isnan(coords[i - minl])) or np.any(np.isnan(cells[i - minl])):
137169
del energy[i - minl]
138170
del coords[i - minl]
139171
del cells[i - minl]
@@ -191,7 +223,10 @@ def get_frame(fname):
191223
with open_file(logf) as f1:
192224
lines = f1.readlines()
193225

194-
energy, cells, coords, force, stress, virial = get_coords_from_log(lines, natoms)
226+
relax_stru_files = get_relax_stru_files(os.path.dirname(logf))
227+
228+
energy, cells, coords, force, stress, virial = get_coords_from_log(lines, natoms, stru_files=relax_stru_files)
229+
195230

196231
magmom, magforce = get_mag_force(lines)
197232

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
INPUT_PARAMETERS RUNNING ABACUS-DFT
2+
3+
#Parameters (1.General)
4+
suffix ABACUS # suffix of OUTPUT DIR
5+
nspin 1 # 1/2/4
6+
symmetry 0 # 0/1
7+
esolver_type ksdft # ksdft/ofdft/sdft/tddft/lj/dp
8+
dft_functional pbe # lda/pbe/scan/hf/pbe0/hse/libxc
9+
ks_solver genelpa # genelpa/scalapack_avx for lcao, cg/dav for pw
10+
vdw_method none # d3/d3_bj/none
11+
12+
#Parameters (2.Iteration)
13+
calculation cell-relax # scf/relax/cell-relax/md
14+
ecutwfc 100 # Rydberg, in lcao is for grid density
15+
scf_thr 1e-7 # Rydberg
16+
scf_nmax 100
17+
#printe 300 # default eq scf_nmax
18+
relax_nmax 30
19+
relax_method bfgs_trad # cg/bfgs/bfgs_trad/sd/"fire"
20+
force_thr_ev 0.05
21+
# stress_thr 1 # GPa
22+
23+
#Parameters (3.Basis)
24+
basis_type lcao # lcao or pw
25+
# kspacing 0.14 0.50 0.14 # replace KPT
26+
gamma_only 1 # 0/1, replace KPT
27+
28+
#Parameters (4.Smearing)
29+
smearing_method mp # mp/gauss/fixed/mp-n/fd
30+
smearing_sigma 0.008 # Rydberg
31+
32+
#Parameters (5.Mixing)
33+
mixing_type broyden # pulay/broyden
34+
mixing_ndim 20
35+
#mixing_beta 0.4 # use default
36+
#mixing_gg0 1.0 # use default
37+
38+
#Parameters (6.Calculation)
39+
cal_force 1
40+
cal_stress 1
41+
#init_chg atomic # atomic/auto/file
42+
#init_wfc atomic # atomic/file
43+
out_stru 1 # print STRU in OUT
44+
out_chg -1 # -1 no, 0 binary, 1 cube, more number as cube prec
45+
out_bandgap 1
46+
out_mul 1 # print charge and mag of atom in mulliken.txt
47+
# out_wfc_lcao 0 # 0 no, 1 txt, 2 dat
48+
49+
50+
# #Parameters (7. Dipole Correction)
51+
# efield_flag 1 # open added potential, if 0, all below useless
52+
# dip_cor_flag 1 # open dipole correction
53+
# efield_dir 1 # direction of dipole correction, 0,1,2 for x,y,z
54+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
K_POINTS
2+
0
3+
Gamma
4+
1 1 1 0 0 0
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
ATOMIC_SPECIES
2+
Ga 69.7230 Ga.upf upf201
3+
As 74.9216 As.PD04.PBE.UPF upf201
4+
5+
NUMERICAL_ORBITAL
6+
Ga_gga_7au_100Ry_2s2p2d1f.orb
7+
As_gga_8au_100Ry_2s2p1d.orb
8+
9+
LATTICE_CONSTANT
10+
1.8897160000
11+
12+
LATTICE_VECTORS
13+
5.9515362652 -0.0000000000 0.0000000000
14+
-0.0000000000 5.9515362652 -0.0000000000
15+
0.0000000000 -0.0000000000 5.9515362652
16+
17+
ATOMIC_POSITIONS
18+
Direct
19+
20+
Ga #label
21+
0.0000 #magnetism
22+
4 #number of atoms
23+
1.0000000000 0.0000000000 1.0000000000 m 1 1 1
24+
1.0000000000 0.5000000000 0.5000000000 m 1 1 1
25+
0.5000000000 0.0000000000 0.5000000000 m 1 1 1
26+
0.5000000000 0.5000000000 1.0000000000 m 1 1 1
27+
28+
As #label
29+
0.0000 #magnetism
30+
4 #number of atoms
31+
0.2500000000 0.2500000000 0.2500000000 m 1 1 1
32+
0.2500000000 0.7500000000 0.7500000000 m 1 1 1
33+
0.7500000000 0.2500000000 0.7500000000 m 1 1 1
34+
0.7500000000 0.7500000000 0.2500000000 m 1 1 1
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
ATOMIC_SPECIES
2+
Ga 69.7230 Ga.upf upf201
3+
As 74.9216 As.PD04.PBE.UPF upf201
4+
5+
NUMERICAL_ORBITAL
6+
Ga_gga_7au_100Ry_2s2p2d1f.orb
7+
As_gga_8au_100Ry_2s2p1d.orb
8+
9+
LATTICE_CONSTANT
10+
1.8897160000
11+
12+
LATTICE_VECTORS
13+
6.5556050607 -0.0000000000 0.0000000000
14+
-0.0000000000 6.5556050607 -0.0000000000
15+
0.0000000000 -0.0000000000 6.5556050607
16+
17+
ATOMIC_POSITIONS
18+
Direct
19+
20+
Ga #label
21+
0.0000 #magnetism
22+
4 #number of atoms
23+
1.0000000000 0.0000000000 1.0000000000 m 1 1 1
24+
1.0000000000 0.5000000000 0.5000000000 m 1 1 1
25+
0.5000000000 0.0000000000 0.5000000000 m 1 1 1
26+
0.5000000000 0.5000000000 1.0000000000 m 1 1 1
27+
28+
As #label
29+
0.0000 #magnetism
30+
4 #number of atoms
31+
0.2500000000 0.2500000000 0.2500000000 m 1 1 1
32+
0.2500000000 0.7500000000 0.7500000000 m 1 1 1
33+
0.7500000000 0.2500000000 0.7500000000 m 1 1 1
34+
0.7500000000 0.7500000000 0.2500000000 m 1 1 1
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
ATOMIC_SPECIES
2+
Ga 69.7230 Ga.upf upf201
3+
As 74.9216 As.PD04.PBE.UPF upf201
4+
5+
NUMERICAL_ORBITAL
6+
Ga_gga_7au_100Ry_2s2p2d1f.orb
7+
As_gga_8au_100Ry_2s2p1d.orb
8+
9+
LATTICE_CONSTANT
10+
1.8897160000
11+
12+
LATTICE_VECTORS
13+
6.3401004195 -0.0000000000 0.0000000000
14+
-0.0000000000 6.3401004195 -0.0000000000
15+
0.0000000000 -0.0000000000 6.3401004195
16+
17+
ATOMIC_POSITIONS
18+
Direct
19+
20+
Ga #label
21+
0.0000 #magnetism
22+
4 #number of atoms
23+
1.0000000000 0.0000000000 1.0000000000 m 1 1 1
24+
1.0000000000 0.5000000000 0.5000000000 m 1 1 1
25+
0.5000000000 0.0000000000 0.5000000000 m 1 1 1
26+
0.5000000000 0.5000000000 1.0000000000 m 1 1 1
27+
28+
As #label
29+
0.0000 #magnetism
30+
4 #number of atoms
31+
0.2500000000 0.2500000000 0.2500000000 m 1 1 1
32+
0.2500000000 0.7500000000 0.7500000000 m 1 1 1
33+
0.7500000000 0.2500000000 0.7500000000 m 1 1 1
34+
0.7500000000 0.7500000000 0.2500000000 m 1 1 1
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
ATOMIC_SPECIES
2+
Ga 69.7230 Ga.upf upf201
3+
As 74.9216 As.PD04.PBE.UPF upf201
4+
5+
NUMERICAL_ORBITAL
6+
Ga_gga_7au_100Ry_2s2p2d1f.orb
7+
As_gga_8au_100Ry_2s2p1d.orb
8+
9+
LATTICE_CONSTANT
10+
1.8897160000
11+
12+
LATTICE_VECTORS
13+
6.1458183424 -0.0000000000 0.0000000000
14+
-0.0000000000 6.1458183424 -0.0000000000
15+
0.0000000000 -0.0000000000 6.1458183424
16+
17+
ATOMIC_POSITIONS
18+
Direct
19+
20+
Ga #label
21+
0.0000 #magnetism
22+
4 #number of atoms
23+
1.0000000000 0.0000000000 1.0000000000 m 1 1 1
24+
1.0000000000 0.5000000000 0.5000000000 m 1 1 1
25+
0.5000000000 0.0000000000 0.5000000000 m 1 1 1
26+
0.5000000000 0.5000000000 1.0000000000 m 1 1 1
27+
28+
As #label
29+
0.0000 #magnetism
30+
4 #number of atoms
31+
0.2500000000 0.2500000000 0.2500000000 m 1 1 1
32+
0.2500000000 0.7500000000 0.7500000000 m 1 1 1
33+
0.7500000000 0.2500000000 0.7500000000 m 1 1 1
34+
0.7500000000 0.7500000000 0.2500000000 m 1 1 1
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
ATOMIC_SPECIES
2+
Ga 69.7230 Ga.upf upf201
3+
As 74.9216 As.PD04.PBE.UPF upf201
4+
5+
NUMERICAL_ORBITAL
6+
Ga_gga_7au_100Ry_2s2p2d1f.orb
7+
As_gga_8au_100Ry_2s2p1d.orb
8+
9+
LATTICE_CONSTANT
10+
1.8897160000
11+
12+
LATTICE_VECTORS
13+
6.2881167169 -0.0000000039 -0.0000000010
14+
-0.0000000039 6.2881167169 0.0000000005
15+
-0.0000000010 0.0000000005 6.2881167191
16+
17+
ATOMIC_POSITIONS
18+
Direct
19+
20+
Ga #label
21+
0.0000 #magnetism
22+
4 #number of atoms
23+
0.0000000081 0.9999999941 0.9999999959 m 1 1 1
24+
0.0000000081 0.5000000079 0.5000000109 m 1 1 1
25+
0.4999999941 0.9999999941 0.5000000109 m 1 1 1
26+
0.4999999941 0.5000000079 0.9999999959 m 1 1 1
27+
28+
As #label
29+
0.0000 #magnetism
30+
4 #number of atoms
31+
0.2499999989 0.2499999990 0.2499999966 m 1 1 1
32+
0.2499999989 0.7499999990 0.7499999966 m 1 1 1
33+
0.7499999989 0.2499999990 0.7499999966 m 1 1 1
34+
0.7499999989 0.7499999990 0.2499999966 m 1 1 1
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
ATOMIC_SPECIES
2+
Ga 69.7230 Ga.upf upf201
3+
As 74.9216 As.PD04.PBE.UPF upf201
4+
5+
NUMERICAL_ORBITAL
6+
Ga_gga_7au_100Ry_2s2p2d1f.orb
7+
As_gga_8au_100Ry_2s2p1d.orb
8+
9+
LATTICE_CONSTANT
10+
1.8897160000
11+
12+
LATTICE_VECTORS
13+
6.2881167169 -0.0000000039 -0.0000000010
14+
-0.0000000039 6.2881167169 0.0000000005
15+
-0.0000000010 0.0000000005 6.2881167191
16+
17+
ATOMIC_POSITIONS
18+
Direct
19+
20+
Ga #label
21+
0.0000 #magnetism
22+
4 #number of atoms
23+
0.0000000081 0.9999999941 0.9999999959 m 1 1 1
24+
0.0000000081 0.5000000079 0.5000000109 m 1 1 1
25+
0.4999999941 0.9999999941 0.5000000109 m 1 1 1
26+
0.4999999941 0.5000000079 0.9999999959 m 1 1 1
27+
28+
As #label
29+
0.0000 #magnetism
30+
4 #number of atoms
31+
0.2499999989 0.2499999990 0.2499999966 m 1 1 1
32+
0.2499999989 0.7499999990 0.7499999966 m 1 1 1
33+
0.7499999989 0.2499999990 0.7499999966 m 1 1 1
34+
0.7499999989 0.7499999990 0.2499999966 m 1 1 1

0 commit comments

Comments
 (0)