Exemple #1
0
    style={"color":"MediumSeaGreen"}

class Sphere(m.Particle):
    radius=3
    frozen = True
    style={"color":"orange"}

class Test(m.Particle):
    radius=0
    frozen = True
    style={"color":"orange"}


p = m.Potential.morse(d=100, a=1, max=5)

m.bind(p, A, Sphere)
m.bind(p, A, Test)
m.bind(p, A, m.Cuboid)

m.bind(p, A, m.Universe.boundary_conditions.bottom)
m.bind(p, A, m.Universe.boundary_conditions.top)
m.bind(p, A, m.Universe.boundary_conditions.left)
m.bind(p, A, m.Universe.boundary_conditions.right)
m.bind(p, A, m.Universe.boundary_conditions.front)
m.bind(p, A, m.Universe.boundary_conditions.back)


# above the sphere
Sphere(m.Universe.center + [5, 0, 0])
A(m.Universe.center + [5, 0, Sphere.radius + dist])
Exemple #2
0
    class A(m.Particle):
        radius = 0.5
        dynamics = m.Overdamped
        mass = 10
        style = {"color": "MediumSeaGreen"}

    class B(m.Particle):
        radius = 0.5
        dynamics = m.Overdamped
        mass = 10
        style = {"color": "skyblue"}


c1 = C(position=center - (3, 0, 0))
c2 = C(position=center + (7, 0, 0))

c1.A(2000)
c2.B(2000)

p1 = m.Potential.glj(e=7, m=1, max=1)
p2 = m.Potential.glj(e=7, m=1, max=2)
m.bind(p1, C.A, C.A, bound=True)
m.bind(p2, C.B, C.B, bound=True)

rforce = m.forces.random(0, 10)
m.bind(rforce, C.A)
m.bind(rforce, C.B)

m.run()
Exemple #3
0
           cutoff=cutoff)

# Create a 12-6 inter-atom potential
# The smallest radius for which the potential will be constructed.
# The largest radius for which the potential will be constructed.
# The first parameter of the Lennard-Jones potential.
# The second parameter of the Lennard-Jones potential.
# The tolerance to which the interpolation should match the exact
# potential.
pot_ArAr = m.Potential.LJ126(range=(0.275, 1.0),
                             A=9.5075e-06,
                             B=6.1545e-03,
                             tol=1.0e-3)

# bind the potential with Argon type
m.bind(pot_ArAr, Argon)

# create a lattice of particles
# these are number of particles in each dimension.
nx = ceil(pow(nr_parts, 1.0 / 3))
hx = dim[0] / nx
ny = ceil(sqrt(nr_parts / nx))
hy = dim[1] / ny
nz = ceil(nr_parts / nx / ny)
hz = dim[2] / nz

# iterate over the how many particles we want, set thier
# initial positions and velocities, and add them to the
# universe.
for i in range(0, nx):
    x[0] = 0.05 + i * hx
Exemple #4
0
#pot_yc = m.Potential.glj(e=500, r0=10, m=5, k=100, min=0.1, max=50*Cell.radius, tol=0.1)
pot_yc = m.Potential.glj(e=100,
                         r0=5,
                         m=3,
                         k=500,
                         min=0.1,
                         max=50 * Cell.radius,
                         tol=0.1)
pot_cc = m.Potential.glj(e=1, r0=2, m=2, min=0.05, max=2.2 * Cell.radius)

# bind the potential with the *TYPES* of the particles
m.Universe.bind(pot_yc, Yolk, Cell)
m.Universe.bind(pot_cc, Cell, Cell)

# create a random force. In overdamped dynamcis, we neeed a random force to
# enable the objects to move around, otherwise they tend to get trapped
# in a potential
rforce = m.forces.random(0, 100, durration=0.5)

# bind it just like any other force
m.bind(rforce, Cell)

yolk = Yolk(position=center - [0., 0., yshift])

for i, p in enumerate(m.random_points(m.SolidSphere, count)):
    pos = p * clump_radius + center + [0., 0., cshift]
    Cell(position=pos)

