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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ dist
dpdata.egg-info
_version.py
!tests/cp2k/aimd/cp2k.log
!tests/cp2k/restart_aimd/ch4.log
__pycache__
19 changes: 13 additions & 6 deletions dpdata/cp2k/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,42 @@
delimiter_patterns.append(delimiter_p1)
delimiter_patterns.append(delimiter_p2)
avail_patterns = []

avail_patterns.append(re.compile(r'^ INITIAL POTENTIAL ENERGY'))
avail_patterns.append(re.compile(r'^ ENSEMBLE TYPE'))

class Cp2kSystems(object):
"""
deal with cp2k outputfile
"""
def __init__(self, log_file_name, xyz_file_name):
def __init__(self, log_file_name, xyz_file_name, restart=False):
self.log_file_object = open(log_file_name, 'r')
self.xyz_file_object = open(xyz_file_name, 'r')
self.log_block_generator = self.get_log_block_generator()
self.xyz_block_generator = self.get_xyz_block_generator()
self.restart_flag = restart
self.cell=None

if self.restart_flag:
self.handle_single_log_frame(next(self.log_block_generator))

def __del__(self):
self.log_file_object.close()
self.xyz_file_object.close()

def __iter__(self):
return self

def __next__(self):
info_dict = {}
log_info_dict = self.handle_single_log_frame(next(self.log_block_generator))
xyz_info_dict = self.handle_single_xyz_frame(next(self.xyz_block_generator))
eq1 = [v1==v2 for v1,v2 in zip(log_info_dict['atom_numbs'], xyz_info_dict['atom_numbs'])]
eq2 = [v1==v2 for v1,v2 in zip(log_info_dict['atom_names'], xyz_info_dict['atom_names'])]
eq3 = [v1==v2 for v1,v2 in zip(log_info_dict['atom_types'], xyz_info_dict['atom_types'])]
assert all(eq1), (log_info_dict,xyz_info_dict,'There may be errors in the file')
assert all(eq2), (log_info_dict,xyz_info_dict,'There may be errors in the file')
assert all(eq3), (log_info_dict,xyz_info_dict,'There may be errors in the file')
assert log_info_dict['energies']==xyz_info_dict['energies'], (log_info_dict['energies'],xyz_info_dict['energies'],'There may be errors in the file')
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')
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')
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')
assert log_info_dict['energies']==xyz_info_dict['energies'], (log_info_dict['energies'], xyz_info_dict['energies'],'There may be errors in the file')
info_dict.update(log_info_dict)
info_dict.update(xyz_info_dict)
return info_dict
Expand Down Expand Up @@ -111,6 +117,7 @@ def handle_single_log_frame(self, lines):
force_lines.append(line)
if energy_pattern_1.match(line):
energy = float(energy_pattern_1.match(line).groupdict()['number']) * AU_TO_EV
#print('1to', energy)
if energy_pattern_2.match(line):
energy = float(energy_pattern_2.match(line).groupdict()['number']) * AU_TO_EV
if cell_length_pattern.match(line):
Expand Down
14 changes: 11 additions & 3 deletions dpdata/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ def __init__ (self,
- ``gaussian/log``: gaussian logs
- ``gaussian/md``: gaussian ab initio molecular dynamics
- ``cp2k/output``: cp2k output file
- ``cp2k/aimd_output``: cp2k aimd output dir(contains *pos*.xyz and *.log file)
- ``cp2k/aimd_output``: cp2k aimd output dir(contains *pos*.xyz and *.log file); optional `restart=True` if it is a cp2k restarted task.
- ``pwmat/movement``: pwmat md output file
- ``pwmat/out.mlmd``: pwmat scf output file

Expand Down Expand Up @@ -1091,13 +1091,21 @@ def has_virial(self) :
return ('virials' in self.data)

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

# @register_from_funcs.register_funcs('cp2k/restart_aimd_output')
# def from_cp2k_aimd_output(self, file_dir, restart=True):
# xyz_file = sorted(glob.glob("{}/*pos*.xyz".format(file_dir)))[0]
# log_file = sorted(glob.glob("{}/*.log".format(file_dir)))[0]
# for info_dict in Cp2kSystems(log_file, xyz_file, restart):
# l = LabeledSystem(data=info_dict)
# self.append(l)

@register_from_funcs.register_funcs('fhi_aims/md')
def from_fhi_aims_output(self, file_name, md=True, begin=0, step =1):
self.data['atom_names'], \
Expand Down
2 changes: 1 addition & 1 deletion dpdata/vasp/outcar.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,5 @@ def analyze_block(lines, ntot, nelm) :
tmp_l = lines[jj]
info = [float(ss) for ss in tmp_l.split()]
coord.append(info[:3])
force.append(info[3:])
force.append(info[3:6])
return coord, cell, energy, force, virial, is_converge
35 changes: 35 additions & 0 deletions tests/cp2k/restart_aimd/CH4-pos-1.xyz
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
5
i = 6, time = 3.000, E = -8.0715742982
H 5.3857900416 4.0742097705 3.5811120132
H 3.9199512866 4.7900150110 4.3285090053
H 5.6002847426 5.6077224621 4.4496425595
H 5.3479559215 4.1480369706 5.3848299963
C 5.0220694622 4.6784611518 4.4577943630
5
i = 7, time = 3.500, E = -8.0711045977
H 5.3848978757 4.0776224380 3.5814113731
H 3.9208809250 4.7887262191 4.3220837446
H 5.6114006618 5.6027985800 4.4525980866
H 5.3547898958 4.1463117535 5.3804926360
C 5.0205568908 4.6788387910 4.4584233243
5
i = 8, time = 4.000, E = -8.0707608306
H 5.3835297528 4.0817338403 3.5830596000
H 3.9234320791 4.7879031911 4.3168681896
H 5.6214054135 5.5987495057 4.4552276547
H 5.3599417537 4.1448123874 5.3752072465
C 5.0191820720 4.6790259231 4.4589444566
5
i = 9, time = 4.500, E = -8.0705194159
H 5.3817673668 4.0863967978 3.5858600160
H 3.9273863696 4.7876326936 4.3129364024
H 5.6300924745 5.5954927653 4.4575136286
H 5.3633363130 4.1434413688 5.3691425751
C 5.0179801128 4.6790427107 4.4593553989
5
i = 10, time = 5.000, E = -8.0703422670
H 5.3797263472 4.0914106472 3.5895251624
H 3.9324173150 4.7880020164 4.3103298482
H 5.6372698671 5.5929282695 4.4594480504
H 5.3649502724 4.1420701065 5.3625404656
C 5.0169867769 4.6789178539 4.4596571950
Loading