Skip to content

Commit bee8521

Browse files
authored
Merge pull request #1 from felix5572/cp2k-aimd-restart
add unittest to cp2k restart
2 parents c96ae3e + 773233e commit bee8521

File tree

9 files changed

+69
-16
lines changed

9 files changed

+69
-16
lines changed

dpdata/cp2k/output.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,23 @@ def __init__(self, log_file_name, xyz_file_name, restart=False):
3232
if self.restart_flag:
3333
self.handle_single_log_frame(next(self.log_block_generator))
3434

35-
3635
def __del__(self):
3736
self.log_file_object.close()
3837
self.xyz_file_object.close()
38+
3939
def __iter__(self):
4040
return self
41-
def __next__(self):
4241

42+
def __next__(self):
4343
info_dict = {}
4444
log_info_dict = self.handle_single_log_frame(next(self.log_block_generator))
4545
xyz_info_dict = self.handle_single_xyz_frame(next(self.xyz_block_generator))
4646
eq1 = [v1==v2 for v1,v2 in zip(log_info_dict['atom_numbs'], xyz_info_dict['atom_numbs'])]
4747
eq2 = [v1==v2 for v1,v2 in zip(log_info_dict['atom_names'], xyz_info_dict['atom_names'])]
4848
eq3 = [v1==v2 for v1,v2 in zip(log_info_dict['atom_types'], xyz_info_dict['atom_types'])]
49-
assert all(eq1), (log_info_dict,xyz_info_dict,'There may be errors in the file')
50-
assert all(eq2), (log_info_dict,xyz_info_dict,'There may be errors in the file')
51-
assert all(eq3), (log_info_dict,xyz_info_dict,'There may be errors in the file')
49+
assert all(eq1), (log_info_dict,xyz_info_dict,'There may be errors in the file. If it is a restart task; use restart=True')
50+
assert all(eq2), (log_info_dict,xyz_info_dict,'There may be errors in the file. If it is a restart task; use restart=True')
51+
assert all(eq3), (log_info_dict,xyz_info_dict,'There may be errors in the file. If it is a restart task; use restart=True')
5252
assert log_info_dict['energies']==xyz_info_dict['energies'], (log_info_dict['energies'], xyz_info_dict['energies'],'There may be errors in the file')
5353
info_dict.update(log_info_dict)
5454
info_dict.update(xyz_info_dict)