# run the simulator interactive
m.Simulator.run()
Exemple #5
0
import mechanica as m

m.init(dt=0.1, dim=[15, 5, 5], cutoff = 3,
       bc={'x':('periodic','reset')})

class A(m.Particle):
    species = ['S1', 'S2', 'S3']
    style = {"colormap" : {"species" : "S1",
                           "map" : "rainbow",
                           "range" : "auto"}}


a1 = A(m.universe.center - [0, 1, 0])
a2 = A(m.universe.center + [-5, 1, 0], velocity=[0.5, 0, 0])

pressure = m.forces.ConstantForce([0.1, 0, 0])

m.bind(pressure, A, "S1")

a1.species.S1 = 0
a2.species.S1 = 0.1

m.run()
Exemple #6
0
                                 epsilon=0.1,
                                 r0=0.6,
                                 eta=4,
                                 tol=0.05,
                                 min=0.01,
                                 max=3)
pot_vb = m.Potential.soft_sphere(kappa=5,
                                 epsilon=0,
                                 r0=4.8,
                                 eta=4,
                                 tol=0.05,
                                 min=3,
                                 max=5.5)

# bind the potential with the *TYPES* of the particles
m.bind(pot_rr, Receptor, Receptor)
m.bind(pot_vr, Receptor, Virus)
m.bind(pot_vb, Big, Virus)

# create a random force (Brownian motion), zero mean of given amplitide
tstat = m.forces.random(0, 0.1)
vtstat = m.forces.random(0, 0.1)

# bind it just like any other force
m.bind(tstat, Receptor)

m.bind(vtstat, Virus)

b = Big(position=center, velocity=[0., 0., 0.])

Virus(position=center + [0, 0, Big.radius + 0.75])
Exemple #7
0
import mechanica as m
import numpy as np

cutoff = 8
count = 3

# dimensions of universe
dim = np.array([20., 20., 20.])
center = dim / 2

m.init(dim=dim, cutoff=cutoff)


class B(m.Particle):
    mass = 1
    dynamics = m.Overdamped


# make a glj potential, this automatically reads the
# particle radius to determine rest distance.
pot = m.Potential.glj(e=1)

m.bind(pot, B, B)

p1 = B(center + (-2, 0, 0))
p2 = B(center + (2, 0, 0))
p1.radius = 1
p2.radius = 2

m.Simulator.run()
Exemple #8
0
class C(m.Particle):
    radius = 10
    frozen = True
    style = {"color": "orange"}


pc = m.Potential.glj(e=10, m=3, max=5)
pa = m.Potential.glj(e=2, m=4, max=3.0)
pb = m.Potential.glj(e=1, m=4, max=1)
pab = m.Potential.harmonic(k=10, r0=0, min=0.01, max=0.55)

# simple harmonic potential to pull particles
h = m.Potential.harmonic(k=40, r0=0.001, max=5)

m.bind(pc, A, C)
m.bind(pc, B, C)
m.bind(pa, A, A)
#m.bind(pb, B, B)
#m.bind(pab, A, B)

r = m.forces.random(0, 5)

m.bind(r, A)
#m.bind(r, B)

c = C(m.Universe.center)

pos_a = m.random_points(m.SolidSphere, 3000, dr=0.25, phi=(0, 0.60 * np.pi)) \
    * ((1 + 0.25/2) * C.radius)  + m.Universe.center
Exemple #9
0

# locations of initial receptor positions
receptor_pts = m.random_points(m.SolidSphere, receptor_count) * 5 + center

pot_nr = m.Potential.well(k=15, n=3, r0=7)
pot_rr = m.Potential.soft_sphere(kappa=15,
                                 epsilon=0,
                                 r0=0.3,
                                 eta=2,
                                 tol=0.05,
                                 min=0.01,
                                 max=1)

# bind the potential with the *TYPES* of the particles
m.bind(pot_rr, Receptor, Receptor)
m.bind(pot_nr, Nucleus, Receptor)

