from exex.basics import *
Example 1: Photosynthesis
Page 297 from Nivaldo J. Tro’s Chemistry
In photosynthesis, plants convert carbon dioxide and water into glucose \(\left(\mathrm{C}_6 \mathrm{H}_{12} \mathrm{O}_6\right)\) according to the reaction: \[ 6 \mathrm{CO}_2(g)+6 \mathrm{H}_2 \mathrm{O}(l) \stackrel{\text { sunlight }}{\longrightarrow} 6 \mathrm{O}_2(g)+\mathrm{C}_6 \mathrm{H}_{12} \mathrm{O}_6(a q) \] Suppose you determine that a particular plant consumes \(37.8 \mathrm{~g}\) of \(\mathrm{CO}_2\) in one week. Assuming that there is more than enough water present to react with all of the \(\mathrm{CO}_2\), what mass of glucose (in grams) can the plant synthesize from the \(\mathrm{CO}_2\) ?
= Compound('CO2') CO2
= Compound('H2O') H2O
= Compound('O2') O2
= Compound('C6H1206') C6H12O6
= Reaction(reactants=[CO2, H2O], products=[O2, C6H12O6]) r
r
exex.reaction.core.Reaction(formula='1C₁O₂ + 1H₂O₁ --> 1O₂ + 1C₆H₁₂₀₆', is_balanced=False)
r.balance()
r.formula
'12C₁O₂ + 1206H₂O₁ --> 615O₂ + 2C₆H₁₂₀₆'
= dict(
data = {'mass': '23.1 g', 'temperature': '23 celsius'},
CO2 = {'mass': '31.3 kilogram', 'volume': '31.3 milliliter'},
C6H1206 = {'pressure': '22 atm'},
Environment ={'total_mass': '141.3 kg'}
Reaction )
data
{'CO2': {'mass': '23.1 g', 'temperature': '23 celsius'},
'C6H1206': {'mass': '31.3 kilogram', 'volume': '31.3 milliliter'},
'Environment': {'pressure': '22 atm'},
'Reaction': {'total_mass': '141.3 kg'}}
L(data)
(#4) ['CO2','C6H1206','Environment','Reaction']
data.items()
dict_items([('CO2', {'mass': '23.1 g', 'temperature': '23 celsius'}), ('C6H1206', {'mass': '31.3 kilogram', 'volume': '31.3 milliliter'}), ('Environment', {'pressure': '22 atm'}), ('Reaction', {'total_mass': '141.3 kg'})])
'Reaction'] = None data[
data
{'CO2': {'mass': '23.1 g', 'temperature': '23 celsius'},
'C6H1206': {'mass': '31.3 kilogram', 'volume': '31.3 milliliter'},
'Environment': {'pressure': '22 atm'},
'Reaction': None}
def is_chemical_formulas(x: str) -> bool:
pass
import re
= 'hello' txt
= re.search("([A-Z][a-z]?)(\d*(?:(?:[\.|\,])\d+(?:\%)?)?)|(?:[\(|\[])([^()]*(?:(?:[\(|\[]).*(?:[\)|\]]))?[^()]*)(?:[\)|\]])(\d*(?:(?:[\.|\,]?)\d+(?:\%)?))", txt) x
def extract_data(x):
= x['Reaction'] if 'Reaction' in x else None
reaction = x['Environment'] if 'Environment' in x else None environment
extract_data(data)
{'CO2': {'mass': '23.1 g', 'temperature': '23 celsius'},
'C6H1206': {'mass': '31.3 kilogram', 'volume': '31.3 milliliter'},
'Environment': {'pressure': '22 atm'},
'Reaction': None}
for k, v in data.items():
print(k, v)
CO2 {'mass': '23.1 g', 'temperature': '23 celsius'}
C6H1206 {'mass': '31.3 kilogram', 'volume': '31.3 milliliter'}
Environment {'pressure': '22 atm'}
Reaction {'total_mass': '141.3 kg'}
#L(data).get
#L(data).attrgot()
r.initial_condition(data)