NutMEG.reactor package¶
Subpackages¶
Submodules¶
NutMEG.reactor.reactor module¶
Module to store a reactive environment which we can name, such as methanogenesis at Enceladus.
Holds an environment, composition and series of reactions in which we have an interest. Environmental parameters are in SI units unless otherwise specified.
Most recent changes: database fixes May 2020.
@author P M Higgins
-
class
NutMEG.reactor.reactor.
reactor
(name, env=None, reactionlist={}, composition={}, pH=7.0, workoutID=True, *args, **kwargs)¶ Bases:
object
Class for storing reagents and reactions, and able to perform them.
-
name
¶ name of reactor. Used for database management (table name and LocID)
- Type
str
-
reactionlist
¶ reactions which may be performed in the format {‘reaction eq’ : {type(reaction) : NutMEG.reaction.reaction like}}. This allows for the same reaction to be included twice if we’d like to interpret it in different ways e.g. as a thermodynamic interaction or as a redox reaction.
- Type
dict
-
composition
¶ reagents which can be found in the reactor in the format { ‘reagent name’ : NutMEG.reaction.reagent like}
- Type
dict
-
pH
¶ pH of the reactor, important for some interactions. Default is 7.0
- Type
float, optional
-
ReactIDs
¶ IDs of each reaction in the reactor, for saving to the database.
- Type
tuple
-
env
¶ Local temperature, pressure and volume. Default RTP.
- Type
environment, optional
-
composition_inputs
¶ If there is a net flow of reagents in/out of the reactor, set add them to this dictionary with their name as the key, and rate in M/s as the value.
- Type
dict, kwarg
-
add_reaction
(rxxn, overwrite=False)¶ Add a new reaction rxxn to reactionlist, unifying it with the environment.
Pass overwrite as True if you want to overwrite the data we currently have about the reagents with what you have passed.
-
change_P
(P)¶ Update reactor pressure in Pa
-
change_T
(T)¶ Update reactor temperature in K
-
change_vol
(V)¶ Update reactor volume V in m^3
-
getconcs
()¶ Returns the composition dicionary as a string.
-
perform_reaction
(re_eq, n, re_type=<class 'NutMEG.reaction.reaction.reaction'>)¶ Perform the reaction n molar times.
- Parameters
re_eq (str) – reaction equation as it appears in reactionlist. If this equation is not in reactionlist an error is raised.
n (float) – number of moles of reaction to perform.
re_type (reaction like, optional) – The type of reaction to perform, if it is a subtype of NutMEG.reaction.reaction. Default is NutMEG.reaction.reaction.
-
print_composition
()¶ print a list of the composition
-
print_reactions
()¶ print the list of reaction equations.
-
classmethod
r_from_db
(name, LocID, dbpath='/Users/pete/github2/NutMEG/NutMEG/util/../../NutMEG_db')¶ Extract a reactor from the SQL database at dbpath.
Returns the saved reactor object
- Parameters
name (str) – name of the reactor. Required for table name.
LocID (str) – LocID of the reaactor to extract.
dbpath (str, optional) – location of the database file. Default is NutMEG_db outside the module directory.
-
rlist_from_ReactIDs
(ReactIDs)¶ Set reactionlist from a list of ReactIDs
-
unify_reaction
(rxxn, overwrite=False)¶ Add the reaction and its reagents to the reactor, ensuring there is only one of each reagent type in the reactor.
Returns the reaction after unification
- Parameters
rxxn (NutMEG.reaction.reaction like) – reaction to unify
overwrite (bool) – if True, overwrite the current composition with the activities of the reagents in rxxn. Default is False.
Notes
The reaction passed will end up pointing to the composition of the reactor. Pass overwrite as True to update the values in the composition, False to use the values we already have. If overwrite is False, and the reaction has a reagent which is not in this reactor’s composition, it will be added.
-
update_composition
(t)¶ If there are inflows into the composition, make the changes there would be in time t [s]
-
NutMEG.reactor.reactor_dbhelper module¶
-
class
NutMEG.reactor.reactor_dbhelper.
rdb_helper
(host, dbpath='/Users/pete/github2/NutMEG/NutMEG/util/../../NutMEG_db')¶ Bases:
object
Class from managing how reactors and their attributes are stored in NutMEG’s database. There are three main tables of interest here: Reactor, Reactions and Composition. Each reactor with a unique
name
will also have its own table, in case child classes ofreactor
have their own attributes they want saving.-
host
¶ host reactor to be saving.
- Type
reactor like
-
dbpath
¶ path to the SQL database. If not passed it will be set to the default (NutMEG_db in your working directory). The default can be changed in NutMEG/utils/NuMEGparams.
- Type
str
-
dbdict
¶ Parameters which will be imported into the database.
- Type
dict
-
Composition_db_sqlparams
()¶ Get a dictionary of the values and datatypes to enter into the Composition table.
-
add_to_Composition
()¶ Add the composition of the reactor to the Composition table if it is not already saved. Return the CompID.
-
add_to_Reactions
(rxxn)¶ Add the reaction passed rxxn to the Reactions table if it is not already saved. Return the ReactID of the reaction in the table.
-
createtable
(replace=False)¶ Create a table in the database for this reactor type. If replace is True, delete the old entry.
-
extract_from_Composition
(CompID)¶ Extract the composition with ID CompID, and update the host reactor.
-
extract_from_Reactions
(ReactID, dbdict=None)¶ Extract the data from the database and initialise a new reaction with its parameters.
-
static
from_db
(name, LocID, dbdict={'CompID': ['TEXT', ''], 'Pressure': ['REAL', 0], 'Temperature': ['REAL', 0], 'Volume': ['REAL', 0], 'composition_inputs': ['TEXT', '{}'], 'pH': ['REAL', 0], 'reactions': ['TEXT', '']}, dbpath='/Users/pete/github2/NutMEG/NutMEG/util/../../NutMEG_db')¶ Extract the data from the database and return a dictionary of parameters to initialise the reactor.
-
get_comp_activities
()¶ Return a composition activity dictionary as a string
-
get_db_sqlparams
(dbdict=None)¶ Get the parameters to import into the database as a dictionary. Pass a dbdict as a dictionary if you want to write your own.
-
print_table
()¶ Print out the table containing data for the current host species
-
static
reaction_db_sqlparams
(rxxn)¶ Get a dictionary of the values and datatypes to enter into the Reactions table.
-
to_db
()¶ Send the reactor’s parameters to be stored in the database’s table for this reactor type.
If this reactor is already in the database, reset its LocID to match.
-
update_CompID
()¶
-
update_ReactIDs
()¶ If a new reaction has been added, use this to make sure all the ReactIDs match.
-
update_reactor_db
()¶ Update the Reactor table, which helps point to the reactor type tables.
-
workoutID
(dbdict=None)¶ Find this reactor’s ID from the database, and if there’s no entry create one.
-