ecell4 module

ecell4.util submodule

ecell4.util.run_simulation(t, y0=None, volume=1.0, model=None, solver='ode', ndiv=None, species_list=None, structures=None, observers=(), rndseed=None)

Run a simulation with the given model and plot the result on IPython notebook with matplotlib.

Parameters
tarray or Real

A sequence of time points for which to solve for ‘m’.

y0dict

Initial condition.

volumeReal or Real3, optional

A size of the simulation volume. Keyword ‘v’ is a shortcut for specifying ‘volume’.

modelModel, optional

Keyword ‘m’ is a shortcut for specifying ‘model’.

solverstr, tuple or Factory, optional

Solver type. Choose one from ‘ode’, ‘gillespie’, ‘spatiocyte’, ‘meso’, ‘bd’, ‘egfrd’, and ‘sgfrd’. Default is ‘ode’. When tuple is given, the first value must be str as explained above. All the rest is used as arguments for the corresponding factory class. Keyword ‘s’ is a shortcut for specifying ‘solver’.

ndivint, optional

A number of time points. If t is an array, ignored. If None, log all.

species_listlist of str, optional

A list of names of Species observed. If None, log all. Default is None.

structureslist or dict, optional

A dictionary which gives pairs of a name and shape of structures. Not fully supported yet.

observersObserver or list, optional

A list of extra observer references.

rndseedint, optional

A random seed for a simulation. This argument will be ignored when ‘solver’ is given NOT as a string.

Returns
resultResult
ecell4.util.ensemble_simulations(t, y0=None, volume=1.0, model=None, solver='ode', ndiv=None, species_list=None, structures=None, observers=(), rndseed=None, repeat=1, method=None, \*\*kwargs)

Run simulations multiple times and return its ensemble. Arguments are almost same with ecell4.util.simulation.run_simulation. observers and progressbar is not available here.

Parameters
repeatint, optional

A number of runs. Default is 1.

methodstr, optional

The way for running multiple jobs. Choose one from ‘serial’, ‘multiprocessing’, ‘sge’, ‘slurm’, ‘azure’. Default is None, which works as ‘serial’.

**kwargsdict, optional

Optional keyword arugments are passed through to run_serial, run_sge, or run_multiprocessing. See each function for more details.

Returns
valueResultList
ecell4.util.load_world(filename)

Load a world from the given HDF5 filename. The return type is determined by ecell4_base.core.load_version_information.

Parameters
filenamestr

A HDF5 filename.

Returns
wWorld

Return one from BDWorld, EGFRDWorld, MesoscopicWorld, ODEWorld, GillespieWorld and SpatiocyteWorld.

ecell4.util.number_observer(t=None, targets=None)

Return a number observer. If t is None, return NumberObserver. If t is a number, return FixedIntervalNumberObserver. If t is an iterable (a list of numbers), return TimingNumberObserver.

Parameters
tfloat, list or tuple, optional. default None

A timing of the observation. See above.

targetslist or tuple, optional. default None

A list of strings suggesting Species observed.

Returns
obsNumberObserver, FixedIntervalNumberObserver or TimingNumberObserver
ecell4.util.get_model(is_netfree=False, without_reset=False, seeds=None, effective=False)

Generate a model with parameters in the global scope, SPECIES_ATTRIBUTES and REACTIONRULES.

Parameters
is_netfreebool, optional

Return NetfreeModel if True, and NetworkModel if else. Default is False.

without_resetbool, optional

Do not reset the global variables after the generation if True. Default is False.

seedslist, optional

A list of seed Species for expanding the model. If this is not None, generate a NetfreeModel once, and return a NetworkModel, which is an expanded form of that with the given seeds. Default is None.

effectivebool, optional

See NetfreeModel.effective and Netfree.set_effective. Only meaningfull with option is_netfree=True. Default is False

Returns
modelNetworkModel, NetfreeModel
ecell4.util.show(target, \*args, \*\*kwargs)

An utility function to display the given target object in the proper way.

class ecell4.util.Session(model=None, y0=None, structures=None, volume=1.0)

Bases: object

Methods

ensemble(self, t[, solver, rndseed, ndiv, …])

Run simulations multiple times and return its ensemble.

run(self, t[, solver, rndseed, ndiv, …])

