20
20
21
21
class Cp2kSystems (object ):
22
22
"""
23
- deal with cp2k outputfile
23
+ deal with cp2k outputfile
24
24
"""
25
25
def __init__ (self , log_file_name , xyz_file_name ):
26
26
self .log_file_object = open (log_file_name , 'r' )
@@ -69,7 +69,7 @@ def get_log_block_generator(self):
69
69
break
70
70
if delimiter_flag is True :
71
71
raise RuntimeError ('This file lacks some content, please check' )
72
-
72
+
73
73
def get_xyz_block_generator (self ):
74
74
p3 = re .compile (r'^\s*(\d+)\s*' )
75
75
while True :
@@ -116,7 +116,7 @@ def handle_single_log_frame(self, lines):
116
116
if cell_length_pattern .match (line ):
117
117
cell_A = float (cell_length_pattern .match (line ).groupdict ()['A' ]) * AU_TO_ANG
118
118
cell_B = float (cell_length_pattern .match (line ).groupdict ()['B' ]) * AU_TO_ANG
119
- cell_C = float (cell_length_pattern .match (line ).groupdict ()['C' ]) * AU_TO_ANG
119
+ cell_C = float (cell_length_pattern .match (line ).groupdict ()['C' ]) * AU_TO_ANG
120
120
cell_flag += 1
121
121
if cell_angle_pattern .match (line ):
122
122
cell_alpha = np .deg2rad (float (cell_angle_pattern .match (line ).groupdict ()['alpha' ]))
@@ -148,10 +148,10 @@ def handle_single_log_frame(self, lines):
148
148
element_index += 1
149
149
element_dict [line_list [2 ]]= [element_index ,1 ]
150
150
atom_types_list .append (element_dict [line_list [2 ]][0 ])
151
- forces_list .append ([float (line_list [3 ])* AU_TO_EV_EVERY_ANG ,
152
- float (line_list [4 ])* AU_TO_EV_EVERY_ANG ,
151
+ forces_list .append ([float (line_list [3 ])* AU_TO_EV_EVERY_ANG ,
152
+ float (line_list [4 ])* AU_TO_EV_EVERY_ANG ,
153
153
float (line_list [5 ])* AU_TO_EV_EVERY_ANG ])
154
-
154
+
155
155
atom_names = list (element_dict .keys ())
156
156
atom_numbs = []
157
157
for ii in atom_names :
@@ -190,8 +190,8 @@ def handle_single_xyz_frame(self, lines):
190
190
element_index += 1
191
191
element_dict [line_list [0 ]]= [element_index ,1 ]
192
192
atom_types_list .append (element_dict [line_list [0 ]][0 ])
193
- coords_list .append ([float (line_list [1 ])* AU_TO_ANG ,
194
- float (line_list [2 ])* AU_TO_ANG ,
193
+ coords_list .append ([float (line_list [1 ])* AU_TO_ANG ,
194
+ float (line_list [2 ])* AU_TO_ANG ,
195
195
float (line_list [3 ])* AU_TO_ANG ])
196
196
atom_names = list (element_dict .keys ())
197
197
atom_numbs = []
@@ -203,29 +203,30 @@ def handle_single_xyz_frame(self, lines):
203
203
info_dict ['coords' ] = np .asarray ([coords_list ]).astype ('float32' )
204
204
info_dict ['energies' ] = np .array ([energy ]).astype ('float32' )
205
205
info_dict ['orig' ]= [0 ,0 ,0 ]
206
- return info_dict
206
+ return info_dict
207
207
208
208
#%%
209
209
210
210
def get_frames (fname ) :
211
211
coord_flag = False
212
212
force_flag = False
213
213
eV = 2.72113838565563E+01 # hatree to eV
214
- angstrom = 5.29177208590000E-01 # Bohrto Angstrom
214
+ angstrom = 5.29177208590000E-01 # Bohrto Angstrom
215
215
fp = open (fname )
216
216
atom_symbol_list = []
217
217
cell = []
218
218
coord = []
219
219
force = []
220
-
220
+ coord_count = 0
221
221
for idx , ii in enumerate (fp ) :
222
222
if 'CELL| Vector' in ii :
223
223
cell .append (ii .split ()[4 :7 ])
224
224
if 'Atom Kind Element' in ii :
225
225
coord_flag = True
226
226
coord_idx = idx
227
+ coord_count += 1
227
228
# get the coord block info
228
- if coord_flag :
229
+ if coord_flag and ( coord_count == 1 ) :
229
230
if (idx > coord_idx + 1 ) :
230
231
if (ii == '\n ' ) :
231
232
coord_flag = False
0 commit comments