nodes: 0, module; 1, function_definition; 2, function_name:sort_basis_dict; 3, parameters; 4, block; 5, identifier:bs; 6, expression_statement; 7, comment:# yapf: disable; 8, expression_statement; 9, comment:# yapf: enable; 10, comment:# Add integers for the elements (being optimistic that element 150 will be found someday); 11, expression_statement; 12, expression_statement; 13, if_statement; 14, for_statement; 15, return_statement; 16, comment:"""Sorts a basis set dictionary into a standard order
  
      This, for example, allows the written file to be more easily read by humans by,
      for example, putting the name and description before more detailed fields.
  
      This is generally for cosmetic reasons. However, users will generally like things
      in a consistent order
      """; 17, assignment; 18, call; 19, assignment; 20, identifier:_use_odict; 21, block; 22, else_clause; 23, pattern_list; 24, call; 25, comment:# If this is a dictionary, sort recursively; 26, comment:# If this is a list, sort each element but DO NOT sort the list itself.; 27, block; 28, identifier:bs_sorted; 29, identifier:_keyorder; 30, list; 31, attribute; 32, argument_list; 33, identifier:bs_sorted; 34, call; 35, expression_statement; 36, block; 37, identifier:k; 38, identifier:v; 39, attribute; 40, argument_list; 41, if_statement; 42, comment:# Schema stuff; 43, string; 44, string; 45, string; 46, comment:# Auxiliary block; 47, string; 48, string; 49, string; 50, string; 51, string; 52, string; 53, comment:# Basis set metadata; 54, string; 55, string; 56, string; 57, string; 58, string; 59, string; 60, string; 61, string; 62, string; 63, string; 64, comment:# Reference stuff; 65, string; 66, string; 67, comment:# Version metadata; 68, string; 69, string; 70, comment:# Sources of components; 71, string; 72, comment:# Elements and data; 73, string; 74, string; 75, string; 76, string; 77, string; 78, string; 79, comment:# Shell information; 80, string; 81, string; 82, string; 83, string; 84, string; 85, string; 86, string; 87, string; 88, string; 89, string; 90, identifier:_keyorder; 91, identifier:extend; 92, list_comprehension; 93, identifier:sorted; 94, argument_list; 95, assignment; 96, expression_statement; 97, identifier:bs_sorted; 98, identifier:items; 99, call; 100, block; 101, elif_clause; 102, string_content:molssi_bse_schema; 103, string_content:schema_type; 104, string_content:schema_version; 105, string_content:jkfit; 106, string_content:jfit; 107, string_content:rifit; 108, string_content:admmfit; 109, string_content:dftxfit; 110, string_content:dftjfit; 111, string_content:name; 112, string_content:names; 113, string_content:aliases; 114, string_content:flags; 115, string_content:family; 116, string_content:description; 117, string_content:role; 118, string_content:auxiliaries; 119, string_content:notes; 120, string_content:function_types; 121, string_content:reference_description; 122, string_content:reference_keys; 123, string_content:version; 124, string_content:revision_description; 125, string_content:data_source; 126, string_content:elements; 127, string_content:references; 128, string_content:ecp_electrons; 129, string_content:electron_shells; 130, string_content:ecp_potentials; 131, string_content:components; 132, string_content:function_type; 133, string_content:region; 134, string_content:angular_momentum; 135, string_content:exponents; 136, string_content:coefficients; 137, string_content:ecp_type; 138, string_content:angular_momentum; 139, string_content:r_exponents; 140, string_content:gaussian_exponents; 141, string_content:coefficients; 142, call; 143, for_in_clause; 144, call; 145, keyword_argument; 146, identifier:bs_sorted; 147, call; 148, assignment; 149, identifier:isinstance; 150, argument_list; 151, expression_statement; 152, call; 153, comment:# Note - the only nested list is with coeffs, which shouldn't be sorted; 154, comment:#        (so we don't have to recurse into lists of lists); 155, block; 156, identifier:str; 157, argument_list; 158, identifier:x; 159, call; 160, attribute; 161, argument_list; 162, identifier:key; 163, lambda; 164, identifier:OrderedDict; 165, argument_list; 166, identifier:bs_sorted; 167, call; 168, identifier:v; 169, identifier:dict; 170, assignment; 171, identifier:isinstance; 172, argument_list; 173, expression_statement; 174, identifier:x; 175, identifier:range; 176, argument_list; 177, identifier:bs; 178, identifier:items; 179, lambda_parameters; 180, call; 181, identifier:bs_sorted; 182, identifier:dict; 183, argument_list; 184, subscript; 185, call; 186, identifier:v; 187, identifier:list; 188, assignment; 189, integer:150; 190, identifier:x; 191, attribute; 192, argument_list; 193, identifier:bs_sorted; 194, identifier:bs_sorted; 195, identifier:k; 196, identifier:sort_basis_dict; 197, argument_list; 198, subscript; 199, list_comprehension; 200, identifier:_keyorder; 201, identifier:index; 202, subscript; 203, identifier:v; 204, identifier:bs_sorted; 205, identifier:k; 206, conditional_expression:sort_basis_dict(x) if isinstance(x, dict) else x; 207, for_in_clause; 208, identifier:x; 209, integer:0; 210, call; 211, call; 212, identifier:x; 213, identifier:x; 214, identifier:v; 215, identifier:sort_basis_dict; 216, argument_list; 217, identifier:isinstance; 218, argument_list; 219, identifier:x; 220, identifier:x; 221, identifier:dict
code: def sort_basis_dict(bs):
      """Sorts a basis set dictionary into a standard order
  
      This, for example, allows the written file to be more easily read by humans by,
      for example, putting the name and description before more detailed fields.
  
      This is generally for cosmetic reasons. However, users will generally like things
      in a consistent order
      """
  
      # yapf: disable
      _keyorder = [
          # Schema stuff
          'molssi_bse_schema', 'schema_type', 'schema_version',
  
          # Auxiliary block
           'jkfit', 'jfit', 'rifit', 'admmfit', 'dftxfit', 'dftjfit',
  
          # Basis set metadata
          'name', 'names', 'aliases', 'flags', 'family', 'description', 'role', 'auxiliaries',
          'notes', 'function_types',
  
          # Reference stuff
          'reference_description', 'reference_keys',
  
          # Version metadata
          'version', 'revision_description',
  
          # Sources of components
          'data_source',
  
          # Elements and data
          'elements', 'references', 'ecp_electrons',
          'electron_shells', 'ecp_potentials', 'components',
  
          # Shell information
          'function_type', 'region', 'angular_momentum', 'exponents',
          'coefficients',
          'ecp_type', 'angular_momentum', 'r_exponents', 'gaussian_exponents',
          'coefficients'
      ]
      # yapf: enable
  
      # Add integers for the elements (being optimistic that element 150 will be found someday)
      _keyorder.extend([str(x) for x in range(150)])
  
      bs_sorted = sorted(bs.items(), key=lambda x: _keyorder.index(x[0]))
      if _use_odict:
          bs_sorted = OrderedDict(bs_sorted)
      else:
          bs_sorted = dict(bs_sorted)
  
      for k, v in bs_sorted.items():
          # If this is a dictionary, sort recursively
          # If this is a list, sort each element but DO NOT sort the list itself.
          if isinstance(v, dict):
              bs_sorted[k] = sort_basis_dict(v)
          elif isinstance(v, list):
              # Note - the only nested list is with coeffs, which shouldn't be sorted
              #        (so we don't have to recurse into lists of lists)
              bs_sorted[k] = [sort_basis_dict(x) if isinstance(x, dict) else x for x in v]
  
      return bs_sorted