Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions dpdata/cp2k/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,13 @@ def get_frames (fname) :
eV = EnergyConversion("hartree", "eV").value()
angstrom = LengthConversion("bohr", "angstrom").value()
GPa = PressureConversion("eV/angstrom^3", "GPa").value()
atom_symbol_idx_list = []
atom_symbol_list = []
cell = []
coord = []
force = []
stress = []
cell_count = 0
coord_count = 0


fp = open(fname)
# check if output is converged, if not, return sys = 0
Expand All @@ -253,7 +253,8 @@ def get_frames (fname) :
if idx > header_idx[-1] :
if 'CELL| Vector' in ii:
cell.append(ii.split()[4:7])

if 'Atomic kind:' in ii:
atom_symbol_list.append(ii.split()[3])
if 'Atom Kind Element' in ii :
coord_flag = True
coord_idx = idx
Expand All @@ -265,7 +266,7 @@ def get_frames (fname) :
coord_flag = False
else :
coord.append(ii.split()[4:7])
atom_symbol_list.append(ii.split()[2])
atom_symbol_idx_list.append(ii.split()[1])
if 'ENERGY|' in ii :
energy = (ii.split()[8])
if ' Atom Kind ' in ii :
Expand Down Expand Up @@ -296,20 +297,24 @@ def get_frames (fname) :

#conver to float array and add extra dimension for nframes
cell = np.array(cell)
cell = cell.astype(float)
cell = cell.astype('float32')
cell = cell[np.newaxis, :, :]
coord = np.array(coord)
coord = coord.astype(float)
coord = coord.astype('float32')
coord = coord[np.newaxis, :, :]
atom_symbol_idx_list = np.array(atom_symbol_idx_list)
atom_symbol_idx_list = atom_symbol_idx_list.astype(int)
atom_symbol_idx_list = atom_symbol_idx_list - 1
atom_symbol_list = np.array(atom_symbol_list)
atom_symbol_list = atom_symbol_list[atom_symbol_idx_list]
force = np.array(force)
force = force.astype(float)
force = force.astype('float32')
force = force[np.newaxis, :, :]

# virial is not necessary
if stress:
stress = np.array(stress)
stress = stress.astype(float)
stress = stress.astype('float32')
stress = stress[np.newaxis, :, :]
# stress to virial conversion, default unit in cp2k is GPa
# note the stress is virial = stress * volume
Expand All @@ -321,11 +326,10 @@ def get_frames (fname) :
force = force * eV / angstrom
# energy unit conversion, default unit in cp2k is hartree
energy = float(energy) * eV
energy = np.array(energy)
energy = np.array(energy).astype('float32')
energy = energy[np.newaxis]



tmp_names, symbol_idx = np.unique(atom_symbol_list, return_index=True)
atom_types = []
atom_numbs = []
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
30 changes: 30 additions & 0 deletions tests/cp2k/cp2k_duplicate_header/deepmd/type.raw
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
0
1
0
1
0
1
0
1
0
1
0
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
3 changes: 3 additions & 0 deletions tests/cp2k/cp2k_duplicate_header/deepmd/type_map.raw
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fe1
Fe2
O
4,541 changes: 4,541 additions & 0 deletions tests/cp2k/cp2k_element_replace/cp2k_output_element_replace

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading