Skip to content

Commit aeaf1fd

Browse files
authored
Merge pull request #140 from dmh1998dmh/master
adding cp2k/restart_aimd_ouput
2 parents 30e6929 + bee8521 commit aeaf1fd

File tree

16 files changed

+4177
-12
lines changed

16 files changed

+4177
-12
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ dist
2020
dpdata.egg-info
2121
_version.py
2222
!tests/cp2k/aimd/cp2k.log
23+
!tests/cp2k/restart_aimd/ch4.log
2324
__pycache__

dpdata/cp2k/output.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,42 @@
1414
delimiter_patterns.append(delimiter_p1)
1515
delimiter_patterns.append(delimiter_p2)
1616
avail_patterns = []
17-
1817
avail_patterns.append(re.compile(r'^ INITIAL POTENTIAL ENERGY'))
1918
avail_patterns.append(re.compile(r'^ ENSEMBLE TYPE'))
2019

2120
class Cp2kSystems(object):
2221
"""
2322
deal with cp2k outputfile
2423
"""
25-
def __init__(self, log_file_name, xyz_file_name):
24+
def __init__(self, log_file_name, xyz_file_name, restart=False):
2625
self.log_file_object = open(log_file_name, 'r')
2726
self.xyz_file_object = open(xyz_file_name, 'r')
2827
self.log_block_generator = self.get_log_block_generator()
2928
self.xyz_block_generator = self.get_xyz_block_generator()
29+
self.restart_flag = restart
3030
self.cell=None
31+
32+
if self.restart_flag:
33+
self.handle_single_log_frame(next(self.log_block_generator))
34+
3135
def __del__(self):
3236
self.log_file_object.close()
3337
self.xyz_file_object.close()
38+
3439
def __iter__(self):
3540
return self
41+
3642
def __next__(self):
3743
info_dict = {}
3844
log_info_dict = self.handle_single_log_frame(next(self.log_block_generator))
3945
xyz_info_dict = self.handle_single_xyz_frame(next(self.xyz_block_generator))
4046
eq1 = [v1==v2 for v1,v2 in zip(log_info_dict['atom_numbs'], xyz_info_dict['atom_numbs'])]
4147
eq2 = [v1==v2 for v1,v2 in zip(log_info_dict['atom_names'], xyz_info_dict['atom_names'])]
4248
eq3 = [v1==v2 for v1,v2 in zip(log_info_dict['atom_types'], xyz_info_dict['atom_types'])]
43-
assert all(eq1), (log_info_dict,xyz_info_dict,'There may be errors in the file')
44-
assert all(eq2), (log_info_dict,xyz_info_dict,'There may be errors in the file')
45-
assert all(eq3), (log_info_dict,xyz_info_dict,'There may be errors in the file')
46-
assert log_info_dict['energies']==xyz_info_dict['energies'], (log_info_dict['energies'],xyz_info_dict['energies'],'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')
52+
assert log_info_dict['energies']==xyz_info_dict['energies'], (log_info_dict['energies'], xyz_info_dict['energies'],'There may be errors in the file')
4753
info_dict.update(log_info_dict)
4854
info_dict.update(xyz_info_dict)
4955
return info_dict
@@ -111,6 +117,7 @@ def handle_single_log_frame(self, lines):
111117
force_lines.append(line)
112118
if energy_pattern_1.match(line):
113119
energy = float(energy_pattern_1.match(line).groupdict()['number']) * AU_TO_EV
120+
#print('1to', energy)
114121
if energy_pattern_2.match(line):
115122
energy = float(energy_pattern_2.match(line).groupdict()['number']) * AU_TO_EV
116123
if cell_length_pattern.match(line):

dpdata/system.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,7 +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)
1029+
- ``cp2k/aimd_output``: cp2k aimd output dir(contains *pos*.xyz and *.log file); optional `restart=True` if it is a cp2k restarted task.
10301030
- ``pwmat/movement``: pwmat md output file
10311031
- ``pwmat/out.mlmd``: pwmat scf output file
10321032
@@ -1091,13 +1091,21 @@ def has_virial(self) :
10911091
return ('virials' in self.data)
10921092

10931093
@register_from_funcs.register_funcs('cp2k/aimd_output')
1094-
def from_cp2k_aimd_output(self, file_dir):
1094+
def from_cp2k_aimd_output(self, file_dir, restart=False):
10951095
xyz_file=sorted(glob.glob("{}/*pos*.xyz".format(file_dir)))[0]
10961096
log_file=sorted(glob.glob("{}/*.log".format(file_dir)))[0]
1097-
for info_dict in Cp2kSystems(log_file, xyz_file):
1097+
for info_dict in Cp2kSystems(log_file, xyz_file, restart):
10981098
l = LabeledSystem(data=info_dict)
10991099
self.append(l)
11001100

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)
1108+
11011109
@register_from_funcs.register_funcs('fhi_aims/md')
11021110
def from_fhi_aims_output(self, file_name, md=True, begin=0, step =1):
11031111
self.data['atom_names'], \

dpdata/vasp/outcar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,5 +128,5 @@ def analyze_block(lines, ntot, nelm) :
128128
tmp_l = lines[jj]
129129
info = [float(ss) for ss in tmp_l.split()]
130130
coord.append(info[:3])
131-
force.append(info[3:])
131+
force.append(info[3:6])
132132
return coord, cell, energy, force, virial, is_converge

tests/cp2k/restart_aimd/CH4-pos-1.xyz

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
5
2+
i = 6, time = 3.000, E = -8.0715742982
3+
H 5.3857900416 4.0742097705 3.5811120132
4+
H 3.9199512866 4.7900150110 4.3285090053
5+
H 5.6002847426 5.6077224621 4.4496425595
6+
H 5.3479559215 4.1480369706 5.3848299963
7+
C 5.0220694622 4.6784611518 4.4577943630
8+
5
9+
i = 7, time = 3.500, E = -8.0711045977
10+
H 5.3848978757 4.0776224380 3.5814113731
11+
H 3.9208809250 4.7887262191 4.3220837446
12+
H 5.6114006618 5.6027985800 4.4525980866
13+
H 5.3547898958 4.1463117535 5.3804926360
14+
C 5.0205568908 4.6788387910 4.4584233243
15+
5
16+
i = 8, time = 4.000, E = -8.0707608306
17+
H 5.3835297528 4.0817338403 3.5830596000
18+
H 3.9234320791 4.7879031911 4.3168681896
19+
H 5.6214054135 5.5987495057 4.4552276547
20+
H 5.3599417537 4.1448123874 5.3752072465
21+
C 5.0191820720 4.6790259231 4.4589444566
22+
5
23+
i = 9, time = 4.500, E = -8.0705194159
24+
H 5.3817673668 4.0863967978 3.5858600160
25+
H 3.9273863696 4.7876326936 4.3129364024
26+
H 5.6300924745 5.5954927653 4.4575136286
27+
H 5.3633363130 4.1434413688 5.3691425751
28+
C 5.0179801128 4.6790427107 4.4593553989
29+
5
30+
i = 10, time = 5.000, E = -8.0703422670
31+
H 5.3797263472 4.0914106472 3.5895251624
32+
H 3.9324173150 4.7880020164 4.3103298482
33+
H 5.6372698671 5.5929282695 4.4594480504
34+
H 5.3649502724 4.1420701065 5.3625404656
35+
C 5.0169867769 4.6789178539 4.4596571950

0 commit comments

Comments
 (0)