๐ Documentation
Welcome to the PyReactLab-Core documentation! Here you'll find all the information you need to get started with PyReactLab-Core, including installation instructions, usage guides, and API references.
โ๏ธ Reaction Analysis made easy
pyreactlab_core.core.chem_react
PhaseRule = Literal['gas', 'liquid', 'aqueous', 'solid']
module-attribute
ReactionMode = Literal['<=>', '=>', '=']
module-attribute
logger = logging.getLogger(__name__)
module-attribute
ChemReact(reaction_mode_symbol: ReactionMode)
Chemical Reaction Utilities
The ChemReact class provides utilities for analyzing and processing chemical reactions in various phases and conditions. These reactions can be represented in different ways depending on the dominant factors influencing them:
- Use = โ when thermodynamics dominates
- Use <=> โ when kinetics + thermodynamics matter
- Use => โ when kinetics only matter
Initialize the ChemReactUtils class.
Parameters
reaction_mode_symbol : ReactionMode, optional The symbol used to separate reactants and products in a reaction equation.
Notes
- Use "<=>" when kinetics + thermodynamics matter
- Use "=" when thermodynamics dominates
- Use "=>" when kinetics only matter
Source code in pyreactlab_core/core/chem_react.py
P_Ref = PRESSURE_REF_Pa / 100000.0
class-attribute
instance-attribute
R = R_CONST_J__molK
class-attribute
instance-attribute
T_Ref = TEMPERATURE_REF_K
class-attribute
instance-attribute
available_phases = PhaseRule.__args__
class-attribute
instance-attribute
reaction_mode_symbol = reaction_mode_symbol
instance-attribute
system_inputs: Dict[str, Any]
property
Get the system inputs.
analyze_overall_reactions(reactions: List[Dict[str, str]]) -> Dict[str, List[str]]
Analyze a list of chemical reactions and classify species as consumed, produced, or intermediate.
Parameters
reactions : list A list of dictionaries, each containing a reaction string and its name.
Returns
dict A dictionary containing three lists: 'consumed', 'produced', and 'intermediate'. - 'consumed': List of species consumed in the reactions. - 'produced': List of species produced in the reactions. - 'intermediate': List of species that are both consumed and produced in the reactions.
Source code in pyreactlab_core/core/chem_react.py
analyze_overall_reactions_v2(reactions: Dict[str, Any]) -> Dict[str, List[str]]
Analyze a list of chemical reactions and classify species as consumed, produced, or intermediate (version 2).
Parameters
reactions : list A list of dictionaries, each containing a reaction string and its name.
Returns
dict A dictionary containing three lists: 'consumed', 'produced', and 'intermediate'. - 'consumed': List of species consumed in the reactions. - 'produced': List of species produced in the reactions. - 'intermediate': List of species that are both consumed and produced in the reactions.
Source code in pyreactlab_core/core/chem_react.py
analyze_reaction(reaction_pack: Dict[str, str], phase_rule: Optional[str] = None) -> Dict[str, Any]
Analyze a chemical reaction and extract relevant information.
Parameters
reaction_pack : dict A dictionary containing the reaction and its name. phase_rule : str, optional The phase of the reaction, which can be 'gas', 'liquid', 'aqueous', or 'solid'.
Returns
dict A dictionary containing the analyzed reaction data, including reactants, products, reaction coefficient, and carbon count.
Source code in pyreactlab_core/core/chem_react.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | |
count_carbon(molecule: str, coefficient: float) -> float
Count the number of carbon atoms in a molecule.
Parameters
molecule : str The chemical formula of the molecule. coefficient : float The coefficient of the molecule in the reaction.
Returns
float The number of carbon atoms in the molecule multiplied by the coefficient.
Source code in pyreactlab_core/core/chem_react.py
count_reaction_states(reaction_dict: Dict[str, str]) -> Dict[str, int]
Counts the number of unique states in a reaction as g, l, aq, or s.
Parameters
reaction_dict: dict A dictionary where keys are component names and values are their states.
Returns
dict A dictionary with the counts of each state (g, l, aq, s).
Source code in pyreactlab_core/core/chem_react.py
define_component_id(reaction_res)
Define component ID
Parameters
reaction_res: dict reaction_res
Returns
component_list: list component list component_dict: dict component dict comp_list: list component list comp_coeff: list component coefficient
Source code in pyreactlab_core/core/chem_react.py
define_component_id_v2(reaction_res)
staticmethod
Define component ID (version 2)
Parameters
reaction_res: dict reaction_res
Returns
component_list: list component list component_dict: dict component dict comp_list: list component list comp_coeff: list component coefficient component_state_list: list component state list
Source code in pyreactlab_core/core/chem_react.py
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 | |
determine_reaction_phase(reaction_dict: Dict[str, str]) -> str
Determine the phase of a reaction based on the states of its components.
Parameters
reaction_dict: dict A dictionary where keys are component names and values are their states.
Returns
str The phase of the reaction, which can be 'gas', 'liquid', 'aqueous', 'solid', or a combination of these.
Source code in pyreactlab_core/core/chem_react.py
phase_rule_analysis(phase_rule: Optional[str] = None) -> str
Analyze the phase rule of a reaction.
Parameters
phase_rule : str, optional The phase rule of the reaction.
Returns
phase_symbol : str The phase symbol of the reaction, which can be 'g', 'l', or 'empty'.
Source code in pyreactlab_core/core/chem_react.py
reaction_phase_analysis(reaction_res: Dict[str, Any])
Analyze the reaction phase and separate reactants and products by their phases.
Parameters
reaction_res: dict A dictionary containing the reaction results, including reactants and products.
Returns
Source code in pyreactlab_core/core/chem_react.py
state_name_set(state_set: set) -> List[str]
Convert state set to full names
Parameters
state_set: set Set of states
Returns
state_names: list List of full state names
Source code in pyreactlab_core/core/chem_react.py
โ๏ธ Reaction Stoichiometry made easy
pyreactlab_core.docs.chem_balance
ARROW_RE = re.compile('\\s*(<=>|=>|->|=)\\s*')
module-attribute
logger = logging.getLogger(__name__)
module-attribute
Species(raw: str, formula: str, charge: int, atoms: Dict[str, int])
dataclass
atoms: Dict[str, int]
instance-attribute
charge: int
instance-attribute
formula: str
instance-attribute
raw: str
instance-attribute
balance(equation: str | Reaction, method: str = 'algebraic', medium: str = 'auto') -> Optional[str]
Balance a chemical equation using the specified method.
Parameters
equation : str The unbalanced chemical equation as a string. method : str, optional The balancing method to use. Options are: - "algebraic": Uses algebraic matrix method. - "half": Uses half-reaction method (redox/ionic friendly). - "oxidation": Uses oxidation-number method. Default is "algebraic". medium : str, optional The medium for half-reaction method. Options are: - "auto": Automatically detect medium. - "acid": Acidic medium. - "base": Basic medium. Default is "auto".
Returns
str The balanced chemical equation as a string.
Source code in pyreactlab_core/docs/chem_balance.py
balance_algebraic(equation: str, include_charge: str = 'auto') -> str
Source code in pyreactlab_core/docs/chem_balance.py
balance_half_reaction(equation: str, medium: str = 'auto') -> str
Redox/ionic-friendly mode: - decides acid/base for medium='auto' without allowing BOTH H+ and OH- - adds only needed helpers on LHS, then solves with charge conservation - moves negative coefficients across, cancels both sides, normalizes - falls back to algebraic for non-ionic reactions
Source code in pyreactlab_core/docs/chem_balance.py
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 | |