2020
2121class Cp2kSystems (object ):
2222 """
23- deal with cp2k outputfile
23+ deal with cp2k outputfile
2424 """
2525 def __init__ (self , log_file_name , xyz_file_name ):
2626 self .log_file_object = open (log_file_name , 'r' )
@@ -69,7 +69,7 @@ def get_log_block_generator(self):
6969 break
7070 if delimiter_flag is True :
7171 raise RuntimeError ('This file lacks some content, please check' )
72-
72+
7373 def get_xyz_block_generator (self ):
7474 p3 = re .compile (r'^\s*(\d+)\s*' )
7575 while True :
@@ -116,7 +116,7 @@ def handle_single_log_frame(self, lines):
116116 if cell_length_pattern .match (line ):
117117 cell_A = float (cell_length_pattern .match (line ).groupdict ()['A' ]) * AU_TO_ANG
118118 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
120120 cell_flag += 1
121121 if cell_angle_pattern .match (line ):
122122 cell_alpha = np .deg2rad (float (cell_angle_pattern .match (line ).groupdict ()['alpha' ]))
@@ -148,10 +148,10 @@ def handle_single_log_frame(self, lines):
148148 element_index += 1
149149 element_dict [line_list [2 ]]= [element_index ,1 ]
150150 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 ,
153153 float (line_list [5 ])* AU_TO_EV_EVERY_ANG ])
154-
154+
155155 atom_names = list (element_dict .keys ())
156156 atom_numbs = []
157157 for ii in atom_names :
@@ -190,8 +190,8 @@ def handle_single_xyz_frame(self, lines):
190190 element_index += 1
191191 element_dict [line_list [0 ]]= [element_index ,1 ]
192192 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 ,
195195 float (line_list [3 ])* AU_TO_ANG ])
196196 atom_names = list (element_dict .keys ())
197197 atom_numbs = []
@@ -203,29 +203,30 @@ def handle_single_xyz_frame(self, lines):
203203 info_dict ['coords' ] = np .asarray ([coords_list ]).astype ('float32' )
204204 info_dict ['energies' ] = np .array ([energy ]).astype ('float32' )
205205 info_dict ['orig' ]= [0 ,0 ,0 ]
206- return info_dict
206+ return info_dict
207207
208208#%%
209209
210210def get_frames (fname ) :
211211 coord_flag = False
212212 force_flag = False
213213 eV = 2.72113838565563E+01 # hatree to eV
214- angstrom = 5.29177208590000E-01 # Bohrto Angstrom
214+ angstrom = 5.29177208590000E-01 # Bohrto Angstrom
215215 fp = open (fname )
216216 atom_symbol_list = []
217217 cell = []
218218 coord = []
219219 force = []
220-
220+ coord_count = 0
221221 for idx , ii in enumerate (fp ) :
222222 if 'CELL| Vector' in ii :
223223 cell .append (ii .split ()[4 :7 ])
224224 if 'Atom Kind Element' in ii :
225225 coord_flag = True
226226 coord_idx = idx
227+ coord_count += 1
227228 # get the coord block info
228- if coord_flag :
229+ if coord_flag and ( coord_count == 1 ) :
229230 if (idx > coord_idx + 1 ) :
230231 if (ii == '\n ' ) :
231232 coord_flag = False
0 commit comments