Reaction-network
Reaction-network is a Python package (version 8.3.0) for synthesis planning and predicting chemical reaction pathways in inorganic materials synthesis. It focuses on representing and analyzing chemical reactions, materials, and their relationships within a network structure. The library has a regular release cadence, with major versions introducing significant architectural changes.
Common errors
-
TypeError: plot_reaction_network() missing 1 required positional argument: 'network'
cause Attempting to use the old top-level `plot_reaction_network` function, which was removed in version 8.0.0 and replaced by a method on `ReactionNetwork` instances.fixIf your code calls `plot_reaction_network(my_network)`, change it to `my_network.plot()`. -
TypeError: ReactionEntryGenerator.__init__() missing 1 required positional argument: 'config'
cause In `reaction-network` v8.0.0+, the `ReactionEntryGenerator` constructor requires a `ReactionGenerationConfig` object, which was not provided.fixInstantiate `ReactionGenerationConfig` first, then pass it: `from reaction_network import ReactionEntryGenerator, ReactionGenerationConfig; config = ReactionGenerationConfig(); generator = ReactionEntryGenerator(config)`. -
ModuleNotFoundError: No module named 'graphviz'
cause The `graphviz` Python package is not installed, which is required for plotting functionality, or the system-level Graphviz executable is missing or not in PATH.fixInstall the Python package: `pip install graphviz`. Also ensure the Graphviz executable is installed on your operating system (e.g., `sudo apt install graphviz` on Linux, `brew install graphviz` on macOS). -
reaction_network.parser.ParseError: Invalid reaction string format: ...
cause The reaction string provided to `Reaction.from_string` or `ReactionParser` does not conform to the stricter parsing rules introduced in version 8.0.0.fixConsult the official documentation for the correct syntax of reaction strings in `reaction-network` v8+ and adjust your string accordingly, paying attention to phases and coefficients.
Warnings
- breaking The top-level `plot_reaction_network` utility function has been removed in version 8.0.0. Network plotting is now a method of the `ReactionNetwork` object.
- breaking The `ReactionEntryGenerator` class constructor in v8.0.0+ now requires a `ReactionGenerationConfig` object as its primary argument. Direct instantiation without this config will raise an error.
- gotcha For plotting reaction networks using `ReactionNetwork.plot()`, both the Python `graphviz` package (`pip install graphviz`) and the system-level Graphviz executable must be installed. The Python package alone is insufficient for rendering.
- breaking Version 8.0.0 introduced stricter parsing rules for reaction strings, affecting `Reaction.from_string` and `ReactionParser`. Previously accepted formats might now raise `ParseError`.
Install
-
pip install reaction-network
Imports
- Reaction
from reaction_network import Reaction
- ReactionNetwork
from reaction_network import ReactionNetwork
- ReactionParser
from reaction_network import ReactionParser
- ReactionEntryGenerator
from reaction_network import ReactionEntryGenerator
- ReactionGenerationConfig
from reaction_network import ReactionGenerationConfig
Quickstart
from reaction_network import Reaction, ReactionNetwork
# Define reactions
r1 = Reaction.from_string("A + B -> C")
r2 = Reaction.from_string("C + D -> E")
r3 = Reaction.from_string("A + D -> F") # A side reaction
# Create a network
rn = ReactionNetwork([r1, r2, r3])
# Print materials and reactions
print(f"Materials: {rn.materials}")
print(f"Reactions: {rn.reactions}")
# To plot the network (requires graphviz Python package and system executable)
# rn.plot(filename="reaction_network.png", fmt="png")