uclchem.makerates.reaction ========================== .. py:module:: uclchem.makerates.reaction .. autoapi-nested-parse:: UCLCHEM Reaction. Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: uclchem.makerates.reaction.CoupledReaction uclchem.makerates.reaction.Reaction Functions ~~~~~~~~~ .. autoapisummary:: uclchem.makerates.reaction.skip_reaction_validation Attributes ~~~~~~~~~~ .. autoapisummary:: uclchem.makerates.reaction.ER_REACTION_TYPES uclchem.makerates.reaction.LH_REACTION_TYPES uclchem.makerates.reaction.REACTION_TYPES uclchem.makerates.reaction.TUNNELING_REACTION_TYPES uclchem.makerates.reaction.logger uclchem.makerates.reaction.reaction_header .. py:class:: CoupledReaction(input: list[str | float] | Reaction) Bases: :py:obj:`Reaction` Representation of reactions that are coupled to another Reaction instance. This means that if a reaction has a parameter changed by, for example, `network.change_binding_energy()`, every CoupledReaction that has that instance as its partner also has its binding energy changed to that value. Initialize the CoupledReaction. :param input: Either a Reaction object to copy, or a list with reaction data. :type input: list[str | float] | Reaction .. py:method:: get_partner() -> Reaction | None Get the partner. :returns: partner of this reaction. :rtype: Reaction | None .. py:method:: set_partner(partner: Reaction) -> None Set the partner. :param partner: partner of this reaction. :type partner: Reaction :raises TypeError: if `parter` is not an instance of a `Reaction`. .. py:attribute:: partner :type: Reaction | None :value: None .. py:class:: Reaction(input_row: list[str | float] | Reaction, reaction_source: str | None = None) Representation of reactions. Initialize a Reaction object. :param input_row: Either a Reaction object to copy, or a list/array with reaction data :type input_row: list[str | float] | Reaction :param reaction_source: Optional source identifier for the reaction. Default = None. :type reaction_source: str | None :raises ValueError: If the length of `input_row` is not long enough. .. py:method:: changes_surface_count() -> bool Check whether a grain reaction changes number of particles on the surface. 2 reactants to 2 products won't but two reactants combining to one will. :returns: whether the number of ice molecules changes by this reaction. :rtype: bool .. py:method:: changes_total_mantle() -> bool Check if the total grains on the mantle are changed by the reaction. :returns: Whether the total ice abundance is affected by this reaction. :rtype: bool .. py:method:: check_charge_conservation() -> None Check that the charge is conserved by this reaction. Grain reactions don't need to conserve charge, because grains can absorb/release electrons, so they are ignored. :raises ValueError: If charge is not conserved by the reaction. .. py:method:: check_element_conservation() -> None Check the conservation of elements. :raises ValueError: If the elements are not conserved by the reaction. .. py:method:: check_temperature_collision(other: Reaction) -> bool Check if two reactions have overlapping temperature ranges. Returning True means there is a collision. :param other: Another reaction :type other: Reaction :returns: Whether there is a collision (True), or not (False) :rtype: bool :raises NotImplementedError: If `other` is not a `Reaction` instance. Currently we can only compare against instantiated Reaction objects. .. py:method:: convert_gas_to_surf() -> None Convert the gas-phase species to surface species in place for this reaction. If any ions are produced, the ion is assumed to become neutral because it is on the surface. If any electrons are produced, they are assumed to be absorbed by the grain. .. py:method:: convert_surf_to_bulk() -> None Convert the surface species to bulk species in place for this reaction. .. py:method:: generate_ode_bit(i: int, species_names: list[str]) -> None Generate the ODE string of this reaction. :param i: index of reaction in network in python format (counting from 0) :type i: int :param species_names: List of species names so we can find index of reactants in species list :type species_names: list[str] .. py:method:: get_alpha() -> float Get the alpha parameter from the Kooij-Arrhenius equation. :returns: the alpha parameter of the reaction :rtype: float .. py:method:: get_beta() -> float Get the beta parameter from the Kooij-Arrhenius equation. :returns: the beta parameter of the reaction :rtype: float .. py:method:: get_exothermicity() -> float Get the cooling/heating for the reaction in erg s^-1. :returns: the reaction enthalpy change :rtype: float .. py:method:: get_extrapolation() -> bool Get whether extrapolation is applied for this reaction. :returns: whether extrapolation is applied. :rtype: bool .. py:method:: get_gamma() -> float Get the gamma parameter from the Kooij-Arrhenius equation. :returns: the gamma parameter of the reaction :rtype: float .. py:method:: get_products() -> list[str] Get the four products present in the reaction,. padded with NAN for nonexistent entries. :returns: The four products names :rtype: list[str] .. py:method:: get_pure_products() -> list[str] Get only the pure species that are products,. no reaction types and NAN entries. :returns: The list of produced species. :rtype: list[str] .. py:method:: get_pure_reactants() -> list[str] Get only the pure species, no reaction types and NAN entries. :returns: The list of reacting species. :rtype: list[str] .. py:method:: get_reactants() -> list[str] Get the four reactants present in the reaction,. padded with NAN for nonexistent entries. :returns: The four reactants names :rtype: list[str] .. py:method:: get_reaction_type() -> str Get the type of a reaction from the reactants. First check the third reactant for a reaction type, then the second. If there are none in there, it will be regarded as a two body reaction. :returns: reaction type :rtype: str .. py:method:: get_reduced_mass() -> float Get the reduced mass to be used to calculate tunneling rate in. atomic mass units. :returns: reduced mass of moving atoms :rtype: float .. py:method:: get_sorted_products() -> list[str] Get the four products present in the reaction,. sorted for fast comparisons. :returns: The four sorted products names :rtype: list[str] .. py:method:: get_sorted_reactants() -> list[str] Get the four reactants present in the reaction,. sorted for fast comparisons. :returns: The four sorted reactant names :rtype: list[str] .. py:method:: get_source() -> str | None Get the source of the reaction. :returns: The source of the reaction :rtype: str | None .. py:method:: get_temphigh() -> float Get the higher temperature boundary of the reaction in Kelvin. :returns: the higher temperature boundary :rtype: float .. py:method:: get_templow() -> float Get the lower temperature boundary of the reaction in Kelvin. :returns: the lower temperature boundary :rtype: float .. py:method:: is_bulk_reaction(include_reactants: bool = True, include_products: bool = True, strict: bool = False) -> bool Check whether it is a bulk reaction. Defaults to non-strict since many. important bulk reactions interact with the surface. By default it is NOT strict (strict=False); any species in the bulk returns true If strict=True; all species must be on the ice phase :param include_reactants: Include the reactants. Defaults to True. :type include_reactants: bool :param include_products: Include the products. Defaults to True. :type include_products: bool :param strict: Choose between all (true) or any (false) must in the bulk. Defaults to False. :type strict: bool :returns: Is it a bulk reaction? :rtype: bool .. py:method:: is_gas_reaction(include_reactants: bool = True, include_products: bool = True, strict: bool = True) -> bool Check whether it is a gas reaction. By default it is strict - all. reactions must be in the gas-phase - if strict=False; any reaction in the gas-phase returns true. :param include_reactants: Include the reactants. Defaults to True. :type include_reactants: bool :param include_products: Include the products. Defaults to True. :type include_products: bool :param strict: Choose between all (true) or any (false) must be gas phase. Defaults to True. :type strict: bool :returns: Is it a gas phase reaction? :rtype: bool .. py:method:: is_ice_reaction(include_reactants: bool = True, include_products: bool = True, strict: bool = True) -> bool Check whether it is an ice (surface OR bulk) reaction. By default it is strict (strict=True); all species must be in the ice phase If strict=False; any species in ice phase returns True :param include_reactants: Include the reactants. Defaults to True. :type include_reactants: bool :param include_products: Include the products. Defaults to True. :type include_products: bool :param strict: Choose between all (true) or any (false) must be ice phase. Defaults to True. :type strict: bool :returns: Is it an ice phase reaction? :rtype: bool .. py:method:: is_surface_reaction(include_reactants: bool = True, include_products: bool = True, strict: bool = False) -> bool Check whether it is a surface reaction. Defaults to non-strict since many. important surface reactions can lead to desorption in some way. By default it is NOT strict (strict=False); any species on the surface returns true If strict=True; all species must be on the ice phase :param include_reactants: Include the reactants. Defaults to True. :type include_reactants: bool :param include_products: Include the products. Defaults to True. :type include_products: bool :param strict: Choose between all (true) or any (false) must be on the surface. Defaults to False. :type strict: bool :returns: Is it a surface reaction? :rtype: bool .. py:method:: predict_reduced_mass() -> None Predict the reduced mass of the tunneling particle in this reaction. This is used in the calculation of the tunneling rates. .. rubric:: Examples >>> reaction = Reaction(["#CH3OH", "#H", "LH", "#CH3O", "#H2", "NAN", "NAN"] + [0] * 10) >>> # Setting a custom reduced mass >>> reaction.set_reduced_mass(20.0) >>> >>> # The custom reduced mass that we set. >>> reaction.get_reduced_mass() 20.0 >>> # Predicting the reduced mass of the reaction >>> reaction.predict_reduced_mass() >>> reaction.get_reduced_mass() 1.0 >>> # It is called upon Reaction instantiation >>> reaction = Reaction(["#CH3OH", "#OH", "LH", "#CH3O", "#H2O", "NAN", "NAN"] + [0] * 10) >>> reaction.get_reduced_mass() # mass of atomic hydrogen 1.0 .. py:method:: set_alpha(alpha: float) -> None Set the alpha parameter from the Kooij-Arrhenius equation. :param alpha: the alpha parameter of the reaction :type alpha: float .. py:method:: set_beta(beta: float) -> None Set the beta parameter from the Kooij-Arrhenius equation. :param beta: the beta parameter of the reaction :type beta: float .. py:method:: set_exothermicity(rate: float) -> None Set the cooling/heating for the reaction in erg s^-1. :param rate: the reaction enthalpy change :type rate: float .. py:method:: set_extrapolation(flag: bool) -> None Set whether extrapolation is applied for this reaction. :param flag: whether extrapolation is applied. :type flag: bool :raises AssertionError: If ``flag`` is not a boolean. .. py:method:: set_gamma(gamma: float) -> None Set the gamma parameter from the Kooij-Arrhenius equation. :param gamma: the gamma parameter of the reaction :type gamma: float .. py:method:: set_products(products: list[str]) -> None Set the four products present in the reaction, padded with NAN for nonexistent entries. :param products: The four products names :type products: list[str] .. py:method:: set_reactants(reactants: list[str]) -> None Set the four reactants present in the reaction,. padded with NAN for nonexistent entries. :param reactants: The four reactants names :type reactants: list[str] .. py:method:: set_reduced_mass(reduced_mass: float) -> None Set the reduced mass to be used to calculate tunneling rate in. atomic mass units. :param reduced_mass: reduced mass of moving atoms :type reduced_mass: float .. py:method:: set_source(source: str) -> None Set the source of the reaction. :param source: The source of the reaction :type source: str .. py:method:: set_temphigh(temphigh: float) -> None Set the higher temperature boundary of the reaction in Kelvin. :param temphigh: the higher temperature boundary :type temphigh: float .. py:method:: set_templow(templow: float) -> None Set the lower temperature boundary of the reaction in Kelvin. :param templow: the lower temperature boundary :type templow: float .. py:method:: to_UCL_format() -> str Convert a reaction to UCLCHEM reaction file format. :returns: string representing species :rtype: str .. py:attribute:: body_count :value: -1 .. py:attribute:: duplicate :value: False .. py:attribute:: source :value: None .. py:function:: skip_reaction_validation() -> collections.abc.Iterator[None] Context manager to temporarily disable reaction validation. This is useful when loading pre-validated networks where you do not necessarily want to check element and charge conservation. :Yields: *None* -- Control is yielded to the ``with`` block. .. rubric:: Examples >>> with skip_reaction_validation(): ... reaction = Reaction(["#C2N", "LH", "NAN", "#CH3CNH", "NAN", "NAN", "NAN"]+ [0] * 10) >>> reaction = Reaction(["#C2N", "LH", "NAN", "#CH3CNH", "NAN", "NAN", "NAN"] + [0] * 10) Traceback (most recent call last): ... ValueError: Elements not conserved in a reaction. The following reaction caused this error: #C2N + LH -> #CH3CNH. ... .. py:data:: ER_REACTION_TYPES .. py:data:: LH_REACTION_TYPES .. py:data:: REACTION_TYPES :value: ['PHOTON', 'CRP', 'CRPHOT', 'FREEZE', 'DESORB', 'THERM', 'DESOH2', 'DESCR', 'DEUVCR', 'H2FORM',... .. py:data:: TUNNELING_REACTION_TYPES .. py:data:: logger .. py:data:: reaction_header :value: ['REACTANT 1', 'REACTANT 2', 'REACTANT 3', 'PRODUCT 1', 'PRODUCT 2', 'PRODUCT 3', 'PRODUCT 4',...