def __init__(self):
        KernelProvider.get().load_from_dir(platform_utils.get_readdy_plugin_dir())
        self.simulation = Simulation()
        self.simulation.set_kernel("CPU")

        self.fig = plt.figure()
        self.ax = self.fig.add_subplot(111, projection='3d')
        plt.ioff()
        self.fig.show()
        self.prev_pos = {}
        self.current_plot = None

        self.T = 4000000
Example #2
0
    def __init__(self):
        KernelProvider.get().load_from_dir(
            platform_utils.get_readdy_plugin_dir())
        self.simulation = Simulation()
        self.simulation.set_kernel("CPU")

        self.fig = plt.figure()
        self.ax = self.fig.add_subplot(111, projection='3d')
        plt.ioff()
        self.fig.show()
        self.prev_pos = {}
        self.current_plot = None

        self.T = 4000000
    def setUpClass(cls):
        cls.kernel_provider = KernelProvider.get()
        cls.kernel_provider.load_from_dir(
            platform_utils.get_readdy_plugin_dir())
        cls.simulation = Simulation()
        cls.simulation.set_kernel("SingleCPU")

        cls.fig = plt.figure()
        cls.ax = cls.fig.add_subplot(111, projection='3d')
        cls.prev_pos = {}
        cls.fig.show()
        cls.ax.set_xlim([-3, 3])
        cls.ax.set_ylim([-3, 3])
        cls.ax.set_zlim([-3, 3])
        cls.current_plot = None
        plt.ioff()
Example #4
0
    def setUpClass(cls):
        cls.kernel_provider = api.KernelProvider.get()
        cls.kernel_provider.load_from_dir(putils.get_readdy_plugin_dir())
        cls.dir = tempfile.mkdtemp("test-config-io")
        cls.fname = os.path.join(cls.dir, "test_io_utils.h5")

        sim = api.Simulation()
        sim.set_kernel("CPU")
        sim.register_particle_type("A", 1.)
        sim.register_particle_type("B", 2.)
        sim.register_particle_type("C", 3.)
        sim.register_reaction_conversion("mylabel", "A", "B", .00001)
        sim.register_reaction_conversion("A->B", "A", "B", 1.)
        fusion_rate = 0.4
        educt_distance = 0.2
        sim.register_reaction_fusion("B+C->A", "B", "C", "A", fusion_rate, educt_distance, .5, .5)
        with contextlib.closing(io.File.create(cls.fname)) as f:
            sim.run_scheme_readdy(True).write_config_to_file(f).configure_and_run(1, 0.1)
Example #5
0
    def setUpClass(cls):
        cls.kernel_provider = api.KernelProvider.get()
        cls.kernel_provider.load_from_dir(putils.get_readdy_plugin_dir())
        cls.dir = tempfile.mkdtemp("test-config-io")
        cls.fname = os.path.join(cls.dir, "test_io_utils.h5")

        sim = api.Simulation()
        sim.set_kernel("CPU")
        sim.register_particle_type("A", 1., 0.)
        sim.register_particle_type("B", 2., 0.)
        sim.register_particle_type("C", 3., 0.)
        sim.register_reaction_conversion("mylabel", "A", "B", .00001)
        sim.register_reaction_conversion("A->B", "A", "B", 1.)
        fusion_rate = 0.4
        educt_distance = 0.2
        sim.register_reaction_fusion("B+C->A", "B", "C", "A", fusion_rate, educt_distance, .5, .5)
        with contextlib.closing(io.File(cls.fname, io.FileAction.CREATE, io.FileFlag.OVERWRITE)) as f:
            sim.run_scheme_readdy(True).write_config_to_file(f).configure_and_run(1, 0.1)
