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

add_new_cells_to_grid(cell_gp_dict)[source]
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'
clear_dead_cells_from_grid()[source]
clear_mol_time_courses()[source]
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
find_reaction(match_string)[source]

Returns reaction that matches stringrepr.

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:
grid_data_from_func(func)[source]
grid_toggle_update(updated=False)[source]
influx_change_gamma(influx, variance_fact, upper=None, lower=None)[source]
influx_change_range(param_space)[source]
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_class_conversions(fraction_reactions)[source]
init_degradation()[source]
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_diffusion()[source]
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_influx()[source]
init_influxed_mols(fraction_influx=None)[source]

Select molecules that will be fluxed in in the external environment.

init_localities(number_localities, max_time_course_length=0, params_dict=None)[source]
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_class_sizes()[source]
init_mol_classes()[source]
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_reaction_universe()[source]
init_reactions()[source]
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
init_transports()[source]
map_variables()[source]
metabolite_grid_data_dict()[source]

Return dictionary of spatial concentration data per metabolite

metabolite_internal_grid_data_dict()[source]

Return dictionary of spatial concentration data per metabolite (within cells)

microfluid_chemostat(run_time=None)[source]
mix_metabolites(verbose=False)[source]

Mixes all metabolites over the grid perfectly

molecule_classes
mols_per_class_dict
perfect_mix(verbose=False)[source]

Perfect mix shuffles all gps

pick_mol_class(weighted_classes, rand_gen=None)[source]

Randomly select a molecule class with probability proportional to a weight.

Parameters:
Returns:

the selected class with its energy level and list index

Return type:

VirtualMicrobes.event.Molecule.MoleculeClass, energy, pos index

populate_localities(population)[source]
population_grid_data(data_func)[source]
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

population_grid_neighborhood_data(neighborhood_pop_func, neighborhood='competition')[source]
print_state()[source]
print_values()[source]
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

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

reactions_dict
reset_grid_concentrations(conc=None)[source]
reset_grid_influx()[source]

Reinitialize the global infux dict and the per sub environment influx rates.

reset_locality_updates()[source]
resize_time_courses(new_max_time_points)[source]
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]
set_mol_concentrations_from_time_point()[source]
set_tot_volume()[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

update_cells_on_grid(cell_gp_dict)[source]
update_localities()[source]
update_reaction_universe(path)[source]

Updates reaction universe by adding newly added molecules and reactions to the environment. Does NOT support the removal of metabolites / reactions, as this will often be very artificial for cells that are still using them.

update_volume(volume=None)[source]
upgrade()[source]

Upgrading from older pickled version of class to latest version. Version information is saved as class variable and should be updated when class invariants (e.g. fields) are added.

class VirtualMicrobes.environment.Environment.Locality(params, internal_molecules, influx_reactions, degradation_reactions, env_rand, max_time_course_length=0)[source]

Bases: object

add_cell(cell)[source]
add_small_molecule(mol, concentration=0.0)[source]
class_version = '1.0'
clear_locality()[source]

Clear the cells in this locality.

clear_mol_time_courses()[source]
get_cells()[source]
get_expression_level(rea, exporting=False)[source]
get_gene_prod_conc(gene)[source]
get_internal_mol_conc(mol)[source]
get_mol_concentration_dict()[source]

Get molecule concentration dictionary

get_mol_influx_dict()[source]

Get influx dictionary from locality dictionary

get_mol_per_class_concentration_dict()[source]
get_mol_per_class_influx_dict()[source]
get_mol_time_course_dict(max_tp=None)[source]

Get time course of molecule

get_small_mol_conc(mol)[source]
init_external_mols(conc=None)[source]
init_mol_time_course(mol_struct, length=None)[source]
init_mol_views()[source]

Sets alias to molecules in locality (QoL implementation)

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
init_variables_map()[source]
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_cell_internal_mols(cell)[source]
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.

remove_cell(cell)[source]
resize_time_courses(new_max_time_points)[source]
set_gene_prod_conc(gene, conc)[source]
set_mol_concentrations_from_time_point()[source]
set_small_mol_conc(mol, val)[source]
spill_dead_cell_contents(cell, prod_as_bb=None, factor=None)[source]
tp_index
update_small_mol_concentrations(concentration_dict)[source]
update_small_mol_degradation_rates(degradation_dict)[source]
update_small_mol_influxes(influx_dict, no_influx=1e-20)[source]
upgrade()[source]

Upgrading from older pickled version of class to latest version. Version information is saved as class variable and should be updated when class invariants (e.g. fields) are added.

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
dummy()[source]
fill_grid(vals, order='lr_tb')[source]
get_gp(x, y)[source]
get_nei_gp(gp, direction_vect)[source]
gp_iter
gp_iter_in_order(order='lr_tb')[source]
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
init_grid(rows, cols, neighborhood_dict, wrap_ew=None, wrap_ns=None)[source]
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 and rows 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 representation
Returns:
Return type:VirtualMicrobes.my_tools.utility.Coord
perfect_mix(rand_gen)[source]
rows_iter(rows, order='lr_tb')[source]

Iterate over gps in the selected rows

set_gp(x, y, gp)[source]
swap_content(gp1, gp2)[source]
swap_gps(gp1, gp2)[source]
swap_pos(pos1, pos2)[source]
toggle_gps_updated(updated=False)[source]
un_neighbor(gp, nei_rel_coord, neighborhood)[source]
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).

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).

update_gp(x, y, val)[source]
exception VirtualMicrobes.environment.Grid.GridError(value)[source]

Bases: exceptions.Exception

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:

GridPoint

nei_grid_coords(neighborhood_name, area=None)[source]
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.
updated
class VirtualMicrobes.environment.Grid.Neighborhood(neighbors)[source]

Bases: object

Neighborhood as grid indices (x,y coord tuples) relative to a focal gridpoint.

construct_moore_n(perim=1, exclude_self=True)[source]
construct_named_neighborhood(name)[source]
construct_neighbors(neighbors)[source]
construct_neumann_n(manhatten=1, exclude_self=True)[source]
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

N (0, 1) |
W E (-1,0) (1,0) |
S (0,-1) |

|________________________________________|

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.
exception VirtualMicrobes.environment.Grid.PositionOutsideGridError(x, y)[source]

Bases: VirtualMicrobes.environment.Grid.GridError

VirtualMicrobes.environment.Grid.mirror_rel_coord(coord)[source]

Module contents