original_docstring:  Function that will provide an "interface" for interactive
              line assignment in a notebook environment.
  
              Basic functionality is looping over a series of peaks,
              which will query splatalogue for known transitions in the
              vicinity. If the line is known in Splatalogue, it will
              throw it into an Transition object and flag it as known.
              Conversely, if it's not known in Splatalogue it will defer
              assignment, flagging it as unassigned and dumping it into
              the `uline` attribute.
  
          Parameters
          ----------
           auto: bool
               If True the assignment process does not require user input, otherwise will prompt user.
          
docstring: Function that will provide an "interface" for interactive
  line assignment in a notebook environment.
  
  Basic functionality is looping over a series of peaks,
  which will query splatalogue for known transitions in the
  vicinity. If the line is known in Splatalogue, it will
  throw it into an Transition object and flag it as known.
  Conversely, if it's not known in Splatalogue it will defer
  assignment, flagging it as unassigned and dumping it into
  the `uline` attribute.
  
  Parameters
  
  bool
  If True the assignment process does not require user input, otherwise will prompt user.
docstring_tokens: Function that will provide an " interface " for interactive line assignment in a notebook environment . Basic functionality is looping over a series of peaks which will query splatalogue for known transitions in the vicinity . If the line is known in Splatalogue it will throw it into an Transition object and flag it as known . Conversely if it ' s not known in Splatalogue it will defer assignment flagging it as unassigned and dumping it into the ` uline ` attribute . Parameters bool If True the assignment process does not require user input otherwise will prompt user .
code: def process_splatalogue(self, auto=True, progressbar=True):
          """ Function that will provide an "interface" for interactive
              line assignment in a notebook environment.
  
              Basic functionality is looping over a series of peaks,
              which will query splatalogue for known transitions in the
              vicinity. If the line is known in Splatalogue, it will
              throw it into an Transition object and flag it as known.
              Conversely, if it's not known in Splatalogue it will defer
              assignment, flagging it as unassigned and dumping it into
              the `uline` attribute.
  
          Parameters
          ----------
           auto: bool
               If True the assignment process does not require user input, otherwise will prompt user.
          """
          ulines = self.line_lists["Peaks"].get_ulines()
          self.logger.info(f"Beginning Splatalogue lookup on {len(ulines)} lines.")
          iterator = enumerate(ulines)
          if progressbar is True:
              iterator = tqdm(iterator)
          for index, uline in iterator:
              frequency = uline.frequency
              self.logger.info(f"Searching for frequency {frequency:,.4f}")
              # Call splatalogue API to search for frequency
              if self.session.freq_abs is True:
                  width = self.session.freq_prox
              else:
                  width = self.session.freq_prox * frequency
              splat_df = analysis.search_center_frequency(frequency, width=width)
              if splat_df is not None:
                  # Filter out lines that are way too unlikely on grounds of temperature
                  splat_df = splat_df.loc[splat_df["E_U (K)"] <= self.t_threshold]
                  # Filter out quack elemental compositions
                  for index, row in splat_df.iterrows():
                      # Convert the string into a chemical formula object
                      try:
                          # Clean vibrational state and torsional specification
                          cation_flag = False
                          clean_formula = row["Species"].split("v")[0]
                          # Remove labels
                          for label in [
                              "l-",
                              "c-",
                              "t-",
                              ",",
                              "-gauche",
                              "cis-",
                              "trans-",
                              "trans",
                              "anti",
                              "sym",
                              "=",
                          ]:
                              clean_formula = clean_formula.replace(label, "")
                          # Remove the torsional states
                          clean_formula = clean_formula.split("-")[-1]
                          # These are typically charged, and the chemical fomrula parsing does not play well
                          if "+" in clean_formula:
                              cation_flag = True
                              clean_formula = clean_formula.replace("+", "")
                          formula_obj = formula(clean_formula)
                          # Add the charge back on
                          if cation_flag is True:
                              clean_formula += "+"
                          # Check if proposed molecule contains atoms not
                          # expected in composition
                          comp_check = all(
                              str(atom) in self.session.composition
                              for atom in formula_obj.atoms
                          )
                          if comp_check is False:
                              # If there are crazy things in the mix, forget about it
                              self.logger.info("Molecule " + clean_formula + " rejected.")
                              splat_df.drop(index, inplace=True)
                      except:
                          self.logger.warning(
                              "Could not parse molecule " + clean_formula + " rejected."
                          )
                          splat_df.drop(index, inplace=True)
                  nitems = len(splat_df)
  
                  splat_df = analysis.calc_line_weighting(
                      frequency,
                      splat_df,
                      prox=self.session.freq_prox,
                      abs=self.session.freq_abs,
                  )
                  if splat_df is not None:
                      self.logger.info(
                          f"Found {len(splat_df)} candidates for frequency {frequency:,.4f}, index {index}."
                      )
                      if self.verbose is True:
                          display(HTML(splat_df.to_html()))
                      try:
                          if auto is False:
                              # If not automated, we need a human to look at frequencies
                              # Print the dataframe for notebook viewing
                              splat_index = int(
                                  input(
                                      "Please choose an assignment index: 0 - "
                                      + str(nitems - 1)
                                  )
                              )
                          else:
                              # If automated, choose closest frequency
                              splat_index = 0
                          self.logger.info(f"Index {splat_index} was chosen.")
                          ass_df = splat_df.iloc[[splat_index]]
                          splat_df.to_csv(
                              f"queries/{self.session.experiment}-{index}.csv",
                              index=False,
                          )
                          ass_dict = {
                              "uline": False,
                              "frequency": frequency,
                              "intensity": uline.intensity,
                              "name": ass_df["Chemical Name"][0],
                              "catalog_frequency": ass_df["Frequency"][0],
                              "catalog_intensity": ass_df["CDMS/JPL Intensity"][0],
                              "formula": ass_df["Species"][0],
                              "r_qnos": ass_df["Resolved QNs"][0],
                              # "S": ass_df["$S_{ij}^2 D^2$"][0],
                              "ustate_energy": ass_df["E_U (K)"][0],
                              "weighting": ass_df["Weighting"][0],
                              "source": "CDMS/JPL",
                              "deviation": frequency - ass_df["Frequency"][0],
                          }
                          # Update the Transition entry
                          uline.__dict__.update(**ass_dict)
                      except ValueError:
                          # If nothing matches, keep in the U-line
                          # pile.
                          self.logger.info(f"Deferring assignment for index {index}.")
                  else:
                      # Throw into U-line pile if no matches at all
                      self.logger.info(f"No species known for {frequency:,.4f}")
          self.logger.info("Splatalogue search finished.")
