parameters: (self, entry, surface)
return_statement: return reaction, revReaction
docstring: Read a kinetics ``entry`` for a single reaction as loaded from a
          Chemkin-format file. Returns a :class:`Reaction` object with the
          reaction and its associated kinetics.
docstring_summary: Read a kinetics ``entry`` for a single reaction as loaded from a
          Chemkin-format file. Returns a :class:`Reaction` object with the
          reaction and its associated kinetics.
docstring_tokens: Read a kinetics entry for a single reaction as loaded from a Chemkin - format file . Returns a : class : Reaction object with the reaction and its associated kinetics .
function: def read_kinetics_entry(self, entry, surface):
          """
          Read a kinetics ``entry`` for a single reaction as loaded from a
          Chemkin-format file. Returns a :class:`Reaction` object with the
          reaction and its associated kinetics.
          """
  
          # Handle non-default units which apply to this entry
          energy_units = self.energy_units
          quantity_units = self.quantity_units
          if 'units' in entry.lower():
              for units in sorted(QUANTITY_UNITS, key=lambda k: -len(k)):
                  pattern = re.compile(r'units *\/ *{} *\/'.format(re.escape(units)),
                                       flags=re.IGNORECASE)
                  m = pattern.search(entry)
                  if m:
                      entry = pattern.sub('', entry)
                      quantity_units = QUANTITY_UNITS[units]
                      break
  
              for units in sorted(ENERGY_UNITS, key=lambda k: -len(k)):
                  pattern = re.compile(r'units *\/ *{} *\/'.format(re.escape(units)),
                                       re.IGNORECASE)
                  m = pattern.search(entry)
                  if m:
                      entry = pattern.sub('', entry)
                      energy_units = ENERGY_UNITS[units]
                      break
  
          lines = entry.strip().splitlines()
  
          # The first line contains the reaction equation and a set of modified Arrhenius parameters
          tokens = lines[0].split()
          A = float(tokens[-3])
          b = float(tokens[-2])
          Ea = float(tokens[-1])
          reaction = ''.join(tokens[:-3]) + '\n'
          original_reaction = reaction  # for use in error messages
  
          # Identify tokens in the reaction expression in order of
          # decreasing length
          locs = {}
          for i in range(self.Slen, 0, -1):
              for j in range(len(reaction)-i+1):
                  test = reaction[j:j+i]
                  if test in self.species_tokens:
                      reaction = reaction[:j] + ' '*(i-1) + reaction[j+i-1:]
                      locs[j] = test[:-1], 'species'
                  elif test in self.other_tokens:
                      reaction = reaction[:j] + '\n'*i + reaction[j+i:]
                      locs[j] = test, self.other_tokens[test]
  
          # Anything that's left should be a stoichiometric coefficient or a '+'
          # between species
          for token in reaction.split():
              j = reaction.find(token)
              i = len(token)
              reaction = reaction[:j] + ' '*i + reaction[j+i:]
              if token == '+':
                  continue
  
              try:
                  locs[j] = int(token), 'coeff'
              except ValueError:
                  try:
                      locs[j] = float(token), 'coeff'
                  except ValueError:
                      raise InputError('Unexpected token "{}" in reaction expression "{}".',
                                       token, original_reaction)
  
          reactants = []
          products = []
          stoichiometry = 1
          lhs = True
          for token, kind in [v for k,v in sorted(locs.items())]:
              if kind == 'equal':
                  reversible = token in ('<=>', '=')
                  lhs = False
              elif kind == 'coeff':
                  stoichiometry = token
              elif lhs:
                  reactants.append((stoichiometry, token, kind))
                  stoichiometry = 1
              else:
                  products.append((stoichiometry, token, kind))
                  stoichiometry = 1
  
          if lhs:
              raise InputError("Failed to find reactant/product delimiter in reaction string.")
  
          # Create a new Reaction object for this reaction
          reaction = Reaction(reactants=[], products=[], reversible=reversible,
                              parser=self)
  
          def parse_expression(expression, dest):
              third_body_name = None
              third_body = False  # simple third body reaction (non-falloff)
              photon = False
              for stoichiometry, species, kind in expression:
                  if kind == 'third-body':
                      third_body = True
                      third_body_name = 'M'
                  elif kind == 'falloff3b':
                      third_body_name = 'M'
                  elif kind.startswith('falloff3b:'):
                      third_body_name = kind.split()[1]
                  elif kind == 'photon':
                      photon = True
                  else:
                      dest.append((stoichiometry, self.species_dict[species]))
  
              return third_body_name, third_body, photon
  
          third_body_name_r, third_body, photon_r = parse_expression(reactants, reaction.reactants)
          third_body_name_p, third_body, photon_p = parse_expression(products, reaction.products)
  
          if third_body_name_r != third_body_name_p:
              raise InputError('Third bodies do not match: "{}" and "{}" in'
                  ' reaction entry:\n\n{}', third_body_name_r, third_body_name_p, entry)
  
          if photon_r:
              raise InputError('Reactant photon not supported. '
                               'Found in reaction:\n{}', entry.strip())
          if photon_p and reversible:
              self.warn('Found reversible reaction containing a product photon:'
                  '\n{0}\nIf the "--permissive" option was specified, this will '
                  'be converted to an irreversible reaction with the photon '
                  'removed.'.format(entry.strip()))
              reaction.reversible = False
  
          reaction.third_body = third_body_name_r
  
          # Determine the appropriate units for k(T) and k(T,P) based on the number of reactants
          # This assumes elementary kinetics for all reactions
          rStoich = sum(r[0] for r in reaction.reactants) + (1 if third_body else 0)
          if rStoich < 1:
              raise InputError('No reactant species for reaction {}.', reaction)
  
          length_dim = 3 * (rStoich - 1)
          quantity_dim = rStoich - 1
          kunits = self.get_rate_constant_units(length_dim, 'cm',
                                                quantity_dim, quantity_units)
          klow_units = self.get_rate_constant_units(length_dim + 3, 'cm',
                                                    quantity_dim + 1, quantity_units)
  
          # The rest of the first line contains Arrhenius parameters
          arrhenius = Arrhenius(
              A=(A, kunits),
              b=b,
              Ea=(Ea, energy_units),
              parser=self
          )
  
          low_rate = None
          high_rate = None
          falloff = None
          pdep_arrhenius = []
          efficiencies = {}
          coverages = []
          cheb_coeffs = []
          revReaction = None
          is_sticking = None
          motz_wise = None
          Tmin = Tmax = Pmin = Pmax = None  # Chebyshev parameters
          degreeT = degreeP = None
  
          # Note that the subsequent lines could be in any order
          for line in lines[1:]:
              if not line.strip():
                  continue
              tokens = line.split('/')
              parsed = False
  
              if 'stick' in line.lower():
                  parsed = True
                  is_sticking = True
  
              if 'mwon' in line.lower():
                  parsed = True
                  motz_wise = True
  
              if 'mwoff' in line.lower():
                  parsed = True
                  motz_wise = False
  
              if 'dup' in line.lower():
                  # Duplicate reaction
                  parsed = True
                  reaction.duplicate = True
  
              if 'low' in line.lower():
                  # Low-pressure-limit Arrhenius parameters for "falloff" reaction
                  parsed = True
                  tokens = tokens[1].split()
                  low_rate = Arrhenius(
                      A=(float(tokens[0].strip()), klow_units),
                      b=float(tokens[1].strip()),
                      Ea=(float(tokens[2].strip()), energy_units),
                      parser=self
                  )
  
              elif 'high' in line.lower():
                  # High-pressure-limit Arrhenius parameters for "chemically
                  # activated" reaction
                  parsed = True
                  tokens = tokens[1].split()
                  high_rate = Arrhenius(
                      A=(float(tokens[0].strip()), kunits),
                      b=float(tokens[1].strip()),
                      Ea=(float(tokens[2].strip()), energy_units),
                      parser=self
                  )
                  # Need to fix units on the base reaction:
                  arrhenius.A = (arrhenius.A[0], klow_units)
  
              elif 'rev' in line.lower():
                  parsed = True
                  reaction.reversible = False
                  tokens = tokens[1].split()
                  # If the A factor in the rev line is zero, don't create the reverse reaction
                  if float(tokens[0].strip()) != 0.0:
                      # Create a reaction proceeding in the opposite direction
                      revReaction = Reaction(reactants=reaction.products,
                                             products=reaction.reactants,
                                             third_body=reaction.third_body,
                                             reversible=False,
                                             parser=self)
  
                      rev_rate = Arrhenius(
                          A=(float(tokens[0].strip()), klow_units),
                          b=float(tokens[1].strip()),
                          Ea=(float(tokens[2].strip()), energy_units),
                          parser=self
                      )
                      if third_body:
                          revReaction.kinetics = ThreeBody(rev_rate)
                      else:
                          revReaction.kinetics = ElementaryRate(rev_rate)
  
              elif 'ford' in line.lower():
                  parsed = True
                  tokens = tokens[1].split()
                  reaction.forward_orders[tokens[0].strip()] = float(tokens[1])
  
              elif 'troe' in line.lower():
                  # Troe falloff parameters
                  parsed = True
                  tokens = tokens[1].split()
                  falloff = Troe(A=float(tokens[0].strip()),
                                 T3=float(tokens[1].strip()),
                                 T1=float(tokens[2].strip()),
                                 T2=float(tokens[3].strip()) if len(tokens) > 3 else None)
              elif 'sri' in line.lower():
                  # SRI falloff parameters
                  parsed = True
                  tokens = tokens[1].split()
                  A = float(tokens[0].strip())
                  B = float(tokens[1].strip())
                  C = float(tokens[2].strip())
                  try:
                      D = float(tokens[3].strip())
                      E = float(tokens[4].strip())
                  except (IndexError, ValueError):
                      D = None
                      E = None
  
                  if D is None or E is None:
                      falloff = Sri(A=A, B=B, C=C)
                  else:
                      falloff = Sri(A=A, B=B, C=C, D=D, E=E)
  
              elif 'cov' in line.lower():
                  parsed = True
                  C = tokens[1].split()
                  coverages.append(
                      [C[0], fortFloat(C[1]), fortFloat(C[2]), fortFloat(C[3])])
  
              elif 'cheb' in line.lower():
                  # Chebyshev parameters
                  parsed = True
                  tokens = [t.strip() for t in tokens]
                  if contains(tokens, 'TCHEB'):
                      index = get_index(tokens, 'TCHEB')
                      tokens2 = tokens[index+1].split()
                      Tmin = float(tokens2[0].strip())
                      Tmax = float(tokens2[1].strip())
                  if contains(tokens, 'PCHEB'):
                      index = get_index(tokens, 'PCHEB')
                      tokens2 = tokens[index+1].split()
                      Pmin = (float(tokens2[0].strip()), 'atm')
                      Pmax = (float(tokens2[1].strip()), 'atm')
                  if contains(tokens, 'TCHEB') or contains(tokens, 'PCHEB'):
                      pass
                  elif degreeT is None or degreeP is None:
                      tokens2 = tokens[1].split()
                      degreeT = int(float(tokens2[0].strip()))
                      degreeP = int(float(tokens2[1].strip()))
                      cheb_coeffs.extend([float(t.strip()) for t in tokens2[2:]])
                  else:
                      tokens2 = tokens[1].split()
                      cheb_coeffs.extend([float(t.strip()) for t in tokens2])
  
              elif 'plog' in line.lower():
                  # Pressure-dependent Arrhenius parameters
                  parsed = True
                  tokens = tokens[1].split()
                  pdep_arrhenius.append([float(tokens[0].strip()), Arrhenius(
                      A=(float(tokens[1].strip()), kunits),
                      b=float(tokens[2].strip()),
                      Ea=(float(tokens[3].strip()), energy_units),
                      parser=self
                  )])
              elif len(tokens) >= 2:
                  # Assume a list of collider efficiencies
                  parsed = True
                  for collider, efficiency in zip(tokens[0::2], tokens[1::2]):
                      efficiencies[collider.strip()] = float(efficiency.strip())
  
              if not parsed:
                  raise InputError('Unparsable line:\n"""\n{}\n"""', line)
  
          # Decide which kinetics to keep and store them on the reaction object.
          # At most one of the special cases should be true
          tests = [cheb_coeffs, pdep_arrhenius, low_rate, high_rate, third_body,
                   surface]
          if sum(bool(t) for t in tests) > 1:
              raise InputError('Reaction {} contains parameters for more than '
                               'one reaction type.', original_reaction)
  
          if cheb_coeffs:
              if Tmin is None or Tmax is None:
                  raise InputError('Missing TCHEB line for reaction {}', reaction)
              if Pmin is None or Pmax is None:
                  raise InputError('Missing PCHEB line for reaction {}', reaction)
              if len(cheb_coeffs) != degreeT * degreeP:
                  raise InputError('Incorrect number of Chebyshev coefficients. '
                      'Expected {}*{} = {} but got {}', degreeT, degreeP,
                      degreeT * degreeP, len(cheb_coeffs))
              if quantity_units == self.quantity_units:
                  quantity_units = None
              reaction.kinetics = Chebyshev(
                  Tmin=Tmin, Tmax=Tmax, Pmin=Pmin, Pmax=Pmax,
                  quantity_units=quantity_units,
                  coeffs=np.array(cheb_coeffs, np.float64).reshape((degreeT, degreeP)))
          elif pdep_arrhenius:
              reaction.kinetics = PDepArrhenius(
                  pressures=[P for P, arrh in pdep_arrhenius],
                  pressure_units="atm",
                  arrhenius=[arrh for P, arrh in pdep_arrhenius]
              )
          elif low_rate is not None:
              reaction.kinetics = Falloff(high_rate=arrhenius,
                                          low_rate=low_rate,
                                          F=falloff,
                                          efficiencies=efficiencies)
          elif high_rate is not None:
              reaction.kinetics = ChemicallyActivated(high_rate=high_rate,
                                                      low_rate=arrhenius,
                                                      F=falloff,
                                                      efficiencies=efficiencies)
          elif third_body:
              reaction.kinetics = ThreeBody(high_rate=arrhenius,
                                            efficiencies=efficiencies)
          elif reaction.third_body:
              raise InputError('Reaction equation implies pressure '
                  'dependence but no alternate rate parameters (i.e. HIGH or '
                  'LOW) were given for reaction {}.', reaction)
          elif surface:
              reaction.kinetics = SurfaceRate(rate=arrhenius,
                                              coverages=coverages,
                                              is_sticking=is_sticking,
                                              motz_wise=motz_wise)
          else:
              reaction.kinetics = ElementaryRate(arrhenius)
  
          if revReaction:
              revReaction.duplicate = reaction.duplicate
              revReaction.kinetics.efficiencies = reaction.kinetics.efficiencies
  
          return reaction, revReaction
