VirtualMicrobes.simulation package

Submodules

VirtualMicrobes.simulation.Simulation module

class VirtualMicrobes.simulation.Simulation.EvoSystem(params, **kwargs)[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]
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)[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

version info

1.0 -> 2.0 : a hack to fix a problem with parameter updating. In previous versions of the code updating the parameters was inadvertently done by asigning an updated dictionary to self.params . This, however, ignores the fact that other class instances ( e.g. population, environment cells ) keep their own reference to the parameters. These now point to the old version of parameters and will never be updated. See ‘upgrade’ for the hack.

add_data_point(time_point)[source]
add_graphs_data(time_point)[source]
auto_restart_opts(retry_list=None, time=None)[source]
backup_pop_stats()[source]
class_version = '2.5'

version – :author:

clean_up_consumers(consumers, time_out=0.5)[source]

Terminates consumer processes and their associated process trees

Parameters:
  • consumers – list of consumer :class:multiprocessing.Process
  • time_out
clean_up_processes(consumers=None)[source]
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, graphs_single_core=None, clean=True)[source]

Initialize a Graphs object that is a container for all online graphs generated during simulation. :param show: plot graphs on the X (blocking) :param graphs_single_core: generate graphs in the main process (no subprocesses)

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_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_and_save_phylo_graphs(max_tree_depth, time_point)[source]
plot_best_genome_structure(time_point)[source]
plot_grid_graphs(time_point)[source]
plot_networks(time_point)[source]
plot_phylo_tree(max_tree_depth, labels)[source]
plot_pop_stats()[source]
plot_time_course(time_point)[source]
print_system_details()[source]
prune_data_store_files()[source]
reload_unique_count()[source]
reopen_phylo_shelf(save_file=None)[source]
save(time=None)[source]

Save the simulation state as a snapshot.

Parameters:time – time point in the simulation
save_dir
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.

start_parallel_jobs(jobs, num_procs=None)[source]

Start a number of jobs in parallel.

Put a set of (plotting) jobs in a queue, to be run by parallel ‘consumer’ processes.

Parameters:
  • jobs – list of Processes or tuples of (object, method) to initialize a :class:utility.Task
  • num_procs – number of parallel consumer processes

:returns tuple with the new tasks queue and consumers assigned to the jobs in the queue

store_command_line_string()[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]
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)[source]
VirtualMicrobes.simulation.Simulation.mut_ks_dict_func(kss, rand_gen, mut_par_space, mut_func_single_param)[source]
VirtualMicrobes.simulation.Simulation.partial_mut_func_single_param(val, rand, mut_par_space)[source]
VirtualMicrobes.simulation.Simulation.partial_mut_ks_dict_func(val, rand, mut_par_space)[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.class_settings module

Created on Dec 16, 2014

@author: thocu

VirtualMicrobes.simulation.continue module

VirtualMicrobes.simulation.continue.main(argv=None)[source]
VirtualMicrobes.simulation.continue.parse_opts(opt_strings)[source]
VirtualMicrobes.simulation.continue.to_argparse_opts(opts)[source]

VirtualMicrobes.simulation.start module

VirtualMicrobes.simulation.start.main(argv=None)[source]
VirtualMicrobes.simulation.start.parse_combining_opts(opt_strings)[source]
VirtualMicrobes.simulation.start.parse_fixed_opts(opt_strings)[source]
VirtualMicrobes.simulation.start.to_argparse_opts(opts)[source]

VirtualMicrobes.simulation.start_multi module

VirtualMicrobes.simulation.start_multi.main(argv=None)[source]
VirtualMicrobes.simulation.start_multi.parse_combining_opts(opt_strings)[source]
VirtualMicrobes.simulation.start_multi.parse_fixed_opts(opt_strings)[source]
VirtualMicrobes.simulation.start_multi.to_argparse_opts(opts)[source]

VirtualMicrobes.simulation.vermicelli module

simulation.start_sim – Simulate evolution of Virtual Microbes

simulation.start_sim is a Setup script for simulations of the Virtual Microbes program

It defines simulation options

@author: thocu

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

@license: unlicence

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

Module contents