VirtualMicrobes.simulation package

Submodules

VirtualMicrobes.simulation.Simulation module

‘ Top level Simulation class that contains all objects and parameters of the simulation. Has a simulate method that executes the simulation loop, methods to save and reload, as well as initiate data storage and plotting.

class VirtualMicrobes.simulation.Simulation.EvoSystem(params)[source]

Bases: object

Sets up the Environment and the Population.

reinit_system_params(params, **param_updates)[source]
setup_environment()[source]
class VirtualMicrobes.simulation.Simulation.ODE_simulation(params)[source]

Bases: VirtualMicrobes.simulation.Simulation.Simulation

Set up a simulation. Initialize an EvoSystem and an Integrator. EvoSystem consists of a Population and Environment that are co-dependent. This is because a Cell in a Population can only choose its Reactions once the environment is set up and the reaction space is ready, while the reaction space can only be fully known, when all internal molecules have been defined in relation to Cells in the Population. To circumvent the problem, internal molecules will only exist as ‘ideal’ type molecules and then every Cell will contain a mapping from ‘ideal’ molecules to actual variables of the system.

init_spatial_integrator(diffusion_steps=None, report_frequency=None, step_function=None, init_step_size=None, absolute_error=None, relative_error=None, global_time=0.0)[source]
init_time_course_lengths()[source]
max_time_course_length()[source]
simulation_burn_in(burn_in_time=None, simulation_steps=1)[source]
simulation_step(global_time=None, diffusion_steps=None, delta_t_between_diff=None, report_frequency=None, release_delay=None, update_relative_error=None, verbal=False)[source]

A simulation step will run the integration of cycle of a cell’s life:

  • setup the variables_map needed
  • simulate internal dynamics
  • save variables states back to python objects (if no errors occured or > maxtries)
class VirtualMicrobes.simulation.Simulation.Simulation(params)[source]

Bases: object

Base class for Simulation objects.

Stores the simulation parameters.

Initializes output and storage paths and file for stdout and stderr logging.

Initializes a data store class for storing data points and time series.

Initializes a graphs class for output graphing, that will be fed with data points from the data store.

Has method for the main simulation loop.

Stores simulation snapshots that can be reloaded for further simulation or post analysis.

add_graphs_data(time_point)[source]
auto_restart_opts(retry_list=None, time=None)[source]

Automatically restart the simulation after the population became extinct.

A simulation can be automatically restarted from a previous save point. The save points to retry from in the retry_list are updated such that the most recent point is retried first and removed from this list. This ensures that a subsequent restart will not be attempted from the same save point, but will instead skip back to a preceding save point. When restarting the simulation, new parameter values will be chosen for a selected set of parameters, by applying a scaling factor v.

Parameters:retry_list (list) – list of population snapshots that can still be retried for restart
Returns:
Return type:(population save to retry, new parameter settings for retry)
backup_pop_stats()[source]
class_version = '2.6'
close_phylo_shelf()[source]
copy_config_files()[source]
describe_environment()[source]
init_data_store(clean=True, create=True)[source]

Initialize a DataStore object for storage of simulation data.

Data are kept in storage for retrieval by plotting functions until a call is made to write the raw data to a file (write_data).

init_error_log_file(save_dir=None, name='log', suffix='.err', labels=[])[source]
init_ffmpeg()[source]
init_graphs(show=None, clean=True, create=True)[source]

Initialize a Graphs object that contains simulation graphs.

Parameters:show – plot graphs on the X (blocking)
init_log_file(save_dir=None, name='log', suffix='.out', labels=[])[source]
init_log_files()[source]
init_phylo_linker_dict()[source]

Create a linker dict that maps phylogenetic units (PhyloUnit) to unique indices. This linker dict is used to mediate parent-child relations, while preventing that pickling recurses (heavily) on the phylogeny (no direct references to the objects)

init_save_dir(clean=None, remove_globs=['*.txt', '*.sav', '*.pck', '*.log', '*.err'])[source]
init_unique_gene_key()[source]

Initialize a generator for unique keys for use in the linker dict (see above).

init_unique_phylo_key()[source]

Initialize a generator for unique keys for use in the linker dict (see above).

open_log_file(name)[source]
open_phylo_shelf(name, flag)[source]

Open a Shelf like database object that can store (part of) phylogenetic units (PhyloUnit) to disk.

plot_and_save_graphs(time_point)[source]

Depending on the initialization parameter ‘graphs_single_core’ this will either run all plotting in functions in sequence (appending None to processes) or construct a list of job processes/ task tuples, to be run in parallel batch processes, separate from the main thread. These processes will be either put in a job queue or separately started by ‘_start_parallel_jobs’.

Parameters:time_point – simulation time point
plot_best_genome_structure(time_point)[source]
plot_grid_graphs(time_point)[source]
plot_networks(time_point)[source]
plot_pop_stats()[source]
plot_time_course(time_point)[source]
print_system_details()[source]
prune_data_store_files()[source]
reload_unique_gene_count()[source]
reload_unique_phylo_count()[source]
reopen_phylo_shelf(save_file=None)[source]
save(time=None, store=False)[source]