# create a random force (Brownian motion), zero mean of given amplitide
tstat = m.forces.random(0, 3)
vtstat = m.forces.random(0, 5)

# bind it just like any other force
m.bind(tstat, Receptor)

n = Nucleus(position=center, velocity=[0., 0., 0.])

for p in receptor_pts:
    Receptor(p)

# run the simulator interactive
Exemple #10
0
    style = {"color": "skyblue"}


class Yolk(m.Particle):
    """
    The yolk type, only have a single instance of this
    """

    radius = 10
    frozen = True
    style = {"color": "orange"}


# Make some potentials (forces) to connect the different cell types together.

m.bind(p_yolk, Cell, Yolk)
m.bind(p_yolk, Actin, Yolk)
m.bind(p_cell, Cell, Cell)
m.bind(p_cellactin, Cell, Actin)

r = m.forces.random(0, 5)

m.bind(r, Cell)
#m.bind(r, Actin)

# make a yolk at the center of the simulation domain
yolk = Yolk(m.Universe.center)

# create the initial cell positions
cell_positions = m.random_points(m.SolidSphere, 6000, dr=dr, phi=(0, epiboly_percent * np.pi)) \
    * ((1 + dr/2) * Yolk.radius)  + yolk.position
Exemple #11
0
pot_yc = m.Potential.glj(e=100, r0=5, m=3, k=500, min=0.1,  max=1.5 * Big.radius, tol=0.1)
#pot_cc = m.Potential.glj(e=0,   r0=2, m=2, k=10,  min=0.05, max=1 * Big.radius)
pot_cc = m.Potential.harmonic(r0=0, k=0.1, max=10)

#pot_yc = m.Potential.glj(e=10, r0=1, m=3, min=0.1, max=50*Small.radius, tol=0.1)
#pot_cc = m.Potential.glj(e=100, r0=5, m=2, min=0.05, max=0.5*Big.radius)

# bind the potential with the *TYPES* of the particles
m.Universe.bind(pot_yc, Big, Small)
m.Universe.bind(pot_cc, Small, Small)

# create a random force. In overdamped dynamcis, we neeed a random force to
# enable the objects to move around, otherwise they tend to get trapped
# in a potential
rforce = m.forces.random(0, 100, durration=0.5)

# bind it just like any other force
m.bind(rforce, Small)

yolk = Big(position=center)


for p in m.random_points(m.Sphere, count):
    pos = p * (Big.radius + Small.radius) + center
    Small(position=pos)


# run the simulator interactive
m.Simulator.run()
Exemple #12
0
           'x': 'periodic',
           'z': 'no_slip',
           'y': 'periodic'
       },
       perfcounter_period=100)

# lattice spacing
a = 0.7


class A(m.Particle):
    radius = 0.3
    style = {"color": "seagreen"}
    dynamics = m.Newtonian
    mass = 10


dpd = m.Potential.dpd(sigma=1.5)

m.bind(dpd, A, A)

f = m.forces.ConstantForce([0.01, 0, 0])

m.bind(f, A)

uc = m.lattice.sc(a, A)

parts = m.lattice.create_lattice(uc, [15, 15, 15])

m.run()
Exemple #13
0
# simple harmonic potential to pull particles
h = m.Potential.harmonic(k=200, r0=0.001, max = 5)

#h = m.Potential.linear(k=0.5,  max = 5)

#pb= m.Potential.glj(e=0.00001, r0=0.1, m=3, min=0.01, max=Blue.radius*3)
pb = m.Potential.coulomb(q=0.01, min=0.01, max=3)

# potential between the small and big particles
pot = m.Potential.glj(e=1, m=2, max=5)

Big(m.Universe.center)

Big.style.visible = False

m.bind(pot, Big, Blue)

m.bind(pb, Blue, Blue)


parts, bonds = m.bind_sphere(h, type=Blue, n=4, phi=(0.55 * np.pi, 1 * np.pi), radius = Big.radius + Blue.radius)