code_tokens: def process_splatalogue ( self , auto = True , progressbar = True ) : ulines = self . line_lists [ "Peaks" ] . get_ulines ( ) self . logger . info ( f"Beginning Splatalogue lookup on {len(ulines)} lines." ) iterator = enumerate ( ulines ) if progressbar is True : iterator = tqdm ( iterator ) for index , uline in iterator : frequency = uline . frequency self . logger . info ( f"Searching for frequency {frequency:,.4f}" ) if self . session . freq_abs is True : width = self . session . freq_prox else : width = self . session . freq_prox * frequency splat_df = analysis . search_center_frequency ( frequency , width = width ) if splat_df is not None : splat_df = splat_df . loc [ splat_df [ "E_U (K)" ] <= self . t_threshold ] for index , row in splat_df . iterrows ( ) : try : cation_flag = False clean_formula = row [ "Species" ] . split ( "v" ) [ 0 ] for label in [ "l-" , "c-" , "t-" , "," , "-gauche" , "cis-" , "trans-" , "trans" , "anti" , "sym" , "=" , ] : clean_formula = clean_formula . replace ( label , "" ) clean_formula = clean_formula . split ( "-" ) [ - 1 ] if "+" in clean_formula : cation_flag = True clean_formula = clean_formula . replace ( "+" , "" ) formula_obj = formula ( clean_formula ) if cation_flag is True : clean_formula += "+" comp_check = all ( str ( atom ) in self . session . composition for atom in formula_obj . atoms ) if comp_check is False : self . logger . info ( "Molecule " + clean_formula + " rejected." ) splat_df . drop ( index , inplace = True ) except : self . logger . warning ( "Could not parse molecule " + clean_formula + " rejected." ) splat_df . drop ( index , inplace = True ) nitems = len ( splat_df ) splat_df = analysis . calc_line_weighting ( frequency , splat_df , prox = self . session . freq_prox , abs = self . session . freq_abs , ) if splat_df is not None : self . logger . info ( f"Found {len(splat_df)} candidates for frequency {frequency:,.4f}, index {index}." ) if self . verbose is True : display ( HTML ( splat_df . to_html ( ) ) ) try : if auto is False : splat_index = int ( input ( "Please choose an assignment index: 0 - " + str ( nitems - 1 ) ) ) else : splat_index = 0 self . logger . info ( f"Index {splat_index} was chosen." ) ass_df = splat_df . iloc [ [ splat_index ] ] splat_df . to_csv ( f"queries/{self.session.experiment}-{index}.csv" , index = False , ) ass_dict = { "uline" : False , "frequency" : frequency , "intensity" : uline . intensity , "name" : ass_df [ "Chemical Name" ] [ 0 ] , "catalog_frequency" : ass_df [ "Frequency" ] [ 0 ] , "catalog_intensity" : ass_df [ "CDMS/JPL Intensity" ] [ 0 ] , "formula" : ass_df [ "Species" ] [ 0 ] , "r_qnos" : ass_df [ "Resolved QNs" ] [ 0 ] , "ustate_energy" : ass_df [ "E_U (K)" ] [ 0 ] , "weighting" : ass_df [ "Weighting" ] [ 0 ] , "source" : "CDMS/JPL" , "deviation" : frequency - ass_df [ "Frequency" ] [ 0 ] , } uline . __dict__ . update ( ** ass_dict ) except ValueError : self . logger . info ( f"Deferring assignment for index {index}." ) else : self . logger . info ( f"No species known for {frequency:,.4f}" ) self . logger . info ( "Splatalogue search finished." )
short_docstring: Function that will provide an "interface" for interactive
  line assignment in a notebook environment.