dpdata/system.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,8 +1026,7 @@ def __init__ (self,
10261026
- ``gaussian/log``: gaussian logs
10271027
- ``gaussian/md``: gaussian ab initio molecular dynamics
10281028
- ``cp2k/output``: cp2k output file
1029-
- ``cp2k/aimd_output``: cp2k aimd output dir(contains *pos*.xyz and *.log file)
1030-
- ``cp2k/restart_aimd_output``: cp2k restart aimd output dir(contains *pos*.xyz and *.log file)
1029+
- ``cp2k/aimd_output``: cp2k aimd output dir(contains *pos*.xyz and *.log file); optional `restart=True` if it is a cp2k restarted task.
10311030
- ``pwmat/movement``: pwmat md output file
10321031
- ``pwmat/out.mlmd``: pwmat scf output file
10331032
@@ -1099,13 +1098,13 @@ def from_cp2k_aimd_output(self, file_dir, restart=False):
10991098
l = LabeledSystem(data=info_dict)
11001099
self.append(l)
11011100

1102-
@register_from_funcs.register_funcs('cp2k/restart_aimd_output')
1103-
def from_cp2k_aimd_output(self, file_dir, restart=True):
1104-
xyz_file = sorted(glob.glob("{}/*pos*.xyz".format(file_dir)))[0]
1105-
log_file = sorted(glob.glob("{}/*.log".format(file_dir)))[0]
1106-
for info_dict in Cp2kSystems(log_file, xyz_file, restart):
1107-
l = LabeledSystem(data=info_dict)
1108-
self.append(l)
1101+
# @register_from_funcs.register_funcs('cp2k/restart_aimd_output')
1102+
# def from_cp2k_aimd_output(self, file_dir, restart=True):
1103+
# xyz_file = sorted(glob.glob("{}/*pos*.xyz".format(file_dir)))[0]
1104+
# log_file = sorted(glob.glob("{}/*.log".format(file_dir)))[0]
1105+
# for info_dict in Cp2kSystems(log_file, xyz_file, restart):
1106+
# l = LabeledSystem(data=info_dict)
1107+
# self.append(l)
11091108

11101109
@register_from_funcs.register_funcs('fhi_aims/md')
11111110
def from_fhi_aims_output(self, file_name, md=True, begin=0, step =1):
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
9.999999046325683594e+00 0.000000000000000000e+00 0.000000000000000000e+00 6.123233468832451221e-16 9.999999046325683594e+00 0.000000000000000000e+00 6.123233468832451221e-16 6.123233468832451221e-16 9.999999046325683594e+00
2+
9.999999046325683594e+00 0.000000000000000000e+00 0.000000000000000000e+00 6.123233468832451221e-16 9.999999046325683594e+00 0.000000000000000000e+00 6.123233468832451221e-16 6.123233468832451221e-16 9.999999046325683594e+00
3+
9.999999046325683594e+00 0.000000000000000000e+00 0.000000000000000000e+00 6.123233468832451221e-16 9.999999046325683594e+00 0.000000000000000000e+00 6.123233468832451221e-16 6.123233468832451221e-16 9.999999046325683594e+00
4+
9.999999046325683594e+00 0.000000000000000000e+00 0.000000000000000000e+00 6.123233468832451221e-16 9.999999046325683594e+00 0.000000000000000000e+00 6.123233468832451221e-16 6.123233468832451221e-16 9.999999046325683594e+00
5+
9.999999046325683594e+00 0.000000000000000000e+00 0.000000000000000000e+00 6.123233468832451221e-16 9.999999046325683594e+00 0.000000000000000000e+00 6.123233468832451221e-16 6.123233468832451221e-16 9.999999046325683594e+00
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
5.385789871215820312e+00 4.074209690093994141e+00 3.581111907958984375e+00 3.919951200485229492e+00 4.790015220642089844e+00 4.328508853912353516e+00 5.600284576416015625e+00 5.607722282409667969e+00 4.449642658233642578e+00 5.347955703735351562e+00 4.148036956787109375e+00 5.384829998016357422e+00 5.022069454193115234e+00 4.678461074829101562e+00 4.457794189453125000e+00
2+
5.384897708892822266e+00 4.077622413635253906e+00 3.581411361694335938e+00 3.920881032943725586e+00 4.788726329803466797e+00 4.322083950042724609e+00 5.611400604248046875e+00 5.602798461914062500e+00 4.452598094940185547e+00 5.354789733886718750e+00 4.146311759948730469e+00 5.380492687225341797e+00 5.020556926727294922e+00 4.678838729858398438e+00 4.458423137664794922e+00
3+
5.383529663085937500e+00 4.081733703613281250e+00 3.583059549331665039e+00 3.923432111740112305e+00 4.787903308868408203e+00 4.316868305206298828e+00 5.621405601501464844e+00 5.598749637603759766e+00 4.455227851867675781e+00 5.359941959381103516e+00 4.144812583923339844e+00 5.375207424163818359e+00 5.019182205200195312e+00 4.679026126861572266e+00 4.458944320678710938e+00
4+
5.381767272949218750e+00 4.086396694183349609e+00 3.585860013961791992e+00 3.927386283874511719e+00 4.787632465362548828e+00 4.312936305999755859e+00 5.630092620849609375e+00 5.595492839813232422e+00 4.457513809204101562e+00 5.363336086273193359e+00 4.143441200256347656e+00 5.369142532348632812e+00 5.017980098724365234e+00 4.679042816162109375e+00 4.459355354309082031e+00
5+
5.379726409912109375e+00 4.091410636901855469e+00 3.589525222778320312e+00 3.932417392730712891e+00 4.788002014160156250e+00 4.310329914093017578e+00 5.637269973754882812e+00 5.592928409576416016e+00 4.459447860717773438e+00 5.364950180053710938e+00 4.142070293426513672e+00 5.362540245056152344e+00 5.016986846923828125e+00 4.678917884826660156e+00 4.459657192230224609e+00
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-2.196387023925781250e+02
2+
-2.196259307861328125e+02
3+
-2.196165771484375000e+02
4+
-2.196100006103515625e+02
5+
-2.196051788330078125e+02
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-2.169162631034851074e-01 3.279730081558227539e-01 6.035397052764892578e-01 7.185621261596679688e-01 1.594181656837463379e-01 4.608764052391052246e-01 -3.765185177326202393e-01 3.857482671737670898e-01 -1.248831078410148621e-01 -6.494076848030090332e-01 1.203697919845581055e-01 -4.328375160694122314e-01 5.217282772064208984e-01 -9.955028891563415527e-01 -5.069978833198547363e-01
2+
-1.989514529705047607e-01 2.921981513500213623e-01 5.636984109878540039e-01 6.776738762855529785e-01 1.945625692605972290e-01 5.051451325416564941e-01 -4.636886715888977051e-01 3.652833104133605957e-01 -1.360401511192321777e-01 -7.025374770164489746e-01 9.427926689386367798e-02 -3.964312076568603516e-01 6.848884224891662598e-01 -9.483894705772399902e-01 -5.365054011344909668e-01
3+
-1.648406237363815308e-01 2.307343930006027222e-01 4.815881848335266113e-01 5.865107774734497070e-01 2.308490723371505737e-01 5.361675620079040527e-01 -5.500597357749938965e-01 3.308701217174530029e-01 -1.434295028448104858e-01 -7.340555787086486816e-01 5.354630947113037109e-02 -3.259690999984741211e-01 8.598077297210693359e-01 -8.481215834617614746e-01 -5.483376383781433105e-01
4+
-1.165429651737213135e-01 1.469107717275619507e-01 3.615300059318542480e-01 4.501595497131347656e-01 2.673597633838653564e-01 5.535713434219360352e-01 -6.303640604019165039e-01 2.890907227993011475e-01 -1.467755436897277832e-01 -7.438977956771850586e-01 -1.830625406000763178e-04 -2.249499261379241943e-01 1.038020730018615723e+00 -7.053260803222656250e-01 -5.432190895080566406e-01
5+
-5.708466097712516785e-02 4.539745301008224487e-02 2.101059257984161377e-01 2.773819267749786377e-01 3.029201626777648926e-01 5.577098131179809570e-01 -6.990006566047668457e-01 2.466197013854980469e-01 -1.458370834589004517e-01 -7.330569624900817871e-01 -6.438967585563659668e-02 -9.865168482065200806e-02 1.209161996841430664e+00 -5.326966047286987305e-01 -5.230426192283630371e-01
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
0
2+
0
3+
0
4+
0
5+
1
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
H
2+
C

tests/test_cp2k_aimd_output.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,44 @@
1+
2+
#%%
13
import os
24
import numpy as np
35
import unittest
46
from context import dpdata
57
from comp_sys import CompLabeledSys
6-
8+
#%%
79
class TestCp2kAimdOutput(unittest.TestCase, CompLabeledSys):
8-
def setUp (self) :
10+
def setUp(self):
911
self.system_1 = dpdata.LabeledSystem('cp2k/aimd',fmt='cp2k/aimd_output')
1012
self.system_2 = dpdata.LabeledSystem('cp2k/aimd/deepmd', fmt='deepmd/raw')
1113
self.places = 6
1214
self.e_places = 6
1315
self.f_places = 6
1416
self.v_places = 4
1517

18+
class TestCp2kAimdRestartOutput(unittest.TestCase, CompLabeledSys):
19+
def setUp(self):
20+
self.system_1 = dpdata.LabeledSystem('cp2k/restart_aimd',fmt='cp2k/aimd_output', restart=True)
21+
self.system_2 = dpdata.LabeledSystem('cp2k/restart_aimd/deepmd', fmt='deepmd/raw')
22+
self.places = 6
23+
self.e_places = 6
24+
self.f_places = 6
25+
self.v_places = 4
26+
27+
class TestCp2kAimdOutputError(unittest.TestCase):
28+
def setUp(self):
29+
pass
30+
31+
def restart_error(self):
32+
with self.assertRaises(AssertionError):
33+
dpdata.LabeledSystem('cp2k/restart_aimd', fmt='cp2k/aimd_output', restart=False)
34+
1635
if __name__ == '__main__':
1736
unittest.main()
37+
38+
39+
#%%
40+
# print(1)
41+
# system_1 = dpda.La
42+
# system_1 = dpdata.LabeledSystem('cp2k/restart_aimd',fmt='cp2k/aimd_output', restart=True)
43+
44+
# %%

0 commit comments

Comments
 (0)