Skip to content

Commit 2bbfc9b

Browse files
Liu-RXLiuRenxi
andauthored
adapt abacus/md interface to MD output without stress calculation. (#301)
* adapt abacus/md interface to MD output without stress calculation. * add unit test for abacus md without stress output. * Add files via upload * add assertion failed reason for abacus/md interface Co-authored-by: LiuRenxi <[email protected]>
1 parent 31552db commit 2bbfc9b

File tree

8 files changed

+723
-42
lines changed

8 files changed

+723
-42
lines changed

dpdata/abacus/md.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,17 @@ def get_coord_dump_freq(inlines):
3333
def get_coords_from_dump(dumplines, natoms):
3434
nlines = len(dumplines)
3535
total_natoms = sum(natoms)
36-
nframes_dump = int(nlines/(total_natoms + 13))
37-
36+
calc_stress = False
37+
if "VIRIAL" in dumplines[6]:
38+
calc_stress = True
39+
else:
40+
assert("POSITIONS" in dumplines[6] and "FORCE" in dumplines[6]), "keywords 'POSITIONS' and 'FORCE' cannot be found in the 6th line. Please check."
41+
nframes_dump = -1
42+
if calc_stress:
43+
nframes_dump = int(nlines/(total_natoms + 13))
44+
else:
45+
nframes_dump = int(nlines/(total_natoms + 9))
46+
assert(nframes_dump > 0), "Number of lines in MD_dump file = %d. Number of atoms = %d. The MD_dump file is incomplete."%(nlines, total_natoms)
3847
cells = np.zeros([nframes_dump, 3, 3])
3948
stresses = np.zeros([nframes_dump, 3, 3])
4049
forces = np.zeros([nframes_dump, total_natoms, 3])
@@ -47,12 +56,17 @@ def get_coords_from_dump(dumplines, natoms):
4756
# read in LATTICE_VECTORS
4857
for ix in range(3):
4958
cells[iframe, ix] = np.array([float(i) for i in re.split('\s+', dumplines[iline+3+ix])[-3:]]) * celldm
50-
stresses[iframe, ix] = np.array([float(i) for i in re.split('\s+', dumplines[iline+7+ix])[-3:]])
59+
if calc_stress:
60+
stresses[iframe, ix] = np.array([float(i) for i in re.split('\s+', dumplines[iline+7+ix])[-3:]])
5161
for iat in range(total_natoms):
52-
coords[iframe, iat] = np.array([float(i) for i in re.split('\s+', dumplines[iline+11+iat])[-6:-3]])*celldm
53-
forces[iframe, iat] = np.array([float(i) for i in re.split('\s+', dumplines[iline+11+iat])[-3:]])
62+
if calc_stress:
63+
coords[iframe, iat] = np.array([float(i) for i in re.split('\s+', dumplines[iline+11+iat])[-6:-3]])*celldm
64+
forces[iframe, iat] = np.array([float(i) for i in re.split('\s+', dumplines[iline+11+iat])[-3:]])
65+
else:
66+
coords[iframe, iat] = np.array([float(i) for i in re.split('\s+', dumplines[iline+7+iat])[-6:-3]])*celldm
67+
forces[iframe, iat] = np.array([float(i) for i in re.split('\s+', dumplines[iline+7+iat])[-3:]])
5468
iframe += 1
55-
assert(iframe == nframes_dump)
69+
assert(iframe == nframes_dump), "iframe=%d, nframe_dump=%d. Number of frames does not match number of lines in MD_dump."%(iframe, nframes_dump)
5670
cells *= bohr2ang
5771
coords *= bohr2ang
5872
stresses *= kbar2evperang3
@@ -66,7 +80,7 @@ def get_energy(outlines, ndump, dump_freq):
6680
if nenergy%dump_freq == 0:
6781
energy.append(float(line.split()[-2]))
6882
nenergy+=1
69-
assert(ndump == len(energy))
83+
assert(ndump == len(energy)), "Number of total energies in running_md.log = %d. Number of frames in MD_dump = %d. Please check."%(len(energy), ndump)
7084
energy = np.array(energy)
7185
return energy
7286

tests/abacus.md.nostress/INPUT

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
INPUT_PARAMETERS
2+
#Parameters (General)
3+
suffix autotest
4+
pseudo_dir ./
5+
ntype 1
6+
nbands 8
7+
calculation md
8+
9+
#Parameters (Accuracy)
10+
ecutwfc 20
11+
scf_nmax 20
12+
13+
basis_type pw
14+
md_nstep 3
15+
16+
#cal_stress 1
17+
stress_thr 1e-6
18+
cal_force 1
19+
force_thr_ev 1.0e-3
20+
21+
ks_solver cg
22+
mixing_type pulay
23+
mixing_beta 0.7
24+
25+
md_type -1
26+
md_dt 1
27+
md_tfirst 0
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
MDSTEP: 0
2+
LATTICE_CONSTANT: 10.200000000000
3+
LATTICE_VECTORS
4+
0.500000000000 0.500000000000 0.000000000000
5+
0.500000000000 0.000000000000 0.500000000000
6+
0.000000000000 0.500000000000 0.500000000000
7+
INDEX LABEL POSITIONS FORCE (eV/Angstrom)
8+
0 Si 0.000000000000 0.000000000000 0.000000000000 -0.885362725259 0.500467424429 0.150239620221
9+
1 Si 0.241000000000 0.255000000000 0.250999999999 0.885362725259 -0.500467424429 -0.150239620221
10+
11+
12+
MDSTEP: 1
13+
LATTICE_CONSTANT: 10.200000000000
14+
LATTICE_VECTORS
15+
0.500000000000 0.500000000000 0.000000000000
16+
0.500000000000 0.000000000000 0.500000000000
17+
0.000000000000 0.500000000000 0.500000000000
18+
INDEX LABEL POSITIONS FORCE (eV/Angstrom)
19+
0 Si 0.999208682339 0.500447306737 0.500134280856 -0.728804779648 0.408578746723 0.107042476463
20+
1 Si 0.241791317661 0.254552693263 0.250865719143 0.728804779648 -0.408578746723 -0.107042476463
21+
22+
23+
MDSTEP: 2
24+
LATTICE_CONSTANT: 10.200000000000
25+
LATTICE_VECTORS
26+
0.500000000000 0.500000000000 0.000000000000
27+
0.500000000000 0.000000000000 0.500000000000
28+
0.000000000000 0.500000000000 0.500000000000
29+
INDEX LABEL POSITIONS FORCE (eV/Angstrom)
30+
0 Si 0.997114226602 0.501624803733 0.500458153134 -0.316038867402 0.171613491764 0.014802659803
31+
1 Si 0.243885773398 0.253375196267 0.250541846865 0.316038867402 -0.171613491764 -0.014802659803
32+
33+
34+
MDSTEP: 3
35+
LATTICE_CONSTANT: 10.200000000000
36+
LATTICE_VECTORS
37+
0.500000000000 0.500000000000 0.000000000000
38+
0.500000000000 0.000000000000 0.500000000000
39+
0.000000000000 0.500000000000 0.500000000000
40+
INDEX LABEL POSITIONS FORCE (eV/Angstrom)
41+
0 Si 0.994451593844 0.503106810892 0.500786060548 0.204324467775 -0.117398116295 -0.052955519257
42+
1 Si 0.246548406156 0.251893189108 0.250213939451 -0.204324467775 0.117398116295 0.052955519257
43+
44+

0 commit comments

Comments
 (0)