nodes: 0, module; 1, function_definition; 2, function_name:construct_reference_system; 3, parameters; 4, block; 5, identifier:symbols; 6, default_parameter; 7, default_parameter; 8, expression_statement; 9, if_statement; 10, expression_statement; 11, expression_statement; 12, if_statement; 13, expression_statement; 14, comment:# go symbols in adsorbate; 15, comment:# to add reference species in procedural manner; 16, for_statement; 17, expression_statement; 18, expression_statement; 19, comment:# put references in order so that each reference; 20, comment:# only adds one one additional species in each step; 21, comment:# while references:; 22, comment:#     for i, reference in enumerate(references):; 23, comment:#         if len(set(ase.symbols.string2symbols(reference[1])) -; 24, comment:#                 set(x[0] for x in sorted_references)) == 1:; 25, comment:#             sorted_references.append(references.pop(i)); 26, comment:#             break; 27, return_statement; 28, identifier:candidates; 29, None; 30, identifier:options; 31, None; 32, comment:"""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
      """; 33, boolean_operator; 34, block; 35, else_clause; 36, assignment; 37, assignment; 38, comparison_operator:candidates is None; 39, block; 40, else_clause; 41, assignment; 42, identifier:symbol; 43, identifier:symbols; 44, block; 45, assignment; 46, assignment; 47, identifier:references; 48, call; 49, attribute; 50, expression_statement; 51, block; 52, identifier:references; 53, dictionary; 54, identifier:sorted_candidates; 55, list; 56, identifier:candidates; 57, None; 58, expression_statement; 59, block; 60, identifier:added_symbols; 61, list; 62, expression_statement; 63, for_statement; 64, identifier:sorted_references; 65, list; 66, identifier:references; 67, call; 68, identifier:hasattr; 69, argument_list; 70, identifier:options; 71, identifier:no_hydrogen; 72, assignment; 73, expression_statement; 74, string; 75, string; 76, string; 77, string; 78, string; 79, string; 80, string; 81, string; 82, string; 83, assignment; 84, expression_statement; 85, expression_statement; 86, call; 87, identifier:candidate; 88, identifier:candidates; 89, block; 90, else_clause; 91, identifier:list; 92, argument_list; 93, identifier:options; 94, string; 95, identifier:add_hydrogen; 96, False; 97, assignment; 98, string_content:H2; 99, string_content:H2O; 100, string_content:NH3; 101, string_content:N2; 102, string_content:CH4; 103, string_content:CO; 104, string_content:H2S; 105, string_content:HCl; 106, string_content:O2; 107, identifier:candidates; 108, identifier:sorted_candidates; 109, assignment; 110, assignment; 111, attribute; 112, argument_list; 113, expression_statement; 114, comment:# Add partial adsorbate species; 115, comment:# is subset of reference species; 116, comment:# and reference species; 117, comment:# is subset of full adsorbate species set; 118, if_statement; 119, block; 120, call; 121, string_content:no_hydrogen; 122, identifier:add_hydrogen; 123, True; 124, identifier:odd_candidates; 125, list_comprehension; 126, identifier:candidates; 127, binary_operator:[c for c in sorted_candidates if c in candidates] \
              + odd_candidates; 128, identifier:added_symbols; 129, identifier:append; 130, identifier:symbol; 131, assignment; 132, boolean_operator; 133, block; 134, raise_statement; 135, attribute; 136, argument_list; 137, identifier:c; 138, for_in_clause; 139, if_clause; 140, list_comprehension; 141, line_continuation:\; 142, identifier:odd_candidates; 143, identifier:_symbols; 144, call; 145, boolean_operator; 146, line_continuation:\; 147, comparison_operator:candidate not in references.values(); 148, expression_statement; 149, break_statement; 150, call; 151, identifier:references; 152, identifier:items; 153, identifier:c; 154, identifier:candidates; 155, comparison_operator:c not in sorted_candidates; 156, identifier:c; 157, for_in_clause; 158, if_clause; 159, attribute; 160, argument_list; 161, comparison_operator:set(added_symbols) <= set(list(references.keys()) + _symbols); 162, line_continuation:\; 163, comparison_operator:set(list(references.keys()) + _symbols) <= set(symbols); 164, identifier:candidate; 165, call; 166, assignment; 167, identifier:UserWarning; 168, argument_list; 169, identifier:c; 170, identifier:sorted_candidates; 171, identifier:c; 172, identifier:sorted_candidates; 173, comparison_operator:c in candidates; 174, attribute; 175, identifier:string2symbols; 176, identifier:candidate; 177, call; 178, call; 179, call; 180, call; 181, attribute; 182, argument_list; 183, subscript; 184, identifier:candidate; 185, call; 186, identifier:c; 187, identifier:candidates; 188, identifier:ase; 189, identifier:symbols; 190, identifier:set; 191, argument_list; 192, identifier:set; 193, argument_list; 194, identifier:set; 195, argument_list; 196, identifier:set; 197, argument_list; 198, identifier:references; 199, identifier:values; 200, identifier:references; 201, identifier:symbol; 202, attribute; 203, argument_list; 204, identifier:added_symbols; 205, binary_operator:list(references.keys()) + _symbols; 206, binary_operator:list(references.keys()) + _symbols; 207, identifier:symbols; 208, parenthesized_expression; 209, identifier:format; 210, keyword_argument; 211, keyword_argument; 212, keyword_argument; 213, keyword_argument; 214, keyword_argument; 215, call; 216, identifier:_symbols; 217, call; 218, identifier:_symbols; 219, concatenated_string; 220, identifier:symbol; 221, identifier:symbol; 222, identifier:symbols; 223, identifier:symbols; 224, identifier:_symbols; 225, identifier:_symbols; 226, identifier:candidates; 227, identifier:candidates; 228, identifier:references; 229, call; 230, identifier:list; 231, argument_list; 232, identifier:list; 233, argument_list; 234, string:"No candidate satisfied {symbol}. Add more candidates\n"; 235, string:"    Symbols {symbols}\n"; 236, string:"    _Symbols {_symbols}\n"; 237, string:"    References {references}\n"; 238, string:"    Candidates {candidates}\n"; 239, identifier:list; 240, argument_list; 241, call; 242, call; 243, call; 244, attribute; 245, argument_list; 246, attribute; 247, argument_list; 248, attribute; 249, argument_list; 250, identifier:references; 251, identifier:keys; 252, identifier:references; 253, identifier:keys; 254, identifier:references; 255, identifier:keys
code: 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