def extract_from_Composition(self, CompID): """Extract the composition with ID CompID, and update the host reactor. """ db = sqlite3.connect(self.dbpath) cursor = db.cursor() try: cursor.execute("SELECT * FROM Composition WHERE CompID = ?", (CompID,)) params = cursor.fetchone() Comp = ast.literal_eval(params[1]) pH = params[2] except: db.close() finally: db.close() fullcomp = {} for k, v in Comp.items(): temp_reagent = rxn.reagent(k, self.host.env, phase=rxn.reagent.get_phase_str(k), conc=v, activity=v) fullcomp[temp_reagent.name] = temp_reagent # include H+ H = rxn.reagent('H+', self.host.env, charge=1, conc=10**-pH, phase='aq', activity=10**-pH) fullcomp[H.name] = H self.host.composition.update(fullcomp)
def setup_sulfatereduction(R, k_RTP=1): """ Set up a sulate reduction reaction to pass to the sulfate reducer as its metabolism. Use the reactor R.""" # set up reagents. No need for composition as that is saved in the reactor. H2aq = reaction.reagent('H2(aq)', R.env, phase='aq') SO4 = reaction.reagent('SO4--', R.env, phase='aq', charge=-2) H = reaction.reagent('H+', R.env, phase='aq', charge=1) HS = reaction.reagent('HS-', R.env, phase='aq', charge=-1) H2O = reaction.reagent('H2O(l)', R.env, phase='l') # put reagents into a reaction. Dictionary values are the molar ratios. thermalSR = reaction.reaction({ H2aq: 4, SO4: 1, H: 1 }, { HS: 1, H2O: 4 }, R.env) # not important for this code, but a rate constant is required # to set up an organism in NutMEG. thermalSR.rate_constant_RTP = k_RTP return thermalSR
def initial_conditions(self, H2ppm, HSact=1e-10, setupcomp=True, addreaction=True): """ Set up a basic configuration, with pH 0 sulfuric acid droplet and dissolved H2. H2ppm : float H2 parts per million in the atmosphere around the droplet. HSact : float HS activity to use. Default is 1e-10 setupcomp : bool Whether to set up the standard composition. Default True addreaction : bool Whether to include sulfate reduction in the reactionlist """ if setupcomp: mol_H2 = VenusDrop.getgasconc('H2(aq)', self.env.P*H2ppm/(1e6), self.env.T, P_bar=self.env.P) mol_SO4 = 0.5 # assume fully dissoiated at pH 0 (from H2SO4) mol_H = 1.0 # pH zero mol_HS = HSact #? don't know, let's assume biogenic only. SO4 = reaction.reagent('SO4--', self.env, phase='aq', charge=-2, conc=mol_SO4, activity=mol_SO4) H2 = reaction.reagent('H2(aq)', self.env, phase='aq', conc=mol_H2, activity=mol_H2) H = reaction.reagent('H+', self.env, phase='aq', charge=1, conc=mol_H, activity=mol_H) HS = reaction.reagent('HS-', self.env, phase='aq', charge=-1, conc=HSact, activity=HSact) H2O = reaction.reagent('H2O(l)', self.env, phase='l', conc=55.5, phase_ss=True, activity=1) # add these reagents to the composition of the VenusDrop self.composition.update({H2.name:H2, SO4.name:SO4, H.name:H, H2O.name:H2O, HS.name:HS}) self.pH = -math.log10((self.composition['H+'].activity)) if addreaction: # put together an overall reaction fro sulfate reduction r = {self.composition['H2(aq)']:4, self.composition['SO4--']:1, self.composition['H+']:1} p = {self.composition['HS-']:1, self.composition['H2O(l)']:4} thermaloa = reaction.reaction(r,p,self.env) # add this reaction to the VenusDrop reactor. self.add_reaction(thermaloa, overwrite=True)
def setup_methanogenesis(R, k_RTP=1): """ Set up a methanogenesis reaction to pass to the methanogen as its metabolism. Use the reactor R.""" # set up reagents. No need for composition as that is saved in the reactor. H2aq = reaction.reagent('H2(aq)', R.env, phase='aq') H2O = reaction.reagent('H2O(l)', R.env, phase='l') CO2 = reaction.reagent('CO2(aq)', R.env, phase='aq') CH4 = reaction.reagent('CH4(g)', R.env, phase='aq') # put reagents into a reaction. Dictionary values are the molar ratios. thermalSR = reaction.reaction({CO2: 1, H2aq: 4}, {CH4: 1, H2O: 2}, R.env) # not important for this code, but a rate constant is required # to set up an organism in NutMEG. thermalSR.rate_constant_RTP = k_RTP return thermalSR
def extract_from_Reactions(self, ReactID, dbdict=None): """ Extract the data from the database and initialise a new reaction with its parameters. """ # self.reaction_db_sqlparams(dbdict=dbdict) db = sqlite3.connect(self.dbpath) cursor = db.cursor() try: # extract all the data in alphabetical order by column names. # sloght fudge here because we only need the keys from # reaction_db_sqlparams tempdict = {'Type':['TEXT',0], 'equation':['TEXT',0], 'reactants':['TEXT',0], 'products':['TEXT',0]} cursor.execute(sqlsc.SELECTcolumns('Reactions', tempdict, 'ReactID'), (ReactID,)) Params = cursor.fetchone() except: raise finally: db.close() for k, nv in zip(sorted(tempdict.keys()), Params): tempdict[k] = [tempdict[k][0], nv] # now rebuild a reaction from this data # concentrations are zero for now, once in reactor they will be # unified with its composition. reactants, products = {}, {} if tempdict['Type'][1] == str(rxn.reaction): for k, v in ast.literal_eval(tempdict['reactants'][1]).items(): temp_reagent = rxn.reagent(k, self.host.env, phase=rxn.reagent.get_phase_str(k)) reactants[temp_reagent] = v for k, v in ast.literal_eval(tempdict['products'][1]).items(): temp_reagent = rxn.reagent(k, self.host.env, phase=rxn.reagent.get_phase_str(k)) products[temp_reagent] = v return rxn.reaction(reactants, products, self.host.env) else: raise IntegrityError('NutMEG is not set up to recover this ' + \ 'type of reaction from the database yet!')
def setup_methanogenesis(self, R): """return a methanogenesis reaction object in reactor R""" CO2 = reaction.reagent('CO2(aq)', R.env, phase='aq') H2aq = reaction.reagent('H2(aq)', R.env, phase='aq') CH4aq = reaction.reagent('CH4(g)', R.env, phase='g') H2O = reaction.reagent('H2O(l)', R.env, phase='l') thermalMG = reaction.reaction({ CO2: 1, H2aq: 4 }, { CH4aq: 1, H2O: 2 }, R.env) thermalMG.rate_constant_RTP = self.k_RTP # default is the one we calculated base on methanogens (LB3 pg 11) return thermalMG
def setup_sulfatereduction(R, k_RTP=0.0001): """Create a simple sulfate reduction reaction as a standard thermodynamic reaction inside reactor R. The reagents have no special properties, we can add those later """ H2aq = reaction.reagent('H2(aq)', R.env, phase='aq') SO4 = reaction.reagent('SO4--', R.env, phase='aq', charge=-2) H = reaction.reagent('H+', R.env, phase='aq', charge=1) HS = reaction.reagent('HS-', R.env, phase='aq', charge=-1) H2O = reaction.reagent('H2O(l)', R.env, phase='l') # the overall reaction is 4H2 + SO4(2-) + H(+) -> HS(-) + 4H2O thermalSR = reaction.reaction({H2aq:4, SO4:1, H:1}, {HS:1, H2O:4}, R.env) # we need to manually set the RTP rate constant for use in biochemistry thermalSR.rate_constant_RTP = k_RTP return thermalSR
def setup_methanogenesis(R, k_RTP=0.0001): """Create a simple methanogenesis reaction as a standard thermodynamic reaction inside reactor R. The reagents have no special properties, we can add those later """ # introduce some reagents CO2 = reaction.reagent('CO2(aq)', R.env, phase='aq') H2aq = reaction.reagent('H2(aq)', R.env, phase='aq') CH4aq = reaction.reagent('CH4(g)', R.env, phase='g') H2O = reaction.reagent('H2O(l)', R.env, phase='l') # the overall reaction is CO2 + 4H2 -> CH4 + 2H2O thermalMG = reaction.reaction({CO2:1, H2aq:4}, {CH4aq:1, H2O:2}, R.env) # we need to manually set the RTP rate constant for use in biochemistry thermalMG.rate_constant_RTP = k_RTP return thermalMG
def initial_conditions(R, comp={}): """Set up the reactor R to use by populating it with reagents. To change the concentrations used pass then in the dict comp in the format {Name : conc} """ # metabolic concentrations mol_CO2 = comp.pop('CO2(aq)', 0.001) mol_CH4 = comp.pop('CH4(g)', 1e-7) mol_H2 = comp.pop('H2(aq)', 0.001) mol_SO4 = comp.pop('SO4--', 0.001) mol_HS = comp.pop('HS-', 1e-7) # life also needs a source of N and P mol_NH3 = comp.pop('NH3(aq)', 0.1) mol_H2PO4 = comp.pop('H2PO4-', 0.1) # concentration of H is tied to pH. mol_H=10**(-R.pH) # now set up as reagents CO2 = reaction.reagent('CO2(aq)', R.env, phase='aq', conc=mol_CO2, activity=mol_CO2) H2aq = reaction.reagent('H2(aq)', R.env, phase='aq', conc=mol_H2, activity=mol_H2) CH4aq = reaction.reagent('CH4(g)', R.env, phase='g', conc=mol_CH4, activity=mol_CH4) H2O = reaction.reagent('H2O(l)', R.env, phase='l', conc=55.5, activity=1, phase_ss=True) H = reaction.reagent('H+', R.env, charge=1, conc=mol_H, phase='aq', activity=mol_H) SO4 = reaction.reagent('SO4--', R.env, phase='aq', charge=-2, conc=mol_SO4, activity= mol_SO4) HS = reaction.reagent('HS-', R.env, phase='aq', charge=-1, conc=mol_HS, activity=mol_HS) # add these to the composition of R. This will be shared between # the organisms R.composition = {CO2.name:CO2, H2aq.name:H2aq, CH4aq.name:CH4aq, H2O.name:H2O, H.name:H, SO4.name:SO4, HS.name:HS} # add in the extra nutrients R.composition['NH3(aq)'] = reaction.reagent('NH3(aq)', R.env, phase='aq', conc=mol_NH3, activity=mol_NH3) R.composition['H2PO4-'] = reaction.reagent('H2PO4-', R.env, phase='aq', conc=mol_H2PO4, activity=mol_H2PO4)
def build_ATP_reaction(self, celldata): """Create a reaction object describing the formation of ATP using cell parameters. celldata is in the form [activity ADP, activity P, activity ATP, pH] """ ADP = rxn.reagent('+H3ADP1-(aq)', self.locale.env, activity=celldata[0], phase='aq') P = rxn.reagent('H3PO4(aq)', self.locale.env, activity=celldata[1], phase='aq') ATP = rxn.reagent('+H4ATP-(aq)', self.locale.env, activity=celldata[2], phase='aq') #H = reaction.reagent('H+', self.env, activity=(10**-celldata[3]), # phase='aq', molar_ratio=2.) H2O = rxn.reagent('H2O(l)', self.locale.env, phase='l', conc=55.5, phase_ss=True, activity=1.0) self.ATP_production = rxn.reaction({ ADP: 1, P: 1 }, { ATP: 1, H2O: 1 }, self.locale.env) self.ATP_production.rto_current_env() self.ATP_production.update_molar_gibbs_from_quotient( updatestdGibbs=False) self.G_P = self.ATP_production.molar_gibbs
def update_reagent(self, name, ppm): """ Update the concentration of a specific reagent based on its atmospheric ppm name : str Name of the reagent to update ppm : float atmospheric concentration to use """ mol_r = VenusDrop.getgasconc(name, self.env.P*ppm/(1e6), self.env.T, P_bar=self.env.P) r = reaction.reagent(name, self.env, phase='aq', charge=0, conc=mol_r, activity=mol_r) self.composition.update({r.name:r})
def initial_conditions(self, R, scale=1.0, NH3conc=0.1, H2Sconc=0.1, setupcomp=True): """ set up the reactor by filling it with reagents and adding methanogeneis. scale : float scale by which to change the activity of CO2 and H2, if desired. NH3conc : float concentration of NH3 to put into the reactor H2Sconc : float concentration of H2S to put into the reactor. setupcomp : boolean True to set up the composition as well as the reaction. False to just add a methanogenesis reaction. """ if setupcomp: mol_CO2 = self.params['mol_CO2'] * scale #LB3 pg11 mol_CH4 = self.params['mol_CH4'] mol_H2 = self.params['mol_H2'] * scale Pconc = self.params['Pconc'] mol_H = 10**(-R.pH) # reagents CO2 = reaction.reagent('CO2(aq)', R.env, phase='aq', conc=mol_CO2, activity=mol_CO2) H2aq = reaction.reagent('H2(aq)', R.env, phase='aq', conc=mol_H2, activity=mol_H2) CH4aq = reaction.reagent('CH4(g)', R.env, phase='g', conc=mol_CH4, activity=mol_CH4) H2O = reaction.reagent('H2O(l)', R.env, phase='l', conc=55.5, phase_ss=True) # el = reaction.reagent('e-', self.env, charge=-1) H = reaction.reagent('H+', R.env, charge=1, conc=mol_H, phase='aq', activity=mol_H) R.composition = { CO2.name: CO2, H2aq.name: H2aq, CH4aq.name: CH4aq, H2O.name: H2O, H.name: H } # add in CHNOPS, in elemental form for now # we already have C in the form of CO2 and CH4 R.composition['NH3(aq)'] = reaction.reagent('NH3(aq)', R.env, phase='aq', conc=NH3conc, activity=NH3conc) # P and S we dont actually know, so let's arbitrarily say 1 micromole R.composition['P(aq)'] = reaction.reagent('P(aq)', R.env, phase='aq', conc=Pconc, activity=Pconc, thermo=False) R.composition['H2S(aq)'] = reaction.reagent('H2S(aq)', R.env, phase='aq', conc=H2Sconc, activity=H2Sconc, thermo=False) el = reaction.reagent('e-', R.env, charge=-1) # overall r = {R.composition['CO2(aq)']: 1, R.composition['H2(aq)']: 4} p = {R.composition['CH4(g)']: 1, R.composition['H2O(l)']: 2} thermaloa = reaction.reaction(r, p, R.env) R.add_reaction(thermaloa)
def initial_conditions(self, pH, mol_CO2, Pconc, H2Oact=1.0, oceanvals=False, mol_CO2_oc=None): """ Set up the initial conditions of the ocean in the configuration defined in the initialisation. Attributes ---------- pH : float wider ocean (273 K) pH mol_CO2 : float Calculated activity of CO2 at this ocean location. Pconc : ufloat Concentration of phosphorus H2Oact : float, optional water activity, default 1.0. oceanvals : boolean, optional whether computing the wider ocean CO2 activity is needed. mol_CO2_oc : float, optional wider ocean CO2 activity. Default is None (then calculated here) """ if mol_CO2_oc == None: mol_CO2_oc = mol_CO2 if oceanvals: #get wider ocean CO_2 mol_CO2_oc = Enceladus.get_CO2_from_HTHeating(T=273.15, pH=pH)[0] mol_CH4 = (self.mixingratios['CH4']/self.mixingratios['CO2'])*mol_CO2_oc#2.75*mol_CO2 #0.34*mol_CO2 mol_H2 = (self.mixingratios['H2']/self.mixingratios['CO2'])*mol_CO2_oc#11*mol_CO2 #103*mol_CO2 mol_NH3 = (self.mixingratios['NH3']/self.mixingratios['CO2'])*mol_CO2_oc mol_H2S = (self.mixingratios['H2S']/self.mixingratios['CO2'])*mol_CO2_oc # ^ from the ratios in the plumes, hence are upper limits mol_H=uf(10**(-pH),0) if self.nominals: mol_CH4 = mol_CH4.n mol_H2 = mol_H2.n mol_NH3 = mol_NH3.n mol_H2S = mol_H2S.n mol_H=uf(10**(-pH),0).n # reagents CO2 = reaction.reagent('CO2(aq)', self.env, phase='g', conc=mol_CO2, activity=mol_CO2) H2aq = reaction.reagent('H2(aq)', self.env, phase='aq', conc=mol_H2, activity=mol_H2) CH4aq = reaction.reagent('Methane(aq)', self.env, phase='g', conc=mol_CH4, activity=mol_CH4) H2O = reaction.reagent('H2O(l)', self.env, phase='l', conc=uf(55.5, 0), activity=uf(H2Oact,0)) el = reaction.reagent('e-', self.env, charge=-1) H = reaction.reagent('H+', self.env, charge=1, conc=mol_H, phase='aq', activity=mol_H) self.composition = {CO2.name:CO2, H2aq.name:H2aq, CH4aq.name:CH4aq, H2O.name:H2O, H.name:H} # overall r = {self.composition['CO2(aq)']:1, self.composition['H2(aq)']:4} p = {self.composition['Methane(aq)']:1, self.composition['H2O(l)']:2} thermaloa = reaction.reaction(r,p,self.env) # redox fr = {self.composition['CO2(aq)']:1, self.composition['H+']:8, el:8} fp = {self.composition['Methane(aq)']:1, self.composition['H2O(l)']:2} fwd = reaction.redox_half(fr, fp, self.env, 8, -0.244) rr = {self.composition['H+']:8, el:8} rp = {self.composition['H2(aq)']:4} # E ref: Karp, Gerald, Cell and Molecular Biology, 5th Ed., Wiley, 2008 rvs = reaction.redox_half(rr, rp, self.env, 8, -0.421) # redox cell reaction is thermal overall rx = reaction.redox(fwd, rvs, thermaloa, 8, self.env) self.reactionlist = {thermaloa.equation:{type(thermaloa):thermaloa, type(rx):rx}} # add in CHNOPS, in elemental form for now # we already have C in the form of CO2 and CH4 self.composition['NH3(aq)'] = reaction.reagent('NH3(aq)', self.env, phase='aq', conc=mol_NH3, activity=mol_NH3) # from Glein, Baross, Waite 2015 # P and S we don't actually know. self.composition['P(aq)'] = reaction.reagent('P(aq)', self.env, phase='aq', conc=Pconc, activity=Pconc, thermo=False) self.composition['H2S(aq)'] = reaction.reagent('H2S(aq)', self.env, phase='aq', conc=mol_H2S, activity=mol_H2S, thermo=False)