Skip to content

wl5e/buffer-prep-calculator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Buffer Prep Calculator

A GMP-compliant command-line tool for calculating required volumes of stock solutions and diluent (solvent) when preparing buffer solutions. It accepts a JSON recipe describing multiple components with their stock and target concentrations, plus a final volume, and outputs a clear preparation table with exact volumes to add. Designed with pharmaceutical GMP environments in mind, it includes timestamps, optional batch IDs, and robust error checking.

Features

  • JSON recipe input – define multiple components with names, stock concentrations, and target concentrations
  • Concentration unit support – M, mM, µM, nM; automatic conversion to base units
  • Volume unit selection – L, mL, µL; output in the same unit
  • Solvent volume calculation – automatically computes the amount of diluent needed to reach the final volume
  • GMP-friendly output – timestamp, batch ID, clear preparation table
  • Error prevention – alerts if a stock solution is too dilute, or if the sum of stock volumes exceeds the total volume
  • Zero external dependencies – uses only Python standard library (pytest needed for development)

Installation

Requires Python 3.8 or later. No additional packages are needed to run the calculator.

git clone https://github.com/your-username/buffer-prep-calculator.git
cd buffer-prep-calculator

For development and running tests, install the test dependencies:

pip install -r requirements.txt

Usage

python buffer_prep.py --recipe recipe.json --volume 1000 --unit mL [--batch BATCH123]

Recipe file format (JSON)

{
  "components": [
    {
      "name": "Tris-HCl",
      "stock_conc": 1.0,
      "stock_unit": "M",
      "target_conc": 0.05,
      "target_unit": "M"
    },
    {
      "name": "EDTA",
      "stock_conc": 500,
      "stock_unit": "mM",
      "target_conc": 1,
      "target_unit": "mM"
    }
  ]
}

Example output

Buffer Preparation Record
=========================
Date: 2026-04-10 15:42:00
Batch ID: BATCH001
Final Volume: 1000.000 mL

Component                 Stock Conc      Target Conc     Volume to Add (mL)
---------------------------------------------------------------------------
Tris-HCl                  1.000 M         0.050 M         50.000
EDTA                      0.500 M         0.001 M          2.000
Solvent (diluent)         ---             ---             948.000

Error handling

  • If a stock concentration is lower than the target concentration, the tool exits with an explanatory message.
  • If the sum of required stock volumes exceeds the final volume, an error is raised.
  • Invalid JSON, missing fields, or unsupported units are reported clearly.

License

MIT License – see LICENSE file.

Author

Collins Amatu Gorgerat

About

A GMP-compliant buffer preparation calculator that determines required volumes of stock solutions and diluent for given target concentrations and final volume.

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors

Languages