Skip to main content

logo

License PyPI version Powered by: Pixi Code style: ruff codecov docs python 3.12

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)

KBI Analysis

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.

Comparison of KBI values across tools

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
  • 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.34

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

Source distribution (sdist)

Source distribution for kbkit 1.0.34
File Size Uploaded
kbkit-1.0.34.tar.gz 117.2 kB Details

Release files / kbkit-1.0.34.tar.gz

Download URL kbkit-1.0.34.tar.gz
Size 117.2 kB
Tags Source
SHA-256 checksum
How to use checksums
4704866b80dadeb4e99ff9eb6a00eb4473557f303b63134ce28c4c5c806cf072
BLAKE2b-256 checksum
How to use checksums
749b8689267a93357e3b87f4107f89b768a71f55ddee8aacd4353fa139b773a1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release history Release notifications | RSS feed

1.0.36

1 release file

1.0.35

1 release file

This release

1.0.34 This release

1 release file

1.0.33

1 release file

1.0.32

1 release file

1.0.31

1 release file

1.0.30

1 release file

1.0.29

1 release file

1.0.28

1 release file

1.0.27

1 release file

1.0.26

1 release file

1.0.25

1 release file

1.0.24

1 release file

1.0.23

1 release file

1.0.22

1 release file

1.0.21

1 release file

1.0.20

1 release file

1.0.19

1 release file

1.0.18

1 release file

1.0.17

1 release file

1.0.16

1 release file

1.0.15

1 release file

1.0.14

1 release file

1.0.13

1 release file

1.0.12

1 release file

1.0.11

1 release file

1.0.10

1 release file

1.0.9

1 release file

1.0.8

1 release file

1.0.7

1 release file

1.0.6

1 release file

1.0.5

1 release file

1.0.4

1 release file

1.0.3

1 release file

1.0.2

1 release file

1.0.1

1 release file

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