#for b in bonds:
#    print("energy(", b.id, "): ", b.energy())


#print("parts: ", parts)


#parts[0].destroy()
Exemple #14
0
           'top':{'velocity':[-0.4, 0, 0]}},
       perfcounter_period=100)

# lattice spacing
a = 0.3

#m.universe.boundary_conditions.left.restore = 0.5

class A (m.Particle):
    radius = 0.2
    style={"color":"seagreen"}
    dynamics = m.Newtonian
    mass=10

dpd = m.Potential.dpd(alpha=0.3, gamma=1, sigma=1, cutoff=0.6)
dpd_wall = m.Potential.dpd(alpha=0.5, gamma=10, sigma=1, cutoff=0.1)
dpd_left = m.Potential.dpd(alpha=1, gamma=100, sigma=0, cutoff=0.5)

m.bind(dpd, A, A)
m.bind(dpd_wall, A, m.Universe.boundary_conditions.top)
m.bind(dpd_left, A, m.Universe.boundary_conditions.left)


uc = m.lattice.sc(a, A)

parts = m.lattice.create_lattice(uc, [25, 25, 25])

print(m.universe.boundary_conditions)

m.show()
class B(m.Particle):
    radius = 0.3
    style = {"color": "red"}
    dynamics = m.Overdamped


class Fixed(m.Particle):
    radius = 0.3
    style = {"color": "blue"}
    frozen = True


repulse = m.Potential.coulomb(q=0.08, min=0.01, max=2 * a)

m.bind(repulse, A, A)
m.bind(repulse, A, B)

f = m.forces.ConstantForce(lambda: [0.3, 1 * np.sin(0.4 * m.Universe.time), 0],
                           0.01)

m.bind(f, B)

pot = m.Potential.power(r0=0.5 * a, alpha=2)

uc = m.lattice.sc(a, A,
                  lambda i, j: m.Bond(pot, i, j, dissociation_energy=1.3))

parts = m.lattice.create_lattice(uc, [15, 15, 15])

for p in parts[14, :].flatten():
Exemple #16
0
class Sphere(m.Particle):
    radius = 3
    frozen = True
    style = {"color": "orange"}


class Test(m.Particle):
    radius = 0
    frozen = True
    style = {"color": "orange"}


p = m.Potential.glj(e=1, m=2, max=10)

m.bind(p, A, Sphere)
m.bind(p, A, Test)
m.bind(p, A, m.Cuboid)
m.bind(p, A, A)

# above the sphere
#Sphere(m.Universe.center + [5, 0, 0])

#A(m.Universe.center + [5, 0, 5.8])

# above the test
Test(m.Universe.center + [0, -10, 3])
#A(m.Universe.center + [0, -10, 5.8])

