VirtualMicrobes.environment package¶
Submodules¶
VirtualMicrobes.environment.Environment module¶
Created on Mar 9, 2014
@author: thocu
-
class
VirtualMicrobes.environment.Environment.
Environment
(params, max_time_course_length=0)[source]¶ Bases:
object
-
cells_grid_diffusion
(diff_rate=None)[source]¶ Cell diffusion on the grid.
- diff_rate : float
- Diffusion rate of cells to neighboring grid points.
-
class_version
= '1.1'¶
-
energy_mols
¶
-
energy_precursors
()[source]¶ Return set of metabolites that are direct precursors for the energy class molecules.
Construct this set by iterating over energy classes and map them to reactions that produce the energy classes.
Returns: Return type: class:OrderedSet
-
expression_grid_data_dict
()[source]¶ Return dictionary of spatial concentration data per metabolite (within cells)
-
external_molecules
¶
-
fluctuate
(time, p_fluct=None, influx_rows=None, influx_cols=None, mols=None, influx_dict=None)[source]¶ Influx fluctuation on the grid.
Sets new influx rates for influxed molecules depending on fluctuation frequency. Influx rates may vary between different sub-environments. Each sub-environment may define its own set of molecules that can be fluxed in.
Parameters: - time (int) – simulation time
- p_fluct (float) – fluctuation frequency per influxed molecule
- influx_rows (iterable) – a sequence of row indices on which molecules are exclusively influxed
- influx_cols (iterable) – a sequence of columnt indices on which molecules are exclusively influxed
- mols (list of :class:`VirtualMicrobes.event.Molecule.Molecule`s) – molecules for which new influx rates should be set
- influx_dict (dict) – mapping from
VirtualMicrobes.event.Molecule.Molecule
to influx rate (float)
-
func_on_grid
(gp_func, rows=None, cols=None)[source]¶ Apply a function to a set of grid points.
The function gp_func should take a
VirtualMicrobes.environment.Environment.Locality
as argument. A subset of grid points are selected by using rows and cols lists. If both rows and cols are given, select gps as a mesh of intersecting rows and cols.Parameters: - gp_func (function) – function on
VirtualMicrobes.environment.Environment.Locality
- rows (iterable) – sequence of indices for grid row selection
- cols (iterable) – sequence of indices for grid column selection
- gp_func (function) – function on
-
init_anabolic_reactions
(nr_anabolic=None, nr_reactants=None, max_products=None, max_path_conversion=None, max_free_energy=None)[source]¶ Initialize the set of anabolic reactions.
Anabolic reactions combine small molecules into larger molecules. If the total free energy of product(s) is larger than that of the substrates, energy molecules will also be consumed in the reaction until reaction is (as) balanced (as possible).
Parameters: - nr_catabolic (int) – number of reactions to generate
- max_products (int) – maximum number of species produced in the reaction
- min_energy (int) – minimum amount of energy produced as energy molecules
- max_path_conversion (int) – maximum nr of reactions producing any molecule species
- max_free_energy (int) – maximum free energy loss from reaction
Returns: Return type: list of
VirtualMicrobes.event.Reaction.Convert
reactions
-
init_catabolic_reactions
(nr_catabolic=None, max_products=None, min_energy=None, max_path_conversion=None)[source]¶ Initialize the set of catabolic reactions.
Catabolic reactions break down large molecules into smaller molecules. If the total free energy of products is lower than that of the substrate, energy molecules will also be produced in the reaction until reaction is (as) balanced (as possible).
Parameters: - nr_catabolic (int) – number of reactions to generate
- max_products (int) – maximum number of species produced in the reaction, excluding energy
- min_energy (int) – minimum amount of energy produced as energy molecules
- max_path_conversion (int) – maximum nr of reactions producing any molecule species
Returns: Return type: list of
VirtualMicrobes.event.Reaction.Convert
reactions
-
init_degradation_dict
(degr_const=None, ene_degr_const=None, bb_degr_const=None, degradation_variance_shape=None)[source]¶ Initialize a global dictionary for degradation rates of molecules in the external environment.
-
init_external_mol_vals_on_grid
(init_conc=None)[source]¶ Initialize concentrations, degradation and influx rates of molecules on the grid.
-
init_global_influx_dict
(influx=None)[source]¶ Initialize a global dictionary for influx rates of molecules in the external environment.
-
init_grid
(verbose=False)[source]¶ Initialize the spatial grid. Set wrapping and barriers on particular neighborhoods.
-
init_influxed_mols
(fraction_influx=None)[source]¶ Select molecules that will be fluxed in in the external environment.
-
init_membrane_diffusion_dict
(diff_const=None, ene_diff_const=None, energy_proportional=None, diff_scaling_func=<function <lambda>>)[source]¶
-
init_microfluid_cycle
()[source]¶ Sets up a list of dictionaries to iterate cycles of fixed external concentrations
-
init_mol_toxicities
(toxicity_avrg=None, toxicity_variance_shape=None, toxic_building_block=None)[source]¶
-
init_mols_to_reactions
()[source]¶ Create dictionaries of reactions, keyed on the molecules procuced and consumed in the reactions.
-
init_sub_envs
(row_divs=None, col_divs=None, partial_influx=None, influx_combinations=None)[source]¶ Initialize sub-environments by dividing up the grid along rows and columns.
Within each subenvironment, influx can change independently. When partial_influx is chosen between 0 and 1, influxed molecules will only appear in a fraction of the subenvironments on the grid.
Parameters: - row_divs (int) – nr of divisions on y-axis
- col_divs (int) – nr of divisions on x-axis
- partial_influx (float) – fraction of molecules that will be influxed in each sub-environment
-
metabolite_internal_grid_data_dict
()[source]¶ Return dictionary of spatial concentration data per metabolite (within cells)
-
molecule_classes
¶
-
mols_per_class_dict
¶
-
pick_mol_class
(weighted_classes, rand_gen=None)[source]¶ Randomly select a molecule class with probability proportional to a weight.
Parameters: - weighted_classes (list of
VirtualMicrobes.event.Molecule.MoleculeClass
, weight (float) tuples) – molecule classes with their respective weights - rand_gen (RNG) – RNG
Returns: the selected class with its energy level and list index
Return type: VirtualMicrobes.event.Molecule.MoleculeClass
, energy, pos index- weighted_classes (list of
-
population_grid_data_dict
(marker_names, marker_select_func)[source]¶ Return a dictionary of spatial distribution of values per marker
Parameters: - marker_names – markers to probe on the grid
- marker_select_func – how to select a marker value
when there are multiple individuals with different values per grid
-
rand_anabolic_reaction_scheme
(resource_classes, energy_classes, product_classes, nr_reactants, max_products, max_free_energy, max_ene_energy=1, rand=None)[source]¶ Construct a random anabolic reaction scheme.
Construction is done by randomly selecting a molecule classes as the substrates of the reaction and than select the molecule classes that will be the product of the reaction. The total energy of reactants ( + energy) >= products.
Parameters: - resource_classes (list of
VirtualMicrobes.event.Molecules.MoleculeClass
) – all resource molecule classes - energy_classes (list of
VirtualMicrobes.event.Molecules.MoleculeClass
) – energy molecule classes - max_products (int) – maximum number of products in reaction scheme
- max_ene_energy (int) – maximum energy level that can be provided by energy metabolites as reaction substrate
Returns: Return type: reaction scheme tuple ( list of reactants, list of products, stoichiometries
- resource_classes (list of
-
rand_catabolic_reaction_scheme
(substrate_classes, product_classes, energy_classes, max_products, min_energy, rand_gen=None)[source]¶ Construct a random catabolic reaction scheme.
Typically a catabolic reaction breaks down a large, energy rich molecule into smaller molecules. Energy molecules may be produced in this reaction.
Construction is done by randomly selecting a molecule class as the substrate of the reaction and than select the molecule classes that will be the product of the reaction. The total energy of reactants = products (+ energy).
Parameters: - substrate_classes (list of
VirtualMicrobes.event.Molecules.MoleculeClass
) – all resource molecule classes - product_classes (list of
VirtualMicrobes.event.Molecules.MoleculeClass
) – molecule classes that can be products of the reaction - energy_classes (list of
VirtualMicrobes.event.Molecules.MoleculeClass
) – energy molecule classes - max_products (int) – maximum number of products in reaction scheme
- min_energy (int) – minimum yield in energy metabolites
Returns: Return type: reaction scheme tuple ( list of reactants, list of products, stoichiometries
- substrate_classes (list of
-
reactions_dict
¶
-
reset_grid_influx
()[source]¶ Reinitialize the global infux dict and the per sub environment influx rates.
-
resource_combis_within_energy
(resource_classes, nr, total_energy)[source]¶ Return combinations of resource classes that have exactly a total sum in energy values.
Parameters: - resource_classes (set of :class:`VirtualMicrobes.event.Molecules.MoleculeClass`s) – the set to make combinations from
- nr (int) – number of MCs to combine
- total_energy (int) – the sum of energy values that MCs should have
Returns: Return type: combinations of MCs
-
select_building_blocks
(nr_bb, mol_classes, substrate_weight_function=<function <lambda>>, weight_scaling=2, rand_gen=None)[source]¶
-
start_concentration_dict
(init_conc=None, init_conc_dict=None, no_influx_conc=1e-20)[source]¶ Make dictionary of start concentrations for external molecules.
If the init_conc is not given, start with a concentration that is the equilibrium value based on influx and degradation rates of the metabolite.
Parameters: init_conc –
-
sub_envs_influx_combinations
(richest_first=True)[source]¶ Assign a subset of all influxed molecules per individual sub-environment.
Parameters: fract (float) – fraction of subenvironments where a molecule is fluxed in
-
sub_envs_partial_influx
(fract)[source]¶ Assign a subset of all influxed molecules per individual sub-environment.
Parameters: fract (float) – fraction of subenvironments where a molecule is fluxed in
-
subgrids_gen
(row_divs=1, col_divs=1)[source]¶ Generate partitions of the grid.
Partitions are constructed from the product of row-chunks and column- chunks, such that the grid is divided (approximately) equally according to the number of row- and column divisions.
Parameters: - row_divs (int) – number of divisions in the row dimension
- col_divs (int) – number of divisions in the column dimension
Yields: iterable of ‘(row_nrs, col_nrs)’ partitions of the grid
-
-
class
VirtualMicrobes.environment.Environment.
Locality
(params, internal_molecules, influx_reactions, degradation_reactions, env_rand, max_time_course_length=0)[source]¶ Bases:
object
-
class_version
= '1.0'¶
-
init_time_courses
(length=None)[source]¶ initialize an array to hold time course data of molecules
Parameters: new_max_time_points – max number of time points
-
map_cell_gene_products
(cell)[source]¶ The mapping is a dictionary of dictionaries; in this way, it is possible to recognize the same protein in the two different cells as two separate variables. (see also map_external_molecules)
Parameters: start_index –
-
map_external_molecules
()[source]¶ Mapping of the small molecules to indexes for use in the C integrator. The map is an initially empty dictionary. The first level of indexing is the container , while the second level is the molecules (type) . The container can be a cell or it can be the environment. (see also map_variables)
Parameters: start_index –
-
map_variables
()[source]¶ Setup of the mapping of variables in the system to indexes used by the C encoded integrator part of the simulation:
- small molecules (metabolites, toxins, resources)
- gene products
In practice we start with an empty dictionary and let ‘system’ map molecules and gene products sepselfarately, creating the indexes on the go and reporting back on the last selfused index.
-
tp_index
¶
-
VirtualMicrobes.environment.Grid module¶
Created on Nov 3, 2014
@author: thocu
-
class
VirtualMicrobes.environment.Grid.
Grid
(rows, cols, neighborhood_dict=None, nei_wrapped_ew=None, nei_wrapped_ns=None)[source]¶ Bases:
object
Grid will by default be wrapped, because the Neighborhood will index
-
as_numpy_array
¶
-
columns_iter
(cols, order='tb_lr')[source]¶ Iterate over gps in the selected columns :param cols: selected columns :param order: the order in which gps should be iterated
-
content_iter
¶
-
disconnect_direction
(gp, area, neighborhood)[source]¶ For all neighboring grid points lieing in a particular direction in a named neighborhood of a grid point gp, remove the gp coordinate from their neighborhoods.
e.g. if area is ‘south’ , the southern neighbors of gp will remove gp’s relative coordinate from their neighborhood
Parameters: - gp (
GridPoint
) – Grid point that will get unwrapped. - direction ({'north', 'south', 'east', 'west'}, optional) – The direction relative to the gp.
- neighborhood (str) – named neighborhood for which the unwrapping is done
- gp (
-
gp_iter
¶
-
grid_barriers
(rand_gen, p_row=0.0, pos_row=None, max_fraction_width=None, p_col=0.0, pos_col=None, max_fraction_height=None, neighborhoods=None)[source]¶ Set up barriers in the grid
Parameters: - p_row –
- max_fraction_width –
- p_col –
- max_fraction_height –
- neighborhood –
- rand_gen –
-
make_barrier
(start_coord, length, neighborhood_name, direction='lr')[source]¶ Create a barrier on the grid where interaction between adjacent grid points is blocked.
Create a barrier in the given neighborhood_name by unwrapping gps on opposite sides of a line that is length long, starts at start_gp and extends along direction
-
mesh_iter
(rows, cols, order='lr_tb')[source]¶ iterate over gps in a mesh, defined by intersections of rows and cols
-
normalize_coord
(coord)[source]¶ Transform coordinate coord to an absolute grid coordinate with non- wrapped index.
Applies modulo
cols
androws
on the coordinates x and y value, respectively, to obtain a normalized coordinate.Parameters: coord ( VirtualMicrobes.my_tools.utility.Coord
) – a coordinate on the grid that may be in wrapped index representationReturns: Return type: VirtualMicrobes.my_tools.utility.Coord
-
unwrap_ew
(neighborhood_name)[source]¶ Unwraps a grid neighborhood at its eastern and western borders.
Iterate over all grid points and detect when a grid point has neighbors that wrap over the east or west borders. Then remove the coordinate from the neighborhood.
Parameters: neighborhood_name (str) – The name of the neighborhood to unwrap Notes
For a wrapped neighbor it is true that the difference between the focal gp coordinate and this neighbors (normalized) grid-coordinate is not equal to the its relative-coordinate (to focal gp).
See also
-
unwrap_ns
(neighborhood_name)[source]¶ Unwraps a grid neighborhood at its northern and southern borders.
Iterate over all grid points and detect when a grid point has neighbors that wrap over the north or south borders. Then remove the coordinate from the neighborhood.
Parameters: neighborhood_name (str) – The name of the neighborhood to unwrap Notes
For a wrapped neighbor it is true that the difference between the focal gp coordinate and this neighbors (normalized) grid-coordinate is not equal to the its relative-coordinate (to focal gp).
See also
-
-
class
VirtualMicrobes.environment.Grid.
GridPoint
[source]¶ Bases:
object
-
content
¶
-
coord
¶
-
get_neighbor_at
(rel_coord, neighborhood_name)[source]¶ Get neighboring grid point at a relative coordinate.
Parameters: - rel_coord (
VirtualMicrobes.my_tools.utility.Coord
) – coordinate relative to self - neighborhood_name (str) – Name of the neighborhood.
Returns: The neighboring grid point.
Return type: - rel_coord (
-
nei_rel_coord_to_gp
(neighborhood_name, area=None)[source]¶ List of (relative-coordinate,grid-point) tuples of the named neighborhood.
Parameters: - neighborhood_name (str) – Name of the neighborhood
- area ({'north', 'south', 'east', 'west'}, optional) – Select only neighbors lying in a specific area.
Returns: Return type: list of (
VirtualMicrobes.my_tools.utility.Coord
,GridPoint
) tuples
-
nei_rel_to_grid_coords
(neighborhood_name, area=None)[source]¶ List of (relative-coordinate, grid-coordinate) tuples of the named neighborhood.
Parameters: - neighborhood_name (str) – Name of the neighborhood
- area ({'north', 'south', 'east', 'west'}, optional) – Select only neighbors lying in a specific area
Returns: Return type: list of (
VirtualMicrobes.my_tools.utility.Coord
,VirtualMicrobes.my_tools.utility.Coord
) tuples
-
neighbor_gps
(neighborhood_name, area=None)[source]¶ Return list of grid points in a named neighborhood.
Parameters: - neighborhood_name (str) – Name of the neighborhood.
- area ({'north', 'south', 'east', 'west'}, optional) – Select only neighbors lying in a specific area.
- """ –
-
neighbors
(neighborhood_name, area=None)[source]¶ Return list of grid point content values of neighbors in named neighborhood.
Parameters: - neighborhood_name (str) – Name of the neighborhood.
- area ({'north', 'south', 'east', 'west'}, optional) – Select only neighbors lying in a specific area.
-
pos
¶
-
random_neighbor
(neighborhood_name, rand_gen, area=None)[source]¶ Get random neighbor from a named neighborhood.
Parameters: - neighborhood_name (str) – Name of the neighborhood.
- rand_gen (random generator) – Random generator for neighbor drawing.
- area ({'north', 'south', 'east', 'west'}, optional) – Select only neighbors lying in a specific area.
-
remove_neighbor_at
(rel_coord, neighborhood_name)[source]¶ Remove a coordinate from a named neighborhood.
After removing the relative coordinate rel_coord, the corresponding grid point is no longer considered a neighbor of self when applying neighborhood functions.
Parameters: - rel_coord (
VirtualMicrobes.my_tools.utility.Coord
) – Coordinate relative to self. - neighborhood_name (str) – Name of the neighborhood.
- rel_coord (
-
updated
¶
-
-
class
VirtualMicrobes.environment.Grid.
Neighborhood
(neighbors)[source]¶ Bases:
object
Neighborhood as grid indices (x,y coord tuples) relative to a focal gridpoint.
-
get_rel_coords
(area=None)[source]¶ Return a list of neighborhood coordinates that lie in an area of the compass relative to (0,0)
Parameters: area ({'north', 'south', 'east', 'west'}) – The named area (or ‘hemisphere’) in grid space relative to the origin (0,0). Notes
|________________________________________|
Returns: The coordinates that lie within the named area. Return type: list of :class:`VirtualMicrobes.my_tools.utility.Coord`s
-
has_coord
(rel_coord)[source]¶ Check that relative coordinate is part of this neighborhood.
Parameters: rel_coord ( VirtualMicrobes.my_tools.utility.Coord
) –
-
remove_coord
(remove_coord)[source]¶ Remove a relative coordinate from the neighborhood.
Parameters: remove_coord ( VirtualMicrobes.my_tools.utility.Coord
) –
-
remove_direction
(direction)[source]¶ Remove coordinates lying to the given direction on the grid, where the main compass points are translated into coordinates as follows:
- The main compass points are translated into coordinates as follows:
- N (0, 1)
- W E (-1,0) (1,0)
- S (0,-1)
e.g. when direction is ‘north’, all relative coordinates that lie northerly of the (0,0) will be removed.
Parameters: direction ({'north', 'south', 'east', 'west'}, optional) – Selects those coordinates in the neighborhood that lie in a particular direction (default is None, which implies returninng all coordinates.
-