Skip to content

Updated parser spec with customizable nodes

Espen edited this page Oct 1, 2019 · 2 revisions

Open issues

  • All the short-cut properties are very similar. There should be a way to generalise them and set them in __init__ or somewhere else.
  • The NodeComposer still depends a lot on the actual input format provided. @DropD suggested a more generic form for the NodeComposer that would look like:
example_data = {
    'kpoints_mesh': {
        'args': ([10, 10, 10]),
        'offset': [1, 1, 1]
    },
    'cell_from_structure': {
        'args': (my_structure)
    }
}

def make_node(node_type, data):
    import deepcopy
    new_node = node_type()
    for property, property_args in deepcopy(data).items():
        setter_name = 'set_{}'.format(property)
        setter = getattr(new_node, setter_name)
        args = property_args.pop('args', [])
        kwargs = property_args
        setter(*args, **kwargs)
    return new_node

Initially there is a concern was that this very strict requirement on the format of quantities would make writing new FileParsers more complicated. Or we would have to implement conversion functions that require approximately the same amount of code than the current solution. However, we are already now doing something very similar in requiring a specific format for the quantities. Therefore it would not even be that much of change.