Skip to main content

bindtools

PyPI version Python Version License: MIT DOI

bindtools is a Python library for supramolecular chemistry designed for modeling, fitting, and analyzing binding equilibria. It provides numerical and analytical solvers for complex chemical systems, robust parameter optimization, and Bayesian parameter estimation.


Features

  • Speciation Solvers:
    • Numerical: A Newton-Raphson solver (DoNR and getConcs) JIT-compiled with numba for fast operation.
    • Analytical: High-speed analytical solvers for common topologies (e.g., 1:1, 1:2, 2:1 fast exchange).
  • Flexible Optimization:
    • Uses lmfit to manage model parameters (binding constants, physical observables).
    • Handles various experimental data including NMR integrations, chemical shifts (NMR deltaH/deltaF), and linear concentration-weighted observables (UV-vis / fluorescence).
  • Bayesian Inference & Uncertainty Quantification:
    • Uses emcee for Markov Chain Monte Carlo (MCMC) sampling.
    • Generates trace/chain convergence plots and corner plots using corner and matplotlib.
    • MCMC runs can be serialized and stored as HDF5 files for future analysis.

Package Architecture

bindtools is organized into modular scientific domain subpackages:

  • bindtools.speciation: Chemical equilibrium solvers (Numba JIT Newton-Raphson and vectorized cubic analytical solutions for 1:1, 1:2, and 2:1 systems).
  • bindtools.observables: Physical measurement transforms (ObsType, NMR chemical shifts, integrals, and UV-vis / fluorescence linear absorption).
  • bindtools.models: Model definition (bindingModel), simulation helpers, and optimization engine.
  • bindtools.mcmc: Bayesian parameter estimation (MCMC), priors, likelihoods, and HDF5 serialization.
  • bindtools.plotting: Visualizations for speciation, fit residuals, and MCMC trace/corner diagnostics.
  • bindtools.io: Data export utilities (saveFitCSV).

Core symbols can be imported directly from the top level (import bindtools as bt), while legacy imports (from bindtools import binding as bd) remain fully supported for backwards compatibility.


Installation

bindtools is available on PyPI. You can install it directly using pip:

pip install bindtools

To avoid dependency conflicts, you can set up a dedicated environment with Conda/Mamba and install bindtools inside it:

# 1. Create and configure environment with base scientific dependencies
mamba create -n binding -c conda-forge \
  python jupyter tqdm ipython uncertainties lmfit scipy numpy emcee tqdm numba corner matplotlib numdifftools

# 2. Activate the environment
conda activate binding

# 3. Install bindtools via pip
pip install bindtools

Quick Start

1. Speciation (Solving Concentration Problems)

You can compute the equilibrium concentration of free species (components and complexes) given initial total concentrations, a stoichiometry matrix, and equilibrium constants ($K$ values).

import numpy as np
import bindtools as bt

# Define total concentrations: 50 data points of Host (1e-3 M) and Guest (0 to 1e-2 M)
component_concs = np.zeros((50, 2))
component_concs[:, 0] = 1e-3
component_concs[:, 1] = np.linspace(0, 1e-2, 50)

# Stoichiometry / Equilibrium Matrix
# Row 0: Host balance, Row 1: Guest balance
# Columns represent: [Free Host, Free Guest, Host-Guest Complex (1:1)]
eq_mat = np.array([
    [1, 0, 1],  # [H]_tot = [H] + [HG]
    [0, 1, 1]   # [G]_tot = [G] + [HG]
])

# log10(K) values for each species. 
# Constants for free components are fixed at logK = 0.
# The complex (HG) has logK = 4 (K = 10,000 M^-1).
logK = np.array([0, 0, 4])

# Solve for concentrations at each point
results = []
for total_concs in component_concs:
    spec_concs = bt.getConcs(eq_mat, total_concs, logK)
    results.append(spec_concs)

results = np.array(results)
print("First point [H, G, HG]:", results[0])

2. Model Fitting (bindingModel)

Fit binding models to experimental observables (integrals, chemical shifts, or absorbance):

import bindtools as bt

# Initialize model with stoichiometry, component names, and data
model = bt.bindingModel(
    eqMat=eq_mat,
    compNames=["H", "G"],
    speciesList=["H", "G", "HG"],
    colToComp=col_to_comp,
    rawData=raw_data,
)

# Prepare parameters and fit
model.prepModel()
model.runModel(skip_col=2, method="least_squares")

print("Fitted logK:", model.miniResult.params["logHG"].value)

3. Bayesian MCMC & Uncertainty Estimation

Quantify parameter uncertainties with MCMC sampling and generate corner plots:

obs = [bt.ObsType("concMeas")]
mcmc = bt.MCMC(model, obs, walkers=25, samples=2000)
sampler, bm = mcmc.run(thin=10)

# Diagnostics & plots
mcmc.plot_chain()
mcmc.plot_corner()
mcmc.save("fit_results.hdf")

License

This project is licensed under the MIT License - see the LICENSE file for details.

Metadata

Release files for bindtools 0.3.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bindtools 0.3.4
File Size Uploaded Provenance Actions
bindtools-0.3.4.tar.gz 22.5 kB Without provenance Details for bindtools-0.3.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for bindtools 0.3.4
File Interpreter ABI Platform Actions
bindtools-0.3.4-py3-none-any.whl Python 3 none any Details for bindtools-0.3.4-py3-none-any.whl

Total release size: 50.2 kB

Release files / bindtools-0.3.4.tar.gz

Download URL bindtools-0.3.4.tar.gz
Size 22.5 kB
Tags Source
SHA-256 checksum
How to use checksums
eeb1bbc2550abbc46365b936c9298e72573f2f20c8b8711fa6f6a42a61b7cf7a
BLAKE2b-256 checksum
How to use checksums
c834b2b094c8258649693cfc41e760c5a631623438efaa1e343e301c7a642202
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / bindtools-0.3.4-py3-none-any.whl

Download URL bindtools-0.3.4-py3-none-any.whl
Size 27.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e3a1375dc80e87a5aefb4af7aa0329d8a4bd93c799b2982971339943baaacbbb
BLAKE2b-256 checksum
How to use checksums
88b34a60bb02be0c76f7d6d5530b4f4c9c3468ed40e2fe768420dc4aa418c523
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for bindtools 0.3.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page