@@ -33,8 +33,17 @@ def get_coord_dump_freq(inlines):
33
33
def get_coords_from_dump (dumplines , natoms ):
34
34
nlines = len (dumplines )
35
35
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 )
38
47
cells = np .zeros ([nframes_dump , 3 , 3 ])
39
48
stresses = np .zeros ([nframes_dump , 3 , 3 ])
40
49
forces = np .zeros ([nframes_dump , total_natoms , 3 ])
@@ -47,12 +56,17 @@ def get_coords_from_dump(dumplines, natoms):
47
56
# read in LATTICE_VECTORS
48
57
for ix in range (3 ):
49
58
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 :]])
51
61
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 :]])
54
68
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 )
56
70
cells *= bohr2ang
57
71
coords *= bohr2ang
58
72
stresses *= kbar2evperang3
@@ -66,7 +80,7 @@ def get_energy(outlines, ndump, dump_freq):
66
80
if nenergy % dump_freq == 0 :
67
81
energy .append (float (line .split ()[- 2 ]))
68
82
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 )
70
84
energy = np .array (energy )
71
85
return energy
72
86
0 commit comments