Example #6
0
    def setUpClass(cls):
        cls.kernel_provider = api.KernelProvider.get()
        cls.kernel_provider.load_from_dir(putils.get_readdy_plugin_dir())
        cls.dir = tempfile.mkdtemp("test-config-io")
        cls.fname = os.path.join(cls.dir, "test_io_utils.h5")

        sim = api.Simulation("CPU")
        sim.context.particle_types.add("A", 1.)
        sim.context.particle_types.add("B", 2.)
        sim.context.particle_types.add("C", 3.)
        sim.context.reactions.add_conversion("mylabel", "A", "B", .00001)
        sim.context.reactions.add_conversion("A->B", "A", "B", 1.)
        fusion_rate = 0.4
        educt_distance = 0.2
        sim.context.reactions.add_fusion("B+C->A", "B", "C", "A", fusion_rate, educt_distance, .5, .5)
        with contextlib.closing(io.File.create(cls.fname)) as f:
            loop = sim.create_loop(.1)
            loop.write_config_to_file(f)
            loop.run(1)
Example #7
0
    def setUpClass(cls):
        cls.kernel_provider = api.KernelProvider.get()
        cls.kernel_provider.load_from_dir(putils.get_readdy_plugin_dir())
        cls.dir = tempfile.mkdtemp("test-config-io")
        cls.fname = os.path.join(cls.dir, "test_io_utils.h5")

        sim = api.Simulation("CPU")
        sim.context.particle_types.add("A", 1.)
        sim.context.particle_types.add("B", 2.)
        sim.context.particle_types.add("C", 3.)
        sim.context.reactions.add_conversion("mylabel", "A", "B", .00001)
        sim.context.reactions.add_conversion("A->B", "A", "B", 1.)
        fusion_rate = 0.4
        educt_distance = 0.2
        sim.context.reactions.add_fusion("B+C->A", "B", "C", "A", fusion_rate,
                                         educt_distance, .5, .5)
        with contextlib.closing(io.File.create(cls.fname)) as f:
            loop = sim.create_loop(.1)
            loop.write_config_to_file(f)
            loop.run(1)
