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\) ?

CO2 = Compound('CO2')
H2O = Compound('H2O')
O2 = Compound('O2')
C6H12O6 = Compound('C6H1206')
r = Reaction(reactants=[CO2, H2O], products=[O2, C6H12O6])
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₁₂₀₆'
data = dict(
    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'}
)
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'})])
data['Reaction'] = None
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
txt = 'hello'
x = re.search("([A-Z][a-z]?)(\d*(?:(?:[\.|\,])\d+(?:\%)?)?)|(?:[\(|\[])([^()]*(?:(?:[\(|\[]).*(?:[\)|\]]))?[^()]*)(?:[\)|\]])(\d*(?:(?:[\.|\,]?)\d+(?:\%)?))", txt)
def extract_data(x):
    reaction = x['Reaction'] if 'Reaction' in x else None
    environment = x['Environment'] if 'Environment' in x else None
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)