Skip to content

Commit 27973b6

Browse files
committed
Merge
2 parents c400e0b + 5c5e9de commit 27973b6

File tree

2 files changed

+51
-46
lines changed

2 files changed

+51
-46
lines changed

scripts/pycdt

Lines changed: 49 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ def generate_input(args):
7575
interstitial_elements = args.interstitial_elements
7676
settings = {}
7777
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":{}}
8080
incar = Incar.from_file(args.input_settings_file)
81-
settings['INCAR'] = incar
81+
settings["INCAR"] = incar
8282
else:
8383
settings = loadfn(args.input_settings_file)
8484

@@ -159,15 +159,15 @@ def parse_output(args):
159159
mp_id = None
160160

161161
formula = os.path.split(os.path.abspath(root_fldr))[-1]
162-
initialize_logging(filename=formula+'_parser.log')
162+
initialize_logging(filename=formula+"_parser.log")
163163

164164
# parse results to get defect data and correction terms
165165
defect_data = PostProcess(root_fldr, mp_id, mapi_key).compile_all()
166166

167167
# need to doctor up chemical potentials for dumpfn due to issue with
168168
# 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()}
171171

172172
dumpfn(defect_data, args.defect_data_file_name, cls=MontyEncoder, indent=2)
173173

@@ -194,24 +194,24 @@ def compute_corrections(args):
194194
if args.epsilon:
195195
epsilon = args.epsilon
196196
else:
197-
epsilon = defect_data['epsilon']
197+
epsilon = defect_data["epsilon"]
198198

199-
defects = defect_data['defects']
199+
defects = defect_data["defects"]
200200
for def_ind in range(len(defects)):
201201
if type(defects[def_ind]) == ComputedDefect:
202202
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"])
204204
corrections = defaultdict(list)
205205

206206
formula = defects[0].bulk_structure.composition.reduced_formula
207-
initialize_logging(filename=formula+'_correction.log')
207+
initialize_logging(filename=formula+"_correction.log")
208208

209209
#loading locpot object now is useful for both corrections
210210
bulk_obj = None #store either bulk Locpot or Outcar for saving time
211-
if correction_method == 'freysoldt':
211+
if correction_method == "freysoldt":
212212
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")
215215
def_ent_loader = SingleDefectParser( defect)
216216
bulk_obj = def_ent_loader.freysoldt_loader(bulk_locpot=bulk_obj)
217217

@@ -221,11 +221,11 @@ def compute_corrections(args):
221221
epsilon,
222222
title=plt_title)
223223
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":
226226
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")
229229
def_ent_loader = SingleDefectParser( defect)
230230
bulk_obj = def_ent_loader.kumagai_loader(bulk_outcar=bulk_obj)
231231

@@ -234,10 +234,10 @@ def compute_corrections(args):
234234
correction = get_correction_kumagai( def_ent_loader.defect_entry,
235235
epsilon, title = plt_title)
236236
corr_key = defect.parameters["defect_path"]
237-
corrections[corr_key] = {'charge_correction': correction}
237+
corrections[corr_key] = {"charge_correction": correction}
238238
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'")
241241

242242
dumpfn(corrections, corrections_file_name, cls=MontyEncoder, indent=2)
243243

@@ -258,14 +258,14 @@ def compute_formation_energies(args):
258258

259259
# parse results to get defect data and correction terms
260260
defect_data = loadfn(defect_data_file_name, cls=MontyDecoder)
261-
defects = defect_data['defects']
261+
defects = defect_data["defects"]
262262
for def_ind in range(len(defects)):
263263
if type(defects[def_ind]) == ComputedDefect:
264264
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"])
266266

267267
formula = defects[0].bulk_structure.composition.reduced_formula
268-
initialize_logging(filename=formula+'_formation_energy.log')
268+
initialize_logging(filename=formula+"_formation_energy.log")
269269

270270
if os.path.isfile(corrections_file_name):
271271
correction_data = loadfn(corrections_file_name)
@@ -274,18 +274,18 @@ def compute_formation_energies(args):
274274
computed_defect.corrections = correction_data[corr_key]
275275
elif corrections_file_name == "corrections.json": # Default filename
276276
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
278278
else:
279279
raise OSError([2, "File not found", corrections_file_name])
280280

281281
# Gap
282282
if not args.bandgap:
283-
bandgap = defect_data['gap']
283+
bandgap = defect_data["gap"]
284284
else:
285285
bandgap = args.bandgap
286286

287-
vbm = defect_data['vbm']
288-
mu_range = defect_data['mu_range']
287+
vbm = defect_data["vbm"]
288+
mu_range = defect_data["mu_range"]
289289