Run a simulation with the given model and return the result

ensemble(self, t, solver='ode', rndseed=None, ndiv=None, species_list=None, observers=(), repeat=1, method=None, \*\*kwargs)

Run simulations multiple times and return its ensemble. Arguments are almost same with ecell4.util.simulation.run_simulation. observers and progressbar is not available here.

Parameters
tarray or Real

A sequence of time points for which to solve for ‘m’.

solverstr, tuple or Factory, optional

Solver type. Choose one from ‘ode’, ‘gillespie’, ‘spatiocyte’, ‘meso’, ‘bd’ and ‘egfrd’. Default is ‘ode’. When tuple is given, the first value must be str as explained above. All the rest is used as arguments for the corresponding factory class.

ndivint, optional

A number of time points. If t is an array, ignored. If None, log all.

species_listlist of str, optional

A list of names of Species observed. If None, log all. Default is None.

observersObserver or list, optional

A list of extra observer references.

repeatint, optional

A number of runs. Default is 1.

methodstr, optional

The way for running multiple jobs. Choose one from ‘serial’, ‘multiprocessing’, ‘sge’, ‘slurm’, ‘azure’. Default is None, which works as ‘serial’.

**kwargsdict, optional

Optional keyword arugments are passed through to run_serial, run_sge, or run_multiprocessing. See each function for more details.

Returns
resultslist

A list of Result objects. The list contains n results.

run(self, t, solver='ode', rndseed=None, ndiv=None, species_list=None, observers=())

Run a simulation with the given model and return the result

Parameters
tarray or Real

A sequence of time points for which to solve for ‘m’.

solverstr, tuple or Factory, optional

Solver type. Choose one from ‘ode’, ‘gillespie’, ‘spatiocyte’, ‘meso’, ‘bd’ and ‘egfrd’. Default is ‘ode’. When tuple is given, the first value must be str as explained above. All the rest is used as arguments for the corresponding factory class.

rndseedint, optional

A random seed for a simulation.

ndivint, optional

A number of time points. If t is an array, ignored. If None, log all.

species_listlist of str, optional

A list of names of Species observed. If None, log all. Default is None.

observersObserver or list, optional

A list of extra observer references.

Returns
retResult

The result object

ecell4.datasource submodule

ecell4.datasource.description(entity, collections=None)
ecell4.datasource.whereis(entity, collections=None)
ecell4.datasource.citation(entity, formatter=<class 'ecell4.datasource.pubmed.Formatter'>)

ecell4.extra submodule

ecell4.extra.ensemble.genseeds(n)

Return a random number generator seed for ensemble_simulations. A seed for a single run is given by getseed(rngseed, i).

Parameters
nint

A size of the seed.

Returns
rndseedbytes

A random number seed for multiple runs.

ecell4.extra.ensemble.getseed(myseed, i)

Return a single seed from a long seed given by genseeds.

Parameters
myseedbytes

A long seed given by genseeds(n).

iint

An index less than n.

Returns
rndseedint

A seed (less than (2 ** 31))

ecell4.extra.ensemble.run_azure(target, jobs, n=1, nproc=None, path='.', delete=True, config=None, \*\*kwargs)

Evaluate the given function with each set of arguments, and return a list of results. This function does in parallel with Microsoft Azure Batch.

This function is the work in progress. The argument nproc doesn’t work yet. See ecell4.extra.azure_batch.run_azure for details.

ecell4.extra.ensemble.run_ensemble(target, jobs, repeat=1, method=None, \*\*kwargs)

Evaluate the given function with each set of arguments, and return a list of results.

Parameters
targetfunction

A function to be evaluated. The function must accepts three arguments, which are a list of arguments given as jobs, a job and task id (int).

jobslist

A list of arguments passed to the function.

repeatint, optional

A number of tasks. Repeat the evaluation n times for each job. 1 for default.

methodstr, optional

The way for running multiple jobs. Choose one from ‘serial’, ‘multiprocessing’, ‘sge’, ‘slurm’, ‘azure’. Default is None, which works as ‘serial’.

Returns
resultslist

A list of results. Each element is a list containing repeat results.

ecell4.extra.ensemble.run_multiprocessing(target, jobs, n=1, nproc=None, \*\*kwargs)

