def test_database(self): """Testing database of ABINIT variables.""" varscode = get_codevars() assert varscode is get_codevars() database = varscode["abinit"] # The text of this variable contaings greek symbols in HTML. var = database["cd_frqim_method"] repr(var) str(var) # Print all variables in the database. for name, var in database.items(): #print("testing variable: ", name) assert var.name == name repr(var) str(var) str(var.info) # FIXME #str(var._repr_html_()) # Database methods. database.apropos("ecut") # FIXME #assert len(database.json_dumps_varnames()) for setname in [ "basic", "rlx", "gstate", "eph", "ffield", "paral", "gw", "dfpt", "geo", "bse", "dev", "paw", "dmft", "files", "internal", "w90" ]: assert database.vars_with_varset(setname) for section in database.my_varset_list: assert len(database.vars_with_varset(section)) for charact in database.my_characteristics: print("character:", charact) assert len(database.vars_with_char(charact)) name2varset = database.name2varset assert name2varset["ecut"] == "basic" and name2varset["ionmov"] == "rlx" assert database.group_by_varset("ecut") == {'basic': ['ecut']} natom_var = database["natom"] ecut_var = database["ecut"] assert ecut_var.name == "ecut" assert not ecut_var.isarray assert not ecut_var.depends_on_dimension("natom") assert not ecut_var.depends_on_dimension(natom_var) # FIXME #assert ecut_var.url #assert ecut_var.html_link() and ecut_var.html_link(label="foo") spinat_var = database["spinat"] assert spinat_var.isarray assert spinat_var.depends_on_dimension("natom") assert spinat_var.depends_on_dimension(natom_var) assert not spinat_var.depends_on_dimension("ntypat")
def docvar(varname, executable="abinit"): """Return the `Variable` object associated to this name.""" from abipy.abio.abivar_database.variables import get_codevars return get_codevars()[executable][varname]
def get_abinit_variables(): """Returns the database with the description of the ABINIT variables.""" from abipy.abio.abivar_database.variables import get_codevars return get_codevars()["abinit"]
def main(): def show_examples_and_exit(err_msg=None, error_code=1): """Display the usage of the script.""" sys.stderr.write(get_epilog()) if err_msg: sys.stderr.write("Fatal Error\n" + err_msg + "\n") sys.exit(error_code) parser = get_parser(with_epilog=True) 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) # Get the dabase of variables for codename. from abipy.abio.abivar_database.variables import get_codevars vdb = get_codevars()[options.codename] if options.command == "man": abilab.abinit_help(options.varname) elif options.command == "browse": return vdb[options.varname].browse() elif options.command == "graphviz": if options.varname in vdb.my_varset_list: graph = vdb.get_graphviz(varset=options.varname, vartype=None, engine=options.engine) else: graph = vdb.get_graphviz_varname(varname=options.varname, engine=options.engine) import tempfile directory = tempfile.mkdtemp() print("Producing source files in:", directory) graph.view(directory=directory, cleanup=False) elif options.command == "apropos": vlist = vdb.apropos(options.varname) print_vlist(vlist, options) elif options.command == "find": vlist = [v for v in vdb.values() if options.varname in v.name] print("Find results:\n") print_vlist(vlist, options) elif options.command == "list": if options.mode == "a": # Alphabetical for i, var in enumerate(vdb.values()): print(i, repr(var)) elif options.mode == "s": # Grouped by varset for section in vdb.my_varset_list: print(30 * "#" + " Section: " + section + " " + 30 * "#") print_vlist(vdb.vars_with_section(section), options) elif options.mode == "c": # Grouped by characteristics. for char in vdb.my_characteristics: print(30 * "#" + " Characteristic: " + char + 30 * "#") print_vlist(vdb.vars_with_char(char), options) else: raise ValueError("Wrong mode %s" % options.mode) elif options.command == "withdim": for var in vdb.values(): if var.depends_on_dimension(options.dimname): cprint(repr(var), "yellow") print("dimensions:", str(var.dimensions), "\n") elif options.command == "scheduler": print("Options that can be specified in scheduler.yml:") print(flowtk.PyFlowScheduler.autodoc()) return 0 elif options.command == "manager": # Document TaskManager options and qparams. qtype = options.qtype if qtype == "script": manager = flowtk.TaskManager.from_user_config() script = manager.qadapter.get_script_str( job_name="job_name", launch_dir="workdir", executable="executable", qout_path="qout_file.path", qerr_path="qerr_file.path", stdin="stdin", stdout="stdout", stderr="stderr") print(script) else: print(flowtk.TaskManager.autodoc()) print("qtype supported: %s" % flowtk.all_qtypes()) print( "Use `abidoc.py manager slurm` to have the list of qparams for slurm.\n" ) if qtype is not None: print("QPARAMS for %s" % qtype) flowtk.show_qparams(qtype) elif options.command == "abibuild": abinit_build = flowtk.AbinitBuild() print() print(abinit_build) print() if not options.verbose: print("Use --verbose for additional info") else: print(abinit_build.info) else: raise ValueError("Don't know how to handle command %s" % options.command) return 0
def main(): def show_examples_and_exit(err_msg=None, error_code=1): """Display the usage of the script.""" sys.stderr.write(get_epilog()) if err_msg: sys.stderr.write("Fatal Error\n" + err_msg + "\n") sys.exit(error_code) parser = get_parser(with_epilog=True) 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) # Get the dabase of variables for codename. from abipy.abio.abivar_database.variables import get_codevars vdb = get_codevars()[options.codename] if options.command == "man": abilab.abinit_help(options.varname) elif options.command == "browse": return vdb[options.varname].browse() elif options.command == "graphviz": if options.varname in vdb.my_varset_list: graph = vdb.get_graphviz(varset=options.varname, vartype=None, engine=options.engine) else: graph = vdb.get_graphviz_varname(varname=options.varname, engine=options.engine) import tempfile directory = tempfile.mkdtemp() print("Producing source files in:", directory) graph.view(directory=directory, cleanup=False) elif options.command == "apropos": vlist = vdb.apropos(options.varname) print_vlist(vlist, options) elif options.command == "find": vlist = [v for v in vdb.values() if options.varname in v.name] print("Find results:\n") print_vlist(vlist, options) elif options.command == "list": if options.mode == "a": # Alphabetical for i, var in enumerate(vdb.values()): print(i, repr(var)) elif options.mode == "s": # Grouped by varset for section in vdb.my_varset_list: print(30*"#" + " Section: " + section + " " + 30*"#") print_vlist(vdb.vars_with_section(section), options) elif options.mode == "c": # Grouped by characteristics. for char in vdb.my_characteristics: print(30*"#" + " Characteristic: " + char + 30*"#") print_vlist(vdb.vars_with_char(char), options) else: raise ValueError("Wrong mode %s" % options.mode) elif options.command == "withdim": for var in vdb.values(): if var.depends_on_dimension(options.dimname): cprint(repr(var), "yellow") print("dimensions:", str(var.dimensions), "\n") elif options.command == "scheduler": print("Options that can be specified in scheduler.yml:") print(flowtk.PyFlowScheduler.autodoc()) return 0 elif options.command == "manager": # Document TaskManager options and qparams. qtype = options.qtype if qtype == "script": manager = flowtk.TaskManager.from_user_config() script = manager.qadapter.get_script_str( job_name="job_name", launch_dir="workdir", executable="executable", qout_path="qout_file.path", qerr_path="qerr_file.path", stdin="stdin", stdout="stdout", stderr="stderr") print(script) else: print(flowtk.TaskManager.autodoc()) print("qtype supported: %s" % flowtk.all_qtypes()) print("Use `abidoc.py manager slurm` to have the list of qparams for slurm.\n") if qtype is not None: print("QPARAMS for %s" % qtype) flowtk.show_qparams(qtype) elif options.command == "abibuild": abinit_build = flowtk.AbinitBuild() print() print(abinit_build) print() if not options.verbose: print("Use --verbose for additional info") else: print(abinit_build.info) else: raise ValueError("Don't know how to handle command %s" % options.command) return 0
def is_abivar(varname): """True if s is an ABINIT variable.""" # Add include statement # FIXME: These variables should be added to the database. extra = ["include", "xyzfile"] return varname in get_codevars()["abinit"] or varname in extra
def is_anaddb_var(varname): """True if varname is a valid Anaddb variable.""" return varname in get_codevars()["anaddb"]