KBKit is a Python package for automated Kirkwood-Buff (KB) analysis of molecular simulation data. It provides tools to parse simulation outputs, compute Kirkwood-Buff integrals, and extract thermodynamic properties for binary and multicomponent systems. KBKit supports flexible workflows, including:
- Parsing and processing of simulation data (e.g., RDFs, densities)
- Calculation of KB integrals and related thermodynamic quantities
- Integration of activity coefficient derivatives (numerical or polynomial)
- Automated pipelines for batch analysis
- Calculation of static structure factor and X-ray intensities in the limit of q → 0
- Visualization tools for KB integrals, thermodynamic properties, and static structure factors
KBKit is designed for researchers in computational chemistry, soft matter, and statistical mechanics who need robust, reproducible KB analysis from simulation data. The package is modular, extensible, and integrates easily with Jupyter notebooks and Python scripts.
Installation
Quick install via PyPI
pip install kbkit
Developer install (recommended for contributors or conda users)
Clone the GitHub repository and use the provided Makefile to set up your development environment:
git clone https://github.com/anl-sepsci/kbkit.git
cd kbkit
make setup-dev
This one-liner creates the kbkit-dev conda environment, installs kbkit in editable mode, and runs the test suite.
To install without running tests:
make dev-install
To build and install the package into a clean user environment:
make setup-user
For a full list of available commands:
make help
Documentation
Thorough documentation of KBKit is located at https://kbkit.readthedocs.io/en/latest/.
Examples
Below are several examples on various ways to implement KBKit. See examples/ for complete tutorials.
Calculating Kirkwood-Buff integrals on a single RDF
from pathlib import Path
from kbkit.kbi import KBIntegrator
from kbkit.systems import SystemProperties
syspath = Path("./examples/test_data/size_effects/sys_706")
rdf_path = Path(system_path) / "kbi_rdf_files_50ns" / "rdf_ETHOL_ETHOL.xvg"
# create integrator object from single RDF file
integrator = KBIntegrator.from_rdf(
rdf=rdf_path,
system_properties=SystemProperties(syspath, start=10000),
)
# calculate KBI in thermodynamic limit
kbi = integrator.kbi
# visualize convergence
integ.plot_kbi_compare_extrapolation(integ.weight_type)
Run an automated pipeline for batch analysis
from kbkit.api import Pipeline
# Set up and run the pipeline
pipe = Pipeline(
pure_path="./test_data/pure_components", # path to parent directory containing pure-component subdirectories
pure_systems=["ETHOL_300", "SPCEW_300"], # pure-component subdirectories
base_path="./test_data/ethanol_water_26C", # path to parent directory containing mixture subdirectories
rdf_dir="kbi_rdf_files", # name for rdf-file subdirectory in each mixture directory (this needs to be the same in each system.)
start=10000, # start time (ps) for calculating MD properties (from energy file)
include_mode="npt", # string required in MD output files to be a 'valid' filename
errors="warn", # prints ConvergenceError & returns NaN for non-converged values
molecule_map={
"ETHOL": "ethanol",
"SPCEW": "water",
}, # map molecule types in GROMACS files to molecule name for figures
)
# Access the properties in PropertyResults objects
res = pipe.results
# Convert units to kcal/mol
# current units will be read from existing PropertyResult object
g_ex_res = res["g_ex"].to("kcal/mol")
# make figures for KBI analysis and select thermodynamic properties
figpath = Path("./figures/kb_analysis")
figpath.mkdir(exist_ok=True, parents=True)
pipe.make_figures(xmol="ETHOL", savepath=figpath)
Validation
To verify the consistency of the KBI values, this package was validated using the rdf1.txt RDF dataset. The results were compared against kbkit and pykbi to ensure parity.
The figure above demonstrates that our implementation produces results consistent with established benchmarks, ensuring the validity of the calculations.
File Organization
For running kbkit.Pipeline or its dependencies, the following file structure is required: a structured directory layout that contains a subfolder containing RDF files, an individual file for each pairwise molecule interaction.
This organization enables automated parsing, reproducible KB integrals, and scalable analysis across chemical systems.
- NOTE: KBKit currently supports parsing for GROMACS and LAMMPS files.
An example of file structure (for a GROMACS simulation):
project/
├── system/
│ ├── rdf_dir/
│ │ ├── mol1_mol1.xvg
│ │ ├── mol1_mol2.xvg
│ │ └── mol1_mol2.xvg
│ ├── system_npt.edr
│ ├── system_npt.gro
│ └── system.top
└── molecule1/
├── molecule1_npt.edr
└── molecule1.top
Requirements:
-
Each system to be analyzed must include:
- rdf_dir/ containing .xvg RDF files for all pairwise interactions
- Both molecule IDs in RDF calculation MUST BE in filename
- Topology file: .gro, .top, .lmp
- Energy file: .edr, .log, .lammps
- rdf_dir/ containing .xvg RDF files for all pairwise interactions
-
NOTE: for pure components, just Topology and Energy files are required, RDF files are optional and used only for KBI's, not for thermodynamic analysis.
Citations & References
Cite the Software (JCIM Paper)
If you use this Python package in your research, please cite our peer-reviewed paper in the Journal of Chemical Information and Modeling:
@article{peroutka2026jcim,
author = {Allison A. Peroutka and G. Brian Stephenson and Michael J. Servis},
title = {KBKit: A Python Toolkit for Kirkwood–Buff Theory from Molecular Dynamics},
journal = {Journal of Chemical Information and Modeling},
volume = {66},
issue = {12},
pages = {6821-6828},
year = {2026},
doi = {10.1021/acs.jcim.6c00344}
}
Applied Research
Examples of how this package has been applied:
@article{peroutka2026chemsci,
author = {Allison A. Peroutka and G. Brian Stephenson and Michael J. Servis},
title = {From Molecular to Macroscopic: Predicting Liquid-Liquid Phase Equilibria and Small-Angle Scattering of Mixtures of Organic Liquids from Atomistic Simulation using Kirkwood-Buff Theory },
journal = {Chemical Science},
volume = {17},
issue = {21},
pages = {10411-10421},
year = {2026},
doi = {10.1039/d6sc03294j}
}
Credits
This package was created with Cookiecutter and the jevandezande/pixi-cookiecutter project template.
Metadata
Release files for kbkit 1.0.30
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| kbkit-1.0.30.tar.gz | 116.6 kB | Details |
Release files / kbkit-1.0.30.tar.gz
| Download URL | kbkit-1.0.30.tar.gz |
|---|---|
| Size | 116.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0f422a85832a4b038d6e1385b9d467f343bf7421e6d3089086e0600700cd802e
|
|
BLAKE2b-256 checksum How to use checksums |
184bf41774b186327c6774c34207ad03efd78dc9f2c9890fda9628b85a1d72d0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|