Trajectory Looping: Difference between revisions

From Laboratory of Modeling in Biology and Medicine
Jump to: navigation, search
mNo edit summary
mNo edit summary
 
(32 intermediate revisions by the same user not shown)
Line 1: Line 1:
<div align="center">'''A method for sampling of rare events in stochastic reaction–diffusion systems'''</div><br />
<div align="center">'''A method for sampling rare events in stochastic reaction–diffusion systems'''</div><br />
<div align="center">
With trajectory looping one can use a single trajectory, generated <br />
by a prior simulation of diffusive motions of molecules, to sample <br />
chemical kinetic processes on time scales that are several orders <br />
of magnitude longer than the duration of the diffusive trajectory.<br />
</div><br/>


<div align="center">
<div align="center" width="235px">
https://upload.wikimedia.org/wikipedia/commons/thumb/8/87/Ouroboros_1.jpg/235px-Ouroboros_1.jpg
https://upload.wikimedia.org/wikipedia/commons/thumb/8/87/Ouroboros_1.jpg/235px-Ouroboros_1.jpg<br/>
<span style="color: #888; font-size: 75%">A wyvern eating its own tail ([http://commons.wikimedia.org/wiki/File:Ouroboros_1.jpg <span style="color: #888">public domain</span>]).</span>
</div>
</div>




=== Download ===
<span id="RefZukEtAl"></span>
Source code of a C++ implementation of the method, called '''Looper''', can be retrieved [http://pmbm.ippt.pan.pl/software/looping/looper-v20180314.tar.gz here].
=== Reference ===
* <span class="pmbm">Żuk PJ</span>, <span class="pmbm">Kochańczyk M</span>, <span class="pmbm">Lipniacki T</span>. '''Sampling rare events in stochastic reaction–diffusion systems within trajectory looping''', ''Physical Review&nbsp;E'' <u>98</u>:022401 (2018) [http://doi.org/10.1103/PhysRevE.98.022401 CrossRef] | [http://pmbm.ippt.pan.pl/publications/Zuk-2018-PhysRevE-MS.pdf PDF-ms]




=== Building ===
=== Downloads ===
* [http://pmbm.ippt.pan.pl/software/looping/looper-v20180801.tar.gz '''Looper''' – an implementation of the method in C++]
* [http://pmbm.ippt.pan.pl/software/looping/n_500__f_0.2__eps_0.05.trajectory Example input trajectory] (~2.4 GB, parameters: <i>N</i>=500, &phi;=20%, &epsilon;=0.05, &theta;=100&tau;<sub>B</sub>)


'''Compiler'''<br/>
A decent and recent C++ compiler that supports C++14 standard is required.
The code has been confirmed to compile successfully under Linux with GNU
g++ 8.0 and Clang++ 6.0.


=== On the implementation ===


'''Toolchain'''<br/>
Trajectory looping can be implemented in two different but
Compilation is managed by CMakeTo build Looper under Linux, it should be
equivalent waysOne may first perform multiple joins of the base
sufficient to enter the build directory and execute 'build_release.sh'.
contacts trajectory and in this manner obtain a looped contacts
trajectory of a desired length without considering chemical events.
The looped contacts trajectory, consisting of the base contacts
trajectory and index maps resulting from optimal assignments, provides
a complete information necessary for a subsequent simulation of chemical
trajectory (this way has been presented in Figure 1 in the [[#RefZukEtAl|article]]).


The second way consists in interweaving the simulation of chemical events
with joins of the base contacts trajectory.  This way can be more convenient
for some applications because what is expanding in computer memory is the
ultimate looped chemical trajectory, which is of direct interest, and not
the intermediary looped contacts trajectory, whose desired length may be
hard to guess.  When using the second way, a stop condition can be defined
depending on the chemical state of the system or based on the already
collected chemical event statistics.


===Usage ===
'''Looper''' has been written according to the second way.
 
'''Invocation'''<br/>
Invoke simply as: 
 
  ./Looper trajectory chemprefix
 
'''Multiple input trajectories'''<br/>
More than one trajectory file can be read in and used.  Multiple files should
be listed consecutively before the last invocation argument, e.g., as:
 
  ./Looper traj1.bin traj2.bin traj3.bin chemprefix
 
The order of the use of multiple trajectories is random.  The trajectories
should have the same number of molecules and the same time step.
 
 
'''Multiple simulations: seed'''<br/>
If more than one simulation is to be performed (by setting appropriately
variable kNumOfReplicas in file Settings.hpp), each simulation is seeded
sequentially starting from the value assigned to kSimulationSeedsBase (file
Settings.hpp).  This value can be overridden by setting the environmental
variable LOOPER_SEED_BASE prior to Looper invocation.
 
 
'''Multiple simulations: multi-threading'''<br/>
Multiple simulations of chemical kinetics that use the same base chemical
trajectory can run in parallel.  During run-time, the software chooses the
number of threads based on both the kNumOfReplicas (described above) and
hardware capabilities.  If necessary, this behavior can be tweaked manually
using variable kNumOfThreads (in file Settings.hpp).
 




Line 70: Line 59:


* current step index (4-byte signed integer),
* current step index (4-byte signed integer),
* current time (double-precision real number)
* current time (double-precision real number),
* an ordered series of molecule coordinates.
* an ordered series of molecule coordinates.


Molecule coordinates comprise six values (six double-precision real  
Molecule coordinates comprise six values (six double-precision real  
numbers), out of which three first describe absolute molecule position  
numbers), out of which three first describe absolute molecule position  
(x, y, z) and the remaining three are required to be present but are  
(<i>x</i>, <i>y</i>, <i>z</i>) and the remaining three are only
not used.
placeholders intended to be used in future to describe molecule orientation.
Currently, they are ignored (and thus can be simply, e.g., three zeros).




=== Modifying the source code ===


=== Defining a new chemistry ===
In order to change simulation parameters or define a new system of chemical reactions, one has to modify and recompile the source code of Looper.


In file Chemistry.hpp there are two systems of reactions: ChemistrySystem1  
<div class="toccolours mw-collapsible mw-collapsed" data-expandtext="Show detailed instructions" data-collapsetext="Hide detailed instructions" style="float:left"><div class="mw-collapsible-content">
and ChemistrySystem2, which correspond to the monostable and bistable  
<h4>Defining a reaction system</h4>
reaction systems, respectively, analyzed in the article.
 
In file Chemistry.hpp there are already two systems of reactions: <code>ChemistrySystem1</code>
and <code>ChemistrySystem2</code>, which correspond to the monostable and the bistable  
reaction systems, respectively, analyzed in the [[#RefZukEtAl|article]].


To define and use a new system of reactions, one has to create a class that
To define and use a new system of reactions, one has to create a class that
inherits from the StochasticChemistry class.  The subclass should set initial
inherits from the <code>StochasticChemistry</code> class.  The subclass should set initial
conditions in its constructor and should provide a match_events(...) method.
conditions in its constructor and should provide a <code>match_events()</code> method.
To provide a new system of reactions, please follow the conventions used to
To provide a new system of reactions, please follow the conventions used to
implement ChemistrySystem1 and ChemistrySystem2.
implement <code>ChemistrySystem1</code> and <code>ChemistrySystem2</code>
and associated enums for molecule species. The chemistry to be used in the simulator
is pointed in Settings.hpp with a type alias <code>chemistry_t</code>.


<h4>Various settings</h4>


'''Simulation duration:''' &nbsp;
<code>kTimeEnd</code> in Settings.hpp.


=== Various settings ===
'''Chemical rates and time scaling:''' &nbsp;
<code>kLambda</code> in Settings.hpp.


'''Simulation duration'''<br/>
'''Contact diameter:''' &nbsp;
Variable kTimeEnd in Settings.hpp.
<code>kSearchRadius</code> in Settings.hpp.


'''Contact diameter'''<br/>
'''Skipping frames when writing out:''' &nbsp;
Variable kSearchRadius in Settings.hpp.
<code>kWriteToChemStateFileEverySteps</code> in Settings.hpp


'''Skipping frames when writing output'''<br/>
<h4>Building</h4>
Variable kWriteToChemStateFileEverySteps in Settings.hpp


'''Compiler.'''&nbsp; A decent and recent C++ compiler that supports C++14 standard is required. The code has been confirmed to compile successfully under Linux with GNU
g++ 8.0 and Clang++ 6.0.


'''Toolchain.'''&nbsp; Compilation is managed by CMake.  To build Looper under Linux, it should be sufficient to enter the build directory and execute <code>./build_release.sh</code>.


=== Implementation details ===
<h4>Usage</h4>
 
Invoke simply as:
 
  ./Looper trajectory chemprefix
 
'''Multiple input trajectories.'''&nbsp;
More than one trajectory file can be read in and used.  Multiple files should
be listed consecutively before the last invocation argument, e.g., as:
 
  ./Looper traj1.bin traj2.bin traj3.bin chemprefix
 
The order of the use of multiple trajectories is random.  The trajectories
should have the same number of molecules and the same time step.
 
'''Multiple simulations – seed.'''&nbsp;
If more than one simulation is to be performed (by setting appropriately
variable <code>kNumOfReplicas</code> in file Settings.hpp), each simulation is seeded
sequentially starting from the value assigned to <code>kSimulationSeedsBase</code> (file Settings.hpp).  This value can be overridden by setting the environmental
variable <code>LOOPER_SEED_BASE</code> prior to Looper invocation.
 
'''Multiple simulations – multi-threading.'''&nbsp;
Multiple simulations of chemical kinetics that use the same base chemical
trajectory can run in parallel.  During run-time, the software chooses the
number of threads based on both the <code>kNumOfReplicas</code> (described above) and
hardware capabilities.  If necessary, this behavior can be tweaked manually
using variable <code>kNumOfThreads</code> (in file Settings.hpp).
<br/><br/>
</div></div>
<br/>


In principle, trajectory looping can be applied in two different but
equivalent ways.  One may first perform multiple joins of the base
contacts trajectory and in this manner obtain a looped contacts
trajectory of a desired length without considering chemical events.
The looped contacts trajectory, consisting of the base contacts
trajectory and index maps resulting from optimal assignments, provides
a complete information necessary for a subsequent simulation of chemical
trajectory (this way has been presented in Figure 1 in the article).


The second way consists in interweaving the simulation of chemical events
===Related methods and applications===
with joins of the base contacts trajectory.  This way can be more convenient
A conceptually equivalent approach (published nearly in parallel):
for some applications because what is expanding in computer memory is the
* <span class="pmbm">Bednarek&nbsp;X</span>, <span class="pmbm">Martin&nbsp;S</span>, <span class="pmbm">Ndiaye&nbsp;A</span>, <span class="pmbm">Peres&nbsp;V</span>, <span class="pmbm">Bonnefoy&nbsp;O</span>. '''Extrapolation of DEM simulations to large time scale. Application to the mixing of powder in a conical screw mixer''', ''Chem&nbsp;Eng&nbsp;Sci'' <u>197</u>:223–234 (2019) [https://doi.org/10.1016/j.ces.2018.12.022 CrossRef]
ultimate looped chemical trajectory, which is of direct interest, and not
the intermediary looped contacts trajectory, whose desired length may be
hard to guess. When using the second way, a stop condition can be defined
depending on the chemical state of the of the system or based on the already
collected chemical event statistics. This implementation of trajectory
looping has been written according to the second way.




=== Reference ===
An interesting application of trajectory looping:
* <span class="pmbm">Żuk PJ</span>, <span class="pmbm">Kochańczyk M</span>, <span class="pmbm">Lipniacki T</span>. '''Trajectory looping for sampling rare events in stochastic reaction–diffusion systems''', ''Bioinformatics'' (submitted)
* <span class="pmbm">Lichtenegger&nbsp;T</span> and <span class="pmbm">Miethlinger&nbsp;T</span>. '''On the connection between Lagrangian and Eulerian metrics for recurrent particulate flows''', ''Phys Fluids'' <u>32</u>:113308 (2020) [https://doi.org/10.1063/5.0025597 CrossRef]

Latest revision as of 22:17, 8 May 2023

A method for sampling rare events in stochastic reaction–diffusion systems


With trajectory looping one can use a single trajectory, generated
by a prior simulation of diffusive motions of molecules, to sample
chemical kinetic processes on time scales that are several orders
of magnitude longer than the duration of the diffusive trajectory.


235px-Ouroboros_1.jpg
A wyvern eating its own tail (public domain).


Reference

  • Żuk PJ, Kochańczyk M, Lipniacki T. Sampling rare events in stochastic reaction–diffusion systems within trajectory looping, Physical Review E 98:022401 (2018) CrossRef | PDF-ms


Downloads


On the implementation

Trajectory looping can be implemented in two different but equivalent ways. One may first perform multiple joins of the base contacts trajectory and in this manner obtain a looped contacts trajectory of a desired length without considering chemical events. The looped contacts trajectory, consisting of the base contacts trajectory and index maps resulting from optimal assignments, provides a complete information necessary for a subsequent simulation of chemical trajectory (this way has been presented in Figure 1 in the article).

The second way consists in interweaving the simulation of chemical events with joins of the base contacts trajectory. This way can be more convenient for some applications because what is expanding in computer memory is the ultimate looped chemical trajectory, which is of direct interest, and not the intermediary looped contacts trajectory, whose desired length may be hard to guess. When using the second way, a stop condition can be defined depending on the chemical state of the system or based on the already collected chemical event statistics.

Looper has been written according to the second way.


Format of input trajectory

Looper reads in binary trajectories. They are expected to have a header consisting of:

  • the number of molecules (4-byte signed integer),
  • time step (double-precision real number),
  • length of the edge of the cubical simulation box (positive value) or three (negative) values for lengths of non-cubical but cuboidal box (double-precision real number(s)).

The body of the trajectory file contains multiple frames. A single frame consists of:

  • current step index (4-byte signed integer),
  • current time (double-precision real number),
  • an ordered series of molecule coordinates.

Molecule coordinates comprise six values (six double-precision real numbers), out of which three first describe absolute molecule position (x, y, z) and the remaining three are only placeholders intended to be used in future to describe molecule orientation. Currently, they are ignored (and thus can be simply, e.g., three zeros).


Modifying the source code

In order to change simulation parameters or define a new system of chemical reactions, one has to modify and recompile the source code of Looper.

Defining a reaction system

In file Chemistry.hpp there are already two systems of reactions: ChemistrySystem1 and ChemistrySystem2, which correspond to the monostable and the bistable reaction systems, respectively, analyzed in the article.

To define and use a new system of reactions, one has to create a class that inherits from the StochasticChemistry class. The subclass should set initial conditions in its constructor and should provide a match_events() method. To provide a new system of reactions, please follow the conventions used to implement ChemistrySystem1 and ChemistrySystem2 and associated enums for molecule species. The chemistry to be used in the simulator is pointed in Settings.hpp with a type alias chemistry_t.

Various settings

Simulation duration:   kTimeEnd in Settings.hpp.

Chemical rates and time scaling:   kLambda in Settings.hpp.

Contact diameter:   kSearchRadius in Settings.hpp.

Skipping frames when writing out:   kWriteToChemStateFileEverySteps in Settings.hpp

Building

Compiler.  A decent and recent C++ compiler that supports C++14 standard is required. The code has been confirmed to compile successfully under Linux with GNU g++ 8.0 and Clang++ 6.0.

Toolchain.  Compilation is managed by CMake. To build Looper under Linux, it should be sufficient to enter the build directory and execute ./build_release.sh.

Usage

Invoke simply as:

 ./Looper trajectory chemprefix

Multiple input trajectories.  More than one trajectory file can be read in and used. Multiple files should be listed consecutively before the last invocation argument, e.g., as:

 ./Looper traj1.bin traj2.bin traj3.bin chemprefix

The order of the use of multiple trajectories is random. The trajectories should have the same number of molecules and the same time step.

Multiple simulations – seed.  If more than one simulation is to be performed (by setting appropriately variable kNumOfReplicas in file Settings.hpp), each simulation is seeded sequentially starting from the value assigned to kSimulationSeedsBase (file Settings.hpp). This value can be overridden by setting the environmental variable LOOPER_SEED_BASE prior to Looper invocation.

Multiple simulations – multi-threading.  Multiple simulations of chemical kinetics that use the same base chemical trajectory can run in parallel. During run-time, the software chooses the number of threads based on both the kNumOfReplicas (described above) and hardware capabilities. If necessary, this behavior can be tweaked manually using variable kNumOfThreads (in file Settings.hpp).



Related methods and applications

A conceptually equivalent approach (published nearly in parallel):

  • Bednarek X, Martin S, Ndiaye A, Peres V, Bonnefoy O. Extrapolation of DEM simulations to large time scale. Application to the mixing of powder in a conical screw mixer, Chem Eng Sci 197:223–234 (2019) CrossRef


An interesting application of trajectory looping:

  • Lichtenegger T and Miethlinger T. On the connection between Lagrangian and Eulerian metrics for recurrent particulate flows, Phys Fluids 32:113308 (2020) CrossRef