def fix_filepath(pp_filepath): pseudo = dojopseudo_from_file(pp_filepath) if pseudo is None: print("Error while parsing %s" % pp_filepath) return 1 # Change md5 pseudo.dojo_report["md5"] = pseudo.compute_md5() if pseudo.dojo_report["pseudo_type"] == "norm-conserving": pseudo.dojo_report["pseudo_type"] = "NC" # Add basename if "basename" not in pseudo.dojo_report: pseudo.dojo_report["basename"] = pseudo.basename if pseudo.dojo_report["basename"] != pseudo.basename: print("Inconsistent basename in %s" % pp_filepath) return 1 # Remove ebands #pseudo.dojo_report.pop("ebands", None) #if pseudo.dojo_report.pop("phonon", None) is None: return 0 # Rename entries in FR pseudos. #oldnew = [("deltafactor", "deltafactor_soc"), # ("gbrv_fcc", "gbrv_fcc_soc"), # ("gbrv_bcc", "gbrv_bcc_soc")] #for old, new in oldnew: # if old in pseudo.dojo_report: # pseudo.dojo_report[new] = pseudo.dojo_report.pop(old) #pseudo.dojo_report.reorder() pseudo.dojo_report.json_write() return 0
def fix_filepath(pp_filepath): pseudo = dojopseudo_from_file(pp_filepath) if pseudo is None: print("Error while parsing %s" % pp_filepath) return 1 # Change md5 pseudo.dojo_report["md5"] = pseudo.compute_md5() if pseudo.dojo_report["pseudo_type"] == "norm-conserving": pseudo.dojo_report["pseudo_type"] = "NC" # Add basename if "basename" not in pseudo.dojo_report: pseudo.dojo_report["basename"] = pseudo.basename if pseudo.dojo_report["basename"] != pseudo.basename: print("Inconsistent basename in %s" % pp_filepath) return 1 # Remove ebands #pseudo.dojo_report.pop("ebands", None) #if pseudo.dojo_report.pop("phonon", None) is None: return 0 # Rename entries in FR pseudos. #oldnew = [("deltafactor", "deltafactor_soc"), # ("gbrv_fcc", "gbrv_fcc_soc"), # ("gbrv_bcc", "gbrv_bcc_soc")] #for old, new in oldnew: # if old in pseudo.dojo_report: # pseudo.dojo_report[new] = pseudo.dojo_report.pop(old) #pseudo.dojo_report.reorder() pseudo.dojo_report.json_write() return 0
def check_pseudo_path(path, verbose=0): """ Check a pseudopotential given the filepath. Warnings are printed to stdout. Return 0 if success. """ pseudo = dojopseudo_from_file(path) if pseudo is None: cprint("[%s] Pseudo.from_file returned None. Something wrong in file!" % path, "red") return 1 return check_pseudo(pseudo, verbose=verbose)
def check_pseudo_path(path, verbose=0): """ Check a pseudopotential given the filepath. Warnings are printed to stdout. Return 0 if success. """ pseudo = dojopseudo_from_file(path) if pseudo is None: cprint("[%s] Pseudo.from_file returned None. Something wrong in file!" % path, "red") return 1 return check_pseudo(pseudo, verbose=verbose)
def djrepo_pop(options): """Remove trials from djrepo files.""" for path in options.paths: pseudo = dojopseudo_from_file(path) report = pseudo.dojo_report count = 0 for trial in options.trials: if report.pop(trial, None) is not None: cprint("[%s] removed from %s" % (trial, path), "yellow") count += 1 if count != 0: pseudo.dojo_report.json_write()
def djrepo_pop(options): """Remove trials from djrepo files.""" for path in options.paths: pseudo = dojopseudo_from_file(path) report = pseudo.dojo_report count = 0 for trial in options.trials: if report.pop(trial, None) is not None: cprint("[%s] removed from %s" % (trial, path), "yellow") count += 1 if count != 0: pseudo.dojo_report.json_write()
def get_pseudos(options): """ Find pseudos in paths, return :class:`DojoTable` object sorted by atomic number Z. Accepts filepaths or directory. """ exts = ("psp8", "xml") paths = options.pseudos if len(paths) == 1: # Handle directory argument if os.path.isdir(paths[0]): top = os.path.abspath(paths[0]) paths = find_exts(top, exts, exclude_dirs="_*") # Handle glob syntax e.g. "./*.psp8" elif "*" in paths[0]: paths = glob.glob(paths[0]) if options.verbose > 1: print("Will read pseudo from: %s" % paths) pseudos = [] for p in paths: try: pseudo = dojopseudo_from_file(p) if pseudo is None: cprint("[%s] Pseudo.from_file returned None. Something wrong in file!" % p, "red") continue pseudos.append(pseudo) except Exception as exc: cprint("[%s] Python exception. This pseudo will be ignored" % p, "red") if options.verbose: print(exc) table = DojoTable(pseudos) # Here we select a subset of pseudos according to family or rows if options.rows: table = table.select_rows(options.rows) elif options.family: table = table.select_families(options.family) # here we select chemical symbols. if options.symbols: table = table.select_symbols(options.symbols) return table.sort_by_z()
def get_pseudos(options): """ Find pseudos in paths, return :class:`DojoTable` object sorted by atomic number Z. Accepts filepaths or directory. """ exts = ("psp8", "xml") paths = options.pseudos if len(paths) == 1: # Handle directory argument if os.path.isdir(paths[0]): top = os.path.abspath(paths[0]) paths = find_exts(top, exts, exclude_dirs="_*") # Handle glob syntax e.g. "./*.psp8" elif "*" in paths[0]: paths = glob.glob(paths[0]) if options.verbose > 1: print("Will read pseudo from: %s" % paths) pseudos = [] for p in paths: try: pseudo = dojopseudo_from_file(p) if pseudo is None: cprint("[%s] Pseudo.from_file returned None. Something wrong in file!" % p, "red") continue pseudos.append(pseudo) except Exception as exc: cprint("[%s] Python exception. This pseudo will be ignored" % p, "red") if options.verbose: print(exc) table = DojoTable(pseudos) # Here we select a subset of pseudos according to family or rows if options.rows: table = table.select_rows(options.rows) elif options.family: table = table.select_families(options.family) # here we select chemical symbols. if options.symbols: table = table.select_symbols(options.symbols) return table.sort_by_z()
def djrepo_recalc(options): """ Recompute the deltafactor from the data stored in the dojoreport. This function is used when the deltafactor reference results have been changed. """ for path in options.paths: pseudo = dojopseudo_from_file(path) data = pseudo.dojo_report["deltafactor"] # Recompute delfactor for the different ecut. for ecut, entry in data.items(): new_entry, eos_fit = dojo_dfact_results(pseudo, entry["num_sites"], entry["volumes"], entry["etotals"]) print("ecut: ", ecut, "(new - old) df:", new_entry["dfact_meV"] - entry["dfact_meV"]) data[ecut] = new_entry # Write new djson file. pseudo.dojo_report.json_write() return 0
def djrepo_recalc(options): """ Recompute the deltafactor from the data stored in the dojoreport. This function is used when the deltafactor reference results have been changed. """ for path in options.paths: pseudo = dojopseudo_from_file(path) data = pseudo.dojo_report["deltafactor"] # Recompute delfactor for the different ecut. for ecut, entry in data.items(): new_entry, eos_fit = dojo_dfact_results(pseudo, entry["num_sites"], entry["volumes"], entry["etotals"]) print("ecut: ", ecut, "(new - old) df:", new_entry["dfact_meV"] - entry["dfact_meV"]) data[ecut] = new_entry # Write new djson file. pseudo.dojo_report.json_write() return 0
def djrepo_check(options): """Check djrepo files.""" retcode = 0 for path in options.paths: #print(path) pseudo = dojopseudo_from_file(path) report = pseudo.dojo_report validation = report.get("validation", None) if validation is None: retcode += 1 cprint("[%s]: no validation entry" % path) continue hints = report.get("hints", None) if hints is None: retcode += 1 cprint("[%s]: no hints entry" % path) continue for k in ("low", "normal", "high"): if k not in hints: retcode += 1 cprint("[hint=%s]: not present" % k) continue return retcode
def djrepo_check(options): """Check djrepo files.""" retcode = 0 for path in options.paths: #print(path) pseudo = dojopseudo_from_file(path) report = pseudo.dojo_report validation = report.get("validation", None) if validation is None: retcode += 1 cprint("[%s]: no validation entry" % path) continue hints = report.get("hints", None) if hints is None: retcode += 1 cprint("[%s]: no hints entry" % path) continue for k in ("low", "normal", "high"): if k not in hints: retcode += 1 cprint("[hint=%s]: not present" % k) continue return retcode
def main(): def str_examples(): return """\ Usage Example: ppdojo_run.py Si.psp8 => Build pseudo_dojo flow for Si.fhi """ def show_examples_and_exit(error_code=1): """Display the usage of the script.""" print(str_examples()) sys.exit(error_code) parser = argparse.ArgumentParser(epilog=str_examples()) parser.add_argument('-m', '--manager', type=str, default=None, help="Manager file") parser.add_argument('-w', '--workdir', type=str, default=None, help="Working directory. Default: Automatically generated from pseudo name.") parser.add_argument('-d', '--dry-run', default=False, action="store_true", help="Dry run, build the flow without submitting it") parser.add_argument('--paral-kgb', type=int, default=0, help="Paral_kgb input variable.") parser.add_argument('--soc', default=False, action="store_true", help=( "Perform non-collinear run (nspinor==2, kptopt=3). Pseudo must have spin-orbit characteristic")) #parser.add_argument('-n', '--new-ecut', type=int, default=None, action="store", # help="Extend the ecut grid with the new-ecut point") def parse_trials(s): if s == "all": return ["df", "gbrv"] return s.split(",") parser.add_argument('--trials', default="all", type=parse_trials, help=("List of tests e.g --trials=ghosts,df,gbrv\n" " ghosts: tests ghost states in the conduction region.\n" " df: test delta factor against all electron reference.\n" " gbrv: test fcc and bcc lattice parameters against AE reference.\n" " phgamma: test violation of the acoustic sum rule\n")) parser.add_argument('--loglevel', default="ERROR", type=str, help="set the loglevel. Possible values: CRITICAL, ERROR (default), WARNING, INFO, DEBUG") parser.add_argument('-v', '--verbose', default=0, action='count', # -vv --> verbose=2 help='Verbose, can be supplied multiple times to increase verbosity') parser.add_argument('path', help='pseudopotential file.') try: options = parser.parse_args() except Exception as exc: show_examples_and_exit(1) # loglevel is bound to the string value obtained from the command line argument. # Convert to upper case to allow the user to specify --loglevel=DEBUG or --loglevel=debug import logging numeric_level = getattr(logging, options.loglevel.upper(), None) if not isinstance(numeric_level, int): raise ValueError('Invalid log level: %s' % options.loglevel) logging.basicConfig(level=numeric_level) options.manager = abilab.TaskManager.as_manager(options.manager) from pseudo_dojo import logo1 cprint(logo1(), "red") pseudo = dojopseudo_from_file(options.path) if pseudo is None: cprint("Error while parsing: %s" % options.path) cprint("Check your file. Returning 1") return 1 flow = build_flow(pseudo, options) if flow is None: cprint("DOJO_REPORT is already computed for pseudo %s." % options.path, "magenta") return 1 if options.dry_run: flow.build_and_pickle_dump(abivalidate=False) return 0 else: # Run the flow with the scheduler. return flow.make_scheduler().start()
def main(): def str_examples(): return """\ Usage example: dojogbrv.py info => Print all entries in the GBRV database. """ def show_examples_and_exit(err_msg=None, error_code=1): """Display the usage of the script.""" sys.stderr.write(str_examples()) if err_msg: sys.stderr.write("Fatal Error\n" + err_msg + "\n") sys.exit(error_code) # Parent parser for common options. copts_parser = argparse.ArgumentParser(add_help=False) copts_parser.add_argument( '--loglevel', default="ERROR", type=str, help= "set the loglevel. Possible values: CRITICAL, ERROR (default), WARNING, INFO, DEBUG" ) copts_parser.add_argument( '-v', '--verbose', default=0, action='count', # -vv --> verbose=2 help='Verbose, can be supplied multiple times to increase verbosity') copts_parser.add_argument( '-d', '--dry-run', default=False, action="store_true", help= ("Dry run, build the flow and check validity of input files without submitting" )) # Build the main parser. parser = argparse.ArgumentParser( epilog=str_examples(), parents=[copts_parser], formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument('pseudo', help='Pseudopotential file.') # Create the parsers for the sub-commands #subparsers = parser.add_subparsers(dest='command', help='sub-command help', description="Valid subcommands") # Subparser for the gendb command. #p_gendb = subparsers.add_parser('gendb', parents=[copts_parser], help=gbrv_gendb.__doc__) #p_gendb.add_argument('djson_path', help='Path of the djson file.') try: options = parser.parse_args() except Exception as exc: show_examples_and_exit(error_code=1) # loglevel is bound to the string value obtained from the command line argument. # Convert to upper case to allow the user to specify --loglevel=DEBUG or --loglevel=debug import logging numeric_level = getattr(logging, options.loglevel.upper(), None) if not isinstance(numeric_level, int): raise ValueError('Invalid log level: %s' % options.loglevel) logging.basicConfig(level=numeric_level) pseudo = options.pseudo = dojopseudo_from_file(options.pseudo) ecut = ecut_from_pseudo(pseudo) workdir = pseudo.basename + "_DOJO_RELAX" if os.path.exists(workdir): cprint("Directory %s already exists" % workdir, "red") return 1 flow = abilab.Flow(workdir=workdir) pawecutdg = 2 * ecut if pseudo.ispaw else None jth_afcc = dict( La=5.272, Ce=4.769, Pr=4.608, Nd=4.531, Pm=4.499, Sm=4.516, Eu=4.630, Gd=4.723, Tb=4.835, Dy=4.918, Ho=5.012, Er=5.073, Tm=5.120, Yb=5.163, Lu=5.589, ) a_guess = jth_afcc[pseudo.symbol] from pseudo_dojo.dojo.works import RelaxWithGbrvParamsWork ecut_list = [ecut, ecut + 10, ecut + 20] work = RelaxWithGbrvParamsWork(a_guess, "fcc", pseudo, ecut_list=ecut_list, pawecutdg=None, ngkpt=(8, 8, 8)) #ngkpt=(12, 12, 12)) #spin_mode="unpolarized", include_soc=False, tolvrs=1.e-10, smearing="fermi_dirac:0.001 Ha", #ecutsm=0.05, chksymbreak=0) flow.register_work(work) #flow.build_and_pickle_dump(abivalidate=True) #return 0 return flow.make_scheduler().start()
def pseudo(filename): """Returns a `Pseudo` object.""" return dojopseudo_from_file(os.path.join(dirpath, filename))
def pseudos(*filenames): """Returns a PseudoTable constructed from the input filenames located in tests/data/pseudos.""" return DojoTable( [dojopseudo_from_file(os.path.join(dirpath, f)) for f in filenames])
def pseudo(filename): """Returns a `Pseudo` object.""" return dojopseudo_from_file(os.path.join(dirpath, filename))
def pseudos(*filenames): """Returns a PseudoTable constructed from the input filenames located in tests/data/pseudos.""" return DojoTable([dojopseudo_from_file(os.path.join(dirpath, f)) for f in filenames])
def main(): def str_examples(): return """\ Usage Example: dojo_run.py Si.psp8 => Build pseudo_dojo flow for Si.psp8 pseudo """ def show_examples_and_exit(error_code=1): """Display the usage of the script.""" print(str_examples()) sys.exit(error_code) parser = argparse.ArgumentParser(epilog=str_examples()) parser.add_argument('-m', '--manager', type=str, default=None, help="Manager file") parser.add_argument( '-w', '--workdir', type=str, default=None, help= "Working directory. Default: Automatically generated from pseudo name." ) parser.add_argument('-d', '--dry-run', default=False, action="store_true", help="Dry run, build the flow without submitting it") parser.add_argument('--paral-kgb', type=int, default=0, help="Paral_kgb input variable.") parser.add_argument( '--soc', default=False, action="store_true", help= ("Perform non-collinear run (nspinor==2, kptopt=3). Pseudo must have spin-orbit characteristic" )) #parser.add_argument('-n', '--new-ecut', type=int, default=None, action="store", # help="Extend the ecut grid with the new-ecut point") def parse_trials(s): if s == "all": return ["df", "gbrv"] return s.split(",") parser.add_argument('--trials', default="all", type=parse_trials, help="""\ List of tests e.g --trials=ghosts,df,gbrv. ghosts: tests ghost states in the conduction region. df: test delta factor against all electron reference. gbrv: test fcc and bcc lattice parameters against AE reference. phgamma: test violation of the acoustic sum rule raren_relax: Structural relaxation for lantanide + nitrogen in rocksalt structure""" ) parser.add_argument( '--loglevel', default="ERROR", type=str, help= "set the loglevel. Possible values: CRITICAL, ERROR (default), WARNING, INFO, DEBUG" ) parser.add_argument( '-v', '--verbose', default=0, action='count', # -vv --> verbose=2 help='Verbose, can be supplied multiple times to increase verbosity') parser.add_argument('path', help='pseudopotential file.') try: options = parser.parse_args() except Exception as exc: show_examples_and_exit(1) # loglevel is bound to the string value obtained from the command line argument. # Convert to upper case to allow the user to specify --loglevel=DEBUG or --loglevel=debug import logging numeric_level = getattr(logging, options.loglevel.upper(), None) if not isinstance(numeric_level, int): raise ValueError('Invalid log level: %s' % options.loglevel) logging.basicConfig(level=numeric_level) options.manager = abilab.TaskManager.as_manager(options.manager) from pseudo_dojo import logo1 cprint(logo1(), "red") pseudo = dojopseudo_from_file(options.path) if pseudo is None: cprint("Error while parsing: %s" % options.path) cprint("Check your file. Returning 1") return 1 flow = build_flow(pseudo, options) if flow is None: cprint("DOJO_REPORT is already computed for pseudo %s." % options.path, "magenta") return 1 if options.dry_run: flow.build_and_pickle_dump(abivalidate=False) return 0 else: # Run the flow with the scheduler. return flow.make_scheduler().start()