# above the scube
c = m.Cuboid(m.Universe.center + [0, 0, 0],
Exemple #17
0
    radius = 0.1
    dynamics = m.Overdamped
    mass = 5
    style = {"color": "MediumSeaGreen"}


class B(m.Particle):
    radius = 0.1
    dynamics = m.Overdamped
    mass = 10
    style = {"color": "skyblue"}


p = m.Potential.coulomb(q=2, min=0.01, max=3)

m.bind(p, A, A)
m.bind(p, B, B)
m.bind(p, A, B)

r = m.forces.random(0, 1)

m.bind(r, A)

pos = m.random_points(m.SolidCube, 50000) * 10 + m.Universe.center

[A(p) for p in pos]

a = A.items()[0]

[p.become(B) for p in a.neighbors(3)]
Exemple #18
0
pot_bb = m.Potential.soft_sphere(kappa=5, epsilon=0.25, r0=1, \
                                 eta=2, tol = 0.05, min=0.01, max=3)

pot_ab = m.Potential.soft_sphere(kappa=5, epsilon=0.0025, r0=1, \
                                 eta=2, tol = 0.05, min=0.01, max=3)

# bind the potential with the *TYPES* of the particles
m.Universe.bind(pot_aa, A, A)
m.Universe.bind(pot_bb, B, B)
m.Universe.bind(pot_ab, A, B)

# create a random force. In overdamped dynamcis, we neeed a random force to
# enable the objects to move around, otherwise they tend to get trapped
# in a potential

rforce = m.forces.random(0, 5)

# bind it just like any other force
m.bind(rforce, A)
m.bind(rforce, B)

# create particle instances, for a total A_count + B_count cells
for p in np.random.random((A_count, 3)) * 15 + 2.5:
    A(p)

for p in np.random.random((B_count, 3)) * 15 + 2.5:
    B(p)

# run the simulator
m.Simulator.run()
Exemple #19
0
center = dim / 2

# new simulator, don't load any example
m.Simulator(example="", dim=dim, cutoff=cutoff)


class Bead(m.Particle):
    mass = 1
    radius = 0.5
    dynamics = m.Overdamped


pot = m.Potential.glj(e=1)

# bind the potential with the *TYPES* of the particles
m.bind(pot, Bead, Bead)

# create a random force. In overdamped dynamcis, we neeed a random force to
# enable the objects to move around, otherwise they tend to get trapped
# in a potential
rforce = m.forces.random(0, 0.01)
m.bind(rforce, Bead)

r = 0.8 * Bead.radius

positions = [
    center + (x, 0, 0) for x in np.arange(-count * r + r, count * r + r, 2 * r)
]

for p in positions:
    print("position: ", p)
Exemple #20
0
       cutoff=10,
       integrator=m.FORWARD_EULER,
       cells=[3, 3, 3],
       dt=0.001)

class A(m.Particle):
    radius=1
    dynamics = m.Newtonian
    mass=20
    style={"color":"MediumSeaGreen"}


p = m.Potential.glj(e=50, m=6, max=3)
cp = m.Potential.coulomb(q=5000, min=0.05, max=10)

m.bind(p, A, m.Cuboid)
m.bind(cp, A, A)

rforce = m.forces.friction(0.01, 0, 100)

# bind it just like any other force
m.bind(rforce, A)

c = m.Cuboid(m.Universe.center + [0, 0, 0], size=[25, 31, 5])

c.spin = [0.0, 8.5, 0.0]

# uniform random cube
positions = np.random.uniform(low=0, high=30, size=(2500, 3))

for p in positions:
Exemple #21
0
pts = m.random_points(m.Sphere,
                      10000) * (Green.radius + Big.radius) + m.Universe.center

# make the big particle at the middle
Big(m.Universe.center)

# constuct a particle for each position, make
# a list of particles
beads = [Green(p) for p in pts]

# create an explicit bond for each pair in the
# list of particles. The bind_pairwise method
# searches for all possible pairs within a cutoff
# distance and connects them with a bond.
#m.bind_pairwise(pot, beads, 0.7)

rforce = m.forces.random(0, 0.01, durration=0.1)

# hook up the potentials
#m.bind(rforce, Green)
m.bind(pot_yc, Big, Green)
m.bind(pot_cc, Green, Green)

m.bind_pairwise(
    pot,
    [p
     for p in m.Universe.particles if p.position[1] < m.Universe.center[1]], 1)

# run the model
m.show()
Exemple #22
0
class Bead(m.Particle):
    mass = 0.4
    radius = 0.2
    dynamics = m.Overdamped

pot_bb = m.Potential.soft_sphere(kappa=0.2, epsilon=0.05, \
                                 r0=0.2, eta=4, tol=0.01, min=0.01, max=0.5)

# hamonic bond between particles
pot_bond = m.Potential.harmonic(k=0.4, r0=0.2, max=2)

# angle bond potential
pot_ang = m.Potential.harmonic_angle(k=0.2, theta0=0.85 * np.pi, tol=0.1)

# bind the potential with the *TYPES* of the particles
m.bind(pot_bb, Bead, Bead)

# create a random force. In overdamped dynamcis, we neeed a random force to
# enable the objects to move around, otherwise they tend to get trapped
# in a potential
rforce = m.forces.random(0, 0.1)