short_docstring_tokens: Function that will provide an " interface " for interactive line assignment in a notebook environment .
comment: """ Function that will provide an "interface" for interactive
              line assignment in a notebook environment.
  
              Basic functionality is looping over a series of peaks,
              which will query splatalogue for known transitions in the
              vicinity. If the line is known in Splatalogue, it will
              throw it into an Transition object and flag it as known.
              Conversely, if it's not known in Splatalogue it will defer
              assignment, flagging it as unassigned and dumping it into
              the `uline` attribute.
  
          Parameters
          ----------
           auto: bool
               If True the assignment process does not require user input, otherwise will prompt user.
          """$SEP$# Call splatalogue API to search for frequency$SEP$# Filter out lines that are way too unlikely on grounds of temperature$SEP$# Filter out quack elemental compositions$SEP$# Convert the string into a chemical formula object$SEP$# Clean vibrational state and torsional specification$SEP$# Remove labels$SEP$# Remove the torsional states$SEP$# These are typically charged, and the chemical fomrula parsing does not play well$SEP$# Add the charge back on$SEP$# Check if proposed molecule contains atoms not$SEP$# expected in composition$SEP$# If there are crazy things in the mix, forget about it$SEP$# If not automated, we need a human to look at frequencies$SEP$# Print the dataframe for notebook viewing$SEP$# If automated, choose closest frequency$SEP$# "S": ass_df["$S_{ij}^2 D^2$"][0],$SEP$# Update the Transition entry$SEP$# If nothing matches, keep in the U-line$SEP$# pile.$SEP$# Throw into U-line pile if no matches at all