Skip to content

Commit

Permalink
add parsing md stress from output file
Browse files Browse the repository at this point in the history
  • Loading branch information
robinzyb committed Nov 14, 2023
1 parent 699393d commit b8cbc48
Show file tree
Hide file tree
Showing 14 changed files with 2,106 additions and 23 deletions.
10 changes: 5 additions & 5 deletions cp2kdata/block_parser/md_xyz.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
)

def parse_md_ener(ener_file):
print(f"Parsing Energies From {ener_file}")
print(f"Parsing Energies from {ener_file}")
energies_list = np.loadtxt(ener_file, usecols=4, ndmin=1, dtype=np.float64)
return energies_list

def parse_pos_xyz(posxyz_file):
print(f"Parsing Structures From {posxyz_file}")
print(f"Parsing Structures from {posxyz_file}")
fp = zopen(posxyz_file, "r")
lines = fp.readlines()
energies_list = []
Expand All @@ -36,7 +36,7 @@ def parse_pos_xyz(posxyz_file):
return pos_list, energies_list, chemical_symbols

def parse_frc_xyz(frcxyz_file):
print(f"Parsing Froces From {frcxyz_file}")
print(f"Parsing Froces from {frcxyz_file}")
fp = zopen(frcxyz_file, "r")
lines = fp.readlines()
force_list = []
Expand All @@ -57,7 +57,7 @@ def parse_frc_xyz(frcxyz_file):

#NOTE: incomplete function, do not release!
def parse_pos_xyz_from_wannier(wannier_xyz_fiel):
print(f"Parsing Structures From {wannier_xyz_fiel}")
print(f"Parsing Structures from {wannier_xyz_fiel}")
fp = zopen(wannier_xyz_fiel, "r")
lines = fp.readlines()
force_list = []
Expand All @@ -79,7 +79,7 @@ def parse_pos_xyz_from_wannier(wannier_xyz_fiel):
return force_list

