@@ -75,10 +75,10 @@ def generate_input(args):
75
75
interstitial_elements = args .interstitial_elements
76
76
settings = {}
77
77
if args .input_settings_file :
78
- if os .path .split (args .input_settings_file )[1 ] == ' INCAR' :
79
- settings = {' INCAR' :{}}
78
+ if os .path .split (args .input_settings_file )[1 ] == " INCAR" :
79
+ settings = {" INCAR" :{}}
80
80
incar = Incar .from_file (args .input_settings_file )
81
- settings [' INCAR' ] = incar
81
+ settings [" INCAR" ] = incar
82
82
else :
83
83
settings = loadfn (args .input_settings_file )
84
84
@@ -159,15 +159,15 @@ def parse_output(args):
159
159
mp_id = None
160
160
161
161
formula = os .path .split (os .path .abspath (root_fldr ))[- 1 ]
162
- initialize_logging (filename = formula + ' _parser.log' )
162
+ initialize_logging (filename = formula + " _parser.log" )
163
163
164
164
# parse results to get defect data and correction terms
165
165
defect_data = PostProcess (root_fldr , mp_id , mapi_key ).compile_all ()
166
166
167
167
# need to doctor up chemical potentials for dumpfn due to issue with
168
168
# Element not interpretted by MontyEncoder
169
- defect_data [' mu_range' ] = {ckey :{k .symbol :v for k ,v in cdict .items ()}
170
- for ckey , cdict in defect_data [' mu_range' ].items ()}
169
+ defect_data [" mu_range" ] = {ckey :{k .symbol :v for k ,v in cdict .items ()}
170
+ for ckey , cdict in defect_data [" mu_range" ].items ()}
171
171
172
172
dumpfn (defect_data , args .defect_data_file_name , cls = MontyEncoder , indent = 2 )
173
173
@@ -194,24 +194,24 @@ def compute_corrections(args):
194
194
if args .epsilon :
195
195
epsilon = args .epsilon
196
196
else :
197
- epsilon = defect_data [' epsilon' ]
197
+ epsilon = defect_data [" epsilon" ]
198
198
199
- defects = defect_data [' defects' ]
199
+ defects = defect_data [" defects" ]
200
200
for def_ind in range (len (defects )):
201
201
if type (defects [def_ind ]) == ComputedDefect :
202
202
print ("Encountered legacy ComputedDefect object. Converting to DefectEntry type for PyCDT v2.0..." )
203
- defects [def_ind ] = convert_cd_to_de (defects [def_ind ], defect_data [' bulk' ])
203
+ defects [def_ind ] = convert_cd_to_de (defects [def_ind ], defect_data [" bulk" ])
204
204
corrections = defaultdict (list )
205
205
206
206
formula = defects [0 ].bulk_structure .composition .reduced_formula
207
- initialize_logging (filename = formula + ' _correction.log' )
207
+ initialize_logging (filename = formula + " _correction.log" )
208
208
209
209
#loading locpot object now is useful for both corrections
210
210
bulk_obj = None #store either bulk Locpot or Outcar for saving time
211
- if correction_method == ' freysoldt' :
211
+ if correction_method == " freysoldt" :
212
212
for defect in defects :
213
- print (' defect_name: {} q={}' .format ( defect .name , defect .charge ))
214
- print (' -----------------------------------------\n \n ' )
213
+ print (" defect_name: {} q={}" .format ( defect .name , defect .charge ))
214
+ print (" -----------------------------------------\n \n " )
215
215
def_ent_loader = SingleDefectParser ( defect )
216
216
bulk_obj = def_ent_loader .freysoldt_loader (bulk_locpot = bulk_obj )
217
217
@@ -221,11 +221,11 @@ def compute_corrections(args):
221
221
epsilon ,
222
222
title = plt_title )
223
223
corr_key = defect .parameters ["defect_path" ]
224
- corrections [corr_key ] = {' charge_correction' : correction }
225
- elif correction_method == ' kumagai' :
224
+ corrections [corr_key ] = {" charge_correction" : correction }
225
+ elif correction_method == " kumagai" :
226
226
for defect in defects :
227
- print (' defect_name: {} q={}' .format ( defect .name , defect .charge ))
228
- print (' -----------------------------------------\n \n ' )
227
+ print (" defect_name: {} q={}" .format ( defect .name , defect .charge ))
228
+ print (" -----------------------------------------\n \n " )
229
229
def_ent_loader = SingleDefectParser ( defect )
230
230
bulk_obj = def_ent_loader .kumagai_loader (bulk_outcar = bulk_obj )
231
231
@@ -234,10 +234,10 @@ def compute_corrections(args):
234
234
correction = get_correction_kumagai ( def_ent_loader .defect_entry ,
235
235
epsilon , title = plt_title )
236
236
corr_key = defect .parameters ["defect_path" ]
237
- corrections [corr_key ] = {' charge_correction' : correction }
237
+ corrections [corr_key ] = {" charge_correction" : correction }
238
238
else :
239
- print (' Invalid correction method: ' ,correction_method ,' . Select either ' \
240
- '" freysoldt" or " kumagai"' )
239
+ print (" Invalid correction method: " ,correction_method ," . Select either " \
240
+ "' freysoldt' or ' kumagai'" )
241
241
242
242
dumpfn (corrections , corrections_file_name , cls = MontyEncoder , indent = 2 )
243
243
@@ -258,14 +258,14 @@ def compute_formation_energies(args):
258
258
259
259
# parse results to get defect data and correction terms
260
260
defect_data = loadfn (defect_data_file_name , cls = MontyDecoder )
261
- defects = defect_data [' defects' ]
261
+ defects = defect_data [" defects" ]
262
262
for def_ind in range (len (defects )):
263
263
if type (defects [def_ind ]) == ComputedDefect :
264
264
print ("Encountered legacy ComputedDefect object. Converting to DefectEntry type for PyCDT v2.0..." )
265
- defects [def_ind ] = convert_cd_to_de (defects [def_ind ], defect_data [' bulk' ])
265
+ defects [def_ind ] = convert_cd_to_de (defects [def_ind ], defect_data [" bulk" ])
266
266
267
267
formula = defects [0 ].bulk_structure .composition .reduced_formula
268
- initialize_logging (filename = formula + ' _formation_energy.log' )
268
+ initialize_logging (filename = formula + " _formation_energy.log" )
269
269
270
270
if os .path .isfile (corrections_file_name ):
271
271
correction_data = loadfn (corrections_file_name )
@@ -274,18 +274,18 @@ def compute_formation_energies(args):
274
274
computed_defect .corrections = correction_data [corr_key ]
275
275
elif corrections_file_name == "corrections.json" : # Default filename
276
276
print ("No corrections file exists! Plotting formation energies regardless..." )
277
- pass # Don' t bother, the user is not worried about corrections
277
+ pass # Don" t bother, the user is not worried about corrections
278
278
else :
279
279
raise OSError ([2 , "File not found" , corrections_file_name ])
280
280
281
281
# Gap
282
282
if not args .bandgap :
283
- bandgap = defect_data [' gap' ]
283
+ bandgap = defect_data [" gap" ]
284
284
else :
285
285
bandgap = args .bandgap
286
286
287
- vbm = defect_data [' vbm' ]
288
- mu_range = defect_data [' mu_range' ]
287
+ vbm = defect_data [" vbm" ]
288
+ mu_range = defect_data [" mu_range" ]
289
289
290
290
#doctor up mu_range because of cls Monty Decoder issue with Element
291
291
mu_range = {ckey :{Element (k ):v for k ,v in cdict .items ()}
@@ -296,11 +296,11 @@ def compute_formation_energies(args):
296
296
if region == list (mu_range .keys ())[0 ]:
297
297
da_trans = dpd .transition_level_map
298
298
if use_yaml :
299
- with open (' transition_levels.yaml' , 'w' ) as f :
299
+ with open (" transition_levels.yaml" , "w" ) as f :
300
300
yaml .dump (da_trans , f )
301
301
print ("============\n Defect Transition Levels (eV):\n ===========" )
302
302
for dfct_name , trans_lvls in da_trans .items ():
303
- prt_dfct_name = dfct_name .split ('@' )[0 ]
303
+ prt_dfct_name = dfct_name .split ("@" )[0 ]
304
304
print (prt_dfct_name , trans_lvls )
305
305
ky_vals = sorted (trans_lvls .items (), key = lambda x : x [0 ])
306
306
for qpair , trans_lvl in ky_vals :
@@ -311,9 +311,9 @@ def compute_formation_energies(args):
311
311
form_en_plot = dpd .plot ( mu_elts = mu , xlim = None , ylim = None , ax_fontsize = 1.3 , lg_fontsize = 1. ,
312
312
lg_position = None , fermi_level = None , title = None , saved = False )
313
313
form_en_plot .savefig (
314
- region + ' _region_defect_form_energy.' + args .file_format ,
315
- bbox_inches = ' tight' )
316
- print (' printed ' ,region ,' plot' )
314
+ region + " _region_defect_form_energy." + args .file_format ,
315
+ bbox_inches = " tight" )
316
+ print (" printed " ,region ," plot" )
317
317
318
318
319
319
def main ():
@@ -396,7 +396,7 @@ def main():
396
396
" the data."
397
397
correction_string = "Method to be used to compute finite size charge " \
398
398
"correction for the defect-formation energies.\n " \
399
- "Options are ` freysoldt' and ` kumagai'.\n " \
399
+ "Options are ' freysoldt' and ' kumagai'.\n " \
400
400
"If not provided, Freysoldt method is assumed."
401
401
bandgap_string = "User defined band gap to plot the defect formation " \
402
402
"energies.\n By default, Materials Project (MP) bandgap is " \
@@ -419,27 +419,27 @@ def main():
419
419
dest = "mapi_key" , help = mapi_string )
420
420
parser_input_files .add_argument ("-n" , "--nmax" , type = int , default = 80 ,
421
421
dest = "nmax" , help = nmax_string )
422
- parser_input_files .add_argument ("-or" , "--oxi_range" , action = ' append' ,
422
+ parser_input_files .add_argument ("-or" , "--oxi_range" , action = " append" ,
423
423
type = str , nargs = 3 , dest = "oxi_range" ,
424
424
help = oxi_range_string )
425
- parser_input_files .add_argument ("-os" , "--oxi_state" , action = ' append' ,
425
+ parser_input_files .add_argument ("-os" , "--oxi_state" , action = " append" ,
426
426
type = str , nargs = 2 , dest = "oxi_state" ,
427
427
help = oxi_state_string )
428
428
parser_input_files .add_argument ("-t" , "--type" , default = "semiconductor" ,
429
429
type = str , dest = "struct_type" ,
430
430
help = struct_type_string )
431
431
parser_input_files .add_argument ("-noa" , "--no_antisites" ,
432
- action = ' store_false' , dest = "antisites" ,
432
+ action = " store_false" , dest = "antisites" ,
433
433
help = no_antisites_string )
434
434
parser_input_files .add_argument ("-ii" , "--include_interstitials" ,
435
- action = ' store_true' ,
435
+ action = " store_true" ,
436
436
dest = "include_interstitials" ,
437
437
help = include_interstitials_string )
438
438
parser_input_files .add_argument ("interstitial_elements" , type = str ,
439
439
default = [], nargs = "*" , \
440
440
help = interstitial_elements_string )
441
- parser_input_files .add_argument ("--sub" , action = ' append' , type = str ,
442
- nargs = "+" , dest = ' substitutions' ,\
441
+ parser_input_files .add_argument ("--sub" , action = " append" , type = str ,
442
+ nargs = "+" , dest = " substitutions" ,\
443
443
help = substitutions_string )
444
444
parser_input_files .add_argument ("-is" , "--input_settings_file" ,
445
445
type = str , default = None ,
@@ -478,7 +478,7 @@ def main():
478
478
dest = "corrections_file_name" ,
479
479
help = corrections_file_name_string )
480
480
parser_compute_corrections .add_argument ("-p" , "--plot_results" ,
481
- action = ' store_true' ,
481
+ action = " store_true" ,
482
482
dest = "plot_results" ,
483
483
help = plot_results_string )
484
484
parser_compute_corrections .add_argument ("-e" , "--epsilon" , type = float ,
@@ -503,19 +503,25 @@ def main():
503
503
dest = "corrections_file_name" ,
504
504
help = corrections_file_name_string )
505
505
parser_compute_energies .add_argument ("-p" , "--plot_results" ,
506
- action = ' store_true' ,
506
+ action = " store_true" ,
507
507
dest = "plot_results" ,
508
508
help = plot_results_string )
509
509
parser_compute_energies .add_argument ("-bg" , "--bandgap" ,
510
510
type = float , default = 0 , dest = "bandgap" ,
511
511
help = bandgap_string )
512
- parser_compute_energies .add_argument ("-f" , "--format" , default = ' eps' ,
512
+ parser_compute_energies .add_argument ("-f" , "--format" , default = " eps" ,
513
513
dest = "file_format" ,
514
514
help = plot_format_string )
515
515
parser_compute_energies .set_defaults (func = compute_formation_energies )
516
516
517
517
args = parser .parse_args ()
518
- args .func (args )
518
+ try :
519
+ args .func (args )
520
+ except :
521
+ print ("PyCDT is a script that generates vasp input files, parses vasp output"
522
+ " files, and computes the formation energy of charged defects.\n \n "
523
+ "This script works based on several sub-commands with their own options."
524
+ " To see the options for sub-commands, type: pycdt -h" )
519
525
520
526
521
527
if __name__ == "__main__" :
0 commit comments