Create a basic folder tree for dumping DFT calculcations for reaction energies.

    Dear all

    Use this command make the right structure for your folders
    for submitting data for Catalysis Hub's Surface Reactions.

    Start by creating a template file by calling:

    $ cathub make_folders  <template_name>

    Then open the template and modify it to so that it contains information
    about your data. You will need to enter publication/dataset information,
    and specify the types of surfaces, facets and reactions.

    The 'reactions' entry should include two lists for each reaction;
    'reactants' and 'products', corresponding to left- and right hand side of
    each chemical equation respectively.
    Remember to balance the equation by including a prefactor or minus sign
    in the name when relevant. For example:

    reactions:

    -    reactants: ['CCH3star@ontop']

         products: ['Cstar@hollow', 'CH3star@ontop']

    -    reactants: ['CH4gas', '-0.5H2gas', 'star']

         products:  ['CH3star']


    Please include the phase of the species as an extension:

        'gas' for gas phase (i.e. CH4 -> CH4gas)

        'star' for empty slab or adsorbed phase. (i.e. OH -> OHstar)

    The site of adsorbed species is also included as an extension:

        '@site' (i.e. OHstar in bridge-> OHstar@bridge)

    Energy corrections to gas phase molecules can be included as:

        energy_corrections: {H2: 0.1, CH4: -0.15}

    Then, save the template and call:

    $ cathub make_folders <template_name>

    And folders will be created automatically.

    You can create several templates and call make_folders again
    if you, for example, are using different functionals or are
    doing different reactions on different surfaces.

    After creating your folders, add your output files from the
    electronic structure calculations at the positions.
    Accepted file formats include everything that can be read by ASE
    and contains the total potential energy of the calculation, such
    as .traj or .OUTCAR files.

    After dumping your files, run `cathub folder2db <your folder>`
    to collect the data.

def make_folders(template, custom_base):
    """Create a basic folder tree for dumping DFT calculcations for reaction energies.

    Dear all

    Use this command make the right structure for your folders
    for submitting data for Catalysis Hub's Surface Reactions.

    Start by creating a template file by calling:

    $ cathub make_folders  <template_name>

    Then open the template and modify it to so that it contains information
    about your data. You will need to enter publication/dataset information,
    and specify the types of surfaces, facets and reactions.

    The 'reactions' entry should include two lists for each reaction;
    'reactants' and 'products', corresponding to left- and right hand side of
    each chemical equation respectively.
    Remember to balance the equation by including a prefactor or minus sign
    in the name when relevant. For example:

    reactions:

    -    reactants: ['CCH3star@ontop']

         products: ['Cstar@hollow', 'CH3star@ontop']

    -    reactants: ['CH4gas', '-0.5H2gas', 'star']

         products:  ['CH3star']


    Please include the phase of the species as an extension:

        'gas' for gas phase (i.e. CH4 -> CH4gas)

        'star' for empty slab or adsorbed phase. (i.e. OH -> OHstar)

    The site of adsorbed species is also included as an extension:

        '@site' (i.e. OHstar in bridge-> OHstar@bridge)

    Energy corrections to gas phase molecules can be included as:

        energy_corrections: {H2: 0.1, CH4: -0.15}

    Then, save the template and call:

    $ cathub make_folders <template_name>

    And folders will be created automatically.

    You can create several templates and call make_folders again
    if you, for example, are using different functionals or are
    doing different reactions on different surfaces.

    After creating your folders, add your output files from the
    electronic structure calculations at the positions.
    Accepted file formats include everything that can be read by ASE
    and contains the total potential energy of the calculation, such
    as .traj or .OUTCAR files.

    After dumping your files, run `cathub folder2db <your folder>`
    to collect the data.
    """

    def dict_representer(dumper, data):
        return dumper.represent_dict(data.items())

    Dumper.add_representer(collections.OrderedDict, dict_representer)

    if custom_base is None:
        custom_base = os.path.abspath(os.path.curdir)
    template = custom_base + '/' + template

    template_data = ase_tools.REACTION_TEMPLATE
    if not os.path.exists(template):
        with open(template, 'w') as outfile:
            outfile.write(
                yaml.dump(
                    template_data,
                    indent=4,
                    Dumper=Dumper) +
                '\n')
            print("Created template file: {template}\n".format(**locals()) +
                  '  Please edit it and run the script again to create your folderstructure.\n' +
                  '  Run cathub make_folders --help for instructions')
            return

    with open(template) as infile:
        template_data = yaml.load(infile)
        title = template_data['title']
        authors = template_data['authors']
        journal = template_data['journal']
        volume = template_data['volume']
        number = template_data['number']
        pages = template_data['pages']
        year = template_data['year']
        email = template_data['email']
        publisher = template_data['publisher']
        doi = template_data['doi']
        dft_code = template_data['DFT_code']
        dft_functionals = template_data['DFT_functionals']
        reactions = template_data['reactions']
        crystal_structures = template_data['crystal_structures']
        bulk_compositions = template_data['bulk_compositions']
        facets = template_data['facets']
        energy_corrections = template_data['energy_corrections']

    make_folders_template.main(
        title=title,
        authors=eval(authors) if isinstance(
            authors, six.string_types) else authors,
        journal=journal,
        volume=volume,
        number=number,
        pages=pages,
        year=year,
        email=email,
        publisher=publisher,
        doi=doi,
        DFT_code=dft_code,
        DFT_functionals=dft_functionals,
        reactions=eval(reactions) if isinstance(
            reactions, six.string_types) else reactions,
        custom_base=custom_base,
        bulk_compositions=bulk_compositions,
        crystal_structures=crystal_structures,
        facets=facets,
        energy_corrections=energy_corrections
    )
    pub_id = tools.get_pub_id(title, authors, year)
    print(
        "Now dump your DFT output files into the folder, and run 'cathub folder2db {pub_id}'".format(**locals()))