Skip to main content

KBKit: Kirkwood-Buff Analysis Toolkit

Project description

KBKit: Kirkwood-Buff Analysis Toolkit

License PyPI version Powered by: Pixi Code style: ruff GitHub Workflow Status Coverage Status 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

Install via PyPI

To install the latest stable release:

pip install kbkit

Install from source

KBKit can be installed from cloning its github repository and creating an anaconda environment with dependencies.

git clone https://github.com/aperoutka/kbkit.git
cd kbkit

Create an anaconda environment (kbkit) for users, from latest stable release:

make setup-user

Create an anaconda environment (kbkit-dev) for contributers, from current source:

make setup-dev

Examples

Below are several examples on various ways to implement KBKit.

Calculating Kirkwood-Buff integrals on a single RDF

from kbkit.analysis import KBIntegrator

# create integrator object from single RDF file
integrator = KBIntegrator(rdf_file)

# calculate running-KBI
rkbi = integrator.rkbi()

# calculate KBI in thermodynamic limit
kbi = integrator.integrate()

# visualize KBI integration and extrapolation
integrator.plot()

Run an automated pipeline for batch analysis

from kbkit.core import KBPipeline

# Set up and run the pipeline
pipe = KBPipeline(
    base_path="/path/to/systems",                # directory with system data
    pure_path="/path/to/pure_components",        # directory with pure component data
    pure_systems=["acetone_300", "water_300"],   # list of pure systems
    ensemble="npt",                              # ensemble type: npt or nvt
    gamma_integration_type="numerical",          # integration method
    verbose=False                                # logging verbosity
)

# run kbkit pipeline
results = pipe.run()

# Access the results properties
# stored in dataclass (ThermoProperty); attributes: name, value, units
# example for excess energy
ge_obj = results.ge
ge_array = ge_obj.value
ge_units = ge_obj.units
print("GE summary: ", ge_array.shape, ge_units)

# Convert units from kJ/mol -> kcal/mol
# default units will be those from GROMACS
pipe.convert_units("ge", "kcal/mol")

Create plots for thermodynamic properties from pipeline

from kbkit.viz import Plotter

# Map molecule IDs (as present in .top files) to names for figures
molecule_map = {
    "ACETO": "Acetone",
    "TIP4P": "Water",
}
x_mol = "ACETO"  # molecule for x-axis labels

plotter = Plotter(pipeline=pipe, x_mol=x_mol, molecule_map=molecule_map)

# Plot Kirkwood-Buff integrals
plotter.plot("kbi")

# Plot log of activity coefficients
plotter.plot("lngammas")

# Generate all figures (saved to /path/to/systems/kb_analysis)
plotter.make_figures()

Parse GROMACS files

from kbkit.parsers import TopFileParser, EdrFileParser, GroFileParser

# determines molecules present in simulation and their counts
top_parser = TopFileParser(top_file.top)
print("molecule dict: ", top_parser.molecule_counts)
print("molecule names: ", top_parser.molecules)
print("total molecule number: ", top_parser.total_molecules)

# determines electron count for each molecule type
gro_parser = GroFileParser(gro_file.gro)
print("electron dict: ", gro_parser.electron_count)
print("box volume: ", gro_parser.compute_box_volume())

# computes energy properties by calling gmx energy
edr_parser = EdrFileParser(edr_file.edr)
print("List of available properties: ", edr_parser.available_properties())
print("Density array over simulation time: ", edr_parser.extract_timeseries("density"))
print("Average density with std deviation: ", edr_parser.average_property("density", return_std=True))

Calculate static structure factors and x-ray intensities as q → 0

from kbkit.calculators import StaticStructureCalculator

"""
Requires:
    - mol fraction matrix: shape(num compositions, num components)
    - molar_volume: shape(num components), units cm^3/mol
    - n_electrons: shape(num components)
"""
calculator = StaticStructureCalculator(mol_fr, molar_volume, n_electrons)

# update conditions
# if conditions are not updated all calculations will use previous values
calculator.update_conditions(T, Hessian, isothermal_compressibility)

# calculate x-ray intensity
calculator.i0()

Credits

This package was created with Cookiecutter and the jevandezande/pixi-cookiecutter project template.

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

kbkit-1.0.2.tar.gz (63.6 kB view details)

Uploaded Source

File details

Details for the file kbkit-1.0.2.tar.gz.

File metadata

  • Download URL: kbkit-1.0.2.tar.gz
  • Upload date:
  • Size: 63.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for kbkit-1.0.2.tar.gz
Algorithm Hash digest
SHA256 6cb3bcb3b5ccbd84d26a7039c40cf44c16ebbdb0ca3377d6e8f2859ccd5914d3
MD5 11f30b878e313e9e60af183c61260c20
BLAKE2b-256 96db7467cbdafa8cd4380f3ba46ab6016ef25bd87178f4b0be61e4a25d82b59f

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