rxn_network.pathways#
rxn_network.pathways.balanced#
Implements a class for storing a balanced reaction pathway.
- class rxn_network.pathways.balanced.BalancedPathway(reactions, coefficients, costs, balanced=False)[source]#
Bases:
BasicPathway
Helper class for storing multiple ComputedReaction objects which form a single reaction pathway as identified via pathfinding methods. Includes costs for each reaction.
- Parameters:
reactions (list[Reaction]) – list of ComputedReaction objects which occur along path.
coefficients (list[float]) – list of coefficients to balance each corresponding reaction.
costs (list[float]) – list of corresponding costs for each reaction.
balanced (bool) – whether or not the reaction pathway is balanced. Defaults to False and should ideally be set through PathwaySolver.
- get_comp_matrix()[source]#
Gets the composition matrix used in the balancing procedure.
- Returns:
An array representing the composition matrix for a reaction
- Return type:
ndarray
- get_coeff_vector_for_rxn(rxn)[source]#
Gets the net reaction coefficients vector.
- Parameters:
rxn (Reaction) – Reaction object to get coefficients for
- Returns:
An array representing the reaction coefficients vector
- Return type:
np.ndarray
- contains_interdependent_rxns(precursors)[source]#
Whether or not the pathway contains interdependent reactions given a list of provided precursors.
- Parameters:
precursors (list[Composition]) – List of precursor compositions
- Return type:
rxn_network.pathways.base#
Basic interface for a reaction pathway.
- class rxn_network.pathways.base.Pathway[source]#
Bases:
MSONable
Base definition for a reaction pathway.
- property all_reactants: set[Composition]#
Reactant compositions for all reactions in the pathway.
- property all_products: set[Composition]#
Product compositions reaction in the pathway.
- property compositions: list[Composition]#
All compositions in the reaction.
- property reactants: set[Composition]#
The reactant compositions of this whole/net reaction pathway.
- property products: set[Composition]#
The product compositions of this whole/net reaction pathway.
- property intermediates: set[Composition]#
Intermediate compositions in this reaction pathway.
rxn_network.pathways.basic#
Implements a class for storing (unbalanced/unconstrained) collection of reactions forming a reaction pathway.
- class rxn_network.pathways.basic.BasicPathway(reactions, costs=None)[source]#
Bases:
Pathway
Simple pathway class for storing multiple ComputedReaction objects which form a single reaction pathway.
In this class, there are no constraints on stoichiometry. See BalancedPathway for the more constrained version.
Args: reactions: list of ComputedReaction objects making up the pathway. costs: Optional list of corresponding costs for each reaction.
rxn_network.pathways.pathway_set#
Implements a class for conveniently and efficiently storing sets of Pathway-based objects which share entries/reactions.
- class rxn_network.pathways.pathway_set.PathwaySet(reaction_set, indices, coefficients, costs)[source]#
Bases:
MSONable
A lightweight class for storing large sets of Pathway objects. Automatically represents a set of pathways as a (non-rectangular) 2D array of indices corresponding to reactions within a reaction set. This is useful for dumping reaction pathway data to a database.
This object can easily be initialized through the from_paths() constructor.
- Parameters:
reaction_set (ReactionSet) – The reaction set containing all reactions in the pathways.
indices (np.ndarray | list[list[int]]) – A list of lists of indices corresponding to reactions in the reaction set.
coefficients (np.ndarray | list[list[float] | None]) – An array or list of coefficients representing the
multiplicities (i.e., how much of) –
costs (np.ndarray | list[list[float]]) – An array or list of costs for each pathway.
- property paths: list[Pathway]#
Returns list of Pathway objects represented by the PathwaySet. Cached for efficiency.
rxn_network.pathways.plotting#
This module contains functions for plotting experimental reaction pathway data.
- class rxn_network.pathways.plotting.PathwayPlotter(phase_amounts, temps, apply_smoothing=True)[source]#
Bases:
MSONable
WARNING: This is an EXPERIMENTAL CLASS. Use at your own risk.
Helper class for plotting a reaction pathway and the corresponding energy cascade.
Args: phase_amounts: Dicts with format {phase: [amounts]} temps: list of temperatures apply_smoothing: Whether to smooth the data. Default is True.
- plot_energy_cascade(entries)[source]#
Returns a plot of the energy cascade given a list of entries.
- Parameters:
entries (list[ComputedEntry] | GibbsEntrySet) – List of entries or GibbsEntrySet.
- property num_atoms_df: DataFrame#
Returns a dataframe of the number of atoms in each phase.
- property df: DataFrame#
Returns a dataframe of the pathway.
- property compositions: Series#
Returns the composition of the pathway.
rxn_network.pathways.solver#
Implements a reaction pathway solver class which efficiently solves mass balance equations using matrix operations.
- class rxn_network.pathways.solver.Solver(pathways)[source]#
Bases:
MSONable
Base definition for a pathway solver class.
- Parameters:
pathways (PathwaySet) – A PathwaySet object containing the pathways to be combined/balanced.
- class rxn_network.pathways.solver.PathwaySolver(pathways, entries, cost_function, open_elem=None, chempot=0.0, chunk_size=100000, batch_size=None)[source]#
Bases:
Solver
Solver that implements an efficient method (using numba) for finding balanced reaction pathways from a list of graph-derived reaction pathways (i.e. a list of lists of reactions).
If you use this code in your own work, please consider citing this paper:
McDermott, M. J.; Dwaraknath, S. S.; Persson, K. A. A Graph-Based Network for Predicting Chemical Reaction Pathways in Solid-State Materials Synthesis. Nature Communications 2021, 12 (1), 3097. https://doi.org/10.1038/s41467-021-23339-x.
- Parameters:
pathways (PathwaySet) – List of reaction pathways derived from the network.
entries (GibbsEntrySet) – GibbsEntrySet containing all entries in the network.
cost_function (CostFunction) – CostFunction object to use for the solver.
open_elem (str | Element | None) – Optional element to use for pathways with an open element.
chempot (float) – Chemical potential to use for pathways with an open element. Defaults to 0.0.
chunk_size (int) – The number of pathways per chunk to use for balancing. Defaults to 100,000.
batch_size (int | None) – Number of chunks to submit to each CPU at a time. Automatically calculated if not set.
- solve(net_rxn, max_num_combos=4, find_intermediate_rxns=True, intermediate_rxn_energy_cutoff=0.0, use_basic_enumerator=True, use_minimize_enumerator=False, filter_interdependent=True)[source]#
- Parameters:
net_rxn (ComputedReaction | OpenComputedReaction) – The reaction representing the total reaction from precursors to final targets.
max_num_combos (int) – The maximum allowable size of the balanced reaction pathway. At values <=5, the solver will start to take a significant amount of time to run.
find_intermediate_rxns (bool) – Whether to find intermediate reactions; crucial for finding pathways where intermediates react together, as these reactions may not occur in the graph-derived pathways. Defaults to True.
intermediate_rxn_energy_cutoff (float) – An energy cutoff by which to filter down intermediate reactions. This can be useful when there are a large number of possible intermediates. < 0 means allow only exergonic reactions.
use_basic_enumerator (bool) – Whether to use the BasicEnumerator to find intermediate reactions. Defaults to True.
use_minimize_enumerator (bool) – Whether to use the MinimizeGibbsEnumerator to find intermediate reactions. Defaults to False.
filter_interdependent (bool) – Whether or not to filter out pathways where reaction steps are interdependent. Defaults to True.
- Returns:
A list of BalancedPathway objects.
- Return type:
- property entries: GibbsEntrySet#
Entry set used in solver.