Skip to content

Reaction Modules

Reaction

Abstract interface of reaction. Inherit this class to customize a new reaction definition.

create_species(self, species_name)

Create a Species instance if the name is not a pseudo element (e.g. CR, CRPHOT), else return None

Parameters:

Name Type Description Default
species_name str

name of species

required

Returns:

Type Description
Species

Species: Species instance of the input name

Source code in naunet/reactions/reaction.py
def create_species(self, species_name: str) -> Species:
    """
    Create a Species instance if the name is not a pseudo element
    (e.g. CR, CRPHOT), else return None

    Args:
        species_name (str): name of species

    Returns:
        Species: Species instance of the input name
    """

    if species_name and species_name not in Species.known_pseudoelements():
        return Species(species_name)

finalize() classmethod

Reset settings / class attributes if needed

Source code in naunet/reactions/reaction.py
@classmethod
def finalize(cls) -> None:
    """
    Reset settings / class attributes if needed
    """

    pass

initialize() classmethod

Change settings / class attributes if needed

Source code in naunet/reactions/reaction.py
@classmethod
def initialize(cls) -> None:
    """
    Change settings / class attributes if needed
    """

    pass

preprocessing(line) classmethod

Preprocess the input reaction string before initialize a reaction. Called in Network class to deal with input with special meanings.

Parameters:

Name Type Description Default
line str

input string of a reaction

required

Returns:

Type Description
str

str: proceeded input string

Source code in naunet/reactions/reaction.py
@classmethod
def preprocessing(cls, line: str) -> str:
    """
    Preprocess the input reaction string before initialize a reaction.
    Called in Network class to deal with input with special meanings.

    Args:
        line (str): input string of a reaction

    Returns:
        str: proceeded input string
    """

    return line

rate_func(self)

Abstract method should be implemented by child class. Return the reaction rate expression.

Source code in naunet/reactions/reaction.py
@abstractmethod
def rate_func(self):
    """
    Abstract method should be implemented by child class. Return the
    reaction rate expression.

    Raises:
        NotImplementedError
    """

    raise NotImplementedError

rpeq(self, o)

Compare two reactions by their reactants and products.

Parameters:

Name Type Description Default
o object

other reaction instance

required

Returns:

Type Description
bool

bool: True if the reactants and products are the same in two reactions. Otherwise False

Source code in naunet/reactions/reaction.py
def rpeq(self, o: object) -> bool:
    """
    Compare two reactions by their reactants and products.

    Args:
        o (object): other reaction instance

    Returns:
        bool: True if the reactants and products are the same in two
        reactions. Otherwise False
    """

    return Counter(self.reactants) == Counter(o.reactants) and Counter(
        self.products
    ) == Counter(o.products)

ReactionType

The definition of reaction types. Types are categorized by phases (gas, grain, surface) and then divided to sub-groups