aiida-quantumespresso icon indicating copy to clipboard operation
aiida-quantumespresso copied to clipboard

Add some self-contained examples of how to create and run a calculation

Open borellim opened this issue 5 years ago • 1 comments

The previous examples folder was deleted because the scripts were so out-of-date to be more confusing than useful. See #322 and #131 for more context.

While the CLI launchers can be educational, they are not very self-contained and don't show how to create a calculation. We should add a few, either by resurrecting the examples folder or by adding them as downloadable files in the documentation.

borellim avatar Jun 06 '19 14:06 borellim

I also suggest to use in these sample scripts a function that pretty-prints the input nodes, such as this (salvaged from an old protocol file), because it can be very instructive:

def pretty_print_inputs(inputs, level=0):
    """
    Print a nested set of inputs in a human-readable way, indenting each nested level

    :param inputs: a nested dictionary of inputs nodes
    :param level: the nesting level of the current dictionary
    """
    def fmt_indent(level):
        return ' ' * (4 * level)

    for key, value in sorted(inputs.items()):
        if isinstance(value, dict):
            print('{indent:}{key:}: {{'.format(indent=fmt_indent(level), key=key))
            pretty_print_inputs(value, level=level + 1)
            print('{indent:}}}'.format(indent=fmt_indent(level)))
        elif isinstance(value, ParameterData):
            print('{indent:}{key:}'.format(indent=fmt_indent(level), key=key))
            for line in json.dumps(value.get_dict(), indent=4).split('\n'):
                print('{indent:}{line:}'.format(indent=fmt_indent(level), line=line))
        else:
            print('{indent:}{key:}: {value:}'.format(indent=fmt_indent(level), key=key, value=value))

borellim avatar Jun 06 '19 15:06 borellim