Beispiel #1
0
    def docvar(varname):
        from abipy.htc.abivars_db import get_abinit_variables

        if varname == "inputvariable":
            return "inputvariable is a very complicated input variable. Better to ask for help immediately"
        #            return ("When we said that you should pass `inputvariable` to docvar we meant that"
        #                    "you should pass a string with the name of a valid ABINT variable e.g. `ecut`"
        #                    "not `inputvariable` :)")
        return get_abinit_variables()[varname]
Beispiel #2
0
    def docvar(varname):
        from abipy.htc.abivars_db import get_abinit_variables
        if varname == "inputvariable":
            return (
                "inputvariable is a very complicated input variable. Better to ask for help immediately"
            )


#            return ("When we said that you should pass `inputvariable` to docvar we meant that"
#                    "you should pass a string with the name of a valid ABINT variable e.g. `ecut`"
#                    "not `inputvariable` :)")
        return get_abinit_variables()[varname]
Beispiel #3
0
def main():
    def str_examples():
        examples = """\
Usage example:
    abidoc.py man ecut      --> Show documentation for ecut input variable.
    abidoc.py apropos ecut  --> To search in the database for the variables related to ecut.
    abidoc.py find paw      --> To search in the database for the variables whose name contains paw 
    abidoc.py list          --> Print full list of variables 
"""
        return examples

    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)

    # Build the main parser.
    parser = argparse.ArgumentParser(epilog=str_examples(), formatter_class=argparse.RawDescriptionHelpFormatter)

    base_parser = argparse.ArgumentParser(add_help=False)

    base_parser.add_argument('-v', '--verbose', default=0, action='count', # -vv --> verbose=2
                        help='verbose, can be supplied multiple times to increase verbosity')

    var_parser = argparse.ArgumentParser(add_help=False)
    var_parser.add_argument('varname', help="ABINIT variable")

    # Create the parsers for the sub-commands
    subparsers = parser.add_subparsers(dest='command', help='sub-command help', description="Valid subcommands")

    # Subparser for man.
    p_man = subparsers.add_parser('man', parents=[base_parser, var_parser], help="Show documentation for varname.")

    # Subparser for apropos.
    p_apropos = subparsers.add_parser('apropos', parents=[base_parser, var_parser], help="Find variables related to varname.")

    # Subparser for find.
    p_find = subparsers.add_parser('find', parents=[base_parser, var_parser], help="Find all variables whose name contains varname.")

    # Subparser for require.
    #p_require = subparsers.add_parser('require', parents=[base_parser], help="Find all variables required by varname.")

    # Subparser for list.
    p_list = subparsers.add_parser('list', parents=[base_parser], help="List all variables.")
    p_list.add_argument('--mode', default="a", help="Sorte mode, `a` for alphabethical, `s` for sections, `c` for characteristics.")

    try:
        options = parser.parse_args()
    except Exception as exc: 
        show_examples_and_exit(error_code=1)

    database = get_abinit_variables()

    if options.command == "man":
        abinit_help(options.varname)

    elif options.command == "apropos":
        vlist = database.apropos(options.varname)
        print("apropos results:\n")
        print_vlist(vlist, options)

    elif options.command == "find":
        vlist = [v for v in database.values() if options.varname in v.varname]
        print("find results:\n")
        print_vlist(vlist, options)

    elif options.command == "list":

        if options.mode == "a":
            # Alphabetical
            for i, var in enumerate(database.values()):
                print(i, repr(var))

        elif options.mode == "s":
            # Grouped by sections.
            for section in database.sections:
                header = 30*"#" +  " Section: " + section + " " + 30*"#"
                print(header)
                print_vlist(database.vars_with_section(section), options)

        elif options.mode == "c":
            # Grouped by characteristics.
            for char in database.characteristics:
                header = 30*"#" +  " Characteristic: " + char + 30*"#"
                print(header)
                print_vlist(database.vars_with_char(char), options)

        else:
            raise ValueError("Wrong mode %s" % options.mode)

    else:
        raise ValueError("Don't know how to handle command %s" % options.command)
Beispiel #4
0
#!/usr/bin/env python
"""
Script to generate the json files with the list of Abinit variables.
The names are taken from the YAML file extracted from the official documentation.
"""
from abipy.htc.abivars_db import get_abinit_variables

# Get string.
s = get_abinit_variables().json_dumps_varnames()

# Write JSON file.
with open("abinit_vars.json", "w") as fh:
    fh.write(s)