# bind it just like any other force
m.bind(rforce, Bead)

# make a array of positions
xx = np.arange(4., 16, 0.15)

p = None  # previous bead
bead = Bead([xx[0], 10., 10.0])  # current bead
Exemple #23
0
total_height = 2 * Yolk.radius + 2 * C.radius
yshift = total_height/2 - Yolk.radius
cshift = total_height/2 - C.radius - 1

yolk = Yolk(position=center-[0., 0., yshift])

c = C(position=center+[0., 0., cshift])

C.yolk_pos = yolk.position

c.B(4000)

pb  = m.Potential.soft_sphere(kappa=300, epsilon=6, r0=0.5, \
                              eta=2, tol = 0.05, min=0.01, max=3)

pub = m.Potential.soft_sphere(kappa=400, epsilon=0, r0=0.5, \
                              eta=2, tol = 0.05, min=0.01, max=1.5)

py = m.Potential.soft_sphere(kappa=300, epsilon=25, r0=1, \
                             eta=2, tol = 0.04, min=0.01, \
                             max=10, shift=True)

rforce = m.forces.random(0, 1)

m.bind(rforce, C.B)
m.bind(pb, C.B, C.B, bound=True)
m.bind(pub, C.B, C.B, bound=False)
m.bind(py, Yolk, C.B)

m.Simulator.irun()
Exemple #24
0
m.init(dim=dim,
       cutoff=5,
       integrator=m.FORWARD_EULER,
       dt=0.001)

class A(m.Particle):
    radius=0.1
    dynamics = m.Overdamped
    mass=5
    style={"color":"MediumSeaGreen"}

class C(m.Particle):
    radius=10
    frozen = True
    style={"color":"orange"}

C(m.Universe.center)

pos = m.random_points(m.Sphere, 5000) * (C.radius+A.radius)  + m.Universe.center

[A(p) for p in pos]

pc = m.Potential.glj(e=30, m=2, max=5)
pa = m.Potential.coulomb(q=100, min=0.01, max=5)

m.bind(pc, A, C)
m.bind(pa, A, A)

m.show()
Exemple #25
0
           'bottom': {
               'velocity': [0, 0, 0]
           }
       })

# lattice spacing
a = 0.15


class A(m.Particle):
    radius = 0.05
    style = {"color": "seagreen"}
    dynamics = m.Newtonian
    mass = 10


dpd = m.Potential.dpd(alpha=10, sigma=1)

m.bind(dpd, A, A)

# driving pressure
pressure = m.forces.ConstantForce([0.1, 0, 0])

m.bind(pressure, A)

uc = m.lattice.sc(a, A)

parts = m.lattice.create_lattice(uc, [40, 40, 40])

m.run()
Exemple #26
0
# make a ring of of 50 particles
pts = m.points(m.Ring, 100) * (C.radius+B.radius)  + m.Universe.center - [0, 0, 1]

#positions = m.random_points(m.SolidSphere, 5000) * 9 + m.Universe.center

#[A(p) for p in pos_a if p[2] > m.Universe.center[2]]
[B(p) for p in pts]


pc  = m.Potential.glj(e=30, m=2, max=5)
pa   = m.Potential.glj(e=3, m=2.5, max=3)
pb   = m.Potential.glj(e=1, m=4, max=1)
pab  = m.Potential.glj(e=1, m=2, max=1)
ph = m.Potential.harmonic(r0=0.001, k=200)

m.bind(pc, A, C)
m.bind(pc, B, C)
m.bind(pa, A, A)
#m.bind(pb, B, B)
m.bind(pab, A, B)

r = m.forces.random(0, 5)

m.bind(r, A)
m.bind(r, B)

#m.bind_pairwise(ph, [p for p in m.Universe.particles if p.position[2] < m.Universe.center[2] + 1], 2)
m.bind_pairwise(ph, B.items(), 1)
#m.bind_pairwise(ph, B.items(), 2)

def update(e):