Today, I was trying to make a protocol for the following media recipe:
Reagent Stock Final Volume
────────────────────────────────────────────────
M9 salts 612 mL
glucose 200 mg/mL 4 mg/mL 14 mL
thiamine 200 mg/mL 4 mg/mL 14 mL
MgSO₄ 100 mM 1 mM 7 mL
ZnSO₄ 100 mM 10 µM 70 µL
CaCl₂ 1 M 100 µM 70 µL
kanamycin 50 mg/mL 25 µg/mL, 0.5x 350 µL
carbenicillin 100 mg/mL 100 µg/mL, 1x 700 µL
IPTG 1 M 10 µM 7 µL
Note the wide range in volumes: from 612 mL to 7 µL. Currently, it's only possible to operate on quantities with identical units, and so the only way to make this reaction work is to convert everything to µL. (If I convert to mL, the µL volumes get rounded.)
Unfortunately, fixing this is going to be a big change. I'll basically need a full-blown units package. Some ideas about how to do this:
Force units to be predefined with the following information:
type (e.g. volume, mass, etc.)
SI prefixes? (This would just be a shortcut for predefining conversion functions)
symbol
Allow unit conversions to be defined:
Each conversion would specify a input unit, an output unit, and a function.
The function would get the input quantity and a arbitrary user-defined keyword argments, and could do anything it wants to produce an output quantity.
The purpose of the keyword arguments is to allow for information like MW to be provided to the conversion function. These arguments would be set by a context manager, or explicitly passed to a convert() function.
The complete set of conversion functions would comprise a graph. When a conversion is requested, the shortest path from the input unit to the output unit would be calculated, and all the conversion functions along that path would be applied.
Some open questions:
Would the current set of units be a global variable? Global variables are bad, but having to pass around a UnitSystem object everything would be prohibitively annoying.
Today, I was trying to make a protocol for the following media recipe:
Note the wide range in volumes: from 612 mL to 7 µL. Currently, it's only possible to operate on quantities with identical units, and so the only way to make this reaction work is to convert everything to µL. (If I convert to mL, the µL volumes get rounded.)
Unfortunately, fixing this is going to be a big change. I'll basically need a full-blown units package. Some ideas about how to do this:
convert()
function.Some open questions:
UnitSystem
object everything would be prohibitively annoying.