Skip to main content

A Python package for balancing chemical equations and finding possible reactions

Project description

balance-rxns

A Python package for balancing chemical equations and finding possible reactions.

中文文档

Installation

pip install balance-rxns

Features

  • Automatically balance chemical equations
  • Find all possible reactions from given reactants and products
  • Support for complex chemical formulas
  • Accurate calculations based on sympy and pymatgen

Usage

Basic Usage

from balance_rxns import balance_rxns

# Define reactants and products
reactants = ("Fe", "O2")
products = ("FeO", "Fe2O3", "Fe3O4")

# Find all possible balanced equations
results = balance_rxns(reactants, products)

# Print results
for equation, reactant_coeffs, product_coeffs in results:
    print(equation)

Output:

2Fe + O2 -> 2FeO
4Fe + 3O2 -> 2Fe2O3
3Fe + 2O2 -> Fe3O4

Advanced Options

# Limit the number of products
results = balance_rxns(
    reactants=["Cu", "Al2O3"],
    products=["CuAlO2"],
    max_products_in_equation=2,  # Maximum 2 products per equation
    require_all_reactants_used=True  # Require all reactants to be used
)

for equation, r_map, p_map in results:
    print(f"Equation: {equation}")
    print(f"Reactant coefficients: {r_map}")
    print(f"Product coefficients: {p_map}")
    print()

Parameters

  • reactants: List or tuple of reactant chemical formulas
  • products: List or tuple of product chemical formulas
  • max_products_in_equation: Maximum number of products in each equation (default: all)
  • require_all_reactants_used: Whether all reactants must be used (default: True)

Return Value

Returns a list where each element contains:

  1. String representation of the balanced equation
  2. Dictionary of reactants with their coefficients
  3. Dictionary of products with their coefficients

Dependencies

  • pymatgen >= 2024.1.0
  • sympy >= 1.12.0

License

MIT License

Contributing

Issues and Pull Requests are welcome!

Changelog

0.1.0 (2026-01-30)

  • Initial release
  • Support for chemical equation balancing

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

balance_rxns-0.2.0.tar.gz (53.7 kB view details)

Uploaded Source

Built Distribution

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

balance_rxns-0.2.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file balance_rxns-0.2.0.tar.gz.

File metadata

  • Download URL: balance_rxns-0.2.0.tar.gz
  • Upload date:
  • Size: 53.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.4

File hashes

Hashes for balance_rxns-0.2.0.tar.gz
Algorithm Hash digest
SHA256 a9743aeac6c656c798e62bc24d5543a5d3687af8d35b5f84786892a6723897b2
MD5 982a566c116a3adc0068e39c92a707ea
BLAKE2b-256 2dd274197b05684c797a368b0e519085a0ab01cbc2c7bf69db001e844cbe611b

See more details on using hashes here.

File details

Details for the file balance_rxns-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for balance_rxns-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3b06031c3c594dfed3763ec6d252a964fd717f8bb9197c43e757bc28e28feb0c
MD5 427e2051a97e606ac10c0522baa3393c
BLAKE2b-256 28db1f6d282fbbd0d6f532d87b58afe3111ef544d6a63db52ec09f45c0a73dc9

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