Substance Tracking
Substance tracking reports how much of a particular Substance has been used
Usage is defined as the net increase of the amount of a given Substance in a destination set of Containers or Plates during a specified timeframe
When calling
recipe.remove, the Substance is considered to be moved to a special trash container, which is always considered a destinationIf no destinations set is explicitly specified, the set of all Plates is considered to be the destination
If the amount of the substance in the destinations undergoes a net decrease during the timeframe, an error is thrown
Refer to Minimal Recipe document for the recipe being queried in the examples below.
How to use get_substance_used():
def get_substance_used(self, substance: Substance, timeframe: str = 'all', unit: str = None,
destinations: Iterable[Container | Plate] | str = "plates")
substance: The Substance to tracktimeframe: The timeframe over which the net difference should be calculatedunit: The unit to return usage indestinations: A list ofContainersand/orPlatesto be considered destinations. Alternatively, pass in"plates"to consider all plates to be destinations. By default, all plates are considered destinations.Default units for substances are determined by their type:
solids:
gliquids:
mLenzyme:
U
Example calls
How much sodium sulfate was used during the whole recipe if
containeris our only destination?
>>> recipe.get_substance_used(substance=sodium_sulfate, timeframe='all', unit='mmol', destinations=[container])
5.0
We compare the amount of
sodium_sulfateincontainerat the beginning and end of the recipeThere are
0 mmolat the beginning and5 mmolat the endThe net difference for
containeris5 mmol, which is our “amount used”How much water was used during the whole recipe if
containeris our only destination?
>>> recipe.get_substance_used(substance=water, timeframe='all', unit='mmol', destinations=[container])
515.0
We compare the amount of water in
containerat the beginning and end of the recipeThere are
0 mmolof water incontainerat the beginning of the recipe and0 mmolof water incontainerat the end of the recipeThe net difference for
containeris0 mmol.However, trash is always an implicit destination that stores removed substances.
The amount of water in
trashincreases by515 mmolduring the recipeThus, we sum the two amounts and return
515 mmolHow much sodium sulfate was used during
Stage 1ifstock_solutionis our only destination?
>>> recipe.get_substance_used(substance=sodium_sulfate, timeframe='Stage 1', unit='mmol', destinations=[stock_container])
ValueError: Substance tracking assumes a net increase in the amount of the substance being tracked in the destination set.
The amount of sodium_sulfate in the destinations decreased by 5 mmol.
We compare the amount of sodium sulfate in
stock_solutionat the beginning and end ofStage 1During this during stage 1 we transfer
10 mlfromstock_solutiontocontainerBut since
stock_solutionis specified as a destination, and there is a net decrease of5 mmolof sodium sulfateLogically, it would make sense for
stock_solutionto be considered a source and not a destinationThus,
amount_usedthrows an error
Recipe Walkthrough
The contents of all containers in the example recipe during different timeframes are shown below:
Start of Recipe:
container: {water: "0 mmol", sodium_sulfate: "0 mmol"}
stock_solution: {water: "0 mmol", sodium_sulfate: "0 mmol"}
trash: {water: "0 mmol", sodium_sulfate: "0 mmol"}``
Stage 1 (start):
container: {water: "2578 mmol", sodium_sulfate: "25 mmol"}
stock_solution: {water: "0 mmol", sodium_sulfate: "0 mmol"}
trash: {water: "0 mmol", sodium_sulfate: "0 mmol"}``
Stage 1 (end):
stock_solution: {water: "2063 mmol", sodium_sulfate: "20 mmol"}
container: {water: "515 mmol", sodium_sulfate: "5 mmol"}
trash: {water: "0 mmol", sodium_sulfate: "0 mmol"}``
Stage 2 (start):
stock_solution: {water: "2063 mmol", sodium_sulfate: "20 mmol"}
container: {water: "515 mmol", sodium_sulfate: "5 mmol"}
trash: {water: "0 mmol", sodium_sulfate: "0 mmol"}
Stage 2 (end):
stock_solution: {water: "2063 mmol", sodium_sulfate: "20 mmol"}
container: {water: "0 mmol", sodium_sulfate: "5 mmol"}
trash: {water: "515 mmol", sodium_sulfate: "0 mmol"}