Functions to calculate pH, alkalinity, total inorganic carbon and pCO2 in a closed, carbonate-buffered system at equilibrium (i.e. finite liquid and gas/headspace volume at equilibrium) with an optional additional weak acid/base buffer. This is for simplified aqueous geochemical systems commonly encountered in culturing applications. All default constants are based on freshwater and there is no implicit salinity correction included (stability constants can be set manually). For more complex systems, please use a full aquatic chemistry suite instead.

calculate_closed_system_pH(
TIC,
V_liquid,
V_gas,
solubility = calculate_gas_solubility("CO2", temperature),
temperature = qty(25, "C"),
pKa1 = 6.3,
pKa2 = 10.3,
pKw = 14,
buffer = qty(0, "M"),
buffer_pKa,
alkalinity = qty(0, "M")
)

calculate_closed_system_alkalinity(
pH,
TIC,
V_liquid,
V_gas,
solubility = calculate_gas_solubility("CO2", temperature),
temperature = qty(25, "C"),
pKa1 = 6.3,
pKa2 = 10.3,
pKw = 14,
buffer = qty(0, "M"),
buffer_pKa
)

calculate_closed_system_TIC(
pH,
pCO2,
V_gas,
V_liquid,
temperature = qty(25, "C")
)

calculate_closed_system_pCO2(
pH,
TIC,
V_gas,
V_liquid,
solubility = calculate_gas_solubility("CO2", temperature),
temperature = qty(25, "C"),
pKa1 = 6.3,
pKa2 = 10.3
)

## Arguments

TIC total inorganic carbon in the system (an amount quantity) volume of liquid (a volume quantity) volume of the gas/headsapce (a volume quantity) the solubility of CO2, by default is determined based on the temperature of the system the temperature of the system, used to calculate the solubility constant the acid dissociation constant for H2CO3* the acid dissociation constant for bicarbonate (HCO3-) water dissociation constant [optional] total concentration of the pH buffer (a molarity quantity). Assumes that this is a protonated weak acid with the provided buffer_pKa. For weak base buffers, provide a negative molarity quantity instead and the appropriate buffer_pKa. If the buffer is a salt (e.g. Na-Buffer or Buffer-Cl), make sure to add the appropriate molarity to the alkalinity to account for the added ions (positive for hard cations, negative for hard anions). By default no additional buffer is added. buffer acid dissociation constant, required if buffer is provided [optional] charge-weighed NET concentration of all conservative ions [units charge x a molarity quantity] (explicitly conservative alkalinity). Conservative ions are those that do NOT get affected by changes in pH in the pH range of interest (i.e. do not form any acids or bases or have pKas far outside the pH range of interest). E.g. mol/L Na that was added in the form of NaOH, NaHCO3 or as part of a Na-buffer salt; -1 x mol/L Cl that was added as HCl or -2 x mol/L SO4 that was added as H2SO4. Ions from salts that are comprised exclusively of conservative ions (e.g. NaCl, MgSO4) do not need to be included because they cancel out. By default the alkalinity of the system is 0 M. the pH of the system the partial pressure of CO2 (a pressure quantity)

## Functions

• calculate_closed_system_pH: calculate the pH of a closed system. Returns pH.

• calculate_closed_system_alkalinity: calculates the alkalinity of a closed system that is carbonate buffered and has an optional additional weak acid/base buffer. Returns the alkalinity as a molarity quantity. positive = excess cations, negative = excess anions.

• calculate_closed_system_TIC: calculates total inorganic carbon (TIC) in a closed system at equilibrium. Returns TIC as an amount quantity.

• calculate_closed_system_pCO2: calculates the partial pressure of CO2 in the headspace (gas phase) of a closed system at equilibrium. Returns a pressure quantity.

Other carbonate chemistry: open_system, speciation