14
14
delimiter_patterns .append (delimiter_p1 )
15
15
delimiter_patterns .append (delimiter_p2 )
16
16
avail_patterns = []
17
-
18
17
avail_patterns .append (re .compile (r'^ INITIAL POTENTIAL ENERGY' ))
19
18
avail_patterns .append (re .compile (r'^ ENSEMBLE TYPE' ))
20
19
@@ -27,13 +26,22 @@ def __init__(self, log_file_name, xyz_file_name):
27
26
self .xyz_file_object = open (xyz_file_name , 'r' )
28
27
self .log_block_generator = self .get_log_block_generator ()
29
28
self .xyz_block_generator = self .get_xyz_block_generator ()
29
+ self .restart_flag = False
30
+ self .restart_flag_count = 0
30
31
self .cell = None
31
32
def __del__ (self ):
32
33
self .log_file_object .close ()
33
34
self .xyz_file_object .close ()
34
35
def __iter__ (self ):
35
36
return self
36
37
def __next__ (self ):
38
+
39
+ if self .restart_flag_count == 0 :
40
+ if self .check_restart ():
41
+ info_dict = {}
42
+ self .restart_flag_count += 1
43
+ log_info_dict = self .handle_single_log_frame (next (self .log_block_generator ))
44
+
37
45
info_dict = {}
38
46
log_info_dict = self .handle_single_log_frame (next (self .log_block_generator ))
39
47
xyz_info_dict = self .handle_single_xyz_frame (next (self .xyz_block_generator ))
@@ -43,11 +51,22 @@ def __next__(self):
43
51
assert all (eq1 ), (log_info_dict ,xyz_info_dict ,'There may be errors in the file' )
44
52
assert all (eq2 ), (log_info_dict ,xyz_info_dict ,'There may be errors in the file' )
45
53
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' )
54
+ assert log_info_dict ['energies' ]- xyz_info_dict ['energies' ] < 1E-4 , (log_info_dict ['energies' ],xyz_info_dict ['energies' ],'There may be errors in the file' )
47
55
info_dict .update (log_info_dict )
48
56
info_dict .update (xyz_info_dict )
49
57
return info_dict
50
58
59
+ def check_restart (self ):
60
+ restart_patterns = re .compile (r'^ \*\s+ RESTART INFORMATION' )
61
+ restart_flag = False
62
+ for i in range (0 , 10 ):
63
+ line = self .log_file_object .readline ()
64
+ if restart_patterns .match (line ):
65
+ restart_flag = True
66
+ break
67
+
68
+ return restart_flag
69
+
51
70
def get_log_block_generator (self ):
52
71
lines = []
53
72
delimiter_flag = False
@@ -111,6 +130,8 @@ def handle_single_log_frame(self, lines):
111
130
force_lines .append (line )
112
131
if energy_pattern_1 .match (line ):
113
132
energy = float (energy_pattern_1 .match (line ).groupdict ()['number' ]) * AU_TO_EV
133
+ #print('1',float(energy_pattern_1.match(line).groupdict()['number']))
134
+ #print('1to', energy)
114
135
if energy_pattern_2 .match (line ):
115
136
energy = float (energy_pattern_2 .match (line ).groupdict ()['number' ]) * AU_TO_EV
116
137
if cell_length_pattern .match (line ):
@@ -159,9 +180,9 @@ def handle_single_log_frame(self, lines):
159
180
info_dict ['atom_names' ] = atom_names
160
181
info_dict ['atom_numbs' ] = atom_numbs
161
182
info_dict ['atom_types' ] = np .asarray (atom_types_list )
162
- info_dict ['cells' ] = np .asarray ([self .cell ]).astype ('float32 ' )
163
- info_dict ['energies' ] = np .asarray ([energy ]).astype ('float32 ' )
164
- info_dict ['forces' ] = np .asarray ([forces_list ]).astype ('float32 ' )
183
+ info_dict ['cells' ] = np .asarray ([self .cell ]).astype ('float64 ' )
184
+ info_dict ['energies' ] = np .asarray ([energy ]).astype ('float64 ' )
185
+ info_dict ['forces' ] = np .asarray ([forces_list ]).astype ('float64 ' )
165
186
return info_dict
166
187
167
188
def handle_single_xyz_frame (self , lines ):
@@ -203,8 +224,8 @@ def handle_single_xyz_frame(self, lines):
203
224
info_dict ['atom_names' ] = atom_names
204
225
info_dict ['atom_numbs' ] = atom_numbs
205
226
info_dict ['atom_types' ] = np .asarray (atom_types_list )
206
- info_dict ['coords' ] = np .asarray ([coords_list ]).astype ('float32 ' )
207
- info_dict ['energies' ] = np .array ([energy ]).astype ('float32 ' )
227
+ info_dict ['coords' ] = np .asarray ([coords_list ]).astype ('float64 ' )
228
+ info_dict ['energies' ] = np .array ([energy ]).astype ('float64 ' )
208
229
info_dict ['orig' ]= [0 ,0 ,0 ]
209
230
return info_dict
210
231
0 commit comments