Evaluate the given function with each set of arguments, and return a list of results. This function does in parallel by using multiprocessing.

Parameters
targetfunction

A function to be evaluated. The function must accepts three arguments, which are a list of arguments given as jobs, a job and task id (int).

jobslist

A list of arguments passed to the function. All the argument must be picklable.

nint, optional

A number of tasks. Repeat the evaluation n times for each job. 1 for default.

nprocint, optional

A number of cores available once. If nothing is given, all available cores are used.

Returns
resultslist

A list of results. Each element is a list containing n results.

Examples

>>> jobs = ((1, 'spam'), (2, 'ham'), (3, 'eggs'))
>>> target = lambda args, job_id, task_id: (args[1] * args[0])
>>> run_multiprocessing(target, jobs, nproc=2)
[['spam'], ['hamham'], ['eggseggseggs']]
>>> target = lambda args, job_id, task_id: "{:d} {}".format(task_id, args[1] * args[0])
>>> run_multiprocessing(target, jobs, n=2, nproc=2)
[['1 spam', '2 spam'], ['1 hamham', '2 hamham'], ['1 eggseggseggs', '2 eggseggseggs']]
ecell4.extra.ensemble.run_serial(target, jobs, n=1, \*\*kwargs)

Evaluate the given function with each set of arguments, and return a list of results. This function does in series.

Parameters
targetfunction

A function to be evaluated. The function must accepts three arguments, which are a list of arguments given as jobs, a job and task id (int).

jobslist

A list of arguments passed to the function.

nint, optional

A number of tasks. Repeat the evaluation n times for each job. 1 for default.

Returns
resultslist

A list of results. Each element is a list containing n results.

Examples

>>> jobs = ((1, 'spam'), (2, 'ham'), (3, 'eggs'))
>>> target = lambda args, job_id, task_id: (args[1] * args[0])
>>> run_serial(target, jobs)
[['spam'], ['hamham'], ['eggseggseggs']]
>>> target = lambda args, job_id, task_id: "{:d} {}".format(task_id, args[1] * args[0])
>>> run_serial(target, jobs, n=2)
[['1 spam', '2 spam'], ['1 hamham', '2 hamham'], ['1 eggseggseggs', '2 eggseggseggs']]
>>> seeds = genseeds(3)
>>> def target(arg, job_id, task_id):
...     from ecell4.extra.ensemble import getseed
...     return getseed(arg, task_id)
>>> run_serial(target, (seeds, ), n=3)  
[[127152315, 2028054913, 253611282]]
ecell4.extra.ensemble.run_sge(target, jobs, n=1, nproc=None, path='.', delete=True, wait=True, environ=None, modules=(), \*\*kwargs)

Evaluate the given function with each set of arguments, and return a list of results. This function does in parallel on the Sun Grid Engine einvironment.

Parameters
targetfunction

A function to be evaluated. The function must accepts three arguments, which are a list of arguments given as jobs, a job and task id (int). This function can not be a lambda.

jobslist

A list of arguments passed to the function. All the argument must be picklable.

nint, optional

A number of tasks. Repeat the evaluation n times for each job. 1 for default.

nprocint, optional

A number of cores available once. If nothing is given, it runs with no limit.

pathstr, optional

A path for temporary files to be saved. The path is created if not exists. The current directory is used as its default.

deletebool, optional

Whether it removes temporary files after the successful execution. True for default.

waitbool, optional

Whether it waits until all jobs are finished. If False, it just submits jobs. True for default.

environdict, optional

An environment variables used when running jobs. “PYTHONPATH” and “LD_LIBRARY_PATH” is inherited when no environ is given.

moduleslist, optional

A list of module names imported before evaluating the given function. The modules are loaded as: from [module] import *.

Returns
resultslist

A list of results. Each element is a list containing n results.

Examples

>>> jobs = ((1, 'spam'), (2, 'ham'), (3, 'eggs'))
>>> def target(args, job_id, task_id):
...     return (args[1] * args[0])
...
>>> run_sge(target, jobs, nproc=2, path='.tmp')
[['spam'], ['hamham'], ['eggseggseggs']]
>>> def target(args, job_id, task_id):
...     return "{:d} {}".format(task_id, args[1] * args[0])
...
>>> run_sge(target, jobs, n=2, nproc=2, path='.tmp')
[['1 spam', '2 spam'], ['1 hamham', '2 hamham'], ['1 eggseggseggs', '2 eggseggseggs']]
ecell4.extra.ensemble.run_slurm(target, jobs, n=1, nproc=None, path='.', delete=True, wait=True, environ=None, modules=(), \*\*kwargs)

