Python API
- uclchem
- uclchem.tests.test_io_functions
- uclchem.tests.test_photo_on_grain
- uclchem.tests.test_run_stages
- uclchem.tests.test_install
- uclchem.tests.test_ode_conservation
that cannot be compiled by mdx. So we just remove them.
uclchem.utils.generate_param_docs
Simple script to parse defaultparameters.f90 and generate a markdown file that can be copied over to the website docs. Run it with python generate_param_docs.py default_parameter_fortran_file output_markdown_file
uclchem.scripts.example_plotting_script
A script largely intended for people unfamiliar with Python. If you run run_uclchem_tests.py, you'll produce several example model outputs. This script then uses those outputs to demonstrate some simple plotting.
axes​
turn [2,2] array into [4]
uclchem.scripts.grid
uclchem.scripts.run_postprocessing
uclchem.scripts.plot_uclchem_tests
uclchem.scripts.analysis
uclchem.scripts.run_uclchem_tests
uclchem.Makerates.comparespecies
uclchem.Makerates.MakeRates
get_args​
def get_args()
Allows for interacting with MakeRates.py via the command line i.e.
python3 MakeRates.py /home/user/some_directory/custom_settings.yaml --verbosity DEBUG
Returns:
Namespace- Arguments passed via the CLI or their defaults
get_logger​
def get_logger(verbosity_stdout: str, debug: bool)
Define a logger that logs both to file and stdout
uclchem.Makerates.speciesnetwork
uclchem.Makerates.comparenetworks
uclchem.notebooks.1_first_model
uclchem.notebooks.4_chemical_analysis
uclchem.notebooks.2a_modelling_objects_on_disk
uclchem.notebooks.2b_modelling_objects_in_memory
uclchem.notebooks.3_running_a_grid
uclchem.src.uclchem.plot
uclchem.src.uclchem.version
uclchem.src.uclchem.analysis
read_output_file​
def read_output_file(output_file)
Read the output of a UCLCHEM run created with the outputFile parameter into a pandas DataFrame
Arguments:
output_filestr - path to file containing a full UCLCHEM output
Returns:
pandas.DataFrame- A dataframe containing the abundances and physical parameters of the model at every time step.
read_rate_file​
def read_rate_file(rate_file)
Read the output of a UCLCHEM run created with the rateFile parameter into a pandas DataFrame
Arguments:
rate_filestr - path to file containing the UCLCHEM reaction rates.
Returns:
pandas.DataFrame- A dataframe containing the physical parameters, and reaction rates (s-1) at each timestep.
get_change_df​
def get_change_df(rate_df: pd.DataFrame,
species: str,
on_grain: bool = False) -> pd.DataFrame
From a dataframe containing all the reaction rates, get the change of a species over time, due to each reaction.
Arguments:
rate_dfpd.DataFrame - dataframe containing physical parameters and reaction rates over timespeciesstr - species to get the change over timeon_grainbool - whether to analyse the ice phase of this species
Returns:
change_dfpd.DataFrame - change of species over time due to each reaction the species is involved in
create_abundance_plot​
def create_abundance_plot(df, species, figsize=(16, 9), plot_file=None)
Create a plot of the abundance of a list of species through time.
Arguments:
dfpd.DataFrame - Pandas dataframe containing the UCLCHEM output, seeread_output_filespecieslist - list of strings containing species names. Using a $ instead of # or @ will plot the sum of surface and bulk abundances.figsizetuple, optional - Size of figure, width by height in inches. Defaults to (16, 9).plot_filestr, optional - Path to file where figure will be saved. If None, figure is not saved. Defaults to None.
Returns:
fig,ax- matplotlib figure and axis objects
plot_species​
def plot_species(ax, df, species, legend=True, **plot_kwargs)
Plot the abundance of a list of species through time directly onto an axis.
Arguments:
axpyplot.axis - An axis object to plot ondfpd.DataFrame - A dataframe created byread_output_filespeciesstr - A list of species names to be plotted. If species name starts with "$" instead of # or @, plots the sum of surface and bulk abundances
Returns:
pyplot.axis- Modified input axis is returned
analysis​
def analysis(species_name, rates, output_file, rate_threshold=0.99)
A function which loops over every time step in an output file and finds the rate of change of a species at that time due to each of the reactions it is involved in. From this, the most important reactions are identified and printed to file. This can be used to understand the chemical reason behind a species' behaviour.
Arguments:
species_namestr - Name of species to be analysedresult_filestr - The path to the file containing the UCLCHEM outputoutput_filestr - The path to the file where the analysis output will be writtenrate_thresholdfloat,optional - Analysis output will contain the only the most efficient reactions that are responsible for rate_threshold of the total production and destruction rate. Defaults to 0.99.
total_element_abundance​
def total_element_abundance(element, df)
Calculates that the total elemental abundance of a species as a function of time. Allows you to check conservation.
Arguments:
elementstr - Name of elementdfpandas.DataFrame - DataFrame fromread_output_file()
Returns:
pandas.Series- Total abundance of element for all time steps in df.
check_element_conservation​
def check_element_conservation(df,
element_list=["H", "N", "C", "O"],
percent=True)
Check the conservation of major element by comparing total abundance at start and end of model
Arguments:
dfpandas.DataFrame - UCLCHEM output in format fromread_output_fileelement_listlist, optional - List of elements to check. Defaults to ["H", "N", "C", "O"].
Returns:
dict- Dictionary containing the change in the total abundance of each element as a fraction of initial value
get_total_swap​
def get_total_swap(rates: pd.DataFrame, abundances: pd.DataFrame,
reactions: List[Reaction]) -> np.ndarray
Obtain the amount of 'random' swapping per timestep
Arguments:
ratespd.DataFrame - The rates obtained from running an UCLCHEM modelabundancespd.DataFrame - The abundances obtained from running an UCLCHEM modelreactionsList[Reaction] - The reactions used in UCLCHEM
Returns:
np.ndarray- The total swap per timestep
construct_incidence​
def construct_incidence(species: List[Species],
reactions: List[Reaction]) -> np.ndarray
Construct the incidence matrix, a matrix that describes the in and out degree for each of the reactions; useful to matrix multiply by the indvidual fluxes per reaction to obtain a flux (dy) per species.
Arguments:
speciesList[Species] - A list of species SreactionsList[Reaction] - The list of reactions S
Returns:
np.ndarray- A RxS incidence matrix
rates_to_dy_and_flux​
def rates_to_dy_and_flux(
physics: pd.DataFrame,
abundances: pd.DataFrame,
rates: pd.DataFrame,
network: Network = None,
species: list[Species] = None,
reactions: list[Reaction] = None) -> tuple[pd.DataFrame, pd.DataFrame]
Apply postprocessing to obtain the equivalent of GETYDOT from the fortran side; It returns two dataframes:
- ydot: the RHS that is solved in UCLCHEM at every output timestep
- flux_by_reaction: the individual terms that result in ydot when multiplied by the incidence matrix
Arguments:
physicspd.DataFrame - The physics output from running a modelabundancespd.DataFrame - The abundances output from running a modelratespd.DataFrame - The rates output from running a modelnetworkNetwork, optional - The reaction network used to postprocess the rates. Defaults to None.specieslist[Species], optional - The species used to postprocess the rates . Defaults to None.reactionslist[Reaction], optional - The reactions used to postprocess the rates. Defaults to None.
Returns:
tuple[pd.DataFrame, pd.DataFrame]: dy, flux_by_reaction.
analyze_element_per_phase​
def analyze_element_per_phase(element, df)
Calculates that the total elemental abundance of a species as a function of time. Allows you to check conservation.
Arguments:
elementstr - Name of elementdfpandas.DataFrame - DataFrame fromread_output_file()
Returns:
pandas.Series- Total abundance of element for all time steps in df.
uclchem.src.uclchem.constants
uclchem.src.uclchem
The UCLCHEM python module is divided into three parts.
model contains the functions for running chemical models under different physics.
analysis contains functions for reading and plotting output files as well as investigating the chemistry.
tests contains functions for testing the code.
uclchem.src.uclchem.model
outputArrays_to_DataFrame​
def outputArrays_to_DataFrame(physicalParameterArray, chemicalAbundanceArray,
specname, ratesArray)
Convert the output arrays to a pandas dataframe
Arguments:
physicalParameterArraynp.array - Array with the output physical parameterschemicalAbundanceArraynp.array - Array with the output chemical abundancesspecnamelist - List with the names of all the speciesphysParameterlist - Array with all the physical parameter names
Returns:
_type_- description
cloud​
def cloud(param_dict=None,
out_species=None,
return_array=False,
return_dataframe=False,
return_rates=False,
starting_chemistry=None,
timepoints=TIMEPOINTS)
Run cloud model from UCLCHEM
Arguments:
param_dictdict,optional - A dictionary of parameters where keys are any of the variables in defaultparameters.f90 and values are value for current run.out_specieslist, optional - A list of species for which final abundance will be returned. If None, no abundances will be returned.. Defaults to None.return_arraybool, optional - A boolean on whether a np.array should be returned to a user, if both return_array and return_dataframe are false, this function will default to writing outputs to a filereturn_dataframebool, optional - A boolean on whether a pandas.DataFrame should be returned to a user, if both return_array and return_dataframe are false, this function will default to writing outputs to a filestarting_chemistryarray, optional - np.array containing the starting chemical abundances needed by uclchem
Returns:
if return_array and return_dataframe are False:
- A list where the first element is always an integer which is negative if the model failed to run and can be sent to
uclchem.utils.check_error()to see more details. If theout_speciesparametere is provided, the remaining elements of this list will be the final abundances of the species in out_species. if return_array is True: - physicsArray (array): array containing the physical outputs for each written timestep
- chemicalAbunArray (array): array containing the chemical abundances for each written timestep
- abundanceStart (array): array containing the chemical abundances of the last timestep in the format uclchem needs in order to perform an additional run after the initial model
- success_flag (integer): which is negative if the model failed to run and can be sent to
uclchem.utils.check_error()to see more details. if return_dataframe is True: - physicsDF (pandas.DataFrame): DataFrame containing the physical outputs for each written timestep
- chemicalDF (pandas.DataFrame): DataFrame containing the chemical abundances for each written timestep
- abundanceStart (array): array containing the chemical abundances of the last timestep in the format uclchem needs in order to perform an additional run after the initial model
- success_flag (integer): which is negative if the model failed to run and can be sent to
uclchem.utils.check_error()to see more details.
collapse​
def collapse(collapse,
physics_output,
param_dict=None,
out_species=None,
return_array=False,
return_dataframe=False,
return_rates=False,
starting_chemistry=None,
timepoints=TIMEPOINTS)
Run collapse model from UCLCHEM based on Priestley et al 2018 AJ 156 51 (https://ui.adsabs.harvard.edu/abs/2018AJ....156...51P/abstract)
Arguments:
collapsestr - A string containing the collapse type, options are 'BE1.1', 'BE4', 'filament', or 'ambipolar'physics_output(str)- Filename to store physics output, only relevant for 'filament' and 'ambipolar' collapses. If None, no physics output will be saved.param_dictdict,optional - A dictionary of parameters where keys are any of the variables in defaultparameters.f90 and values are value for current run.out_specieslist, optional - A list of species for which final abundance will be returned. If None, no abundances will be returned.. Defaults to None.return_arraybool, optional - A boolean on whether a np.array should be returned to a user, if both return_array and return_dataframe are false, this function will default to writing outputs to a filereturn_dataframebool, optional - A boolean on whether a pandas.DataFrame should be returned to a user, if both return_array and return_dataframe are false, this function will default to writing outputs to a filestarting_chemistryarray, optional - np.array containing the starting chemical abundances needed by uclchem
Returns:
if return_array and return_dataframe are False:
- A list where the first element is always an integer which is negative if the model failed to run and can be sent to
uclchem.utils.check_error()to see more details. If theout_speciesparametere is provided, the remaining elements of this list will be the final abundances of the species in out_species. if return_array is True: - physicsArray (array): array containing the physical outputs for each written timestep
- chemicalAbunArray (array): array containing the chemical abundances for each written timestep
- abundanceStart (array): array containing the chemical abundances of the last timestep in the format uclchem needs in order to perform an additional run after the initial model
- success_flag (integer): which is negative if the model failed to run and can be sent to
uclchem.utils.check_error()to see more details. if return_dataframe is True: - physicsDF (pandas.DataFrame): DataFrame containing the physical outputs for each written timestep
- chemicalDF (pandas.DataFrame): DataFrame containing the chemical abundances for each written timestep
- abundanceStart (array): array containing the chemical abundances of the last timestep in the format uclchem needs in order to perform an additional run after the initial model
- success_flag (integer): which is negative if the model failed to run and can be sent to
uclchem.utils.check_error()to see more details.
hot_core​
def hot_core(temp_indx,
max_temperature,
param_dict=None,
out_species=None,
return_array=False,
return_dataframe=False,
return_rates=False,
starting_chemistry=None,
timepoints=TIMEPOINTS)
Run hot core model from UCLCHEM, based on Viti et al. 2004 and Collings et al. 2004
Arguments:
temp_indxint - Used to select the mass of hot core. 1=1Msun,2=5, 3=10, 4=15, 5=25,6=60]max_temperaturefloat - Value at which gas temperature will stop increasing.param_dictdict,optional - A dictionary of parameters where keys are any of the variables in defaultparameters.f90 and values are value for current run.out_specieslist, optional - A list of species for which final abundance will be returned. If None, no abundances will be returned.. Defaults to None.return_arraybool, optional - A boolean on whether a np.array should be returned to a user, if both return_array and return_dataframe are false, this function will default to writing outputs to a filereturn_dataframebool, optional - A boolean on whether a pandas.DataFrame should be returned to a user, if both return_array and return_dataframe are false, this function will default to writing outputs to a filestarting_chemistryarray, optional - np.array containing the starting chemical abundances needed by uclchem
Returns:
if return_array and return_dataframe are False:
- A list where the first element is always an integer which is negative if the model failed to run and can be sent to
uclchem.utils.check_error()to see more details. If theout_speciesparametere is provided, the remaining elements of this list will be the final abundances of the species in out_species. if return_array is True: - physicsArray (array): array containing the physical outputs for each written timestep
- chemicalAbunArray (array): array containing the chemical abundances for each written timestep
- abundanceStart (array): array containing the chemical abundances of the last timestep in the format uclchem needs in order to perform an additional run after the initial model
- success_flag (integer): which is negative if the model failed to run and can be sent to
uclchem.utils.check_error()to see more details. if return_dataframe is True: - physicsDF (pandas.DataFrame): DataFrame containing the physical outputs for each written timestep
- chemicalDF (pandas.DataFrame): DataFrame containing the chemical abundances for each written timestep
- abundanceStart (array): array containing the chemical abundances of the last timestep in the format uclchem needs in order to perform an additional run after the initial model
- success_flag (integer): which is negative if the model failed to run and can be sent to
uclchem.utils.check_error()to see more details.
cshock​
def cshock(shock_vel,
timestep_factor=0.01,
minimum_temperature=0.0,
param_dict=None,
out_species=None,
return_array=False,
return_dataframe=False,
return_rates=False,
starting_chemistry=None,
timepoints=TIMEPOINTS)
Run C-type shock model from UCLCHEM
Arguments:
shock_velfloat - Velocity of the shock in km/stimestep_factorfloat, optional - Whilst the time is less than 2 times the dissipation time of shock, timestep is timestep_factor*dissipation time. Essentially controls how well resolved the shock is in your model. Defaults to 0.01.minimum_temperaturefloat, optional - Minimum post-shock temperature. Defaults to 0.0 (no minimum). The shocked gas typically cools toinitialTempif this is not set.param_dictdict,optional - A dictionary of parameters where keys are any of the variables in defaultparameters.f90 and values are value for current run.out_specieslist, optional - A list of species for which final abundance will be returned. If None, no abundances will be returned.. Defaults to None.return_arraybool, optional - A boolean on whether a np.array should be returned to a user, if both return_array and return_dataframe are false, this function will default to writing outputs to a filereturn_dataframebool, optional - A boolean on whether a pandas.DataFrame should be returned to a user, if both return_array and return_dataframe are false, this function will default to writing outputs to a filestarting_chemistryarray, optional - np.array containing the starting chemical abundances needed by uclchem
Returns:
if return_array and return_dataframe are False:
- A list where the first element is always an integer which is negative if the model failed to run and can be sent to
uclchem.utils.check_error()to see more details. If the model succeeded, the second element is the dissipation time and further elements are the abundances of all species inout_species. if return_array is True: - physicsArray (array): array containing the physical outputs for each written timestep
- chemicalAbunArray (array): array containing the chemical abundances for each written timestep
- disspation_time (float): dissipation time in years
- abundanceStart (array): array containing the chemical abundances of the last timestep in the format uclchem needs in order to perform an additional run after the initial model
- success_flag (integer): which is negative if the model failed to run and can be sent to
uclchem.utils.check_error()to see more details. if return_dataframe is True: - physicsDF (pandas.DataFrame): DataFrame containing the physical outputs for each written timestep
- chemicalDF (pandas.DataFrame): DataFrame containing the chemical abundances for each written timestep
- disspation_time (float): dissipation time in years
- abundanceStart (array): array containing the chemical abundances of the last timestep in the format uclchem needs in order to perform an additional run after the initial model
- success_flag (integer): which is negative if the model failed to run and can be sent to
uclchem.utils.check_error()to see more details.
jshock​
def jshock(shock_vel,
param_dict=None,
out_species=None,
return_array=False,
return_dataframe=False,
return_rates=False,
starting_chemistry=None,
timepoints=TIMEPOINTS)
Run J-type shock model from UCLCHEM
Arguments:
-
shock_velfloat - Velocity of the shock -
param_dictdict,optional - A dictionary of parameters where keys are any of the variables in defaultparameters.f90 and values are value for current run. -
out_specieslist, optional - A list of species for which final abundance will be returned. If None, no abundances will be returned.. Defaults to None. -
return_arraybool, optional - A boolean on whether a np.array should be returned to a user, if both return_array and return_dataframe are false, this function will default to writing outputs to a file -
return_dataframebool, optional - A boolean on whether a pandas.DataFrame should be returned to a user, if both return_array and return_dataframe are false, this function will default to writing outputs to a file -
starting_chemistryarray, optional - np.array containing the starting chemical abundances needed by uclchemReturns:if return_array and return_dataframe are False:
- A list where the first element is always an integer which is negative if the model failed to run and can be sent to
uclchem.utils.check_error()to see more details. If the model succeeded, the second element is the dissipation time and further elements are the abundances of all species inout_species. if return_array is True: - physicsArray (array): array containing the physical outputs for each written timestep
- chemicalAbunArray (array): array containing the chemical abundances for each written timestep
- abundanceStart (array): array containing the chemical abundances of the last timestep in the format uclchem needs in order to perform an additional run after the initial model
- success_flag (integer): which is negative if the model failed to run and can be sent to
uclchem.utils.check_error()to see more details. if return_dataframe is True: - physicsDF (pandas.DataFrame): DataFrame containing the physical outputs for each written timestep
- chemicalDF (pandas.DataFrame): DataFrame containing the chemical abundances for each written timestep
- abundanceStart (array): array containing the chemical abundances of the last timestep in the format uclchem needs in order to perform an additional run after the initial model
- success_flag (integer): which is negative if the model failed to run and can be sent to
uclchem.utils.check_error()to see more details.
- A list where the first element is always an integer which is negative if the model failed to run and can be sent to
postprocess​
def postprocess(param_dict=None,
out_species=None,
return_array=False,
return_dataframe=False,
return_rates=False,
starting_chemistry=None,
time_array=None,
density_array=None,
gas_temperature_array=None,
dust_temperature_array=None,
zeta_array=None,
radfield_array=None,
coldens_H_array=None,
coldens_H2_array=None,
coldens_CO_array=None,
coldens_C_array=None)
Run cloud model from UCLCHEM
Arguments:
param_dictdict,optional - A dictionary of parameters where keys are any of the variables in defaultparameters.f90 and values are value for current run.out_specieslist, optional - A list of species for which final abundance will be returned. If None, no abundances will be returned.. Defaults to None.return_arraybool, optional - A boolean on whether a np.array should be returned to a user, if both return_array and return_dataframe are false, this function will default to writing outputs to a filereturn_dataframebool, optional - A boolean on whether a pandas.DataFrame should be returned to a user, if both return_array and return_dataframe are false, this function will default to writing outputs to a filestarting_chemistryarray, optional - np.array containing the starting chemical abundances needed by uclchem
Returns:
if return_array and return_dataframe are False:
- A list where the first element is always an integer which is negative if the model failed to run and can be sent to
uclchem.utils.check_error()to see more details. If theout_speciesparametere is provided, the remaining elements of this list will be the final abundances of the species in out_species. if return_array is True: - physicsArray (array): array containing the physical outputs for each written timestep
- chemicalAbunArray (array): array containing the chemical abundances for each written timestep
- abundanceStart (array): array containing the chemical abundances of the last timestep in the format uclchem needs in order to perform an additional run after the initial model
- success_flag (integer): which is negative if the model failed to run and can be sent to
uclchem.utils.check_error()to see more details. if return_dataframe is True: - physicsDF (pandas.DataFrame): DataFrame containing the physical outputs for each written timestep
- chemicalDF (pandas.DataFrame): DataFrame containing the chemical abundances for each written timestep
- abundanceStart (array): array containing the chemical abundances of the last timestep in the format uclchem needs in order to perform an additional run after the initial model
- success_flag (integer): which is negative if the model failed to run and can be sent to
uclchem.utils.check_error()to see more details.
uclchem.src.uclchem.utils
cshock_dissipation_time​
def cshock_dissipation_time(shock_vel, initial_dens)
A simple function used to calculate the dissipation time of a C-type shock. Use to obtain a useful timescale for your C-shock model runs. Velocity of ions and neutrals equalizes at dissipation time and full cooling takes a few dissipation times.
Arguments:
shock_velfloat - Velocity of the shock in km/sinitial_densfloat - Preshock density of the gas in cm
Returns:
float- The dissipation time of the shock in years
check_error​
def check_error(error_code)
Converts the UCLCHEM integer result flag to a simple messaging explaining what went wrong"
Arguments:
error_codeint - Error code returned by UCLCHEM models, the first element of the results list.
Returns:
str- Error message
get_species_table​
def get_species_table()
A simple function to load the list of species in the UCLCHEM network into a pandas dataframe.
Returns:
pandas.DataFrame- A dataframe containing the species names and their details
get_species​
def get_species() -> list[str]
A simple function to load the list of species present in the UCLCHEM network
Returns:
list[str] : A list of species names
get_reaction_table​
def get_reaction_table()
A function to load the reaction table from the UCLCHEM network into a pandas dataframe.
Returns:
pandas.DataFrame- A dataframe containing the reactions and their rates
uclchem.src.uclchem.debug
Functions to help debugging UCLCHEM
get_f2py_signature​
def get_f2py_signature(write=False) -> str
Get the signature of the UCLCHEM fortran code
Arguments:
writebool, optional - Write to disk. Defaults to False.
Returns:
str- Signature of the UCLCHEM fortran code from the f2py wrapper
uclchem.src.uclchem.tests
test_ode_conservation​
def test_ode_conservation(element_list=["H", "N", "C", "O"])
Test whether the ODEs conserve elements. Useful to run each time you change network. Integrator errors may still cause elements not to be conserved but they cannot be conserved if the ODEs are not correct.
Arguments:
element_listlist, optional - A list of elements for which to check the conservation. Defaults to ["H", "N", "C", "O"].
Returns:
dict- A dictionary of the elements in element list with values representing the total rate of change of each element.
uclchem.src.uclchem.makerates.species
is_number​
def is_number(s) -> bool
Try to convert input to a float, if it succeeds, return True.
Arguments:
s- Input element to check for
Returns:
bool- True if a number, False if not.
Species Objects​
class Species()
Species is a class that holds all the information about an individual species in the network. It also has convenience functions to check whether the species is a gas or grain species and to help compare between species.
__init__​
def __init__(inputRow)
A class representing chemical species, it reads in rows which are formatted as follows: NAME,MASS,BINDING ENERGY,SOLID FRACTION,MONO FRACTION,VOLCANO FRACTION,ENTHALPY
Arguments:
inputRow (list):
get_name​
def get_name() -> str
Get the name of the chemical species.
Returns:
str- The name
get_mass​
def get_mass() -> int
Get the molecular mass of the chemical species
Returns:
int- The molecular mass
get_charge​
def get_charge() -> int
Get the charge of the chemical species in e. Positive integer indicates positive ion, negative indicates negative ion. Assumes species are at most charged +1 or -1.
Returns:
int- The charge of the species
set_desorb_products​
def set_desorb_products(new_desorbs: list[str]) -> None
Set the desorption products for species on the surface or in the bulk. It is assumed that there is only one desorption pathway.
Arguments:
new_desorbslist[str] - The new desorption products
get_desorb_products​
def get_desorb_products() -> list[str]
Obtain the desorbtion products of ice species
Returns:
list[str]- The desorption products
set_freeze_products​
def set_freeze_products(product_list: list[str], freeze_alpha: float) -> None
Add the freeze products of the species, one species can have several freeze products.
Arguments:
-
product_listlist[str] - The list of freeze out products -
freeze_alphafloat - The freeze out ratio.It is called alpha, since it is derived from the alpha column in the UCLCHEM reaction format: https://github.com/uclchem/UCLCHEM/blob/08d37f8c3063f8ff8a9a7aa16d9eff0ed4f99538/Makerates/src/network.py#L160
get_freeze_products​
def get_freeze_products() -> dict[list[str], float]
Obtain the product to which the species freeze out
Returns:
dict[str, float]: Reactions and their respective freeze out ratios.
Yields:
Iterator[dict[str, float]]: Iterator that returns all of the freeze out reactions with ratios
get_freeze_products_list​
def get_freeze_products_list() -> list[list[str]]
Returns all the freeze products without their ratios
Returns:
list[list[str]]- List of freeze products
get_freeze_alpha​
def get_freeze_alpha(product_list: list[str]) -> float
Obtain the freeze out ratio of a species for a certain reaction
Arguments:
product_listlist[str] - For a specific reaction, get the freezeout ratio
Returns:
float- The freezeout ratio
is_grain_species​
def is_grain_species() -> bool
Return whether the species is a species on the grain
Returns:
bool- True if it is a grain species.
is_ice_species​
def is_ice_species() -> bool
Return whether the species is a species on the grain
Returns:
bool- True if it is an ice species.
is_surface_species​
def is_surface_species() -> bool
Checks if the species is on the surface
Returns:
bool- True if a surface species
is_bulk_species​
def is_bulk_species() -> bool
Checks if the species is in the bulk
Returns:
bool- True if a bulk species
is_ion​
def is_ion() -> bool
Checks if the species is ionized, either postively or negatively.
Returns:
bool- True if it is an ionized
add_default_freeze​
def add_default_freeze() -> None
Adds a defalt freezeout, which is freezing out to the species itself, but with no ionization.
find_constituents​
def find_constituents(quiet=False)
Loop through the species' name and work out what its consituent atoms are. Then calculate mass and alert user if it doesn't match input mass.
get_n_atoms​
def get_n_atoms() -> int
Obtain the number of atoms in the molecule
Returns:
int- The number of atoms
set_n_atoms​
def set_n_atoms(new_n_atoms: int) -> None
Set the number of atoms
Arguments:
new_n_atomsint - The new number of atoms
__eq__​
def __eq__(other)
Check for equality based on either a string or another Species instance.
Arguments:
otherstr, Species - Another species
Raises:
NotImplementedError- We can only compare between species or strings of species.
Returns:
bool- True if two species are identical.
__lt__​
def __lt__(other) -> bool
Compare the mass of the species
Arguments:
otherSpecies - Another species instance
Returns:
bool- True if less than the other species
__gt__​
def __gt__(other) -> bool
Compare the mass of the species
Arguments:
otherSpecies - Another species instance
Returns:
bool- True if larger than than the other species
uclchem.src.uclchem.makerates
uclchem.src.uclchem.makerates.makerates
run_makerates​
def run_makerates(configuration_file: str = "user_settings.yaml",
write_files: bool = True) -> Network
The main run wrapper for makerates, it loads a configuration, parses it in Network and then returns the Network. It by default writes to the uclchem fortran directory, but this can be skipped.
Arguments:
configuration_filestr, optional - A UCLCHEM Makerates configuration file. Defaults to "user_settings.yaml".write_filesbool, optional - Whether to write the fortran files to the src/fortran_src. Defaults to True.
Raises:
KeyError- The configuration cannot be found
Returns:
Network- A chemical network instance.
get_network​
def get_network(path_to_input_file: Union[str, bytes, os.PathLike] = None,
path_to_species_file: Union[str, bytes, os.PathLike] = None,
path_to_reaction_file: Union[str, bytes, os.PathLike] = None,
verbosity=None)
In memory equivalent of Makerates, can either be used on the original input files for makerates, or on the output files that makerates generates. So either specify:
path_to_input_file exclusive OR (path_to_species_file and path_to_reaction_file)
The latter scenario allows you to reload a reaction network from a network already written by Makerates.
Arguments:
path_to_input_fileUnion[str, bytes, os.PathLike], optional - Path to input file. Defaults to None.path_to_species_fileUnion[str, bytes, os.PathLike], optional - Path to a species.csv in/from the src directory. Defaults to None.path_to_reaction_fileUnion[str, bytes, os.PathLike], optional - Path to a reactions.csv in/from the src directory. Defaults to None.verbosityLEVEL, optional - The verbosity level as specified in logging. Defaults to None.
Raises:
ValueError- You cannot specify both an input configuration and species+reaction.
Returns:
Network- A chemical reaction network.
uclchem.src.uclchem.makerates.network
This python file contains all functions for de-duplicating species and reaction lists, checking for common errors, and automatic addition of reactions such as freeze out, desorption and bulk reactions for three phase models.
Network Objects​
class Network()
The network class stores all the information about reaction network.
__init__​
def __init__(species: list[Species],
reactions: list[Reaction],
user_defined_bulk: list = [],
gas_phase_extrapolation: bool = False,
add_crp_photo_to_grain: bool = False)
A class to store network information such as indices of important reactions.
The class fully utilizes getters and setters, which can be used to add/remove reactions and the species involved. Important is that you do not directly edit the internal dictionaries that store the species and reactions, unless you know what you are doing. The network by default checks for duplicates in species and identical reactions that overlap in temperature ranges, potentially causing problems.
Arguments:
specieslist[Species] - A list of chemical species that are added to the networkreactionslist[Reaction] - A list of chemical reactions that are added to the networkuser_defined_bulklist, optional - List of user defined bulk. Defaults to [].add_crp_photo_to_grainbool, optional - Whether to add CRP, CRPHOT and PHOTON reactions from gas-phase into solid phase too.
add_reactions​
def add_reactions(reactions: Union[Union[Reaction, str], list[Union[Reaction,
str]]])
Add a reaction, list of inputs to the Reaction class or list of reactions to the network.
Arguments:
reactionsUnion[Union[Reaction, str], list[Union[Reaction, str]]] - Reaction or list or reactions
find_similar_reactions​
def find_similar_reactions(reaction: Reaction) -> dict[int, Reaction]
Reactions are similar if the reaction has the same reactants and products, find all reactions that are similar, returning their index and the reaction itself.
Arguments:
reactionReaction - Reaction with possible identical (but for temperature range) reactions in the network
Returns:
dict[int, Reaction]: A dict with the identical reactions.
get_reaction_index​
def get_reaction_index(reaction: Reaction) -> int
Get the index of a reaction in the internal _reactions_dict.
Arguments:
reactionReaction - The reaction to find the index of
Returns:
int- The index of the reaction in the internal _reactions_dict
remove_reaction_by_index​
def remove_reaction_by_index(reaction_idx: int) -> None
Remove a reaction by its index in the internal _reactions_dict, this is the only way to remove reactions that are defined piecewise across temperature ranges.
Arguments:
reaction_idxint - Index of the reaction to remove
remove_reaction​
def remove_reaction(reaction: Reaction) -> None
Remove the reaction by giving the object itself, this only works if the reaction is not piecewise defined across the temperature ranges.
Arguments:
reactionReaction - The reaction you wish to delete.
get_reaction​
def get_reaction(reaction_idx: int) -> Reaction
Obtain a reaction from the reaction set given an index of the internal _reactions_dict.
Arguments:
reaction_idxint - The reaction index
Returns:
Reaction- the desired reaction
set_reaction​
def set_reaction(reaction_idx: int, reaction: Reaction) -> None
This setter explicitely sets the reaction for a certain index.
Arguments:
reaction_idxint - The index to be written toreactionReaction - The reaction to be added to the index.
get_reaction_dict​
def get_reaction_dict() -> dict[int, Reaction]
Returns the whole internal reaction dictionary.
Returns:
dict[int, Reaction]: A copy of the internal reactions dictionary.
set_reaction_dict​
def set_reaction_dict(new_dict: dict[int, Reaction]) -> None
Override the reactions dictionary with a new dictionar.
Arguments:
new_dictdict[int, Reaction] - The new reactions_dictionary.
get_reaction_list​
def get_reaction_list() -> list[Reaction]
Obtain all the reactions in the Network.
Returns:
list[Reaction]- A list with all the reaction objects
get_reactions_by_types​
def get_reactions_by_types(
reaction_type: Union[str, list[str]]) -> list[Reaction]
Get the union of all reactions of a certain type.
Arguments:
reaction_typestr - The reaction type to filter on
Returns:
list[Reaction]- A list of reactions of the specified type
sort_reactions​
def sort_reactions() -> None
Sort the reaction dictionary by reaction type first and by the first reactant second.
add_species​
def add_species(species: Union[Union[Species, str], list[Union[Species,
str]]])
Add species to the network, given a (list of) species. If it is a list of strings, it tries to instantiate a species class with it. It also checks for duplicate entries and filters out attempts to add reaction types to the species.
Arguments:
speciesUnion[Union[Species, str], list[Union[Species, str]]] - A (list of) species or strings.
Raises:
ValueError- If we cannot parse the (list of) reactionsValueError- If an ice specie with binding energy of zero is added.
remove_species​
def remove_species(specie_name: str) -> None
Remove a specie from the network
Arguments:
specie_namestr - Species to remove
get_species_list​
def get_species_list() -> list[Species]
Obtain a list with all the species in the network
Returns:
list[Species]- A list of all the species in the reaction network
get_species_dict​
def get_species_dict() -> dict[str, Species]
Get the internal dictionary that stores all the species, it consists of all species' names as key, with the species object as value.
Returns:
dict[str, Species]: A dictionary with the species
get_specie​
def get_specie(specie_name: str) -> Species
Get the species of the reaction network (from the internal dictionary)
Arguments:
specie_namestr - the name of the species as a string
Returns:
Species- The species object
set_specie​
def set_specie(species_name: str, species: Species) -> None
Set the species of the reaction network in the internal dictionary
Arguments:
species_namestr - The name of the species as stringspeciesSpecies - The Species object to set
set_species_dict​
def set_species_dict(new_species_dict: dict[str, Species]) -> None
Set the internal species dict
Arguments:
new_species_dictdict[str, Species] - The new dictionary to set
sort_species​
def sort_species() -> None
Sort the species based on their mass in ascending order. We always make sure the Electron is last.
check_network​
def check_network() -> None
Run through the list of reactions and check for obvious errors such as duplicate reactions, multiple freeze out routes (to warn, not necessarily an error), etc.
check_and_filter_species​
def check_and_filter_species() -> None
Check every speces in network appears in at least one reaction. Remove any that do not and alert user.
add_bulk_species​
def add_bulk_species() -> None
For three phase models, MakeRates will produce the version of the species in the bulk so that the user doesn't have to endlessly relist the same species
check_freeze_and_desorbs​
def check_freeze_and_desorbs() -> None
add_freeze_reactions() and add_desorb_reactions() automatically generate
all desorption and freeze out reactions. However, user may want to change a species on freeze out
eg C+ becomes C rather than C+. This function checks for that and updates species so they'll
freeze or desorb correctly when reactions are generated.
add_freeze_reactions​
def add_freeze_reactions() -> None
Save the user effort by automatically generating freeze out reactions
add_desorb_reactions​
def add_desorb_reactions() -> None
Save the user effort by automatically generating desorption reactions
add_chemdes_reactions​
def add_chemdes_reactions() -> None
We have the user list all Langmuir-Hinshelwood and Eley-Rideal reactions once. Then we duplicate so that the reaction branches with products on grain and products desorbing.
check_for_excited_species​
def check_for_excited_species() -> bool
Check if there are any exicted species in the network, true if there are any.
add_excited_surface_reactions​
def add_excited_surface_reactions() -> None
All excited species will relax to the ground state if they do not react
the vibrational frequency of the species is used as a pseudo approximation of the rate coefficient
We assume all grain reactions have an excited variant. For example:
A, B LH C will have the variants:
A, B EXSOLID C and A, B EXSOLID C
If only one of the reactants in the base reaction has an excited counterpart then
only one excited version of that reaction is created.
add_bulk_reactions​
def add_bulk_reactions() -> None
We assume any reaction that happens on the surface of grains can also happen in the bulk (just more slowly due to binding energy). The user therefore only lists surface reactions in their input reaction file and we duplicate here.
freeze_checks​
def freeze_checks() -> None
Check that every species freezes out and alert the user if a species freezes out via mutiple routes. This isn't necessarily an error so best just print.
add_CRP_and_PHOTO_reactions_to_grain​
def add_CRP_and_PHOTO_reactions_to_grain() -> None
Add all the gas-phase reactions with CRP, CRPHOT or PHOTON to the grain surface too
duplicate_checks​
def duplicate_checks() -> None
Check reaction network to make sure no reaction appears twice unless they have different temperature ranges.
index_important_reactions​
def index_important_reactions() -> None
We have a whole bunch of important reactions and we want to store their indices. We find them all here.
index_important_species​
def index_important_species() -> None
Obtain the indices for all the important reactions.
branching_ratios_checks​
def branching_ratios_checks() -> None
Check that the branching ratios for the ice reactions sum to 1.0. If they do not, correct them. This needs to be done for LH and LHDES separately since we already added the desorption to the network.
LoadedNetwork Objects​
class LoadedNetwork(Network)
Network version that skips all steps and just loads two lists. This is another here be dragons version, use this with exceeding caution as no checks are performed for you.
Arguments:
Networktype - description
__init__​
def __init__(species: list[Species], reactions: list[Reaction]) -> None
A loader of networks without any checks.
Here be dragons.
Arguments:
specieslist[Species] - A list of species objectsreactionslist[Reaction] - A list of reaction objects.
uclchem.src.uclchem.makerates.io_functions
Functions to read in the species and reaction files and write output files
read_species_file​
def read_species_file(file_name: Path) -> list[Species]
Reads in a Makerates species file
Arguments:
fileNamestr - path to file containing the species list
Returns:
list- List of Species objects
read_reaction_file​
def read_reaction_file(file_name: Path, species_list: list[Species],
ftype: str) -> tuple[list[Reaction], list[Reaction]]
Reads in a reaction file of any kind (user, UMIST, KIDA) produces a list of reactions for the network, filtered by species_list
Arguments:
file_namestr - A file name for the reaction file to read.species_listlist[Species] - A list of chemical species to be used in the reading.ftypestr - 'UMIST','UCL', or 'KIDA' to describe format of file_name
Returns:
list,list- Lists of kept and dropped reactions.
check_reaction​
def check_reaction(reaction_row, keep_list) -> bool
Checks a row parsed from a reaction file and checks it only contains acceptable things. It checks if all species in the reaction are present, and adds the temperature range is none is specified.
Arguments:
reaction_rowlist - List parsed from a reaction file and formatted to be able to called Reaction(reaction_row)keep_listlist - list of elements that are acceptable in the reactant or product bits of row
Returns:
bool- Whether the row contains acceptable entries.
kida_parser​
def kida_parser(kida_file)
KIDA used a fixed format file so we read each line in the chunks they specify and use python built in classes to convert to the necessary types. NOTE KIDA defines some of the same reaction types to UMIST but with different names and coefficients. We fix that by converting them here.
output_drops​
def output_drops(dropped_reactions: list[Reaction],
output_dir: str = None,
write_files: bool = True)
Writes the reactions that are dropped to disk/logs
Arguments:
dropped_reactionslist[Reaction] - The reactions that were droppedoutput_dirstr - The directory that dropped_reactions.csv will be written to.write_filesbool, optional - Whether or not to write the file. Defaults to True.
write_outputs​
def write_outputs(network: Network,
output_dir: str = None,
rates_to_disk: bool = False,
gar_database: dict[str, np.array] = None) -> None
Write the ODE and Network fortran source files to the fortran source.
Arguments:
networknetwork - The makerates Network classoutput_dirbool - The directory to write to.
write_f90_constants​
def write_f90_constants(
replace_dict: Dict[str, int],
output_file_name: Path,
template_file_path: Path = "fortran_templates") -> None
Write the physical reactions to the f2py_constants.f90 file after every run of makerates, this ensures the Fortran and Python bits are compatible with one another.
Arguments:
replace_dictDict[str, int] - The dictionary with keys to replace and their valuesoutput_file_namePath - The path to the target f2py_constants.f90 filetemplate_file_pathPath, optional - The file to use as the template. Defaults to "fortran_templates".
write_python_constants​
def write_python_constants(replace_dict: Dict[str, int],
python_constants_file: Path) -> None
Function to write the python constants to the constants.py file after every run, this ensure the Python and Fortran bits are compatible with one another.
Arguments:
replace_dictDict[str, int]] - Dict with keys to replace and their valuespython_constants_filePath - Path to the target constant files.
write_species​
def write_species(file_name: Path, species_list: list[Species]) -> None
Write the human readable species file. Note UCLCHEM doesn't use this file.
Arguments:
fileNamestr - path to output filespecies_listlist - List of species objects for network
write_reactions​
def write_reactions(fileName, reaction_list) -> None
Write the human readable reaction file.
Arguments:
fileNamestr - path to output filereaction_listlist - List of reaction objects for network
write_odes_f90​
def write_odes_f90(file_name: Path,
species_list: list[Species],
reaction_list: list[Reaction],
rates_to_disk: bool = False) -> None
Write the ODEs in Modern Fortran. This is an actual code file.
Arguments:
file_namestr - Path to file where code will be writtenspecies_listlist - List of species describing networkreaction_listlist - List of reactions describing network
write_jacobian​
def write_jacobian(file_name: Path, species_list: list[Species]) -> None
Write jacobian in Modern Fortran. This has never improved UCLCHEM's speed and so is not used in the code as it stands. Current only works for three phase model.
Arguments:
file_namestr - Path to jacobian filespecies_listspecies_list - List of species AFTER being processed by build_ode_string
build_ode_string​
def build_ode_string(species_list: list[Species],
reaction_list: list[Reaction],
rates_to_disk: bool = False) -> str
A long, complex function that does the messy work of creating the actual ODE code to calculate the rate of change of each species. Test any change to this code thoroughly because ODE mistakes are very hard to spot.
Arguments:
species_listlist - List of species in networkreaction_listlist - List of reactions in networkrates_to_diskbool - Enable the writing of the rates to the disk.
Returns:
str- One long string containing the entire ODE fortran code.
species_ode_string​
def species_ode_string(n: int, species: Species) -> str
Build the string of Fortran code for a species once it's loss and gains strings have been produced.
Arguments:
nint - Index of species in python formatspeciesSpecies - species object
Returns:
str- the fortran code for the rate of change of the species
write_evap_lists​
def write_evap_lists(network_file, species_list: list[Species]) -> int
Two phase networks mimic episodic thermal desorption seen in lab (see Viti et al. 2004) by desorbing fixed fractions of material at specific temperatures. Three phase networks just use binding energy and that fact we set binding energies in bulk to water by default. This function writes all necessary arrays to the network file so these processes work.
Arguments:
network_filefile - Open file object to which the network code is being writtenspecies_listlist[Species] - List of species in network
truncate_line​
def truncate_line(input_string: str, lineLength: int = 72) -> str
Take a string and adds line endings at regular intervals keeps us from overshooting fortran's line limits and, frankly, makes for nicer ode.f90 even if human readability isn't very important
Arguments:
input_stringstr - Line of code to be truncatedlineLengthint, optional - rough line length. Defaults to 72.
Returns:
str- Code string with line endings at regular intervals
write_network_file​
def write_network_file(file_name: Path,
network: Network,
rates_to_disk: bool = False,
gar_database=None)
Write the Fortran code file that contains all network information for UCLCHEM. This includes lists of reactants, products, binding energies, formationEnthalpies and so on.
Arguments:
file_namestr - The file name where the code will be written.networkNetwork - A Network object built from lists of species and reactions.
find_reactant​
def find_reactant(species_list: list[str], reactant: str) -> int
Try to find a reactant in the species list
Arguments:
species_listlist[str] - A list of species in the networkreactantstr - The reactant to be indexed
Returns:
int- The index of the reactant, if it is not found, 9999
get_desorption_freeze_partners​
def get_desorption_freeze_partners(
reaction_list: list[Reaction]) -> list[Reaction]
Every desorption has a corresponding freeze out eg desorption of CO and freeze of CO.
This find the corresponding freeze out for every desorb so that when desorb>>freeze
we can turn off freeze out in UCLCHEM.
Arguments:
reaction_listlist - Reactions in network
Returns:
list- list of indices of freeze out reactions matching order of desorptions.
array_to_string​
def array_to_string(name: str,
array: np.array,
type: str = "int",
parameter: bool = True) -> str
Write an array to fortran source code
Arguments:
namestr - Variable name of array in Fortranarrayiterable - List of values of arraytypestr, optional - The array's type. Must be one of "int","float", or "string".Defaults to "int".parameterbool, optional - Whether the array is a Fortran PARAMETER (constant). Defaults to True.
Raises:
ValueError- Raises an error if type isn't "int","float", or "string"
Returns:
str- String containing the Fortran code to declare this array.
uclchem.src.uclchem.makerates.reaction
Reaction Objects​
class Reaction()
get_reactants​
def get_reactants() -> list[str]
Get the four reactants present in the reaction, padded with NAN for nonexistent
Returns:
list[str]- The four reactants names
get_pure_reactants​
def get_pure_reactants() -> list[str]
Get only the pure species, no reaction types and NAN entries
Returns:
list[str]- The list of reacting species.
get_sorted_reactants​
def get_sorted_reactants() -> list[str]
Get the four reactants present in the reaction, sorted for fast comparisons
Arguments:
reactantslist[str] - The four sorted reactant names
set_reactants​
def set_reactants(reactants: list[str]) -> None
Set the four reactants present in the reaction, padded with NAN for nonexistent
Arguments:
reactantslist[str] - The four reactants names
get_products​
def get_products() -> list[str]
Get the four products present in the reaction, padded with NAN for nonexistent
Arguments:
reactantslist[str] - The four products names
get_pure_products​
def get_pure_products() -> list[str]
Get only the pure species that are products, no reaction types and NAN entries
Returns:
list[str]- The list of produced species.
get_sorted_products​
def get_sorted_products() -> list[str]
Get the four products present in the reaction, sorted for fast comparisons
Arguments:
productslist[str] - The four sorted products names
set_products​
def set_products(products: list[str]) -> None
Set the four products present in the reaction, padded with NAN for nonexistent
Arguments:
productslist[str] - The four products names
get_alpha​
def get_alpha() -> float
Get the alpha parameter from the Kooij-Arrhenius equation
Returns:
float- the alpha parameter of the reaction
set_alpha​
def set_alpha(alpha: float) -> None
Set the alpha parameter from the Kooij-Arrhenius equation
Arguments:
alphafloat - the alpha parameter of the reaction
get_beta​
def get_beta() -> float
Get the beta parameter from the Kooij-Arrhenius equation
Returns:
float- the beta parameter of the reaction
set_beta​
def set_beta(beta: float) -> None
Set the beta parameter from the Kooij-Arrhenius equation
Arguments:
betafloat - the beta parameter of the reaction
set_gamma​
def set_gamma(gamma: float) -> None
Set the gamma parameter from the Kooij-Arrhenius equation
Arguments:
gammafloat - the gamma parameter of the reaction
get_gamma​
def get_gamma() -> float
Get the gamma parameter from the Kooij-Arrhenius equation
Returns:
float- the gamma parameter of the reaction
set_templow​
def set_templow(templow: float) -> None
Set the lower temperature boundary of the reaction in Kelvin
Arguments:
templowfloat - the lower temperature boundary
get_templow​
def get_templow() -> float
Get the lower temperature boundary of the reaction in Kelvin
Returns:
float- the lower temperature boundary
set_temphigh​
def set_temphigh(temphigh: float) -> None
Set the higher temperature boundary of the reaction in Kelvin
Arguments:
templowfloat - the higher temperature boundary
get_temphigh​
def get_temphigh() -> float
Get the higher temperature boundary of the reaction in Kelvin
Returns:
float- the higher temperature boundary
predict_reduced_mass​
def 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.
set_reduced_mass​
def set_reduced_mass(reduced_mass: float) -> None
Set the reduced mass to be used to calculate tunneling rate in AMU
Arguments:
reduced_massfloat - reduced mass of moving atoms
get_reduced_mass​
def get_reduced_mass() -> float
Get the reduced mass to be used to calculate tunneling rate in AMU
Returns:
float- reduced mass of moving atoms
NANCheck​
def NANCheck(a)
Convert any Falsy statement to a NAN string
Arguments:
a- thing to check for falsiness
Returns:
bool- input a if truthy, otherwise NAN
get_reaction_type​
def 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:
str:
get_source​
def get_source() -> str
Get the source of the reaction
Returns:
str- The source of the reaction
set_source​
def set_source(source: str) -> None
Set the source of the reaction
Arguments:
sourcestr - The source of the reaction
convert_surf_to_bulk​
def convert_surf_to_bulk() -> None
Convert the surface species to bulk species in place for this reaction.
convert_gas_to_surf​
def 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.
__eq__​
def __eq__(other) -> bool
Check for equality against another reaction based on the products and reactants. Note that it does not check for the temperature ranges that the reactions might have! The Reaction.check_temperature_collision can be used for this purpose.
Arguments:
other- Another reaction set.
Returns:
bool- equality
check_temperature_collision​
def check_temperature_collision(other) -> bool
Check if two reactions have overlapping temperature ranges, returning True means there is a collision.
Arguments:
other- Another reaction
Raises:
NotImplementedError- Currently we can only compare against instantiated Reaction objects.
Returns:
bool- Whether there is a collision (True), or not (False)
changes_surface_count​
def changes_surface_count()
This checks 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.
changes_total_mantle​
def changes_total_mantle()
Check if the total grains on the mantle are changed by the reaction.
to_UCL_format​
def to_UCL_format()
Convert a reaction to UCLCHEM reaction file format
is_gas_reaction​
def is_gas_reaction(include_reactants=True,
include_products=True,
strict=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.
Arguments:
include_reactantsbool, optional - Include the reactants. Defaults to True.include_productsbool, optional - Include the products. Defaults to True.strictbool, optional - Choose between all (true) or any (false) must be gas phase . Defaults to True.
Returns:
bool- Is it a gas phase reaction?
is_ice_reaction​
def is_ice_reaction(include_reactants=True,
include_products=True,
strict=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
Arguments:
include_reactantsbool, optional - Include the reactants. Defaults to True.include_productsbool, optional - Include the products. Defaults to True.strictbool, optional - Choose between all (true) or any (false) must be ice phase . Defaults to True.
Returns:
bool- Is it an ice phase reaction?
is_surface_reaction​
def is_surface_reaction(include_reactants=True,
include_products=True,
strict=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
Arguments:
include_reactantsbool, optional - Include the reactants. Defaults to True.include_productsbool, optional - Include the products. Defaults to True.strictbool, optional - Choose between all (true) or any (false) must be on the surface . Defaults to False.
Returns:
bool- Is it a surface reaction?
is_bulk_reaction​
def is_bulk_reaction(include_reactants=True,
include_products=True,
strict=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
Arguments:
include_reactantsbool, optional - Include the reactants. Defaults to True.include_productsbool, optional - Include the products. Defaults to True.strictbool, optional - Choose between all (true) or any (false) must in the bulk . Defaults to False.
Returns:
bool- Is it a bulk reaction?
uclchem.plot
uclchem.version
uclchem.analysis
read_output_file​
def read_output_file(output_file)
Read the output of a UCLCHEM run created with the outputFile parameter into a pandas DataFrame
Arguments:
output_filestr - path to file containing a full UCLCHEM output
Returns:
pandas.DataFrame- A dataframe containing the abundances and physical parameters of the model at every time step.
read_rate_file​
def read_rate_file(rate_file)
Read the output of a UCLCHEM run created with the rateFile parameter into a pandas DataFrame
Arguments:
rate_filestr - path to file containing the UCLCHEM reaction rates.
Returns:
pandas.DataFrame- A dataframe containing the physical parameters, and reaction rates (s-1) at each timestep.
get_change_df​
def get_change_df(rate_df: pd.DataFrame,
species: str,
on_grain: bool = False) -> pd.DataFrame
From a dataframe containing all the reaction rates, get the change of a species over time, due to each reaction.
Arguments:
rate_dfpd.DataFrame - dataframe containing physical parameters and reaction rates over timespeciesstr - species to get the change over timeon_grainbool - whether to analyse the ice phase of this species
Returns:
change_dfpd.DataFrame - change of species over time due to each reaction the species is involved in
create_abundance_plot​
def create_abundance_plot(df, species, figsize=(16, 9), plot_file=None)
Create a plot of the abundance of a list of species through time.
Arguments:
dfpd.DataFrame - Pandas dataframe containing the UCLCHEM output, seeread_output_filespecieslist - list of strings containing species names. Using a $ instead of # or @ will plot the sum of surface and bulk abundances.figsizetuple, optional - Size of figure, width by height in inches. Defaults to (16, 9).plot_filestr, optional - Path to file where figure will be saved. If None, figure is not saved. Defaults to None.
Returns:
fig,ax- matplotlib figure and axis objects
plot_species​
def plot_species(ax, df, species, legend=True, **plot_kwargs)
Plot the abundance of a list of species through time directly onto an axis.
Arguments:
axpyplot.axis - An axis object to plot ondfpd.DataFrame - A dataframe created byread_output_filespeciesstr - A list of species names to be plotted. If species name starts with "$" instead of # or @, plots the sum of surface and bulk abundances
Returns:
pyplot.axis- Modified input axis is returned
analysis​
def analysis(species_name, rates, output_file, rate_threshold=0.99)
A function which loops over every time step in an output file and finds the rate of change of a species at that time due to each of the reactions it is involved in. From this, the most important reactions are identified and printed to file. This can be used to understand the chemical reason behind a species' behaviour.
Arguments:
species_namestr - Name of species to be analysedresult_filestr - The path to the file containing the UCLCHEM outputoutput_filestr - The path to the file where the analysis output will be writtenrate_thresholdfloat,optional - Analysis output will contain the only the most efficient reactions that are responsible for rate_threshold of the total production and destruction rate. Defaults to 0.99.
total_element_abundance​
def total_element_abundance(element, df)
Calculates that the total elemental abundance of a species as a function of time. Allows you to check conservation.
Arguments:
elementstr - Name of elementdfpandas.DataFrame - DataFrame fromread_output_file()
Returns:
pandas.Series- Total abundance of element for all time steps in df.
check_element_conservation​
def check_element_conservation(df,
element_list=["H", "N", "C", "O"],
percent=True)
Check the conservation of major element by comparing total abundance at start and end of model
Arguments:
dfpandas.DataFrame - UCLCHEM output in format fromread_output_fileelement_listlist, optional - List of elements to check. Defaults to ["H", "N", "C", "O"].
Returns:
dict- Dictionary containing the change in the total abundance of each element as a fraction of initial value
get_total_swap​
def get_total_swap(rates: pd.DataFrame, abundances: pd.DataFrame,
reactions: List[Reaction]) -> np.ndarray
Obtain the amount of 'random' swapping per timestep
Arguments:
ratespd.DataFrame - The rates obtained from running an UCLCHEM modelabundancespd.DataFrame - The abundances obtained from running an UCLCHEM modelreactionsList[Reaction] - The reactions used in UCLCHEM
Returns:
np.ndarray- The total swap per timestep
construct_incidence​
def construct_incidence(species: List[Species],
reactions: List[Reaction]) -> np.ndarray
Construct the incidence matrix, a matrix that describes the in and out degree for each of the reactions; useful to matrix multiply by the indvidual fluxes per reaction to obtain a flux (dy) per species.
Arguments:
speciesList[Species] - A list of species SreactionsList[Reaction] - The list of reactions S
Returns:
np.ndarray- A RxS incidence matrix
rates_to_dy_and_flux​
def rates_to_dy_and_flux(
physics: pd.DataFrame,
abundances: pd.DataFrame,
rates: pd.DataFrame,
network: Network = None,
species: list[Species] = None,
reactions: list[Reaction] = None) -> tuple[pd.DataFrame, pd.DataFrame]
Apply postprocessing to obtain the equivalent of GETYDOT from the fortran side; It returns two dataframes:
- ydot: the RHS that is solved in UCLCHEM at every output timestep
- flux_by_reaction: the individual terms that result in ydot when multiplied by the incidence matrix
Arguments:
physicspd.DataFrame - The physics output from running a modelabundancespd.DataFrame - The abundances output from running a modelratespd.DataFrame - The rates output from running a modelnetworkNetwork, optional - The reaction network used to postprocess the rates. Defaults to None.specieslist[Species], optional - The species used to postprocess the rates . Defaults to None.reactionslist[Reaction], optional - The reactions used to postprocess the rates. Defaults to None.
Returns:
tuple[pd.DataFrame, pd.DataFrame]: dy, flux_by_reaction.
analyze_element_per_phase​
def analyze_element_per_phase(element, df)
Calculates that the total elemental abundance of a species as a function of time. Allows you to check conservation.
Arguments:
elementstr - Name of elementdfpandas.DataFrame - DataFrame fromread_output_file()
Returns:
pandas.Series- Total abundance of element for all time steps in df.
uclchem.constants
uclchem.model
outputArrays_to_DataFrame​
def outputArrays_to_DataFrame(physicalParameterArray, chemicalAbundanceArray,
specname, ratesArray)
Convert the output arrays to a pandas dataframe
Arguments:
physicalParameterArraynp.array - Array with the output physical parameterschemicalAbundanceArraynp.array - Array with the output chemical abundancesspecnamelist - List with the names of all the speciesphysParameterlist - Array with all the physical parameter names
Returns:
_type_- description
cloud​
def cloud(param_dict=None,
out_species=None,
return_array=False,
return_dataframe=False,
return_rates=False,
starting_chemistry=None,
timepoints=TIMEPOINTS)
Run cloud model from UCLCHEM
Arguments:
param_dictdict,optional - A dictionary of parameters where keys are any of the variables in defaultparameters.f90 and values are value for current run.out_specieslist, optional - A list of species for which final abundance will be returned. If None, no abundances will be returned.. Defaults to None.return_arraybool, optional - A boolean on whether a np.array should be returned to a user, if both return_array and return_dataframe are false, this function will default to writing outputs to a filereturn_dataframebool, optional - A boolean on whether a pandas.DataFrame should be returned to a user, if both return_array and return_dataframe are false, this function will default to writing outputs to a filestarting_chemistryarray, optional - np.array containing the starting chemical abundances needed by uclchem
Returns:
if return_array and return_dataframe are False:
- A list where the first element is always an integer which is negative if the model failed to run and can be sent to
uclchem.utils.check_error()to see more details. If theout_speciesparametere is provided, the remaining elements of this list will be the final abundances of the species in out_species. if return_array is True: - physicsArray (array): array containing the physical outputs for each written timestep
- chemicalAbunArray (array): array containing the chemical abundances for each written timestep
- abundanceStart (array): array containing the chemical abundances of the last timestep in the format uclchem needs in order to perform an additional run after the initial model
- success_flag (integer): which is negative if the model failed to run and can be sent to
uclchem.utils.check_error()to see more details. if return_dataframe is True: - physicsDF (pandas.DataFrame): DataFrame containing the physical outputs for each written timestep
- chemicalDF (pandas.DataFrame): DataFrame containing the chemical abundances for each written timestep
- abundanceStart (array): array containing the chemical abundances of the last timestep in the format uclchem needs in order to perform an additional run after the initial model
- success_flag (integer): which is negative if the model failed to run and can be sent to
uclchem.utils.check_error()to see more details.
collapse​
def collapse(collapse,
physics_output,
param_dict=None,
out_species=None,
return_array=False,
return_dataframe=False,
return_rates=False,
starting_chemistry=None,
timepoints=TIMEPOINTS)
Run collapse model from UCLCHEM based on Priestley et al 2018 AJ 156 51 (https://ui.adsabs.harvard.edu/abs/2018AJ....156...51P/abstract)
Arguments:
collapsestr - A string containing the collapse type, options are 'BE1.1', 'BE4', 'filament', or 'ambipolar'physics_output(str)- Filename to store physics output, only relevant for 'filament' and 'ambipolar' collapses. If None, no physics output will be saved.param_dictdict,optional - A dictionary of parameters where keys are any of the variables in defaultparameters.f90 and values are value for current run.out_specieslist, optional - A list of species for which final abundance will be returned. If None, no abundances will be returned.. Defaults to None.return_arraybool, optional - A boolean on whether a np.array should be returned to a user, if both return_array and return_dataframe are false, this function will default to writing outputs to a filereturn_dataframebool, optional - A boolean on whether a pandas.DataFrame should be returned to a user, if both return_array and return_dataframe are false, this function will default to writing outputs to a filestarting_chemistryarray, optional - np.array containing the starting chemical abundances needed by uclchem
Returns:
if return_array and return_dataframe are False:
- A list where the first element is always an integer which is negative if the model failed to run and can be sent to
uclchem.utils.check_error()to see more details. If theout_speciesparametere is provided, the remaining elements of this list will be the final abundances of the species in out_species. if return_array is True: - physicsArray (array): array containing the physical outputs for each written timestep
- chemicalAbunArray (array): array containing the chemical abundances for each written timestep
- abundanceStart (array): array containing the chemical abundances of the last timestep in the format uclchem needs in order to perform an additional run after the initial model
- success_flag (integer): which is negative if the model failed to run and can be sent to
uclchem.utils.check_error()to see more details. if return_dataframe is True: - physicsDF (pandas.DataFrame): DataFrame containing the physical outputs for each written timestep
- chemicalDF (pandas.DataFrame): DataFrame containing the chemical abundances for each written timestep
- abundanceStart (array): array containing the chemical abundances of the last timestep in the format uclchem needs in order to perform an additional run after the initial model
- success_flag (integer): which is negative if the model failed to run and can be sent to
uclchem.utils.check_error()to see more details.
hot_core​
def hot_core(temp_indx,
max_temperature,
param_dict=None,
out_species=None,
return_array=False,
return_dataframe=False,
return_rates=False,
starting_chemistry=None,
timepoints=TIMEPOINTS)
Run hot core model from UCLCHEM, based on Viti et al. 2004 and Collings et al. 2004
Arguments:
temp_indxint - Used to select the mass of hot core. 1=1Msun,2=5, 3=10, 4=15, 5=25,6=60]max_temperaturefloat - Value at which gas temperature will stop increasing.param_dictdict,optional - A dictionary of parameters where keys are any of the variables in defaultparameters.f90 and values are value for current run.out_specieslist, optional - A list of species for which final abundance will be returned. If None, no abundances will be returned.. Defaults to None.return_arraybool, optional - A boolean on whether a np.array should be returned to a user, if both return_array and return_dataframe are false, this function will default to writing outputs to a filereturn_dataframebool, optional - A boolean on whether a pandas.DataFrame should be returned to a user, if both return_array and return_dataframe are false, this function will default to writing outputs to a filestarting_chemistryarray, optional - np.array containing the starting chemical abundances needed by uclchem
Returns:
if return_array and return_dataframe are False:
- A list where the first element is always an integer which is negative if the model failed to run and can be sent to
uclchem.utils.check_error()to see more details. If theout_speciesparametere is provided, the remaining elements of this list will be the final abundances of the species in out_species. if return_array is True: - physicsArray (array): array containing the physical outputs for each written timestep
- chemicalAbunArray (array): array containing the chemical abundances for each written timestep
- abundanceStart (array): array containing the chemical abundances of the last timestep in the format uclchem needs in order to perform an additional run after the initial model
- success_flag (integer): which is negative if the model failed to run and can be sent to
uclchem.utils.check_error()to see more details. if return_dataframe is True: - physicsDF (pandas.DataFrame): DataFrame containing the physical outputs for each written timestep
- chemicalDF (pandas.DataFrame): DataFrame containing the chemical abundances for each written timestep
- abundanceStart (array): array containing the chemical abundances of the last timestep in the format uclchem needs in order to perform an additional run after the initial model
- success_flag (integer): which is negative if the model failed to run and can be sent to
uclchem.utils.check_error()to see more details.
cshock​
def cshock(shock_vel,
timestep_factor=0.01,
minimum_temperature=0.0,
param_dict=None,
out_species=None,
return_array=False,
return_dataframe=False,
return_rates=False,
starting_chemistry=None,
timepoints=TIMEPOINTS)
Run C-type shock model from UCLCHEM
Arguments:
shock_velfloat - Velocity of the shock in km/stimestep_factorfloat, optional - Whilst the time is less than 2 times the dissipation time of shock, timestep is timestep_factor*dissipation time. Essentially controls how well resolved the shock is in your model. Defaults to 0.01.minimum_temperaturefloat, optional - Minimum post-shock temperature. Defaults to 0.0 (no minimum). The shocked gas typically cools toinitialTempif this is not set.param_dictdict,optional - A dictionary of parameters where keys are any of the variables in defaultparameters.f90 and values are value for current run.out_specieslist, optional - A list of species for which final abundance will be returned. If None, no abundances will be returned.. Defaults to None.return_arraybool, optional - A boolean on whether a np.array should be returned to a user, if both return_array and return_dataframe are false, this function will default to writing outputs to a filereturn_dataframebool, optional - A boolean on whether a pandas.DataFrame should be returned to a user, if both return_array and return_dataframe are false, this function will default to writing outputs to a filestarting_chemistryarray, optional - np.array containing the starting chemical abundances needed by uclchem
Returns:
if return_array and return_dataframe are False:
- A list where the first element is always an integer which is negative if the model failed to run and can be sent to
uclchem.utils.check_error()to see more details. If the model succeeded, the second element is the dissipation time and further elements are the abundances of all species inout_species. if return_array is True: - physicsArray (array): array containing the physical outputs for each written timestep
- chemicalAbunArray (array): array containing the chemical abundances for each written timestep
- disspation_time (float): dissipation time in years
- abundanceStart (array): array containing the chemical abundances of the last timestep in the format uclchem needs in order to perform an additional run after the initial model
- success_flag (integer): which is negative if the model failed to run and can be sent to
uclchem.utils.check_error()to see more details. if return_dataframe is True: - physicsDF (pandas.DataFrame): DataFrame containing the physical outputs for each written timestep
- chemicalDF (pandas.DataFrame): DataFrame containing the chemical abundances for each written timestep
- disspation_time (float): dissipation time in years
- abundanceStart (array): array containing the chemical abundances of the last timestep in the format uclchem needs in order to perform an additional run after the initial model
- success_flag (integer): which is negative if the model failed to run and can be sent to
uclchem.utils.check_error()to see more details.
jshock​
def jshock(shock_vel,
param_dict=None,
out_species=None,
return_array=False,
return_dataframe=False,
return_rates=False,
starting_chemistry=None,
timepoints=TIMEPOINTS)
Run J-type shock model from UCLCHEM
Arguments:
-
shock_velfloat - Velocity of the shock -
param_dictdict,optional - A dictionary of parameters where keys are any of the variables in defaultparameters.f90 and values are value for current run. -
out_specieslist, optional - A list of species for which final abundance will be returned. If None, no abundances will be returned.. Defaults to None. -
return_arraybool, optional - A boolean on whether a np.array should be returned to a user, if both return_array and return_dataframe are false, this function will default to writing outputs to a file -
return_dataframebool, optional - A boolean on whether a pandas.DataFrame should be returned to a user, if both return_array and return_dataframe are false, this function will default to writing outputs to a file -
starting_chemistryarray, optional - np.array containing the starting chemical abundances needed by uclchemReturns:if return_array and return_dataframe are False:
- A list where the first element is always an integer which is negative if the model failed to run and can be sent to
uclchem.utils.check_error()to see more details. If the model succeeded, the second element is the dissipation time and further elements are the abundances of all species inout_species. if return_array is True: - physicsArray (array): array containing the physical outputs for each written timestep
- chemicalAbunArray (array): array containing the chemical abundances for each written timestep
- abundanceStart (array): array containing the chemical abundances of the last timestep in the format uclchem needs in order to perform an additional run after the initial model
- success_flag (integer): which is negative if the model failed to run and can be sent to
uclchem.utils.check_error()to see more details. if return_dataframe is True: - physicsDF (pandas.DataFrame): DataFrame containing the physical outputs for each written timestep
- chemicalDF (pandas.DataFrame): DataFrame containing the chemical abundances for each written timestep
- abundanceStart (array): array containing the chemical abundances of the last timestep in the format uclchem needs in order to perform an additional run after the initial model
- success_flag (integer): which is negative if the model failed to run and can be sent to
uclchem.utils.check_error()to see more details.
- A list where the first element is always an integer which is negative if the model failed to run and can be sent to
postprocess​
def postprocess(param_dict=None,
out_species=None,
return_array=False,
return_dataframe=False,
return_rates=False,
starting_chemistry=None,
time_array=None,
density_array=None,
gas_temperature_array=None,
dust_temperature_array=None,
zeta_array=None,
radfield_array=None,
coldens_H_array=None,
coldens_H2_array=None,
coldens_CO_array=None,
coldens_C_array=None)
Run cloud model from UCLCHEM
Arguments:
param_dictdict,optional - A dictionary of parameters where keys are any of the variables in defaultparameters.f90 and values are value for current run.out_specieslist, optional - A list of species for which final abundance will be returned. If None, no abundances will be returned.. Defaults to None.return_arraybool, optional - A boolean on whether a np.array should be returned to a user, if both return_array and return_dataframe are false, this function will default to writing outputs to a filereturn_dataframebool, optional - A boolean on whether a pandas.DataFrame should be returned to a user, if both return_array and return_dataframe are false, this function will default to writing outputs to a filestarting_chemistryarray, optional - np.array containing the starting chemical abundances needed by uclchem
Returns:
if return_array and return_dataframe are False:
- A list where the first element is always an integer which is negative if the model failed to run and can be sent to
uclchem.utils.check_error()to see more details. If theout_speciesparametere is provided, the remaining elements of this list will be the final abundances of the species in out_species. if return_array is True: - physicsArray (array): array containing the physical outputs for each written timestep
- chemicalAbunArray (array): array containing the chemical abundances for each written timestep
- abundanceStart (array): array containing the chemical abundances of the last timestep in the format uclchem needs in order to perform an additional run after the initial model
- success_flag (integer): which is negative if the model failed to run and can be sent to
uclchem.utils.check_error()to see more details. if return_dataframe is True: - physicsDF (pandas.DataFrame): DataFrame containing the physical outputs for each written timestep
- chemicalDF (pandas.DataFrame): DataFrame containing the chemical abundances for each written timestep
- abundanceStart (array): array containing the chemical abundances of the last timestep in the format uclchem needs in order to perform an additional run after the initial model
- success_flag (integer): which is negative if the model failed to run and can be sent to
uclchem.utils.check_error()to see more details.
uclchem.utils
cshock_dissipation_time​
def cshock_dissipation_time(shock_vel, initial_dens)
A simple function used to calculate the dissipation time of a C-type shock. Use to obtain a useful timescale for your C-shock model runs. Velocity of ions and neutrals equalizes at dissipation time and full cooling takes a few dissipation times.
Arguments:
shock_velfloat - Velocity of the shock in km/sinitial_densfloat - Preshock density of the gas in cm
Returns:
float- The dissipation time of the shock in years
check_error​
def check_error(error_code)
Converts the UCLCHEM integer result flag to a simple messaging explaining what went wrong"
Arguments:
error_codeint - Error code returned by UCLCHEM models, the first element of the results list.
Returns:
str- Error message
get_species_table​
def get_species_table()
A simple function to load the list of species in the UCLCHEM network into a pandas dataframe.
Returns:
pandas.DataFrame- A dataframe containing the species names and their details
get_species​
def get_species() -> list[str]
A simple function to load the list of species present in the UCLCHEM network
Returns:
list[str] : A list of species names
get_reaction_table​
def get_reaction_table()
A function to load the reaction table from the UCLCHEM network into a pandas dataframe.
Returns:
pandas.DataFrame- A dataframe containing the reactions and their rates
uclchem.debug
Functions to help debugging UCLCHEM
get_f2py_signature​
def get_f2py_signature(write=False) -> str
Get the signature of the UCLCHEM fortran code
Arguments:
writebool, optional - Write to disk. Defaults to False.
Returns:
str- Signature of the UCLCHEM fortran code from the f2py wrapper
uclchem.tests
test_ode_conservation​
def test_ode_conservation(element_list=["H", "N", "C", "O"])
Test whether the ODEs conserve elements. Useful to run each time you change network. Integrator errors may still cause elements not to be conserved but they cannot be conserved if the ODEs are not correct.
Arguments:
element_listlist, optional - A list of elements for which to check the conservation. Defaults to ["H", "N", "C", "O"].
Returns:
dict- A dictionary of the elements in element list with values representing the total rate of change of each element.
uclchem.makerates.species
is_number​
def is_number(s) -> bool
Try to convert input to a float, if it succeeds, return True.
Arguments:
s- Input element to check for
Returns:
bool- True if a number, False if not.
Species Objects​
class Species()
Species is a class that holds all the information about an individual species in the network. It also has convenience functions to check whether the species is a gas or grain species and to help compare between species.
__init__​
def __init__(inputRow)
A class representing chemical species, it reads in rows which are formatted as follows: NAME,MASS,BINDING ENERGY,SOLID FRACTION,MONO FRACTION,VOLCANO FRACTION,ENTHALPY
Arguments:
inputRow (list):
get_name​
def get_name() -> str
Get the name of the chemical species.
Returns:
str- The name
get_mass​
def get_mass() -> int
Get the molecular mass of the chemical species
Returns:
int- The molecular mass
get_charge​
def get_charge() -> int
Get the charge of the chemical species in e. Positive integer indicates positive ion, negative indicates negative ion. Assumes species are at most charged +1 or -1.
Returns:
int- The charge of the species
set_desorb_products​
def set_desorb_products(new_desorbs: list[str]) -> None
Set the desorption products for species on the surface or in the bulk. It is assumed that there is only one desorption pathway.
Arguments:
new_desorbslist[str] - The new desorption products
get_desorb_products​
def get_desorb_products() -> list[str]
Obtain the desorbtion products of ice species
Returns:
list[str]- The desorption products
set_freeze_products​
def set_freeze_products(product_list: list[str], freeze_alpha: float) -> None
Add the freeze products of the species, one species can have several freeze products.
Arguments:
-
product_listlist[str] - The list of freeze out products -
freeze_alphafloat - The freeze out ratio.It is called alpha, since it is derived from the alpha column in the UCLCHEM reaction format: https://github.com/uclchem/UCLCHEM/blob/08d37f8c3063f8ff8a9a7aa16d9eff0ed4f99538/Makerates/src/network.py#L160
get_freeze_products​
def get_freeze_products() -> dict[list[str], float]
Obtain the product to which the species freeze out
Returns:
dict[str, float]: Reactions and their respective freeze out ratios.
Yields:
Iterator[dict[str, float]]: Iterator that returns all of the freeze out reactions with ratios
get_freeze_products_list​
def get_freeze_products_list() -> list[list[str]]
Returns all the freeze products without their ratios
Returns:
list[list[str]]- List of freeze products
get_freeze_alpha​
def get_freeze_alpha(product_list: list[str]) -> float
Obtain the freeze out ratio of a species for a certain reaction
Arguments:
product_listlist[str] - For a specific reaction, get the freezeout ratio
Returns:
float- The freezeout ratio
is_grain_species​
def is_grain_species() -> bool
Return whether the species is a species on the grain
Returns:
bool- True if it is a grain species.
is_ice_species​
def is_ice_species() -> bool
Return whether the species is a species on the grain
Returns:
bool- True if it is an ice species.
is_surface_species​
def is_surface_species() -> bool
Checks if the species is on the surface
Returns:
bool- True if a surface species
is_bulk_species​
def is_bulk_species() -> bool
Checks if the species is in the bulk
Returns:
bool- True if a bulk species
is_ion​
def is_ion() -> bool
Checks if the species is ionized, either postively or negatively.
Returns:
bool- True if it is an ionized
add_default_freeze​
def add_default_freeze() -> None
Adds a defalt freezeout, which is freezing out to the species itself, but with no ionization.
find_constituents​
def find_constituents(quiet=False)
Loop through the species' name and work out what its consituent atoms are. Then calculate mass and alert user if it doesn't match input mass.
get_n_atoms​
def get_n_atoms() -> int
Obtain the number of atoms in the molecule
Returns:
int- The number of atoms
set_n_atoms​
def set_n_atoms(new_n_atoms: int) -> None
Set the number of atoms
Arguments:
new_n_atomsint - The new number of atoms
__eq__​
def __eq__(other)
Check for equality based on either a string or another Species instance.
Arguments:
otherstr, Species - Another species
Raises:
NotImplementedError- We can only compare between species or strings of species.
Returns:
bool- True if two species are identical.
__lt__​
def __lt__(other) -> bool
Compare the mass of the species
Arguments:
otherSpecies - Another species instance
Returns:
bool- True if less than the other species
__gt__​
def __gt__(other) -> bool
Compare the mass of the species
Arguments:
otherSpecies - Another species instance
Returns:
bool- True if larger than than the other species
uclchem.makerates
uclchem.makerates.makerates
run_makerates​
def run_makerates(configuration_file: str = "user_settings.yaml",
write_files: bool = True) -> Network
The main run wrapper for makerates, it loads a configuration, parses it in Network and then returns the Network. It by default writes to the uclchem fortran directory, but this can be skipped.
Arguments:
configuration_filestr, optional - A UCLCHEM Makerates configuration file. Defaults to "user_settings.yaml".write_filesbool, optional - Whether to write the fortran files to the src/fortran_src. Defaults to True.
Raises:
KeyError- The configuration cannot be found
Returns:
Network- A chemical network instance.
get_network​
def get_network(path_to_input_file: Union[str, bytes, os.PathLike] = None,
path_to_species_file: Union[str, bytes, os.PathLike] = None,
path_to_reaction_file: Union[str, bytes, os.PathLike] = None,
verbosity=None)
In memory equivalent of Makerates, can either be used on the original input files for makerates, or on the output files that makerates generates. So either specify:
path_to_input_file exclusive OR (path_to_species_file and path_to_reaction_file)
The latter scenario allows you to reload a reaction network from a network already written by Makerates.
Arguments:
path_to_input_fileUnion[str, bytes, os.PathLike], optional - Path to input file. Defaults to None.path_to_species_fileUnion[str, bytes, os.PathLike], optional - Path to a species.csv in/from the src directory. Defaults to None.path_to_reaction_fileUnion[str, bytes, os.PathLike], optional - Path to a reactions.csv in/from the src directory. Defaults to None.verbosityLEVEL, optional - The verbosity level as specified in logging. Defaults to None.
Raises:
ValueError- You cannot specify both an input configuration and species+reaction.
Returns:
Network- A chemical reaction network.
uclchem.makerates.network
This python file contains all functions for de-duplicating species and reaction lists, checking for common errors, and automatic addition of reactions such as freeze out, desorption and bulk reactions for three phase models.
Network Objects​
class Network()
The network class stores all the information about reaction network.
__init__​
def __init__(species: list[Species],
reactions: list[Reaction],
user_defined_bulk: list = [],
gas_phase_extrapolation: bool = False,
add_crp_photo_to_grain: bool = False)
A class to store network information such as indices of important reactions.
The class fully utilizes getters and setters, which can be used to add/remove reactions and the species involved. Important is that you do not directly edit the internal dictionaries that store the species and reactions, unless you know what you are doing. The network by default checks for duplicates in species and identical reactions that overlap in temperature ranges, potentially causing problems.
Arguments:
specieslist[Species] - A list of chemical species that are added to the networkreactionslist[Reaction] - A list of chemical reactions that are added to the networkuser_defined_bulklist, optional - List of user defined bulk. Defaults to [].add_crp_photo_to_grainbool, optional - Whether to add CRP, CRPHOT and PHOTON reactions from gas-phase into solid phase too.
add_reactions​
def add_reactions(reactions: Union[Union[Reaction, str], list[Union[Reaction,
str]]])
Add a reaction, list of inputs to the Reaction class or list of reactions to the network.
Arguments:
reactionsUnion[Union[Reaction, str], list[Union[Reaction, str]]] - Reaction or list or reactions
find_similar_reactions​
def find_similar_reactions(reaction: Reaction) -> dict[int, Reaction]
Reactions are similar if the reaction has the same reactants and products, find all reactions that are similar, returning their index and the reaction itself.
Arguments:
reactionReaction - Reaction with possible identical (but for temperature range) reactions in the network
Returns:
dict[int, Reaction]: A dict with the identical reactions.
get_reaction_index​
def get_reaction_index(reaction: Reaction) -> int
Get the index of a reaction in the internal _reactions_dict.
Arguments:
reactionReaction - The reaction to find the index of
Returns:
int- The index of the reaction in the internal _reactions_dict
remove_reaction_by_index​
def remove_reaction_by_index(reaction_idx: int) -> None
Remove a reaction by its index in the internal _reactions_dict, this is the only way to remove reactions that are defined piecewise across temperature ranges.
Arguments:
reaction_idxint - Index of the reaction to remove
remove_reaction​
def remove_reaction(reaction: Reaction) -> None
Remove the reaction by giving the object itself, this only works if the reaction is not piecewise defined across the temperature ranges.
Arguments:
reactionReaction - The reaction you wish to delete.
get_reaction​
def get_reaction(reaction_idx: int) -> Reaction
Obtain a reaction from the reaction set given an index of the internal _reactions_dict.
Arguments:
reaction_idxint - The reaction index
Returns:
Reaction- the desired reaction
set_reaction​
def set_reaction(reaction_idx: int, reaction: Reaction) -> None
This setter explicitely sets the reaction for a certain index.
Arguments:
reaction_idxint - The index to be written toreactionReaction - The reaction to be added to the index.
get_reaction_dict​
def get_reaction_dict() -> dict[int, Reaction]
Returns the whole internal reaction dictionary.
Returns:
dict[int, Reaction]: A copy of the internal reactions dictionary.
set_reaction_dict​
def set_reaction_dict(new_dict: dict[int, Reaction]) -> None
Override the reactions dictionary with a new dictionar.
Arguments:
new_dictdict[int, Reaction] - The new reactions_dictionary.
get_reaction_list​
def get_reaction_list() -> list[Reaction]
Obtain all the reactions in the Network.
Returns:
list[Reaction]- A list with all the reaction objects
get_reactions_by_types​
def get_reactions_by_types(
reaction_type: Union[str, list[str]]) -> list[Reaction]
Get the union of all reactions of a certain type.
Arguments:
reaction_typestr - The reaction type to filter on
Returns:
list[Reaction]- A list of reactions of the specified type
sort_reactions​
def sort_reactions() -> None
Sort the reaction dictionary by reaction type first and by the first reactant second.
add_species​
def add_species(species: Union[Union[Species, str], list[Union[Species,
str]]])
Add species to the network, given a (list of) species. If it is a list of strings, it tries to instantiate a species class with it. It also checks for duplicate entries and filters out attempts to add reaction types to the species.
Arguments:
speciesUnion[Union[Species, str], list[Union[Species, str]]] - A (list of) species or strings.
Raises:
ValueError- If we cannot parse the (list of) reactionsValueError- If an ice specie with binding energy of zero is added.
remove_species​
def remove_species(specie_name: str) -> None
Remove a specie from the network
Arguments:
specie_namestr - Species to remove
get_species_list​
def get_species_list() -> list[Species]
Obtain a list with all the species in the network
Returns:
list[Species]- A list of all the species in the reaction network
get_species_dict​
def get_species_dict() -> dict[str, Species]
Get the internal dictionary that stores all the species, it consists of all species' names as key, with the species object as value.
Returns:
dict[str, Species]: A dictionary with the species
get_specie​
def get_specie(specie_name: str) -> Species
Get the species of the reaction network (from the internal dictionary)
Arguments:
specie_namestr - the name of the species as a string
Returns:
Species- The species object
set_specie​
def set_specie(species_name: str, species: Species) -> None
Set the species of the reaction network in the internal dictionary
Arguments:
species_namestr - The name of the species as stringspeciesSpecies - The Species object to set
set_species_dict​
def set_species_dict(new_species_dict: dict[str, Species]) -> None
Set the internal species dict
Arguments:
new_species_dictdict[str, Species] - The new dictionary to set
sort_species​
def sort_species() -> None
Sort the species based on their mass in ascending order. We always make sure the Electron is last.
check_network​
def check_network() -> None
Run through the list of reactions and check for obvious errors such as duplicate reactions, multiple freeze out routes (to warn, not necessarily an error), etc.
check_and_filter_species​
def check_and_filter_species() -> None
Check every speces in network appears in at least one reaction. Remove any that do not and alert user.
add_bulk_species​
def add_bulk_species() -> None
For three phase models, MakeRates will produce the version of the species in the bulk so that the user doesn't have to endlessly relist the same species
check_freeze_and_desorbs​
def check_freeze_and_desorbs() -> None
add_freeze_reactions() and add_desorb_reactions() automatically generate
all desorption and freeze out reactions. However, user may want to change a species on freeze out
eg C+ becomes C rather than C+. This function checks for that and updates species so they'll
freeze or desorb correctly when reactions are generated.
add_freeze_reactions​
def add_freeze_reactions() -> None
Save the user effort by automatically generating freeze out reactions
add_desorb_reactions​
def add_desorb_reactions() -> None
Save the user effort by automatically generating desorption reactions
add_chemdes_reactions​
def add_chemdes_reactions() -> None
We have the user list all Langmuir-Hinshelwood and Eley-Rideal reactions once. Then we duplicate so that the reaction branches with products on grain and products desorbing.
check_for_excited_species​
def check_for_excited_species() -> bool
Check if there are any exicted species in the network, true if there are any.
add_excited_surface_reactions​
def add_excited_surface_reactions() -> None
All excited species will relax to the ground state if they do not react
the vibrational frequency of the species is used as a pseudo approximation of the rate coefficient
We assume all grain reactions have an excited variant. For example:
A, B LH C will have the variants:
A, B EXSOLID C and A, B EXSOLID C
If only one of the reactants in the base reaction has an excited counterpart then
only one excited version of that reaction is created.
add_bulk_reactions​
def add_bulk_reactions() -> None
We assume any reaction that happens on the surface of grains can also happen in the bulk (just more slowly due to binding energy). The user therefore only lists surface reactions in their input reaction file and we duplicate here.
freeze_checks​
def freeze_checks() -> None
Check that every species freezes out and alert the user if a species freezes out via mutiple routes. This isn't necessarily an error so best just print.
add_CRP_and_PHOTO_reactions_to_grain​
def add_CRP_and_PHOTO_reactions_to_grain() -> None
Add all the gas-phase reactions with CRP, CRPHOT or PHOTON to the grain surface too
duplicate_checks​
def duplicate_checks() -> None
Check reaction network to make sure no reaction appears twice unless they have different temperature ranges.
index_important_reactions​
def index_important_reactions() -> None
We have a whole bunch of important reactions and we want to store their indices. We find them all here.
index_important_species​
def index_important_species() -> None
Obtain the indices for all the important reactions.
branching_ratios_checks​
def branching_ratios_checks() -> None
Check that the branching ratios for the ice reactions sum to 1.0. If they do not, correct them. This needs to be done for LH and LHDES separately since we already added the desorption to the network.
LoadedNetwork Objects​
class LoadedNetwork(Network)
Network version that skips all steps and just loads two lists. This is another here be dragons version, use this with exceeding caution as no checks are performed for you.
Arguments:
Networktype - description
__init__​
def __init__(species: list[Species], reactions: list[Reaction]) -> None
A loader of networks without any checks.
Here be dragons.
Arguments:
specieslist[Species] - A list of species objectsreactionslist[Reaction] - A list of reaction objects.
uclchem.makerates.io_functions
Functions to read in the species and reaction files and write output files
read_species_file​
def read_species_file(file_name: Path) -> list[Species]
Reads in a Makerates species file
Arguments:
fileNamestr - path to file containing the species list
Returns:
list- List of Species objects
read_reaction_file​
def read_reaction_file(file_name: Path, species_list: list[Species],
ftype: str) -> tuple[list[Reaction], list[Reaction]]
Reads in a reaction file of any kind (user, UMIST, KIDA) produces a list of reactions for the network, filtered by species_list
Arguments:
file_namestr - A file name for the reaction file to read.species_listlist[Species] - A list of chemical species to be used in the reading.ftypestr - 'UMIST','UCL', or 'KIDA' to describe format of file_name
Returns:
list,list- Lists of kept and dropped reactions.
check_reaction​
def check_reaction(reaction_row, keep_list) -> bool
Checks a row parsed from a reaction file and checks it only contains acceptable things. It checks if all species in the reaction are present, and adds the temperature range is none is specified.
Arguments:
reaction_rowlist - List parsed from a reaction file and formatted to be able to called Reaction(reaction_row)keep_listlist - list of elements that are acceptable in the reactant or product bits of row
Returns:
bool- Whether the row contains acceptable entries.
kida_parser​
def kida_parser(kida_file)
KIDA used a fixed format file so we read each line in the chunks they specify and use python built in classes to convert to the necessary types. NOTE KIDA defines some of the same reaction types to UMIST but with different names and coefficients. We fix that by converting them here.
output_drops​
def output_drops(dropped_reactions: list[Reaction],
output_dir: str = None,
write_files: bool = True)
Writes the reactions that are dropped to disk/logs
Arguments:
dropped_reactionslist[Reaction] - The reactions that were droppedoutput_dirstr - The directory that dropped_reactions.csv will be written to.write_filesbool, optional - Whether or not to write the file. Defaults to True.
write_outputs​
def write_outputs(network: Network,
output_dir: str = None,
rates_to_disk: bool = False,
gar_database: dict[str, np.array] = None) -> None
Write the ODE and Network fortran source files to the fortran source.
Arguments:
networknetwork - The makerates Network classoutput_dirbool - The directory to write to.
write_f90_constants​
def write_f90_constants(
replace_dict: Dict[str, int],
output_file_name: Path,
template_file_path: Path = "fortran_templates") -> None
Write the physical reactions to the f2py_constants.f90 file after every run of makerates, this ensures the Fortran and Python bits are compatible with one another.
Arguments:
replace_dictDict[str, int] - The dictionary with keys to replace and their valuesoutput_file_namePath - The path to the target f2py_constants.f90 filetemplate_file_pathPath, optional - The file to use as the template. Defaults to "fortran_templates".
write_python_constants​
def write_python_constants(replace_dict: Dict[str, int],
python_constants_file: Path) -> None
Function to write the python constants to the constants.py file after every run, this ensure the Python and Fortran bits are compatible with one another.
Arguments:
replace_dictDict[str, int]] - Dict with keys to replace and their valuespython_constants_filePath - Path to the target constant files.
write_species​
def write_species(file_name: Path, species_list: list[Species]) -> None
Write the human readable species file. Note UCLCHEM doesn't use this file.
Arguments:
fileNamestr - path to output filespecies_listlist - List of species objects for network
write_reactions​
def write_reactions(fileName, reaction_list) -> None
Write the human readable reaction file.
Arguments:
fileNamestr - path to output filereaction_listlist - List of reaction objects for network
write_odes_f90​
def write_odes_f90(file_name: Path,
species_list: list[Species],
reaction_list: list[Reaction],
rates_to_disk: bool = False) -> None
Write the ODEs in Modern Fortran. This is an actual code file.
Arguments:
file_namestr - Path to file where code will be writtenspecies_listlist - List of species describing networkreaction_listlist - List of reactions describing network
write_jacobian​
def write_jacobian(file_name: Path, species_list: list[Species]) -> None
Write jacobian in Modern Fortran. This has never improved UCLCHEM's speed and so is not used in the code as it stands. Current only works for three phase model.
Arguments:
file_namestr - Path to jacobian filespecies_listspecies_list - List of species AFTER being processed by build_ode_string
build_ode_string​
def build_ode_string(species_list: list[Species],
reaction_list: list[Reaction],
rates_to_disk: bool = False) -> str
A long, complex function that does the messy work of creating the actual ODE code to calculate the rate of change of each species. Test any change to this code thoroughly because ODE mistakes are very hard to spot.
Arguments:
species_listlist - List of species in networkreaction_listlist - List of reactions in networkrates_to_diskbool - Enable the writing of the rates to the disk.
Returns:
str- One long string containing the entire ODE fortran code.
species_ode_string​
def species_ode_string(n: int, species: Species) -> str
Build the string of Fortran code for a species once it's loss and gains strings have been produced.
Arguments:
nint - Index of species in python formatspeciesSpecies - species object
Returns:
str- the fortran code for the rate of change of the species
write_evap_lists​
def write_evap_lists(network_file, species_list: list[Species]) -> int
Two phase networks mimic episodic thermal desorption seen in lab (see Viti et al. 2004) by desorbing fixed fractions of material at specific temperatures. Three phase networks just use binding energy and that fact we set binding energies in bulk to water by default. This function writes all necessary arrays to the network file so these processes work.
Arguments:
network_filefile - Open file object to which the network code is being writtenspecies_listlist[Species] - List of species in network
truncate_line​
def truncate_line(input_string: str, lineLength: int = 72) -> str
Take a string and adds line endings at regular intervals keeps us from overshooting fortran's line limits and, frankly, makes for nicer ode.f90 even if human readability isn't very important
Arguments:
input_stringstr - Line of code to be truncatedlineLengthint, optional - rough line length. Defaults to 72.
Returns:
str- Code string with line endings at regular intervals
write_network_file​
def write_network_file(file_name: Path,
network: Network,
rates_to_disk: bool = False,
gar_database=None)
Write the Fortran code file that contains all network information for UCLCHEM. This includes lists of reactants, products, binding energies, formationEnthalpies and so on.
Arguments:
file_namestr - The file name where the code will be written.networkNetwork - A Network object built from lists of species and reactions.
find_reactant​
def find_reactant(species_list: list[str], reactant: str) -> int
Try to find a reactant in the species list
Arguments:
species_listlist[str] - A list of species in the networkreactantstr - The reactant to be indexed
Returns:
int- The index of the reactant, if it is not found, 9999
get_desorption_freeze_partners​
def get_desorption_freeze_partners(
reaction_list: list[Reaction]) -> list[Reaction]
Every desorption has a corresponding freeze out eg desorption of CO and freeze of CO.
This find the corresponding freeze out for every desorb so that when desorb>>freeze
we can turn off freeze out in UCLCHEM.
Arguments:
reaction_listlist - Reactions in network
Returns:
list- list of indices of freeze out reactions matching order of desorptions.
array_to_string​
def array_to_string(name: str,
array: np.array,
type: str = "int",
parameter: bool = True) -> str
Write an array to fortran source code
Arguments:
namestr - Variable name of array in Fortranarrayiterable - List of values of arraytypestr, optional - The array's type. Must be one of "int","float", or "string".Defaults to "int".parameterbool, optional - Whether the array is a Fortran PARAMETER (constant). Defaults to True.
Raises:
ValueError- Raises an error if type isn't "int","float", or "string"
Returns:
str- String containing the Fortran code to declare this array.
uclchem.makerates.reaction
Reaction Objects​
class Reaction()
get_reactants​
def get_reactants() -> list[str]
Get the four reactants present in the reaction, padded with NAN for nonexistent
Returns:
list[str]- The four reactants names
get_pure_reactants​
def get_pure_reactants() -> list[str]
Get only the pure species, no reaction types and NAN entries
Returns:
list[str]- The list of reacting species.
get_sorted_reactants​
def get_sorted_reactants() -> list[str]
Get the four reactants present in the reaction, sorted for fast comparisons
Arguments:
reactantslist[str] - The four sorted reactant names
set_reactants​
def set_reactants(reactants: list[str]) -> None
Set the four reactants present in the reaction, padded with NAN for nonexistent
Arguments:
reactantslist[str] - The four reactants names
get_products​
def get_products() -> list[str]
Get the four products present in the reaction, padded with NAN for nonexistent
Arguments:
reactantslist[str] - The four products names
get_pure_products​
def get_pure_products() -> list[str]
Get only the pure species that are products, no reaction types and NAN entries
Returns:
list[str]- The list of produced species.
get_sorted_products​
def get_sorted_products() -> list[str]
Get the four products present in the reaction, sorted for fast comparisons
Arguments:
productslist[str] - The four sorted products names
set_products​
def set_products(products: list[str]) -> None
Set the four products present in the reaction, padded with NAN for nonexistent
Arguments:
productslist[str] - The four products names
get_alpha​
def get_alpha() -> float
Get the alpha parameter from the Kooij-Arrhenius equation
Returns:
float- the alpha parameter of the reaction
set_alpha​
def set_alpha(alpha: float) -> None
Set the alpha parameter from the Kooij-Arrhenius equation
Arguments:
alphafloat - the alpha parameter of the reaction
get_beta​
def get_beta() -> float
Get the beta parameter from the Kooij-Arrhenius equation
Returns:
float- the beta parameter of the reaction
set_beta​
def set_beta(beta: float) -> None
Set the beta parameter from the Kooij-Arrhenius equation
Arguments:
betafloat - the beta parameter of the reaction
set_gamma​
def set_gamma(gamma: float) -> None
Set the gamma parameter from the Kooij-Arrhenius equation
Arguments:
gammafloat - the gamma parameter of the reaction
get_gamma​
def get_gamma() -> float
Get the gamma parameter from the Kooij-Arrhenius equation
Returns:
float- the gamma parameter of the reaction
set_templow​
def set_templow(templow: float) -> None
Set the lower temperature boundary of the reaction in Kelvin
Arguments:
templowfloat - the lower temperature boundary
get_templow​
def get_templow() -> float
Get the lower temperature boundary of the reaction in Kelvin
Returns:
float- the lower temperature boundary
set_temphigh​
def set_temphigh(temphigh: float) -> None
Set the higher temperature boundary of the reaction in Kelvin
Arguments:
templowfloat - the higher temperature boundary
get_temphigh​
def get_temphigh() -> float
Get the higher temperature boundary of the reaction in Kelvin
Returns:
float- the higher temperature boundary
predict_reduced_mass​
def 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.
set_reduced_mass​
def set_reduced_mass(reduced_mass: float) -> None
Set the reduced mass to be used to calculate tunneling rate in AMU
Arguments:
reduced_massfloat - reduced mass of moving atoms
get_reduced_mass​
def get_reduced_mass() -> float
Get the reduced mass to be used to calculate tunneling rate in AMU
Returns:
float- reduced mass of moving atoms
NANCheck​
def NANCheck(a)
Convert any Falsy statement to a NAN string
Arguments:
a- thing to check for falsiness
Returns:
bool- input a if truthy, otherwise NAN
get_reaction_type​
def 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:
str:
get_source​
def get_source() -> str
Get the source of the reaction
Returns:
str- The source of the reaction
set_source​
def set_source(source: str) -> None
Set the source of the reaction
Arguments:
sourcestr - The source of the reaction
convert_surf_to_bulk​
def convert_surf_to_bulk() -> None
Convert the surface species to bulk species in place for this reaction.
convert_gas_to_surf​
def 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.
__eq__​
def __eq__(other) -> bool
Check for equality against another reaction based on the products and reactants. Note that it does not check for the temperature ranges that the reactions might have! The Reaction.check_temperature_collision can be used for this purpose.
Arguments:
other- Another reaction set.
Returns:
bool- equality
check_temperature_collision​
def check_temperature_collision(other) -> bool
Check if two reactions have overlapping temperature ranges, returning True means there is a collision.
Arguments:
other- Another reaction
Raises:
NotImplementedError- Currently we can only compare against instantiated Reaction objects.
Returns:
bool- Whether there is a collision (True), or not (False)
changes_surface_count​
def changes_surface_count()
This checks 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.
changes_total_mantle​
def changes_total_mantle()
Check if the total grains on the mantle are changed by the reaction.
to_UCL_format​
def to_UCL_format()
Convert a reaction to UCLCHEM reaction file format
is_gas_reaction​
def is_gas_reaction(include_reactants=True,
include_products=True,
strict=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.
Arguments:
include_reactantsbool, optional - Include the reactants. Defaults to True.include_productsbool, optional - Include the products. Defaults to True.strictbool, optional - Choose between all (true) or any (false) must be gas phase . Defaults to True.
Returns:
bool- Is it a gas phase reaction?
is_ice_reaction​
def is_ice_reaction(include_reactants=True,
include_products=True,
strict=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
Arguments:
include_reactantsbool, optional - Include the reactants. Defaults to True.include_productsbool, optional - Include the products. Defaults to True.strictbool, optional - Choose between all (true) or any (false) must be ice phase . Defaults to True.
Returns:
bool- Is it an ice phase reaction?
is_surface_reaction​
def is_surface_reaction(include_reactants=True,
include_products=True,
strict=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
Arguments:
include_reactantsbool, optional - Include the reactants. Defaults to True.include_productsbool, optional - Include the products. Defaults to True.strictbool, optional - Choose between all (true) or any (false) must be on the surface . Defaults to False.
Returns:
bool- Is it a surface reaction?
is_bulk_reaction​
def is_bulk_reaction(include_reactants=True,
include_products=True,
strict=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
Arguments:
include_reactantsbool, optional - Include the reactants. Defaults to True.include_productsbool, optional - Include the products. Defaults to True.strictbool, optional - Choose between all (true) or any (false) must in the bulk . Defaults to False.
Returns:
bool- Is it a bulk reaction?