Skip to main content

pyreactsim-core is a Python package for representing reaction rates. It provides a flexible and extensible framework for defining and working with reaction rates in chemical engineering applications.

Project description

🧪 PyReactSim-Core

PyPI Downloads PyPI Python Version License Read the Docs

PyReactSim-Core is a Python package for representing reaction rates. It provides a flexible and extensible framework for defining and working with reaction rates in chemical engineering applications.

It is the core reaction-rate layer of the PyReactSim ecosystem and is designed for practical kinetic modeling workflows, from simple power-law expressions to custom rate equations with user-defined parameters and arguments.

✨ Features

  • ⚗️ Reaction Rate Representation: Define and manipulate chemical reaction rates with ease.
  • 🧩 Flexible Rate Expressions: Build kinetic models with custom callables and typed state/argument/parameter containers.
  • 🧪 Concentration or Pressure Basis: Define rate equations on either concentration-based or pressure-based states.
  • 📐 Unit-Aware Inputs: Evaluate rates with CustomProperty-based values and automatic unit conversion support.
  • 🔁 Reusable State Templates: Predefine reaction orders and default state values using X and rXs.
  • 🧱 Pydantic Validation: Validate structure and component/state consistency before runtime.
  • 📚 Ready-to-Run Examples: Includes gas and liquid reaction examples, source-model setup scripts, and thermodynamic database assets.

🧠 Core Concepts

  • ReactionRateExpression: Main model for a rate expression definition (basis, components, reaction, params, args, state, eq).
  • X / rXs: State representation for each component (order, value, unit).
  • rArgs / rParams / rRet: Typed dictionaries (and return model) used by rate-equation callables.
  • calc(...): Main execution path that evaluates the expression from current state and optional runtime arguments (e.g., temperature and pressure).

📦 Installation

You can install PyReactSim-Core using pip:

pip install pyreactsim-core

🚀 Quick Start

from pythermodb_settings.models import CustomProperty
from pyreactsim_core.models import ReactionRateExpression, X, rArgs, rParams, rRet, rXs

# 1) Define your components/reaction and state map
states: rXs = {
	"A-g": X(component=A, order=1, unit="Pa"),
	"B-g": X(component=B, order=2, unit="Pa"),
}

# 2) Define parameters/arguments and return placeholder
params: rParams = {
	"k": CustomProperty(value=1.0e-11, unit="mol/m3.s.Pa2", symbol="k")
}
args: rArgs = {
	"T": CustomProperty(value=500.0, unit="K", symbol="T")
}
ret: rRet = CustomProperty(value=0.0, unit="mol/m3.s", symbol="r")

# 3) Provide your rate equation
def rate_eq(Xs, args, params):
	r = params["k"].value * (Xs["A-g"].value ** Xs["A-g"].order) * (Xs["B-g"].value ** Xs["B-g"].order)
	return CustomProperty(value=r, unit="mol/m3.s", symbol="r")

# 4) Build and evaluate
rate_model = ReactionRateExpression(
	name="example-rate",
	basis="pressure",
	components=[A, B],
	reaction=reaction,
	params=params,
	args=args,
	ret=ret,
	state=states,
	state_key="Formula-State",
	eq=rate_eq,
	component_key="Name-Formula",
)

result = rate_model.calc(
	xi={
		"A-g": CustomProperty(value=2.0e5, unit="Pa", symbol="P_A"),
		"B-g": CustomProperty(value=1.0e5, unit="Pa", symbol="P_B"),
	}
)

print(result)

🗂️ Package Content

Main package:

  • pyreactsim_core/models/rate_exp.py: ReactionRateExpression model and validation.
  • pyreactsim_core/models/rate.py: Runtime calculation engine and argument/state handling.
  • pyreactsim_core/models/rate_exp_refs.py: Shared typed aliases and X state model.
  • pyreactsim_core/configs/info.py: Package metadata.

Examples folder:

  • examples/rates/: Rate-expression examples (gas and liquid kinetics).
  • examples/source/: Model-source creation/loading scripts.
  • examples/thermodb/: Thermodynamic database assets used by source scripts.

🧪 Examples Guide

Use the following scripts as starting points:

  • examples/rates/rate_exp_1.py: Minimal pressure-based rate expression setup.
  • examples/rates/methanol_1.py: Multi-reaction methanol synthesis kinetics (gas phase).
  • examples/rates/esterification_acetic_acid_1.py: Liquid-phase reversible esterification example.
  • examples/source/gas_load_model_source.py: Build/load gas-phase component model source from thermodb files.
  • examples/source/liquid_load_model_source.py: Build/load liquid-phase component model source from thermodb files.

Run an example directly:

python examples/rates/rate_exp_1.py

Note: Some examples rely on companion ecosystem packages and local thermodb assets.

🤝 Contributing

Contributions are highly welcome — bug fixes, new calculation routines, mixture models, extended unit tests, documentation, etc.

📝 License

This project is distributed under the Apache License, Version 2.0, which grants you broad freedom to use, modify, and integrate the software into your own applications or projects, provided that you comply with the conditions outlined in the license. Although Apache 2.0 does not require users to retain explicit author credit beyond standard copyright and license notices, I kindly request that if you incorporate this work into your own software, you acknowledge Sina Gilassi as the original author. Referencing the original repository or documentation is appreciated, as it helps recognize the effort invested in developing and maintaining this project.

❓ FAQ

For any question, contact me on LinkedIn

👨‍💻 Authors

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyreactsim_core-0.1.1.tar.gz (15.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyreactsim_core-0.1.1-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

Details for the file pyreactsim_core-0.1.1.tar.gz.

File metadata

  • Download URL: pyreactsim_core-0.1.1.tar.gz
  • Upload date:
  • Size: 15.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.8

File hashes

Hashes for pyreactsim_core-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7b666acd6b36e84bb68d039f95e2a3db2cc61c0767acf23d4a4a91c4f84b6608
MD5 722e91b277e2c8d79f5df1571fd324cf
BLAKE2b-256 5c86de499fa618df549152f5f742ed581f5a9d26e569306e16cb7ce509d2cef9

See more details on using hashes here.

File details

Details for the file pyreactsim_core-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pyreactsim_core-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b1c78a92abce69cf3cb55c8b2690534879cc5fe95db0bac6e658482e9034173d
MD5 6f951c43c8f82947d3d77cfffe520f8c
BLAKE2b-256 d767e039320db0b3ccb735ecfc7dcd829a93fb476e8ce405cc88c8d995c34c31

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page