Evaluate the given function with each set of arguments, and return a list of results. This function does in parallel with Slurm Workload Manager.

Parameters
targetfunction

A function to be evaluated. The function must accepts three arguments, which are a list of arguments given as jobs, a job and task id (int). This function can not be a lambda.

jobslist

A list of arguments passed to the function. All the argument must be picklable.

nint, optional

A number of tasks. Repeat the evaluation n times for each job. 1 for default.

nprocint, optional

A number of cores available once. If nothing is given, it runs with no limit.

pathstr, optional

A path for temporary files to be saved. The path is created if not exists. The current directory is used as its default.

deletebool, optional

Whether it removes temporary files after the successful execution. True for default.

waitbool, optional

Whether it waits until all jobs are finished. If False, it just submits jobs. True for default.

environdict, optional

An environment variables used when running jobs. “PYTHONPATH” and “LD_LIBRARY_PATH” is inherited when no environ is given.

moduleslist, optional

A list of module names imported before evaluating the given function. The modules are loaded as: from [module] import *.

Returns
resultslist

A list of results. Each element is a list containing n results.

Examples

>>> jobs = ((1, 'spam'), (2, 'ham'), (3, 'eggs'))
>>> def target(args, job_id, task_id):
...     return (args[1] * args[0])
...
>>> run_slurm(target, jobs, nproc=2, path='.tmp')
[['spam'], ['hamham'], ['eggseggseggs']]
>>> def target(args, job_id, task_id):
...     return "{:d} {}".format(task_id, args[1] * args[0])
...
>>> run_slurm(target, jobs, n=2, nproc=2, path='.tmp')
[['1 spam', '2 spam'], ['1 hamham', '2 hamham'], ['1 eggseggseggs', '2 eggseggseggs']]
ecell4.extra.unit.getUnitRegistry(length='meter', time='second', substance='item', volume=None, other=())

Return a pint.UnitRegistry made compatible with ecell4.

Parameters
lengthstr, optional

A default unit for ‘[length]’. ‘meter’ is its default.

timestr, optional

A default unit for ‘[time]’. ‘second’ is its default.

substancestr, optional

A default unit for ‘[substance]’ (the number of molecules). ‘item’ is its default.

volumestr, optional

A default unit for ‘[volume]’. Its default is None, thus ‘[length]**3’.

othertuple, optional

A list of user-defined default units other than the above.

Returns
uregpint.UnitRegistry
ecell4.extra.unit.get_application_registry()

Just return pint._APP_REGISTRY.

ecell4.extra.unit.wrap_quantity(cls)
ecell4.extra.unit.check_model(m, Quantity=None)
exception ecell4.extra.unit.DimensionalityMismatchError

Bases: ValueError

ecell4.mca submodule

ecell4.mca.generate_full_rank_matrix(input_matrix)

do Gaussian elimination and return the decomposed matrices input_matrix: (matrix) return (link_matrix, kernel_matrix, independent_list)

ecell4.mca.unscaled_control_coefficients(stoichiometry, elasticity)
ecell4.mca.invdiag(trace)

return numpy.lib.twodim_base.diag(1.0 / trace) if there’re zeros in the array, set zero for that trace: (array) one dimensional array return (matrix)

ecell4.mca.scale_control_coefficients(ccc, fcc, v, x)
ecell4.mca.scaled_control_coefficients(stoichiometry, elasticity, fluxes, x)

ecell4.plotting submodule

ecell4.plotting: Visualizer of particles based on D3.js, THREE.js and Elegans.

ecell4.plotting.display_pdb(entity, width=400, height=400)
ecell4.plotting.plot_movie(\*args, backend=None, \*\*kwargs)

Generate a movie from received instances of World and show them. See also plot_movie_with_elegans and plot_movie_with_matplotlib.

Parameters
worldslist of World

Worlds to render.

backendstr, optional

backend. Either one of ‘matplotlib’ or ‘elegans’ is supported.

