calculate_ph
Compute pH, buffer recipes and ionisation fractions from pKa values, with exact charge balance and warnings when textbook approximations fail.
Instructions
Calculate pH, buffer composition and buffer recipes, with the working.
Solves the exact charge balance — the same one that draws the titration curve — and puts the textbook approximation next to it. Where the two disagree, the approximation has lost its assumptions and the answer says so instead of quietly being wrong.
Pick the topic: "weak_acid", "weak_base", "strong_acid", "strong_base",
"buffer" (ratio and capacity), "buffer_recipe" (masses to weigh) or
"ionisation" (charged and uncharged fraction of a drug at one pH).
You supply the pKa values from the monograph or table.
Not this tool for: drawing pH against titrant volume, equivalence points or indicator choice (use generate_titration_curve), or drawing the species fractions across the whole pH range (use generate_species_distribution) — this one computes, those draw.
Args: topic: Which case to solve. concentration: Concentration in mol/L. pka: pKa of the acid, or of the conjugate acid of a base. pkb: pKb of the base. pka_values: All pKa values of a polyprotic acid, in order. acid_concentration: [HA] in mol/L. base_concentration: [A⁻] in mol/L. target_ph: Wanted pH ("buffer_recipe") or medium pH ("ionisation"). total_concentration: [HA] + [A⁻] in mol/L. volume_ml: Buffer volume in mL. acid_molar_mass: Acid component, g/mol. base_molar_mass: Base component, g/mol. drug_type: "acid" or "base" ("ionisation").
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| pka | No | ||
| pkb | No | ||
| topic | Yes | ||
| drug_type | No | acid | |
| target_ph | No | ||
| volume_ml | No | ||
| pka_values | No | ||
| concentration | No | ||
| acid_molar_mass | No | ||
| base_molar_mass | No | ||
| acid_concentration | No | ||
| base_concentration | No | ||
| total_concentration | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |