Skip to content

Commit 3c09356

Browse files
pxlxingliangpre-commit-ci[bot]njzjz
authored
fix(abacus): fix bug in read LATTICE_CONSTANT in md (#450)
In ABACUS version >= v3.1.4, the format of file "MD_dump" is different. The lattice constant line is added by the unit "Angstrom" at the end, and the position is the real cartesian coordinate. MD_dump is changed from ``` MDSTEP: 0 LATTICE_CONSTANT: 23.453780000000 LATTICE_VECTORS 1.000000000000 0.000000000000 0.000000000000 0.000000000000 1.000000000000 0.000000000000 0.000000000000 0.000000000000 1.000000000000 VIRIAL (KBAR) 36.689617311102 0.000000000001 -0.000000000000 0.000000000001 36.689617311104 -0.000000000001 -0.000000000000 -0.000000000001 36.689617311147 INDEX LABEL POSITIONS FORCE (eV/Angstrom) 0 Sn 0.000000000000 0.000000000000 0.000000000000 -0.000000000000 0.000000000000 -0.000000000000 1 Sn 0.000000000000 0.250000000000 0.250000000000 -0.000186795145 -0.000453823732 -0.000453823732 ``` to ``` MDSTEP: 0 LATTICE_CONSTANT: 12.411200939060 Angstrom LATTICE_VECTORS 1.000000000000 0.000000000000 0.000000000000 0.000000000000 1.000000000000 0.000000000000 0.000000000000 0.000000000000 1.000000000000 VIRIAL (kbar) 36.689617311101 0.000000000003 -0.000000000000 0.000000000003 36.689617311089 -0.000000000001 -0.000000000000 -0.000000000001 36.689617311135 INDEX LABEL POSITION (Angstrom) FORCE (eV/Angstrom) VELOCITY (Angstrom/fs) 0 Sn 0.000000000000 0.000000000000 0.000000000000 -0.000000000000 -0.000000000001 -0.000000000001 0.001244557166 -0.000346684288 0.000768457739 1 Sn 0.000000000000 3.102800034079 3.102800034079 -0.000186795145 -0.000453823768 -0.000453823768 0.000550996187 -0.000886442775 0.001579501983 ``` --------- Signed-off-by: pxlxingliang <91927439+pxlxingliang@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
1 parent 593bb1e commit 3c09356

9 files changed

Lines changed: 5454 additions & 68 deletions

File tree

dpdata/abacus/md.py

Lines changed: 31 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
import re
32
import warnings
43

54
import numpy as np
@@ -68,69 +67,51 @@ def get_coords_from_dump(dumplines, natoms):
6867
for iline in range(nlines):
6968
if "MDSTEP" in dumplines[iline]:
7069
# read in LATTICE_CONSTANT
71-
celldm = float(dumplines[iline + 1].split(" ")[-1])
70+
# for abacus version >= v3.1.4, the unit is angstrom, and "ANGSTROM" is added at the end
71+
# for abacus version < v3.1.4, the unit is bohr
72+
celldm = float(dumplines[iline + 1].split()[1])
73+
newversion = True
74+
if "Angstrom" not in dumplines[iline + 1]:
75+
celldm *= bohr2ang # transfer unit to ANGSTROM
76+
newversion = False
77+
7278
# read in LATTICE_VECTORS
7379
for ix in range(3):
7480
cells[iframe, ix] = (
75-
np.array(
76-
[
77-
float(i)
78-
for i in re.split("\s+", dumplines[iline + 3 + ix])[-3:]
79-
]
80-
)
81+
np.array([float(i) for i in dumplines[iline + 3 + ix].split()[0:3]])
8182
* celldm
8283
)
8384
if calc_stress:
8485
stresses[iframe, ix] = np.array(
85-
[
86-
float(i)
87-
for i in re.split("\s+", dumplines[iline + 7 + ix])[-3:]
88-
]
86+
[float(i) for i in dumplines[iline + 7 + ix].split()[0:3]]
8987
)
88+
89+
if calc_stress:
90+
skipline = 11
91+
else:
92+
skipline = 7
93+
9094
for iat in range(total_natoms):
91-
if calc_stress:
92-
coords[iframe, iat] = (
93-
np.array(
94-
[
95-
float(i)
96-
for i in re.split("\s+", dumplines[iline + 11 + iat])[
97-
-6:-3
98-
]
99-
]
100-
)
101-
* celldm
102-
)
103-
forces[iframe, iat] = np.array(
104-
[
105-
float(i)
106-
for i in re.split("\s+", dumplines[iline + 11 + iat])[-3:]
107-
]
108-
)
109-
else:
110-
coords[iframe, iat] = (
111-
np.array(
112-
[
113-
float(i)
114-
for i in re.split("\s+", dumplines[iline + 7 + iat])[
115-
-6:-3
116-
]
117-
]
118-
)
119-
* celldm
120-
)
121-
forces[iframe, iat] = np.array(
122-
[
123-
float(i)
124-
for i in re.split("\s+", dumplines[iline + 7 + iat])[-3:]
125-
]
126-
)
95+
# INDEX LABEL POSITION (Angstrom) FORCE (eV/Angstrom) VELOCITY (Angstrom/fs)
96+
# 0 Sn 0.000000000000 0.000000000000 0.000000000000 -0.000000000000 -0.000000000001 -0.000000000001 0.001244557166 -0.000346684288 0.000768457739
97+
# 1 Sn 0.000000000000 3.102800034079 3.102800034079 -0.000186795145 -0.000453823768 -0.000453823768 0.000550996187 -0.000886442775 0.001579501983
98+
# for abacus version >= v3.1.4, the value of POSITION is the real cartessian position, and unit is angstrom, and if cal_force the VELOCITY is added at the end.
99+
# for abacus version < v3.1.4, the real position = POSITION * celldm
100+
coords[iframe, iat] = np.array(
101+
[float(i) for i in dumplines[iline + skipline + iat].split()[2:5]]
102+
)
103+
104+
if not newversion:
105+
coords[iframe, iat] *= celldm
106+
107+
forces[iframe, iat] = np.array(
108+
[float(i) for i in dumplines[iline + skipline + iat].split()[5:8]]
109+
)
127110
iframe += 1
128111
assert iframe == nframes_dump, (
129112
"iframe=%d, nframe_dump=%d. Number of frames does not match number of lines in MD_dump."
130113
% (iframe, nframes_dump)
131114
)
132-
cells *= bohr2ang
133-
coords *= bohr2ang
134115
stresses *= kbar2evperang3
135116
return coords, cells, forces, stresses
136117

tests/abacus.md.newversion/INPUT

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
INPUT_PARAMETERS
2+
#Parameters (1.General)
3+
suffix Sn_nve
4+
calculation md
5+
ntype 1
6+
nbands 160
7+
symmetry 0
8+
pseudo_dir ../../../tests/PP_ORB
9+
orbital_dir ../../../tests/PP_ORB
10+
11+
#Parameters (2.Iteration)
12+
ecutwfc 30
13+
scf_thr 1e-5
14+
scf_nmax 100
15+
16+
#Parameters (3.Basis)
17+
basis_type lcao
18+
ks_solver genelpa
19+
gamma_only 1
20+
21+
#Parameters (4.Smearing)
22+
smearing_method gaussian
23+
smearing_sigma 0.01
24+
25+
#Parameters (5.Mixing)
26+
mixing_type pulay
27+
mixing_beta 0.3
28+
chg_extrap second-order
29+
30+
#Parameters (6.MD)
31+
md_type 0
32+
md_nstep 10
33+
md_dt 1
34+
md_tfirst 300
35+
36+
cal_force 1
37+
cal_stress 1

0 commit comments

Comments
 (0)