Skip to content

Commit 6d62862

Browse files
authored
add element replace parser for cp2k output and refactor the unittest for cp2k output (#234)
* add element replace parser for cp2k output and refactor the unittest for cp2k output * fix typo
1 parent 8d0cb75 commit 6d62862

32 files changed

+5256
-164
lines changed

dpdata/cp2k/output.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,13 @@ def get_frames (fname) :
225225
eV = EnergyConversion("hartree", "eV").value()
226226
angstrom = LengthConversion("bohr", "angstrom").value()
227227
GPa = PressureConversion("eV/angstrom^3", "GPa").value()
228+
atom_symbol_idx_list = []
228229
atom_symbol_list = []
229230
cell = []
230231
coord = []
231232
force = []
232233
stress = []
233-
cell_count = 0
234-
coord_count = 0
234+
235235

236236
fp = open(fname)
237237
# check if output is converged, if not, return sys = 0
@@ -253,7 +253,8 @@ def get_frames (fname) :
253253
if idx > header_idx[-1] :
254254
if 'CELL| Vector' in ii:
255255
cell.append(ii.split()[4:7])
256-
256+
if 'Atomic kind:' in ii:
257+
atom_symbol_list.append(ii.split()[3])
257258
if 'Atom Kind Element' in ii :
258259
coord_flag = True
259260
coord_idx = idx
@@ -265,7 +266,7 @@ def get_frames (fname) :
265266
coord_flag = False
266267
else :
267268
coord.append(ii.split()[4:7])
268-
atom_symbol_list.append(ii.split()[2])
269+
atom_symbol_idx_list.append(ii.split()[1])
269270
if 'ENERGY|' in ii :
270271
energy = (ii.split()[8])
271272
if ' Atom Kind ' in ii :
@@ -296,20 +297,24 @@ def get_frames (fname) :
296297

297298
#conver to float array and add extra dimension for nframes
298299
cell = np.array(cell)
299-
cell = cell.astype(float)
300+
cell = cell.astype('float32')
300301
cell = cell[np.newaxis, :, :]
301302
coord = np.array(coord)
302-
coord = coord.astype(float)
303+
coord = coord.astype('float32')
303304
coord = coord[np.newaxis, :, :]
305+
atom_symbol_idx_list = np.array(atom_symbol_idx_list)
306+
atom_symbol_idx_list = atom_symbol_idx_list.astype(int)
307+
atom_symbol_idx_list = atom_symbol_idx_list - 1
304308
atom_symbol_list = np.array(atom_symbol_list)
309+
atom_symbol_list = atom_symbol_list[atom_symbol_idx_list]
305310
force = np.array(force)
306-
force = force.astype(float)
311+
force = force.astype('float32')
307312
force = force[np.newaxis, :, :]
308313

309314
# virial is not necessary
310315
if stress:
311316
stress = np.array(stress)
312-
stress = stress.astype(float)
317+
stress = stress.astype('float32')
313318
stress = stress[np.newaxis, :, :]
314319
# stress to virial conversion, default unit in cp2k is GPa
315320
# note the stress is virial = stress * volume
@@ -321,11 +326,10 @@ def get_frames (fname) :
321326
force = force * eV / angstrom
322327
# energy unit conversion, default unit in cp2k is hartree
323328
energy = float(energy) * eV
324-
energy = np.array(energy)
329+
energy = np.array(energy).astype('float32')
325330
energy = energy[np.newaxis]
326331

327332

328-
329333
tmp_names, symbol_idx = np.unique(atom_symbol_list, return_index=True)
330334
atom_types = []
331335
atom_numbs = []
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
0
2+
1
3+
0
4+
1
5+
0
6+
1
7+
0
8+
1
9+
0
10+
1
11+
0
12+
1
13+
2
14+
2
15+
2
16+
2
17+
2
18+
2
19+
2
20+
2
21+
2
22+
2
23+
2
24+
2
25+
2
26+
2
27+
2
28+
2
29+
2
30+
2
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fe1
2+
Fe2
3+
O

tests/cp2k/cp2k_element_replace/cp2k_output_element_replace

Lines changed: 4541 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)