Example #8
0
    def execute(self):
        ###################################
        #
        # Units:
        #   - [x] = µm
        #   - [t] = s
        #   - [E] = kJ/mol
        #
        ###################################

        kernel_provider = KernelProvider.get()
        kernel_provider.load_from_dir(platform_utils.get_readdy_plugin_dir())
        simulation = Simulation()
        simulation.set_kernel("CPU")

        ###################################
        #
        # set up simulation box
        #
        ###################################

        box_size = Vec(2, 7, 12)
        simulation.box_size = box_size
        simulation.kbt = 2.437  # room temperature
        simulation.periodic_boundary = [False, False, False]

        ###################################
        #
        # register particle types
        #
        ###################################

        # particle size, see: http://bmccellbiol.biomedcentral.com/articles/10.1186/1471-2121-5-29
        # "The size of the V-ATPase complex is about 15 nm (diameter) x 25 nm (length from lumen side to tip of head)"

        membrane_particle_size = .05

        diffusion_factor = .5
        simulation.register_particle_type("D", 2.5 * diffusion_factor,
                                          .01)  # MinD-ADP (without phosphor)
        simulation.register_particle_type("D_P", 2.5 * diffusion_factor,
                                          .01)  # MinD-ATP (with phosphor)
        simulation.register_particle_type("E", 2.5 * diffusion_factor,
                                          .01)  # MinE
        simulation.register_particle_type("D_PB", .01 * diffusion_factor,
                                          .01)  # MinD-ATP bound
        simulation.register_particle_type("DE", .01 * diffusion_factor,
                                          .01)  # MinDE

        ###################################
        #
        # register reaction types
        #
        ###################################

        reaction_radius = 4 * (
            0.01 + 0.01
        )  # = sum of the particle radii * 5 (5 - magic number such that k_fusion makes sense, sort of) 5 *
        # k_fusion = brentq(lambda x: self.erban_chapman(.093, 2.5 + .01, reaction_radius, x), 1, 5000000)
        k_fusion = 1.0
        print("k_fusion=%s" % k_fusion)
        simulation.register_reaction_conversion("Phosphorylation", "D", "D_P",
                                                .5)
        simulation.register_reaction_fusion("bound MinD+MinE->MinDE", "D_PB",
                                            "E", "DE", k_fusion,
                                            reaction_radius * 3.5, .5, .5)
        simulation.register_reaction_fission("MinDE to MinD and MinE, detach",
                                             "DE", "D", "E", .25,
                                             reaction_radius, .5, .5)

        ###################################
        #
        # register potentials
        #
        ###################################

        membrane_size = Vec(.5, 5, 10)
        layer = Vec(.08, .08, .08)
        extent = membrane_size + 2 * layer
        origin = -.5 * membrane_size - layer
        simulation.register_potential_box(
            "D", 10., origin, extent,
            False)  # (force constant, origin, extent, considerParticleRadius)
        simulation.register_potential_box(
            "D_P", 10., origin, extent,
            False)  # (force constant, origin, extent, considerParticleRadius)
        simulation.register_potential_box(
            "D_PB", 10., origin, extent,
            False)  # (force constant, origin, extent, considerParticleRadius)
        simulation.register_potential_box(
            "E", 10., origin, extent,
            False)  # (force constant, origin, extent, considerParticleRadius)
        simulation.register_potential_box(
            "DE", 10., origin, extent,
            False)  # (force constant, origin, extent, considerParticleRadius)

        # simulation.register_potential_piecewise_weak_interaction("D_P", "D_PB", 3, .02, 2, .05)  # (force constant, desired dist, depth, no interaction dist)

        ###################################
        #
        # membrane particles
        #
        ###################################
        using_membrane_particles = False
        if using_membrane_particles:
            simulation.register_particle_type(
                "M", 0, membrane_particle_size)  # membrane particle
            simulation.register_reaction_enzymatic(
                "Attach to membrane", "M", "D_P", "D_PB", .5,
                .01 + membrane_particle_size)  # .01 + .025  # todo: rate?
            dx = np.linspace(
                origin[0] + layer[0],
                -1 * origin[0] - layer[0],
                int(float(membrane_size[0]) / membrane_particle_size),
                endpoint=True)
            dy = np.linspace(
                origin[1] + layer[1],
                -1 * origin[1] - layer[1],
                int(float(membrane_size[1]) / membrane_particle_size),
                endpoint=True)
            dz = np.linspace(
                origin[2] + layer[2],
                -1 * origin[2] - layer[2],
                int(float(membrane_size[2]) / membrane_particle_size),
                endpoint=True)
            for y in dy:
                for z in dz:
                    simulation.add_particle(
                        "M", Vec(-1 * origin[0] - layer[0], y, z))
            print("done adding membrane particles")
        else:
            simulation.register_reaction_conversion("Phosphorylation", "D_P",
                                                    "D_PB", .5)
            simulation.register_reaction_enzymatic(
                "Enzymatic DP+DPB->DPB + DPB", "D_PB", "D_P", "D_PB", .5, .02)
        using_uniform_distribution = True
        n_minE_particles = 3120
        n_minD_particles = n_minE_particles * 4
        mine_x = np.random.uniform(origin[0] + layer[0],
                                   -1 * origin[0] - layer[0], n_minE_particles)
        mine_y = np.random.uniform(origin[1] + layer[1],
                                   -1 * origin[1] - layer[1], n_minE_particles)
        if using_uniform_distribution:
            mine_z = np.random.uniform(origin[2] + layer[2],
                                       -1 * origin[2] - layer[2],
                                       n_minE_particles)
        else:
            mine_z = np.random.uniform(origin[2] + layer[2],
                                       .5 * (-1 * origin[2] - layer[2]),
                                       n_minE_particles)

        mind_x = np.random.uniform(origin[0] + layer[0],
                                   -1 * origin[0] - layer[0], n_minD_particles)
        mind_y = np.random.uniform(origin[1] + layer[1],
                                   -1 * origin[1] - layer[1], n_minD_particles)
        if using_uniform_distribution:
            mind_z = np.random.uniform(origin[2] + layer[2],
                                       -1 * origin[2] - layer[2],
                                       n_minD_particles)
        else:
            mind_z = np.random.uniform(.5 * (-1 * origin[2] - layer[2]),
                                       -1 * origin[2] - layer[2],
                                       n_minD_particles)

        for i in range(n_minE_particles):
            simulation.add_particle("E", Vec(mine_x[i], mine_y[i], mine_z[i]))

        for i in range(int(.5 * n_minD_particles)):
            simulation.add_particle("D", Vec(mind_x[i], mind_y[i], mind_z[i]))
        for i in range(int(.5 * n_minD_particles), n_minD_particles):
            simulation.add_particle("D_P", Vec(mind_x[i], mind_y[i],
                                               mind_z[i]))

        self.timestep = simulation.get_recommended_time_step(2)

        ###################################
        #
        # register observables
        #
        ###################################

        # simulation.register_observable_center_of_mass(1, self.com_callback_mind, ["D", "D_P", "D_PB"])
        # simulation.register_observable_center_of_mass(1, self.com_callback_mine, ["E"])
        # simulation.register_observable_center_of_mass(1, self.com_callback_minde, ["DE", "D_PB"])
        print("histogram start")
        # simulation.register_observable_histogram_along_axis(100, self.histrogram_callback_minD, np.arange(-3, 3, .1), ["D", "D_P", "D_PB"], 2)
        # simulation.register_observable_histogram_along_axis(100, self.histrogram_callback_minE, np.arange(-3, 3, .1), ["D_PB", "DE"], 2)
        stride = int(.01 / self.timestep)
        self.stride = stride
        print("using stride=%s" % stride)
        bins = np.linspace(-7, 7, 80)
        simulation.register_observable_histogram_along_axis(
            stride, bins, 2, ["D"], self.histogram_callback_minD)
        simulation.register_observable_histogram_along_axis(
            stride, bins, 2, ["D_P"], self.histogram_callback_minDP)
        simulation.register_observable_histogram_along_axis(
            stride, bins, 2, ["D_PB"], self.histogram_callback_minDPB)
        simulation.register_observable_histogram_along_axis(
            stride, bins, 2, ["E"], self.histogram_callback_minE)
        simulation.register_observable_histogram_along_axis(
            stride, bins, 2, ["DE"], self.histogram_callback_minDE)
        simulation.register_observable_histogram_along_axis(
            stride, bins, 2, ["D", "D_P", "D_PB", "DE"],
            self.histogram_callback_M)
        simulation.register_observable_n_particles(
            stride, ["D", "D_P", "D_PB", "E", "DE"], self.n_particles_callback)
        print("histogram end")

        self.n_timesteps = int(1200. / self.timestep)

        print("starting simulation for effectively %s sec" %
              (self.timestep * self.n_timesteps))
        simulation.run_scheme_readdy(True).with_reaction_scheduler(
            "GillespieParallel").configure(self.timestep).run(self.n_timesteps)

        if self._result_fname is not None:
            with open(self._result_fname, 'w') as f:
                np.save(f, np.array(self._hist_data))