Save the simulation state as a snapshot.

Parameters:time (simulation time point) –
Returns:
Return type:filename of simulation save
save_dir

Return the simulation save path.

save_phylo_shelf(name=None, labels=[], suffix='.pck')[source]

Save a snapshot of the phylo_shelf, the global store of PhyloUnit objects.

Creating the snapshot enables reloading simulation saves with a correct state of the phylo_shelf.

set_phylo_shelf_file_name(name=None, suffix='.pck', labels=[])[source]
simulate()[source]

The main simulation loop.

Clear the population changes from previous iteration. Run the ode system. Apply HGT. Calculate death rates, determine deaths. Compete and reproduce. Mutate the offspring. Update the phylogeny. Store data and plot.

store_command_line_string(fn='command_line_string.txt')[source]
store_previous_save_dir()[source]

Save the location for data storage presently used in the simulation.

Useful to keep a history of save locations when simulations are reloaded and run with different data storage locations.

update_data_location(save_dir=None, graphs_name='plots', data_name='data', clean=False, copy_data=True, create=True, current_save_path=None)[source]

Moves existing data to a new location (e.g. when name of project has changed after propagating an existing population)

update_shelf_location(current_save_path=None)[source]
update_sim_params(params_dict)[source]

Update simulation parameters with values in an update dict.

Parameters:params_dict (dict) – dict with updated parameter values
upgrade(odict)[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. (see also __setstate__)

Adapted from recipe at http://code.activestate.com/recipes/521901-upgradable-pickles/

upgrade_graphs()[source]
write_data()[source]
write_params_to_file(save_dir=None, name='params', suffix='.txt', labels=[])[source]
VirtualMicrobes.simulation.Simulation.create_simulation(**param_updates)[source]
VirtualMicrobes.simulation.Simulation.default_params()[source]
VirtualMicrobes.simulation.Simulation.load_sim(file_name, verbose=False, **param_updates)[source]

Load a pickled representation of a saved simulation state.

Complementary method to :save_sim: to load and restore a simulation state. There is a possibility to update simulation parameters. The first stage of unpickling will reload the simulation parameters. This is necessary, because we need to set the ‘as_subprocess’ parameter for decorating Graph methods to be set before class initialization, by retrieving the ‘graphs_single_core’ parameter from the simulation ‘temp_params’ prior to reloading and recreating the pickled Graphs instance in the simulation object.

VirtualMicrobes.simulation.Simulation.load_sim_params(file_name)[source]
VirtualMicrobes.simulation.Simulation.load_simulation(file_name, **param_updates)[source]
VirtualMicrobes.simulation.Simulation.mut_func_single_param(val, rand_g, mut_par_space, up)[source]
VirtualMicrobes.simulation.Simulation.mut_func_single_param_step_uniform(val, rand_g, mut_par_space, up)[source]
VirtualMicrobes.simulation.Simulation.mut_ks_dict_func(kss, rand_gen, mut_par_space, mutate_single_param, up)[source]
VirtualMicrobes.simulation.Simulation.partial_mut_func_single_param(val, rand, mut_par_space, up=True)[source]
VirtualMicrobes.simulation.Simulation.partial_mut_ks_dict_func(val, rand, mut_par_space, up=False)[source]
VirtualMicrobes.simulation.Simulation.pump_exporting_mut_func(val)[source]
VirtualMicrobes.simulation.Simulation.save_pop_cells(sim, name=None, save_dir=None, labels=[], suffix='.sav')[source]
VirtualMicrobes.simulation.Simulation.save_sim(*args, **kwargs)[source]

Make a pickled save state of the simulation.

It (nearly) completely creates a pickle representation of the simulation, from which the simulation can be reloaded and continued, with parameters and state fully restored. Because a global linker dict with database functionality is used to store phylogenetic elements such as Genes, Chromosomes and Cells, a snapshot of this database needs to be created simultaneously. The snapshot of the DB is remembered within the simulation, to allow it to be reloaded when the saved simulation state is reloaded.

VirtualMicrobes.simulation.Simulation.save_single_cell(sim, cell, name=None, save_dir=None, labels=[], suffix='.sav')[source]
VirtualMicrobes.simulation.Simulation.tf_ext_sense_mut_func(val)[source]
VirtualMicrobes.simulation.Simulation.update_default_params(keep_unrecognized=False, verbose=False, **kwargs)[source]

Use simulate_params, pop_params and env_params as defaults and overwrite them with kwargs to construct a parameter dictionary. Warn for all kwargs that have not been consumed. ( default_params() generates all default parameters )

Parameters:
  • simulate_params – dictionary with general simulation parameters
  • pop_params – dictionary with population specific parameters
  • env_params – dictionary with environment specific params

VirtualMicrobes.simulation.virtualmicrobes module

Command Line Interface to the Virtual Microbes Evolutionary Simulator package.

@copyright: 2014 Theoretical Biology and Bioinformatics. All rights reserved.

@license: MIT licence

@contact: thomas.cuypers@gmail.com @deffield updated: Updated

Module contents