ecell4.plotting.plot_movie_with_attractive_mpl(worlds, marker_size=6, figsize=6, grid=True, wireframe=False, species_list=None, max_count=None, angle=None, noaxis=False, interval=0.16, repeat_delay=3000, stride=1, rotate=None, legend=True, whratio=1.33, scale=1, output=None, crf=10, bitrate='1M', \*\*kwargs)

Generate a move from the received list of instances of World, and show it on IPython notebook. This function may require ffmpeg.

Parameters
worldslist or FixedIntervalHDF5Observer

A list of Worlds to render.

marker_sizefloat, default 3

Marker size for all species. Size is passed to scatter function as argument, s=(2 ** marker_size).

figsizefloat, default 6

Size of the plotting area. Given in inch.

species_listarray of string, default None

If set, plot_world will not search the list of species.

max_countInteger, default None

The maximum number of particles to show for each species. None means no limitation.

angletuple, default None

A tuple of view angle which is given as (azim, elev, dist). If None, use default assumed to be (-60, 30, 10).

intervalInteger, default 0.16

Parameters for matplotlib.animation.ArtistAnimation.

strideInteger, default 1

Stride per frame.

rotatetuple, default None

A pair of rotation angles, elev and azim, for animation. None means no rotation, same as (0, 0).

legendbool, default True
whratiofloat, default 1.33

A ratio between figure width and height. Customize this to keep a legend within the figure.

scalefloat, default 1

A length-scaling factor

crfint, default 10

The CRF value can be from 4-63. Lower values mean better quality.

bitratestr, default ‘1M’

Target bitrate

outputstr, default None

An output filename. ‘.webm’ or ‘.mp4’ is only accepted. If None, display a movie on IPython Notebook.

ecell4.plotting.plot_number_observer(\*args, backend=None, \*\*kwargs)

Generate a plot from NumberObservers and show it. See plot_number_observer_with_matplotlib and _with_nya for details.

Parameters
obsNumberObserver (e.g. FixedIntervalNumberObserver)
backendstr, optional

backend. Either one of ‘matplotlib’, ‘plotly’ or ‘elegans’ is supported.

Examples

>>> plot_number_observer(obs1)
>>> plot_number_observer(obs1, backend='plotly')
ecell4.plotting.plot_trajectory(\*args, backend=None, \*\*kwargs)

Generate a plot from received instance of TrajectoryObserver and show it See also plot_trajectory_with_plotly, plot_trajectory_with_elegans and plot_trajectory_with_matplotlib.

Parameters
obsTrajectoryObserver

TrajectoryObserver to render.

backendstr, optional

backend. Either one of ‘matplotlib’, ‘plotly’ or ‘elegans’ is supported.

Examples

>>> plot_trajectory(obs)
ecell4.plotting.plot_world(\*args, backend=None, \*\*kwargs)

Generate a plot from received instance of World and show it. See also plot_world_with_elegans and plot_world_with_matplotlib.

Parameters
worldWorld or str

World or a HDF5 filename to render.

backendstr, optional

backend. Either one of ‘matplotlib’, ‘plotly’ or ‘elegans’ is supported.

Examples

>>> plot_world(w)
>>> plot_world(w, backend='plotly')
ecell4.plotting.plot_world_with_attractive_mpl(world, marker_size=6, figsize=6, grid=True, wireframe=False, species_list=None, max_count=1000, angle=None, legend=True, noaxis=False, whratio=1.33, scale=1.0, \*\*kwargs)

Generate a plot from received instance of World and show it on IPython notebook.

Parameters
worldWorld or str

World to render. A HDF5 filename is also acceptable.

marker_sizefloat, default 3

Marker size for all species. Size is passed to scatter function as argument, s=(2 ** marker_size).

figsizefloat, default 6

Size of the plotting area. Given in inch.

species_listarray of string, default None

If set, plot_world will not search the list of species.

max_countInteger, default 1000

The maximum number of particles to show for each species. None means no limitation.

angletuple, default None

A tuple of view angle which is given as (azim, elev, dist). If None, use default assumed to be (-60, 30, 10).

legendbool, default True
whratiofloat, default 1.33

A ratio between figure width and height. Customize this to keep a legend within the figure.

scalefloat, default 1

A length-scaling factor