6
6
ry2ev = EnergyConversion ("rydberg" , "eV" ).value ()
7
7
kbar2evperang3 = PressureConversion ("kbar" , "eV/angstrom^3" ).value ()
8
8
9
+ def CheckFile (ifile ):
10
+ if not os .path .isfile (ifile ):
11
+ print ("Can not find file %s" % ifile )
12
+ return False
13
+ return True
14
+
9
15
def get_block (lines , keyword , skip = 0 , nlines = None ):
10
16
ret = []
11
17
found = False
@@ -108,7 +114,8 @@ def get_force (outlines, natoms):
108
114
force = []
109
115
force_inlines = get_block (outlines , "TOTAL-FORCE (eV/Angstrom)" , skip = 4 , nlines = np .sum (natoms ))
110
116
if force_inlines is None :
111
- raise RuntimeError ("TOTAL-FORCE (eV/Angstrom) is not found in running_scf.log. Please check." )
117
+ print ("TOTAL-FORCE (eV/Angstrom) is not found in OUT.XXX/running_scf.log. May be you haven't set 'cal_force 1' in the INPUT." )
118
+ return [[]]
112
119
for line in force_inlines :
113
120
force .append ([float (f ) for f in line .split ()[1 :4 ]])
114
121
force = np .array (force )
@@ -127,43 +134,51 @@ def get_stress(outlines):
127
134
128
135
129
136
def get_frame (fname ):
137
+ data = {'atom_names' :[],\
138
+ 'atom_numbs' :[],\
139
+ 'atom_types' :[],\
140
+ 'cells' :[],\
141
+ 'coords' :[],\
142
+ 'energies' :[],\
143
+ 'forces' :[]}
144
+
130
145
if type (fname ) == str :
131
146
# if the input parameter is only one string, it is assumed that it is the
132
147
# base directory containing INPUT file;
133
148
path_in = os .path .join (fname , "INPUT" )
134
149
else :
135
150
raise RuntimeError ('invalid input' )
151
+
152
+ if not CheckFile (path_in ):
153
+ return data
154
+
136
155
with open (path_in , 'r' ) as fp :
137
156
inlines = fp .read ().split ('\n ' )
138
157
139
158
geometry_path_in = get_geometry_in (fname , inlines )
140
159
path_out = get_path_out (fname , inlines )
160
+ if not (CheckFile (geometry_path_in ) and CheckFile (path_out )):
161
+ return data
162
+
141
163
with open (geometry_path_in , 'r' ) as fp :
142
164
geometry_inlines = fp .read ().split ('\n ' )
143
165
with open (path_out , 'r' ) as fp :
144
166
outlines = fp .read ().split ('\n ' )
145
167
146
168
celldm , cell = get_cell (geometry_inlines )
147
169
atom_names , natoms , types , coords = get_coords (celldm , cell , geometry_inlines , inlines )
170
+ data ['atom_names' ] = atom_names
171
+ data ['atom_numbs' ] = natoms
172
+ data ['atom_types' ] = types
148
173
149
174
energy ,converge = get_energy (outlines )
150
175
if not converge :
151
- return {'atom_names' :atom_names ,\
152
- 'atom_numbs' :natoms ,\
153
- 'atom_types' :types ,\
154
- 'cells' :[],\
155
- 'coords' :[],\
156
- 'energies' :[],\
157
- 'forces' :[]}
176
+ return data
158
177
force = get_force (outlines , natoms )
159
178
stress = get_stress (outlines )
160
179
if stress is not None :
161
180
stress *= np .abs (np .linalg .det (cell ))
162
181
163
- data = {}
164
- data ['atom_names' ] = atom_names
165
- data ['atom_numbs' ] = natoms
166
- data ['atom_types' ] = types
167
182
data ['cells' ] = cell [np .newaxis , :, :]
168
183
data ['coords' ] = coords [np .newaxis , :, :]
169
184
data ['energies' ] = np .array (energy )[np .newaxis ]
0 commit comments