function_tokens: def read_kinetics_entry ( self , entry , surface ) : # Handle non-default units which apply to this entry energy_units = self . energy_units quantity_units = self . quantity_units if 'units' in entry . lower ( ) : for units in sorted ( QUANTITY_UNITS , key = lambda k : - len ( k ) ) : pattern = re . compile ( r'units *\/ *{} *\/' . format ( re . escape ( units ) ) , flags = re . IGNORECASE ) m = pattern . search ( entry ) if m : entry = pattern . sub ( '' , entry ) quantity_units = QUANTITY_UNITS [ units ] break for units in sorted ( ENERGY_UNITS , key = lambda k : - len ( k ) ) : pattern = re . compile ( r'units *\/ *{} *\/' . format ( re . escape ( units ) ) , re . IGNORECASE ) m = pattern . search ( entry ) if m : entry = pattern . sub ( '' , entry ) energy_units = ENERGY_UNITS [ units ] break lines = entry . strip ( ) . splitlines ( ) # The first line contains the reaction equation and a set of modified Arrhenius parameters tokens = lines [ 0 ] . split ( ) A = float ( tokens [ - 3 ] ) b = float ( tokens [ - 2 ] ) Ea = float ( tokens [ - 1 ] ) reaction = '' . join ( tokens [ : - 3 ] ) + '\n' original_reaction = reaction # for use in error messages # Identify tokens in the reaction expression in order of # decreasing length locs = { } for i in range ( self . Slen , 0 , - 1 ) : for j in range ( len ( reaction ) - i + 1 ) : test = reaction [ j : j + i ] if test in self . species_tokens : reaction = reaction [ : j ] + ' ' * ( i - 1 ) + reaction [ j + i - 1 : ] locs [ j ] = test [ : - 1 ] , 'species' elif test in self . other_tokens : reaction = reaction [ : j ] + '\n' * i + reaction [ j + i : ] locs [ j ] = test , self . other_tokens [ test ] # Anything that's left should be a stoichiometric coefficient or a '+' # between species for token in reaction . split ( ) : j = reaction . find ( token ) i = len ( token ) reaction = reaction [ : j ] + ' ' * i + reaction [ j + i : ] if token == '+' : continue try : locs [ j ] = int ( token ) , 'coeff' except ValueError : try : locs [ j ] = float ( token ) , 'coeff' except ValueError : raise InputError ( 'Unexpected token "{}" in reaction expression "{}".' , token , original_reaction ) reactants = [ ] products = [ ] stoichiometry = 1 lhs = True for token , kind in [ v for k , v in sorted ( locs . items ( ) ) ] : if kind == 'equal' : reversible = token in ( '<=>' , '=' ) lhs = False elif kind == 'coeff' : stoichiometry = token elif lhs : reactants . append ( ( stoichiometry , token , kind ) ) stoichiometry = 1 else : products . append ( ( stoichiometry , token , kind ) ) stoichiometry = 1 if lhs : raise InputError ( "Failed to find reactant/product delimiter in reaction string." ) # Create a new Reaction object for this reaction reaction = Reaction ( reactants = [ ] , products = [ ] , reversible = reversible , parser = self ) def parse_expression ( expression , dest ) : third_body_name = None third_body = False # simple third body reaction (non-falloff) photon = False for stoichiometry , species , kind in expression : if kind == 'third-body' : third_body = True third_body_name = 'M' elif kind == 'falloff3b' : third_body_name = 'M' elif kind . startswith ( 'falloff3b:' ) : third_body_name = kind . split ( ) [ 1 ] elif kind == 'photon' : photon = True else : dest . append ( ( stoichiometry , self . species_dict [ species ] ) ) return third_body_name , third_body , photon third_body_name_r , third_body , photon_r = parse_expression ( reactants , reaction . reactants ) third_body_name_p , third_body , photon_p = parse_expression ( products , reaction . products ) if third_body_name_r != third_body_name_p : raise InputError ( 'Third bodies do not match: "{}" and "{}" in' ' reaction entry:\n\n{}' , third_body_name_r , third_body_name_p , entry ) if photon_r : raise InputError ( 'Reactant photon not supported. ' 'Found in reaction:\n{}' , entry . strip ( ) ) if photon_p and reversible : self . warn ( 'Found reversible reaction containing a product photon:' '\n{0}\nIf the "--permissive" option was specified, this will ' 'be converted to an irreversible reaction with the photon ' 'removed.' . format ( entry . strip ( ) ) ) reaction . reversible = False reaction . third_body = third_body_name_r # Determine the appropriate units for k(T) and k(T,P) based on the number of reactants # This assumes elementary kinetics for all reactions rStoich = sum ( r [ 0 ] for r in reaction . reactants ) + ( 1 if third_body else 0 ) if rStoich < 1 : raise InputError ( 'No reactant species for reaction {}.' , reaction ) length_dim = 3 * ( rStoich - 1 ) quantity_dim = rStoich - 1 kunits = self . get_rate_constant_units ( length_dim , 'cm' , quantity_dim , quantity_units ) klow_units = self . get_rate_constant_units ( length_dim + 3 , 'cm' , quantity_dim + 1 , quantity_units ) # The rest of the first line contains Arrhenius parameters arrhenius = Arrhenius ( A = ( A , kunits ) , b = b , Ea = ( Ea , energy_units ) , parser = self ) low_rate = None high_rate = None falloff = None pdep_arrhenius = [ ] efficiencies = { } coverages = [ ] cheb_coeffs = [ ] revReaction = None is_sticking = None motz_wise = None Tmin = Tmax = Pmin = Pmax = None # Chebyshev parameters degreeT = degreeP = None # Note that the subsequent lines could be in any order for line in lines [ 1 : ] : if not line . strip ( ) : continue tokens = line . split ( '/' ) parsed = False if 'stick' in line . lower ( ) : parsed = True is_sticking = True if 'mwon' in line . lower ( ) : parsed = True motz_wise = True if 'mwoff' in line . lower ( ) : parsed = True motz_wise = False if 'dup' in line . lower ( ) : # Duplicate reaction parsed = True reaction . duplicate = True if 'low' in line . lower ( ) : # Low-pressure-limit Arrhenius parameters for "falloff" reaction parsed = True tokens = tokens [ 1 ] . split ( ) low_rate = Arrhenius ( A = ( float ( tokens [ 0 ] . strip ( ) ) , klow_units ) , b = float ( tokens [ 1 ] . strip ( ) ) , Ea = ( float ( tokens [ 2 ] . strip ( ) ) , energy_units ) , parser = self ) elif 'high' in line . lower ( ) : # High-pressure-limit Arrhenius parameters for "chemically # activated" reaction parsed = True tokens = tokens [ 1 ] . split ( ) high_rate = Arrhenius ( A = ( float ( tokens [ 0 ] . strip ( ) ) , kunits ) , b = float ( tokens [ 1 ] . strip ( ) ) , Ea = ( float ( tokens [ 2 ] . strip ( ) ) , energy_units ) , parser = self ) # Need to fix units on the base reaction: arrhenius . A = ( arrhenius . A [ 0 ] , klow_units ) elif 'rev' in line . lower ( ) : parsed = True reaction . reversible = False tokens = tokens [ 1 ] . split ( ) # If the A factor in the rev line is zero, don't create the reverse reaction if float ( tokens [ 0 ] . strip ( ) ) != 0.0 : # Create a reaction proceeding in the opposite direction revReaction = Reaction ( reactants = reaction . products , products = reaction . reactants , third_body = reaction . third_body , reversible = False , parser = self ) rev_rate = Arrhenius ( A = ( float ( tokens [ 0 ] . strip ( ) ) , klow_units ) , b = float ( tokens [ 1 ] . strip ( ) ) , Ea = ( float ( tokens [ 2 ] . strip ( ) ) , energy_units ) , parser = self ) if third_body : revReaction . kinetics = ThreeBody ( rev_rate ) else : revReaction . kinetics = ElementaryRate ( rev_rate ) elif 'ford' in line . lower ( ) : parsed = True tokens = tokens [ 1 ] . split ( ) reaction . forward_orders [ tokens [ 0 ] . strip ( ) ] = float ( tokens [ 1 ] ) elif 'troe' in line . lower ( ) : # Troe falloff parameters parsed = True tokens = tokens [ 1 ] . split ( ) falloff = Troe ( A = float ( tokens [ 0 ] . strip ( ) ) , T3 = float ( tokens [ 1 ] . strip ( ) ) , T1 = float ( tokens [ 2 ] . strip ( ) ) , T2 = float ( tokens [ 3 ] . strip ( ) ) if len ( tokens ) > 3 else None ) elif 'sri' in line . lower ( ) : # SRI falloff parameters parsed = True tokens = tokens [ 1 ] . split ( ) A = float ( tokens [ 0 ] . strip ( ) ) B = float ( tokens [ 1 ] . strip ( ) ) C = float ( tokens [ 2 ] . strip ( ) ) try : D = float ( tokens [ 3 ] . strip ( ) ) E = float ( tokens [ 4 ] . strip ( ) ) except ( IndexError , ValueError ) : D = None E = None if D is None or E is None : falloff = Sri ( A = A , B = B , C = C ) else : falloff = Sri ( A = A , B = B , C = C , D = D , E = E ) elif 'cov' in line . lower ( ) : parsed = True C = tokens [ 1 ] . split ( ) coverages . append ( [ C [ 0 ] , fortFloat ( C [ 1 ] ) , fortFloat ( C [ 2 ] ) , fortFloat ( C [ 3 ] ) ] ) elif 'cheb' in line . lower ( ) : # Chebyshev parameters parsed = True tokens = [ t . strip ( ) for t in tokens ] if contains ( tokens , 'TCHEB' ) : index = get_index ( tokens , 'TCHEB' ) tokens2 = tokens [ index + 1 ] . split ( ) Tmin = float ( tokens2 [ 0 ] . strip ( ) ) Tmax = float ( tokens2 [ 1 ] . strip ( ) ) if contains ( tokens , 'PCHEB' ) : index = get_index ( tokens , 'PCHEB' ) tokens2 = tokens [ index + 1 ] . split ( ) Pmin = ( float ( tokens2 [ 0 ] . strip ( ) ) , 'atm' ) Pmax = ( float ( tokens2 [ 1 ] . strip ( ) ) , 'atm' ) if contains ( tokens , 'TCHEB' ) or contains ( tokens , 'PCHEB' ) : pass elif degreeT is None or degreeP is None : tokens2 = tokens [ 1 ] . split ( ) degreeT = int ( float ( tokens2 [ 0 ] . strip ( ) ) ) degreeP = int ( float ( tokens2 [ 1 ] . strip ( ) ) ) cheb_coeffs . extend ( [ float ( t . strip ( ) ) for t in tokens2 [ 2 : ] ] ) else : tokens2 = tokens [ 1 ] . split ( ) cheb_coeffs . extend ( [ float ( t . strip ( ) ) for t in tokens2 ] ) elif 'plog' in line . lower ( ) : # Pressure-dependent Arrhenius parameters parsed = True tokens = tokens [ 1 ] . split ( ) pdep_arrhenius . append ( [ float ( tokens [ 0 ] . strip ( ) ) , Arrhenius ( A = ( float ( tokens [ 1 ] . strip ( ) ) , kunits ) , b = float ( tokens [ 2 ] . strip ( ) ) , Ea = ( float ( tokens [ 3 ] . strip ( ) ) , energy_units ) , parser = self ) ] ) elif len ( tokens ) >= 2 : # Assume a list of collider efficiencies parsed = True for collider , efficiency in zip ( tokens [ 0 : : 2 ] , tokens [ 1 : : 2 ] ) : efficiencies [ collider . strip ( ) ] = float ( efficiency . strip ( ) ) if not parsed : raise InputError ( 'Unparsable line:\n"""\n{}\n"""' , line ) # Decide which kinetics to keep and store them on the reaction object. # At most one of the special cases should be true tests = [ cheb_coeffs , pdep_arrhenius , low_rate , high_rate , third_body , surface ] if sum ( bool ( t ) for t in tests ) > 1 : raise InputError ( 'Reaction {} contains parameters for more than ' 'one reaction type.' , original_reaction ) if cheb_coeffs : if Tmin is None or Tmax is None : raise InputError ( 'Missing TCHEB line for reaction {}' , reaction ) if Pmin is None or Pmax is None : raise InputError ( 'Missing PCHEB line for reaction {}' , reaction ) if len ( cheb_coeffs ) != degreeT * degreeP : raise InputError ( 'Incorrect number of Chebyshev coefficients. ' 'Expected {}*{} = {} but got {}' , degreeT , degreeP , degreeT * degreeP , len ( cheb_coeffs ) ) if quantity_units == self . quantity_units : quantity_units = None reaction . kinetics = Chebyshev ( Tmin = Tmin , Tmax = Tmax , Pmin = Pmin , Pmax = Pmax , quantity_units = quantity_units , coeffs = np . array ( cheb_coeffs , np . float64 ) . reshape ( ( degreeT , degreeP ) ) ) elif pdep_arrhenius : reaction . kinetics = PDepArrhenius ( pressures = [ P for P , arrh in pdep_arrhenius ] , pressure_units = "atm" , arrhenius = [ arrh for P , arrh in pdep_arrhenius ] ) elif low_rate is not None : reaction . kinetics = Falloff ( high_rate = arrhenius , low_rate = low_rate , F = falloff , efficiencies = efficiencies ) elif high_rate is not None : reaction . kinetics = ChemicallyActivated ( high_rate = high_rate , low_rate = arrhenius , F = falloff , efficiencies = efficiencies ) elif third_body : reaction . kinetics = ThreeBody ( high_rate = arrhenius , efficiencies = efficiencies ) elif reaction . third_body : raise InputError ( 'Reaction equation implies pressure ' 'dependence but no alternate rate parameters (i.e. HIGH or ' 'LOW) were given for reaction {}.' , reaction ) elif surface : reaction . kinetics = SurfaceRate ( rate = arrhenius , coverages = coverages , is_sticking = is_sticking , motz_wise = motz_wise ) else : reaction . kinetics = ElementaryRate ( arrhenius ) if revReaction : revReaction . duplicate = reaction . duplicate revReaction . kinetics . efficiencies = reaction . kinetics . efficiencies return reaction , revReaction