Exemple #1
0
import mechanica as m
import numpy as np

# potential cutoff distance
cutoff = 1

# dimensions of universe
dim=[10., 10., 10.]

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

# create a potential representing a 12-6 Lennard-Jones potential
# A The first parameter of the Lennard-Jones potential.
# B The second parameter of the Lennard-Jones potential.
# cutoff
pot = m.Potential.lennard_jones_12_6(0.275 , cutoff, 9.5075e-06 , 6.1545e-03 , 1.0e-3 )


# create a particle type
# all new Particle derived types are automatically
# registered with the universe
class Argon(m.Particle):
    mass = 39.4

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

# uniform random cube
positions = np.random.uniform(low=0, high=10, size=(10000, 3))
Exemple #2
0
# number of particles
count = 6000

# number of time points we avg things
avg_pts = 3

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

# new simulator
m.Simulator(dim=dim,
            cutoff=cutoff,
            integrator=m.FORWARD_EULER,
            bc=m.BOUNDARY_NONE,
            dt=0.001,
            max_distance=0.2,
            threads=8,
            cells=[5, 5, 5])

clump_radius = 8


class Yolk(m.Particle):
    mass = 500000
    radius = 20
    frozen = True


class Cell(m.Particle):
    mass = 10
Exemple #3
0
import mechanica as m

m.Simulator()

class Bead(m.Particle):
    species = ['S1']
    radius = 3

    style = {"colormap" : {"species" : "S1", "map" : "rainbow", "range" : "auto"}}

    def __init__(self, pos, value):
        super().__init__(pos)
        self.species.S1 = value

# make a ring of of 50 particles
pts = m.points(m.Ring, 100) * 4 + m.Universe.center

# constuct a particle for each position, make
# a list of particles
beads = [Bead(p, i/100.) for i, p in enumerate(pts)]

Bead.i = 0

def keypress(e):
    names = m.Colormap.names()
    name = None

    if (e.key_name == "n"):
        Bead.i = (Bead.i + 1) % len(names)
        name = names[Bead.i]
        print("setting colormap to: ", name)
import mechanica as m
import numpy as np

# potential cutoff distance
cutoff = 8

count = 3000

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

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

class Yolk(m.Particle):
    mass = 500000
    radius = 3

class Cell(m.Particle):
    mass = 5
    radius = 0.2
    target_temperature=0
    dynamics = m.Overdamped

pot_bs = m.Potential.soft_sphere(kappa=5, epsilon=20, r0=2.9, \
    eta=3, tol = 0.1, min=0, max=9)
pot_ss = m.Potential.soft_sphere(kappa=10, epsilon=0.000000001, r0=0.2, \
    eta=2, tol = 0.05, min=0, max=3)

# bind the potential with the *TYPES* of the particles
Exemple #5
0
import mechanica as m
import numpy as np

m.Simulator(dim=[25., 25., 25.], dt=0.0005, cutoff=3, bc=m.BOUNDARY_NONE)


class Green(m.Particle):
    mass = 1
    radius = 0.1
    dynamics = m.Overdamped
    style = {'color': 'mediumseagreen'}


class Big(m.Particle):
    mass = 10
    radius = 8
    frozen = True
    style = {'color': 'orange'}


# simple harmonic potential to pull particles
pot = m.Potential.harmonic(k=1, r0=0.1, max=3)

# potentials between green and big objects.
pot_yc = m.Potential.glj(e=1, r0=1, m=3, min=0.01)
pot_cc = m.Potential.glj(e=0.0001, r0=0.1, m=3, min=0.005, max=2)

# random points on surface of a sphere
pts = m.random_points(m.Sphere,
                      10000) * (Green.radius + Big.radius) + m.Universe.center
Exemple #6
0
import mechanica as m
import numpy as np

m.Simulator(dim=[20., 20., 20.], cutoff=8, bc=m.BOUNDARY_NONE)


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


pot = m.Potential.harmonic(k=1, r0=0.1, max=3)

pts = m.random_points(m.SolidCube, 10000) * 18 + m.Universe.center

beads = [Bead(p) for p in pts]

m.bind_pairwise(pot, beads, 1)

m.run()
Exemple #7
0
import mechanica as m
import numpy as np

# potential cutoff distance
cutoff = 8

count = 3

# dimensions of universe
dim = np.array([20., 20., 20.])
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)
cutoff = 10

# number of particles
count = 6000

# number of time points we avg things
avg_pts = 3

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

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

clump_radius = 2

# number of bins we use for averaging
avg_bins = 3

prev_pos = np.zeros((count, 3))
avg_vel = np.zeros((count, 3))
avg_pos = np.zeros((count, 3))
avg_index = 0

# the output display array.
# matplotlib uses (Y:X) axis arrays instead of normal (X:Y)
Exemple #9
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.Simulator(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 #10
0
import mechanica as m
import numpy as np

# potential cutoff distance
cutoff = 1

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

pot = m.Potential.soft_sphere(kappa=10, epsilon=0.1,
    r0=0.6, eta=3, tol = 0.1, min=0.05, max=4)

class Cell(m.Particle):
    mass = 20
    target_temperature = 0
    radius=0.5

m.on_time(Cell.fission, period=1, distribution='exponential')

m.Universe.bind(pot, Cell, Cell)

Cell([10., 10., 10.])

# run the simulator interactive
m.Simulator.run()
Exemple #11
0
import mechanica as m
import numpy as np

# potential cutoff distance
cutoff = 8

receptor_count = 500

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

# new simulator, don't load any example
m.Simulator(example="",
            dim=dim,
            cutoff=cutoff,
            cells=[4, 4, 4],
            integrator=m.RUNGE_KUTTA_4)


class Big(m.Particle):
    mass = 500000
    radius = 3


class Receptor(m.Particle):
    mass = 0.1
    radius = 0.1
    target_temperature = 1
    dynamics = m.Overdamped
Exemple #12
0
import mechanica as m
import numpy as np

# potential cutoff distance
cutoff = 8

receptor_count = 10000

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

# new simulator, don't load any example
m.Simulator(example="", dim=dim, cutoff=cutoff, cells=[4, 4, 4], threads=8)

class Nucleus(m.Particle):
    mass = 500000
    radius = 1

class Receptor(m.Particle):
    mass = 0.2
    radius = 0.05
    target_temperature=1
    #dynamics = m.Overdamped

# 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)
Exemple #13
0
import mechanica as m
import numpy as np

cutoff = 1

m.Simulator(example="", dim=[10., 10., 10.])


class Argon(m.Particle):
    mass = 39.4
    target_temperature = 100


# hook up the destroy method on the Argon type to the
# on_time event
m.on_time(Argon.destroy, period=2, distribution='exponential')

pot = m.Potential.lennard_jones_12_6(0.275, cutoff, 9.5075e-06, 6.1545e-03,
                                     1.0e-3)
m.Universe.bind(pot, Argon, Argon)

tstat = m.forces.berenderson_tstat(10)

m.Universe.bind(tstat, Argon)

size = 100

# uniform random cube
positions = np.random.uniform(low=0, high=10, size=(size, 3))
velocities = np.random.normal(0, 0.2, size=(size, 3))
Exemple #14
0
import mechanica as m

m.Simulator(dim=[6.5, 6.5, 6.5], bc=m.FREESLIP_FULL)


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


m.flux(A, A, "S1", 5)

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

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

parts[24, 24, 24][0].species.S1 = 5000

m.show()