290290
#doctor up mu_range because of cls Monty Decoder issue with Element
291291
mu_range = {ckey:{Element(k):v for k,v in cdict.items()}
@@ -296,11 +296,11 @@ def compute_formation_energies(args):
296296
if region == list(mu_range.keys())[0]:
297297
da_trans = dpd.transition_level_map
298298
if use_yaml:
299-
with open('transition_levels.yaml', 'w') as f:
299+
with open("transition_levels.yaml", "w") as f:
300300
yaml.dump(da_trans, f)
301301
print ("============\nDefect Transition Levels (eV):\n===========")
302302
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]
304304
print (prt_dfct_name, trans_lvls)
305305
ky_vals = sorted(trans_lvls.items(), key=lambda x: x[0])
306306
for qpair, trans_lvl in ky_vals:
@@ -311,9 +311,9 @@ def compute_formation_energies(args):
311311
form_en_plot = dpd.plot( mu_elts=mu, xlim=None, ylim=None, ax_fontsize=1.3, lg_fontsize=1.,
312312
lg_position=None, fermi_level = None, title=None, saved=False)
313313
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")
317317

318318

319319
def main():
@@ -396,7 +396,7 @@ def main():
396396
" the data."
397397
correction_string = "Method to be used to compute finite size charge " \
398398
"correction for the defect-formation energies.\n" \
399-
"Options are `freysoldt' and `kumagai'.\n" \
399+
"Options are 'freysoldt' and 'kumagai'.\n" \
400400
"If not provided, Freysoldt method is assumed."
401401
bandgap_string = "User defined band gap to plot the defect formation " \
402402
"energies.\nBy default, Materials Project (MP) bandgap is " \
@@ -419,27 +419,27 @@ def main():
419419
dest="mapi_key", help=mapi_string)
420420
parser_input_files.add_argument("-n", "--nmax", type=int, default=80,
421421
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",
423423
type=str, nargs=3, dest="oxi_range",
424424
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",
426426
type=str, nargs=2, dest="oxi_state",
427427
help=oxi_state_string)
428428
parser_input_files.add_argument("-t", "--type", default="semiconductor",
429429
type=str, dest="struct_type",
430430
help=struct_type_string)
431431
parser_input_files.add_argument("-noa", "--no_antisites",
432-
action='store_false', dest="antisites",
432+
action="store_false", dest="antisites",
433433
help=no_antisites_string)
434434
parser_input_files.add_argument("-ii", "--include_interstitials",
435-
action='store_true',
435+
action="store_true",
436436
dest="include_interstitials",
437437
help=include_interstitials_string)
438438
parser_input_files.add_argument("interstitial_elements", type=str,
439439
default=[], nargs="*", \
440440
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",\
443443
help=substitutions_string)
444444
parser_input_files.add_argument("-is", "--input_settings_file",
445445
type=str, default=None,
@@ -478,7 +478,7 @@ def main():
478478
dest="corrections_file_name",
479479
help=corrections_file_name_string)
480480
parser_compute_corrections.add_argument("-p", "--plot_results",
481-
action='store_true',
481+
action="store_true",
482482
dest="plot_results",
483483
help=plot_results_string)
484484
parser_compute_corrections.add_argument("-e", "--epsilon", type=float,
@@ -503,19 +503,25 @@ def main():
503503
dest="corrections_file_name",
504504
help=corrections_file_name_string)
505505
parser_compute_energies.add_argument("-p", "--plot_results",
506-
action='store_true',
506+
action="store_true",
507507
dest="plot_results",
508508
help=plot_results_string)
509509
parser_compute_energies.add_argument("-bg", "--bandgap",
510510
type=float, default=0, dest="bandgap",
511511
help=bandgap_string)
512-
parser_compute_energies.add_argument("-f", "--format", default='eps',
512+
parser_compute_energies.add_argument("-f", "--format", default="eps",
513513
dest="file_format",
514514
help=plot_format_string)
515515
parser_compute_energies.set_defaults(func = compute_formation_energies)
516516

517517
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")
519525

520526

521527
if __name__ == "__main__":

setup.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ def readme():
3939
],
4040
license="MIT",
4141
scripts=glob.glob(os.path.join(SETUP_PTH, "scripts", "*")),
42-
test_suite='nose.collector',
43-
tests_require=['nose']#,
44-
#entry_points={'console_scripts':['pycdt=scripts.pycdt']}
42+
test_suite="nose.collector",
43+
tests_require=["nose"]
4544
)
4645

0 commit comments

Comments
 (0)