def rdf_callback(pair):
    global rdf, centers, n_calls, T
    if centers is None:
        centers = pair[0]
    if rdf is None:
        rdf = pair[1]
    else:
        rdf += pair[1]
    n_calls += 1
    if n_calls % 10000 == 0:
        print("%s" % (10. * float(n_calls) / float(T)))


if __name__ == '__main__':
    KernelProvider.get().load_from_dir(platform_utils.get_readdy_plugin_dir())
    simulation = Simulation()
    simulation.set_kernel("CPU")

    box_size = Vec(10, 10, 10)
    simulation.kbt = 2
    simulation.periodic_boundary = [True, True, True]
    simulation.box_size = box_size
    simulation.register_particle_type("A", .2, 1.)
    simulation.register_particle_type("B", .2, 1.)
    simulation.register_potential_harmonic_repulsion("A", "B", 10)
    simulation.add_particle("A", Vec(-2.5, 0, 0))
    simulation.add_particle("B", Vec(0, 0, 0))

    simulation.register_observable_radial_distribution(
        10, np.arange(0, 5, .01), ["A"], ["B"],
Example #10
0
 def setUpClass(cls):
     cls.kernel_provider = KernelProvider.get()
     cls.kernel_provider.load_from_dir(platform_utils.get_readdy_plugin_dir())
Example #11
0
 def __init__(self, kernel, time_step):
     self.kernel_provider = KernelProvider.get()
     self.kernel_provider.load_from_dir(
         platform_utils.get_readdy_plugin_dir())
     self.kernel = kernel
     self.time_step = time_step
 def setUp(self):
     super().setUp()
     self.kernel_provider = KernelProvider.get()
     self.kernel_provider.load_from_dir(platform_utils.get_readdy_plugin_dir())
     self.simulation = Simulation()
Example #13
0
 def setUpClass(cls):
     cls.kernel_provider = KernelProvider.get()
     cls.kernel_provider.load_from_dir(platform_utils.get_readdy_plugin_dir())
     cls.dir = tempfile.mkdtemp("test-observables-io")
Example #14
0
#  3. Neither the name of the copyright holder nor the names of
#     its contributors may be used to endorse or promote products
#     derived from this software without specific
#     prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# load kernels automagically
import readdy.util.platform_utils as putils
from .readdybinding.api import *
from .readdybinding.common import *
from .readdybinding.common.io import *
from .readdybinding.common.util import *

register_blosc_hdf5_plugin()

kernel_provider = KernelProvider.get()
kernel_provider.load_from_dir(putils.get_readdy_plugin_dir())
Example #15
0
#     its contributors may be used to endorse or promote products
#     derived from this software without specific
#     prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import pathlib
import readdy.util.platform_utils as putils
from .readdybinding.api import *
from .readdybinding.common import *
from .readdybinding.common.io import *
from .readdybinding.common.util import *

register_blosc_hdf5_plugin()

kernel_provider = KernelProvider.get()
if putils.get_readdy_plugin_dir().exists():
    kernel_provider.load_from_dir(str(putils.get_readdy_plugin_dir()))
Example #16
0
    def run(self):

        ###################################
        #
        # Units:
        #   - [t] = sec
        #
        ###################################

        tau = 1e-3

        kernel_provider = KernelProvider.get()
        kernel_provider.load_from_dir(platform_utils.get_readdy_plugin_dir())
        simulation = Simulation()
        simulation.set_kernel("CPU")
        simulation.kbt = 1.0
        simulation.box_size = Vec(3, 3, 3)
        simulation.periodic_boundary = [True, True, True]

        D = 1.0
        R = .01
        simulation.register_particle_type("A", D, R)
        simulation.register_particle_type("2A", D, R)
        simulation.register_particle_type("3A", D, R)
        simulation.register_particle_type("B", D, R)
        simulation.register_particle_type("GA", D, R)
        simulation.register_particle_type("GB", D, R)

        reaction_radius = .2
        k1 = 4 * 1e-5
        k2 = 50
        k3 = 10
        k4 = 250

        V = simulation.box_size * simulation.box_size

        N_GA = 100.0
        N_GB = 1000.0

        k_enzymatic = brentq(lambda x: erban_chapman(k1, 2, reaction_radius, x), 1e-10, 5000000000000)
        k_enzymatic = 10. # k_enzymatic for reaction_radius = .1
        print("k_enzymatic=%s" % k_enzymatic)
        print("2 * k3 - k3 * k3 * tau = %s" % (2.0 * k3 - k3 * k3 * tau))
        print("k3 * k3 * tau = %s" % (k3 * k3 * tau))
        print("k_birthA = %s" % (k2 * V / N_GA))
        print("k_birthB = %s" % (k4 * V / N_GB))
        print("sqrt(R*R/D) = %s" % (np.sqrt(reaction_radius * reaction_radius / D)))

        simulation.register_reaction_conversion("2A -> A", "2A", "A", 2.0 * k3 - k3 * k3 * tau)
        simulation.register_reaction_decay("2A -> 0", "2A", k3 * k3 * tau)
        simulation.register_reaction_fusion("A + A -> 2A", "A", "A", "2A", 1.0 / tau, reaction_radius, .5, .5)
        simulation.register_reaction_enzymatic("2A + B -> 2A + A", "2A", "B", "A", k_enzymatic, reaction_radius)
        simulation.register_reaction_fission("GA -> GA + A", "GA", "GA", "A", k2 * V / N_GA, reaction_radius, .5, .5)
        simulation.register_reaction_decay("A -> 0", "A", k3)
        simulation.register_reaction_fission("GB -> GB + B", "GB", "GB", "B", k4 * V / N_GB, reaction_radius, .5, .5)

        simulation.add_particle("A", Vec(0, 0, 0))

        ga_x = np.random.uniform(-0.5 * simulation.box_size[0], 0.5 * simulation.box_size[0], int(N_GA))
        ga_y = np.random.uniform(-0.5 * simulation.box_size[1], 0.5 * simulation.box_size[1], int(N_GA))
        ga_z = np.random.uniform(-0.5 * simulation.box_size[2], 0.5 * simulation.box_size[2], int(N_GA))

        gb_x = np.random.uniform(-0.5 * simulation.box_size[0], 0.5 * simulation.box_size[0], int(N_GB))
        gb_y = np.random.uniform(-0.5 * simulation.box_size[1], 0.5 * simulation.box_size[1], int(N_GB))
        gb_z = np.random.uniform(-0.5 * simulation.box_size[2], 0.5 * simulation.box_size[2], int(N_GB))

        for i in range(int(N_GA)):
            simulation.add_particle("GA", Vec(ga_x[i], ga_y[i], ga_z[i]))
        for i in range(int(N_GB)):
            simulation.add_particle("GB", Vec(gb_x[i], gb_y[i], gb_z[i]))

        N_B = 30000
        boxsize = np.array([simulation.box_size[0], simulation.box_size[1], simulation.box_size[2]])
        for i in range(N_B):
            pos = np.random.random(3) * boxsize - 0.5 * boxsize
            simulation.add_particle("B", Vec(pos[0], pos[1], pos[2]))

        def callback(result):
            n_a, n_b = result[0] + 2 * result[1] + 3 * result[2], result[3]
            self._data[self._t, 0] = n_a
            self._data[self._t, 1] = n_b
            print("(%s,%s,a=%s,a2=%s,a3=%s)"%(n_a, n_b,result[0], result[1], result[2]))

            self.lines.set_xdata(self._data[:self._t, 0])
            self.lines.set_ydata(self._data[:self._t, 1])
            self.ax.relim()
            self.ax.autoscale_view()
            #We need to draw *and* flush
            self.fig.canvas.draw()
            self.fig.canvas.flush_events()

            plt.pause(.1)
            self._t += 1

        simulation.register_observable_n_particles_types(1, ["A", "2A", "3A", "B"], callback)
        print("start run")
        simulation.run(self._timesteps, tau)
Example #17
0
#     its contributors may be used to endorse or promote products
#     derived from this software without specific
#     prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import pathlib
import readdy.util.platform_utils as putils
from .readdybinding.api import *
from .readdybinding.common import *
from .readdybinding.common.io import *
from .readdybinding.common.util import *

register_blosc_hdf5_plugin()

kernel_provider = KernelProvider.get()
if pathlib.Path(putils.get_readdy_plugin_dir()).exists():
    kernel_provider.load_from_dir(putils.get_readdy_plugin_dir())
Example #18
0
 def __init__(self, kernel, time_step):
     self.kernel_provider = KernelProvider.get()
     self.kernel_provider.load_from_dir(platform_utils.get_readdy_plugin_dir())
     self.kernel = kernel
     self.time_step = time_step
 def setUpClass(cls):
     cls.kernel_provider = KernelProvider.get()
     cls.kernel_provider.load_from_dir(
         platform_utils.get_readdy_plugin_dir())
Example #20
0
    def execute(self):
        ###################################
        #
        # Units:
        #   - [x] = µm
        #   - [t] = s
        #   - [E] = kJ/mol
        #
        ###################################

        kernel_provider = KernelProvider.get()
        kernel_provider.load_from_dir(platform_utils.get_readdy_plugin_dir())
        simulation = Simulation()
        simulation.set_kernel("CPU")

        ###################################
        #
        # set up simulation box
        #
        ###################################

        box_size = Vec(2, 7, 12)
        simulation.box_size = box_size
        simulation.kbt = 2.437  # room temperature
        simulation.periodic_boundary = [False, False, False]

        ###################################
        #
        # register particle types
        #
        ###################################

        # particle size, see: http://bmccellbiol.biomedcentral.com/articles/10.1186/1471-2121-5-29
        # "The size of the V-ATPase complex is about 15 nm (diameter) x 25 nm (length from lumen side to tip of head)"

        membrane_particle_size = .05

        diffusion_factor = .5
        simulation.register_particle_type("D", 2.5 * diffusion_factor, .01)  # MinD-ADP (without phosphor)
        simulation.register_particle_type("D_P", 2.5 * diffusion_factor, .01)  # MinD-ATP (with phosphor)
        simulation.register_particle_type("E", 2.5 * diffusion_factor, .01)  # MinE
        simulation.register_particle_type("D_PB", .01 * diffusion_factor, .01)  # MinD-ATP bound
        simulation.register_particle_type("DE", .01 * diffusion_factor, .01)  # MinDE

        ###################################
        #
        # register reaction types
        #
        ###################################

        reaction_radius = 4*(0.01 + 0.01)  # = sum of the particle radii * 5 (5 - magic number such that k_fusion makes sense, sort of) 5 *
        # k_fusion = brentq(lambda x: self.erban_chapman(.093, 2.5 + .01, reaction_radius, x), 1, 5000000)
        k_fusion = 1.0
        print("k_fusion=%s" % k_fusion)
        simulation.register_reaction_conversion("Phosphorylation", "D", "D_P", .5)
        simulation.register_reaction_fusion("bound MinD+MinE->MinDE", "D_PB", "E", "DE", k_fusion, reaction_radius*3.5, .5, .5)
        simulation.register_reaction_fission("MinDE to MinD and MinE, detach", "DE", "D", "E", .25, reaction_radius, .5, .5)

        ###################################
        #
        # register potentials
        #
        ###################################

        membrane_size = Vec(.5, 5, 10)
        layer = Vec(.08, .08, .08)
        extent = membrane_size + 2 * layer
        origin = -.5 * membrane_size - layer
        simulation.register_potential_box("D", 10., origin, extent, False)  # (force constant, origin, extent, considerParticleRadius)
        simulation.register_potential_box("D_P", 10., origin, extent, False)  # (force constant, origin, extent, considerParticleRadius)
        simulation.register_potential_box("D_PB", 10., origin, extent, False)  # (force constant, origin, extent, considerParticleRadius)
        simulation.register_potential_box("E", 10., origin, extent, False)  # (force constant, origin, extent, considerParticleRadius)
        simulation.register_potential_box("DE", 10., origin, extent, False)  # (force constant, origin, extent, considerParticleRadius)

        # simulation.register_potential_piecewise_weak_interaction("D_P", "D_PB", 3, .02, 2, .05)  # (force constant, desired dist, depth, no interaction dist)

        ###################################
        #
        # membrane particles
        #
        ###################################
        using_membrane_particles = False
        if using_membrane_particles:
            simulation.register_particle_type("M", 0, membrane_particle_size)  # membrane particle
            simulation.register_reaction_enzymatic("Attach to membrane", "M", "D_P", "D_PB", .5, .01 + membrane_particle_size)  # .01 + .025  # todo: rate?
            dx = np.linspace(origin[0] + layer[0], -1 * origin[0] - layer[0], int(float(membrane_size[0]) / membrane_particle_size), endpoint=True)
            dy = np.linspace(origin[1] + layer[1], -1 * origin[1] - layer[1], int(float(membrane_size[1]) / membrane_particle_size), endpoint=True)
            dz = np.linspace(origin[2] + layer[2], -1 * origin[2] - layer[2], int(float(membrane_size[2]) / membrane_particle_size), endpoint=True)
            for y in dy:
                for z in dz:
                    simulation.add_particle("M", Vec(-1 * origin[0] - layer[0], y, z))
            print("done adding membrane particles")
        else:
            simulation.register_reaction_conversion("Phosphorylation", "D_P", "D_PB", .5)
            simulation.register_reaction_enzymatic("Enzymatic DP+DPB->DPB + DPB", "D_PB", "D_P", "D_PB", .5, .02)
        using_uniform_distribution = True
        n_minE_particles = 3120
        n_minD_particles = n_minE_particles * 4
        mine_x = np.random.uniform(origin[0] + layer[0], -1 * origin[0] - layer[0], n_minE_particles)
        mine_y = np.random.uniform(origin[1] + layer[1], -1 * origin[1] - layer[1], n_minE_particles)
        if using_uniform_distribution:
            mine_z = np.random.uniform(origin[2] + layer[2], -1 * origin[2] - layer[2], n_minE_particles)
        else:
            mine_z = np.random.uniform(origin[2] + layer[2], .5 * (-1 * origin[2] - layer[2]), n_minE_particles)

        mind_x = np.random.uniform(origin[0] + layer[0], -1 * origin[0] - layer[0], n_minD_particles)
        mind_y = np.random.uniform(origin[1] + layer[1], -1 * origin[1] - layer[1], n_minD_particles)
        if using_uniform_distribution:
            mind_z = np.random.uniform(origin[2] + layer[2], -1 * origin[2] - layer[2], n_minD_particles)
        else:
            mind_z = np.random.uniform(.5 * (-1 * origin[2] - layer[2]), -1 * origin[2] - layer[2], n_minD_particles)

        for i in range(n_minE_particles):
            simulation.add_particle("E", Vec(mine_x[i], mine_y[i], mine_z[i]))

        for i in range(int(.5 * n_minD_particles)):
            simulation.add_particle("D", Vec(mind_x[i], mind_y[i], mind_z[i]))
        for i in range(int(.5 * n_minD_particles), n_minD_particles):
            simulation.add_particle("D_P", Vec(mind_x[i], mind_y[i], mind_z[i]))

        self.timestep = simulation.get_recommended_time_step(2)

        ###################################
        #
        # register observables
        #
        ###################################

        # simulation.register_observable_center_of_mass(1, self.com_callback_mind, ["D", "D_P", "D_PB"])
        # simulation.register_observable_center_of_mass(1, self.com_callback_mine, ["E"])
        # simulation.register_observable_center_of_mass(1, self.com_callback_minde, ["DE", "D_PB"])
        print("histogram start")
        # simulation.register_observable_histogram_along_axis(100, self.histrogram_callback_minD, np.arange(-3, 3, .1), ["D", "D_P", "D_PB"], 2)
        # simulation.register_observable_histogram_along_axis(100, self.histrogram_callback_minE, np.arange(-3, 3, .1), ["D_PB", "DE"], 2)
        stride = int(.01/self.timestep)
        self.stride = stride
        print("using stride=%s" % stride)
        bins = np.linspace(-7, 7, 80)
        simulation.register_observable_histogram_along_axis(stride, bins, 2, ["D"], self.histogram_callback_minD)
        simulation.register_observable_histogram_along_axis(stride, bins, 2, ["D_P"], self.histogram_callback_minDP)
        simulation.register_observable_histogram_along_axis(stride, bins, 2, ["D_PB"], self.histogram_callback_minDPB)
        simulation.register_observable_histogram_along_axis(stride, bins, 2, ["E"], self.histogram_callback_minE)
        simulation.register_observable_histogram_along_axis(stride, bins, 2, ["DE"], self.histogram_callback_minDE)
        simulation.register_observable_histogram_along_axis(stride, bins, 2, ["D", "D_P", "D_PB", "DE"], self.histogram_callback_M)
        simulation.register_observable_n_particles(stride, ["D", "D_P", "D_PB", "E", "DE"], self.n_particles_callback)
        print("histogram end")

        self.n_timesteps = int(1200./self.timestep)

        print("starting simulation for effectively %s sec" % (self.timestep * self.n_timesteps))
        simulation.run_scheme_readdy(True).with_reaction_scheduler("GillespieParallel").configure(self.timestep).run(self.n_timesteps)

        if self._result_fname is not None:
            with open(self._result_fname, 'w') as f:
                np.save(f, np.array(self._hist_data))