Take a list of symbols and construct gas phase
    references system, when possible avoiding O2.
    Candidates can be rearranged, where earlier candidates
    get higher preference than later candidates

    assume symbols sorted by atomic number

def construct_reference_system(
    symbols,
    candidates=None,
    options=None,
):
    """Take a list of symbols and construct gas phase
    references system, when possible avoiding O2.
    Candidates can be rearranged, where earlier candidates
    get higher preference than later candidates

    assume symbols sorted by atomic number
    """
    if hasattr(options, 'no_hydrogen') and options.no_hydrogen:
        add_hydrogen = False
    else:
        add_hydrogen = True

    references = {}
    sorted_candidates = [
        'H2',
        'H2O',
        'NH3',
        'N2',
        'CH4',
        'CO',
        'H2S',
        'HCl',
        'O2']
    if candidates is None:
        candidates = sorted_candidates
    else:
        odd_candidates = [c for c in candidates if c not in sorted_candidates]
        candidates = [c for c in sorted_candidates if c in candidates] \
            + odd_candidates

    added_symbols = []
    # go symbols in adsorbate
    # to add reference species in procedural manner
    for symbol in symbols:
        added_symbols.append(symbol)
        for candidate in candidates:
            _symbols = ase.symbols.string2symbols(candidate)
            # Add partial adsorbate species
            # is subset of reference species
            # and reference species
            # is subset of full adsorbate species set
            if set(added_symbols) <= set(list(references.keys()) + _symbols) \
                    and set(list(references.keys()) + _symbols) <= set(symbols) \
                    and candidate not in references.values():
                references[symbol] = candidate
                break
        else:
            raise UserWarning((
                "No candidate satisfied {symbol}. Add more candidates\n"
                "    Symbols {symbols}\n"
                "    _Symbols {_symbols}\n"
                "    References {references}\n"
                "    Candidates {candidates}\n"
            ).format(
                symbol=symbol,
                symbols=symbols,
                _symbols=_symbols,
                candidates=candidates,
                references=list(references.keys()),
            ))

    sorted_references = []
    references = list(references.items())

    # put references in order so that each reference
    # only adds one one additional species in each step
    # while references:
    #     for i, reference in enumerate(references):
    #         if len(set(ase.symbols.string2symbols(reference[1])) -
    #                 set(x[0] for x in sorted_references)) == 1:
    #             sorted_references.append(references.pop(i))
    #             break

    return references