Introduction

A powerful Python library for mathematical and computational chemistry, designed for students and researchers.

mathchem provides intuitive implementations of fundamental quantum chemistry models and utility functions for chemical calculations.

Quantum Models

Hückel MO theory, Particle in a Box, and Variation Theory implementations.

Stoichiometry

Easy molar mass calculations and chemical formula parsing.

Visualization

Built-in tools to visualize wavefunctions and energy levels.

Installation

pip install cnumathchem

Or install from source:

git clone https://github.com/minseo0388/mathchem.git
cd mathchem
pip install -r requirements.txt

Hückel Approximation

Calculate molecular orbital energies and coefficients for conjugated systems.

Usage

from cnumathchem.huckelapprox import Huckel
import numpy as np

# Adjacency matrix for Benzene
adj_benzene = [
    [0,1,0,0,0,1],
    [1,0,1,0,0,0],
    [0,1,0,1,0,0],
    [0,0,1,0,1,0],
    [0,0,0,1,0,1],
    [1,0,0,0,1,0],
]

mol = Huckel(adj_benzene)
energies, coeffs = mol.solve()

print("MO Energies:", np.round(energies, 4))
print("Total π energy:", np.round(mol.total_pi_energy(6), 4))

Variation Theory

Approximate ground state energies using the variational method.

from cnumathchem.variationtheory import VariationTheory

# Example usage (conceptual)
# Define your Hamiltonian and trial function
# vt = VariationTheory(hamiltonian, trial_func)
# energy = vt.minimize()

Particle in a Box & Others

Solve Schrödinger equation for standard potentials.

1D Particle in a Box

from cnumathchem.particle import ParticleInABox1D

box1 = ParticleInABox1D(L=1.0, m_eff=1.0)
ns, Es1 = box1.spectrum(5)
print("Energies:", Es1)

2D Particle in a Box

from cnumathchem.particle import ParticleInABox2D

box2 = ParticleInABox2D(Lx=1.0, Ly=2.0, m_eff=1.0)
levels = box2.spectrum(3, 3)

Stoichiometry

Calculate molar masses from chemical formulas.

from cnumathchem.stoichiometry import Stoichiometry

mass = Stoichiometry.calculate_molar_mass("C6H12O6")
print(f"Molar Mass of Glucose: {mass} g/mol")