def parse_md_stress(stress_file):
print(f"Parsing Stresses From {stress_file}")
print(f"Parsing Stresses from {stress_file}")
stresses_list = np.loadtxt(
stress_file,
usecols=(2, 3, 4, 5, 6, 7, 8, 9, 10),
Expand Down
5 changes: 4 additions & 1 deletion cp2kdata/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,10 @@ def parse_md(self):
if stress_file_list:
self.stress_tensor_list = parse_md_stress(stress_file_list[0])
else:
self.stress_tensor_list = None
print(f"Parsing Stress from the CP2K output/log file: {self.filename}")
self.stress_tensor_list = parse_stress_tensor_list(self.output_file)



self.num_frames = len(self.energies_list)

Expand Down
35 changes: 18 additions & 17 deletions tests/test_dpdata/test_labeledsys.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,37 @@
aimd_output_path_list = [
"tests/test_dpdata/v7.1/aimd",
"tests/test_dpdata/v7.1/aimd_virial",
"tests/test_dpdata/v7.1/aimd_virial_in_output",
"tests/test_dpdata/v2022.1/aimd",
"tests/test_dpdata/v2023.1/aimd_nvt",
"tests/test_dpdata/v2023.1/aimd_npt_f"
]

e_f_dpdata_list = [
dpdata.LabeledSystem(
file_name = os.path.join(path, "output"),
file_name = os.path.join(path, "output"),
fmt="cp2kdata/e_f"
) for path in e_f_output_path_list
]

e_f_dpdata_ref_list = [
dpdata.LabeledSystem(
file_name = os.path.join(path, "deepmd"),
file_name = os.path.join(path, "deepmd"),
fmt="deepmd/npy"
) for path in e_f_output_path_list
]

aimd_dpdata_list = [
dpdata.LabeledSystem(
file_name = path,
cp2k_output_name="output",
file_name = path,
cp2k_output_name="output",
fmt="cp2kdata/md"
) for path in aimd_output_path_list
]

aimd_dpdata_ref_list = [
dpdata.LabeledSystem(
file_name = os.path.join(path, "deepmd"),
file_name = os.path.join(path, "deepmd"),
fmt="deepmd/npy"
) for path in aimd_output_path_list
]
Expand All @@ -60,14 +61,14 @@
@pytest.fixture(params=test_params, scope='class')
def cp2k_and_ref(request):
return request.param


class TestLabeledSys():
def test_len_func(self, cp2k_and_ref):
assert len(cp2k_and_ref[0]) == len(cp2k_and_ref[1])

def test_add_func(self, cp2k_and_ref):
assert len(cp2k_and_ref[0]+cp2k_and_ref[0]) == len(cp2k_and_ref[1]+cp2k_and_ref[1])
assert len(cp2k_and_ref[0]+cp2k_and_ref[0]) == len(cp2k_and_ref[1]+cp2k_and_ref[1])

def test_atom_numbs(self, cp2k_and_ref):
assert cp2k_and_ref[0].data['atom_numbs'] == cp2k_and_ref[1].data['atom_numbs']
Expand All @@ -91,33 +92,33 @@ def test_nframes(self, cp2k_and_ref):
def test_cell(self, cp2k_and_ref):
assert cp2k_and_ref[0].get_nframes() == cp2k_and_ref[1].get_nframes()
if not cp2k_and_ref[0].nopbc and not cp2k_and_ref[1].nopbc:
np.testing.assert_almost_equal(cp2k_and_ref[0].data['cells'],
cp2k_and_ref[1].data['cells'],
np.testing.assert_almost_equal(cp2k_and_ref[0].data['cells'],
cp2k_and_ref[1].data['cells'],
decimal = 6,
err_msg = 'cell failed')

def test_coord(self, cp2k_and_ref):
def test_coord(self, cp2k_and_ref):
assert cp2k_and_ref[0].get_nframes() == cp2k_and_ref[1].get_nframes()
# think about direct coord
tmp_cell = cp2k_and_ref[0].data['cells']
tmp_cell = np.reshape(tmp_cell, [-1, 3])
tmp_cell_norm = np.reshape(np.linalg.norm(tmp_cell, axis = 1), [-1, 1, 3])
np.testing.assert_almost_equal(cp2k_and_ref[0].data['coords'] / tmp_cell_norm,
cp2k_and_ref[1].data['coords'] / tmp_cell_norm,
np.testing.assert_almost_equal(cp2k_and_ref[0].data['coords'] / tmp_cell_norm,
cp2k_and_ref[1].data['coords'] / tmp_cell_norm,
decimal = 6,
err_msg = 'coord failed')

def test_energy(self, cp2k_and_ref):
np.testing.assert_almost_equal(
cp2k_and_ref[0]['energies'],
cp2k_and_ref[1]['energies'],
cp2k_and_ref[0]['energies'],
cp2k_and_ref[1]['energies'],
decimal = 6,
err_msg = 'energies failed'
)
def test_force(self, cp2k_and_ref):
np.testing.assert_almost_equal(
cp2k_and_ref[0]['forces'],
cp2k_and_ref[1]['forces'],
cp2k_and_ref[0]['forces'],
cp2k_and_ref[1]['forces'],
decimal = 6,
err_msg = 'forces failed'
)
Expand All @@ -128,7 +129,7 @@ def test_virial(self, cp2k_and_ref):
return
np.testing.assert_almost_equal(
cp2k_and_ref[0]['virials'],
cp2k_and_ref[1]['virials'],
cp2k_and_ref[1]['virials'],
decimal = 6,
err_msg = 'virials failed'
)
Expand Down
4 changes: 4 additions & 0 deletions tests/test_dpdata/v7.1/aimd_virial_in_output/AI2KIT-1.ener
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Step Nr. Time[fs] Kin.[a.u.] Temp[K] Pot.[a.u.] Cons Qty[a.u.] UsedTime[s]
0 0.000000 0.023513604 330.000000000 -512.975045883 -512.951532279 0.000000000
1 0.500000 0.022699499 318.574497441 -512.975113772 -512.951532305 127.752896070
2 1.000000 0.022783713 319.756395709 -512.975174180 -512.951532298 11.460700989
51 changes: 51 additions & 0 deletions tests/test_dpdata/v7.1/aimd_virial_in_output/AI2KIT-frc-1.xyz
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
15
i = 0, time = 0.000, E = -512.9750458834
Ag 0.0020053232 0.0027160165 0.0041556009
Ag 0.0000230827 0.0016837965 -0.0016383967
Ag 0.0001844491 -0.0019492545 -0.0014564886
Ag 0.0170862692 -0.0029133072 0.0127247150
Ag -0.0010379394 -0.0038018903 0.0006029206
Ag -0.0004741987 0.0093675975 -0.0028282955
Ag -0.0006190863 -0.0014762446 -0.0036882412
Ag -0.0113652252 -0.0015013958 -0.0001820340
Ag 0.0007548522 0.0014351067 0.0022176462
Ag -0.0007292108 -0.0013749572 0.0006864455
Ag 0.0017459672 -0.0005107115 0.0003941444
Ag -0.0011549449 -0.0006406309 -0.0023452943
Ag 0.0007203645 -0.0002756238 -0.0019195719
O -0.0091816650 -0.0019596434 -0.0085801283
O 0.0006001442 0.0005647641 0.0002384539
15
i = 1, time = 0.500, E = -512.9751137724
Ag 0.0018649757 0.0027893035 0.0040979229
Ag -0.0001792541 0.0016783979 -0.0014106511
Ag 0.0001976847 -0.0018595994 -0.0014756845
Ag 0.0170208464 -0.0029040887 0.0126122231
Ag -0.0012107137 -0.0037316866 0.0003972314
Ag -0.0005554708 0.0094623432 -0.0028511548
Ag -0.0005305983 -0.0014462112 -0.0037837280
Ag -0.0113261344 -0.0014227120 -0.0001236179
Ag 0.0008811138 0.0013586864 0.0023358882
Ag -0.0006748238 -0.0015917383 0.0008739628
Ag 0.0017460866 -0.0003128195 0.0004608919
Ag -0.0011294565 -0.0006990970 -0.0024683620
Ag 0.0006126585 -0.0002914009 -0.0018539529
O -0.0090594253 -0.0018090543 -0.0085702382
O 0.0007114427 -0.0002401588 0.0002303285
15
i = 2, time = 1.000, E = -512.9751741800
Ag 0.0017330546 0.0028544577 0.0040318746
Ag -0.0003809695 0.0016716545 -0.0011803963
Ag 0.0002042521 -0.0017612041 -0.0014840232
Ag 0.0169518593 -0.0028939306 0.0124972303
Ag -0.0013542443 -0.0036587961 0.0002177358
Ag -0.0006390641 0.0095579502 -0.0028716062
Ag -0.0004416931 -0.0014142427 -0.0038875321
Ag -0.0112835709 -0.0013391146 -0.0000622083
Ag 0.0010010589 0.0012892086 0.0024584196
Ag -0.0006212549 -0.0018141751 0.0010651461
Ag 0.0017454961 -0.0001415415 0.0005374765
Ag -0.0011000452 -0.0007670985 -0.0025971583
Ag 0.0005291203 -0.0003006941 -0.0018118877
O -0.0089249761 -0.0016150127 -0.0085215448
O 0.0008011279 -0.0010612237 0.0002105208
51 changes: 51 additions & 0 deletions tests/test_dpdata/v7.1/aimd_virial_in_output/AI2KIT-pos-1.xyz
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
15
i = 0, time = 0.000, E = -512.9750458834
Ag 4.2093700000 4.1847900000 8.7128500000
Ag 2.5428000000 5.5110200000 6.9389800000
Ag 4.7365100000 4.1617300000 5.9808000000
Ag 2.1721700000 5.6512200000 10.0919000000
Ag 3.4260200000 1.5104400000 9.6929400000
Ag 3.3721900000 3.5330800000 11.6657000000
Ag 5.8906400000 2.7991800000 10.4803000000
Ag 5.2835700000 5.5536100000 10.8626000000
Ag 5.8440200000 2.1188300000 7.7979100000
Ag 4.4958400000 1.0836100000 12.1708000000
Ag 1.3198400000 3.3415600000 8.4474700000
Ag 5.3831700000 1.6011800000 5.1075500000
Ag 3.2172100000 1.9390600000 6.7546400000
O 0.9631030000 5.4112900000 8.4212400000
O 1.8220100000 1.3294500000 8.2711300000
15
i = 1, time = 0.500, E = -512.9751137724
Ag 4.2103952666 4.1840661000 8.7126812743
Ag 2.5430285248 5.5107654971 6.9386998600
Ag 4.7359656446 4.1612252290 5.9800989762
Ag 2.1735724047 5.6500940807 10.0925081900
Ag 3.4272394746 1.5099526712 9.6932864170
Ag 3.3725169439 3.5326133395 11.6668969903
Ag 5.8904084941 2.7986940316 10.4810090298
Ag 5.2821292111 5.5527485083 10.8620637992
Ag 5.8428638480 2.1197416623 7.7972235508
Ag 4.4955209983 1.0852272338 12.1703714656
Ag 1.3193548794 3.3430121041 8.4470524420
Ag 5.3836201287 1.6010755106 5.1085782258
Ag 3.2170730525 1.9395020196 6.7537446462
O 0.9614332779 5.4111891349 8.4232955933
O 1.8214547515 1.3333194604 8.2713736671
15
i = 2, time = 1.000, E = -512.9751741800
Ag 4.2113441517 4.1833297043 8.7125538362
Ag 2.5432749886 5.5105126136 6.9383870925
Ag 4.7354720059 4.1606311322 5.9793592159
Ag 2.1749753763 5.6489784769 10.0932022936
Ag 3.4284088663 1.5094001850 9.6936273735
Ag 3.3728390384 3.5321195216 11.6680448657
Ag 5.8901921425 2.7981644155 10.4817747209
Ag 5.2806730523 5.5518130038 10.8614777264
Ag 5.8417764612 2.1205695509 7.7965703072
Ag 4.4952276539 1.0868549694 12.1699122416
Ag 1.3189821456 3.3444601467 8.4465432237
Ag 5.3840115246 1.6010591176 5.1096538314
Ag 3.2169197196 1.9398944490 6.7529247323
O 0.9597540829 5.4108555999 8.4254670100
O 1.8211902360 1.3371386562 8.2716738538
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
15 changes: 15 additions & 0 deletions tests/test_dpdata/v7.1/aimd_virial_in_output/deepmd/type.raw
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
0
0
0
0
0
0
0
0
0
0
0
0
0
1
1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Ag
O
Loading

0 comments on commit b8cbc48

Please sign in to comment.