Example #1
0
class Cell(m.Particle):
    mass = 20
    target_temperature = 0
    radius = 0.5
    events = [
        m.on_time(m.Particle.fission, period=1, distribution='exponential')
    ]
    dynamics = m.Overdamped
Example #2
0
    radius=2.3

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

    def split(self, event):
        print("C.split(" + str(self) + ", event: " + str(event) + ")")
        axis = self.position - C.yolk_pos
        print("axis: " + str(axis))
        m.Cluster.split(self, axis=axis)


m.on_time(C.split, period=0.2, predicate="largest")

class Yolk(m.Particle):
    radius = 10
    mass = 1000000
    dynamics=m.Overdamped
    flozen=True
    style={"color":"gold"}

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])
Example #3
0
    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
m.Universe.bind(pot_bs, Yolk, Cell)
m.Universe.bind(pot_ss, 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, 0.05)

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

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

import sphericalplot as sp

for p in m.random_points(m.SolidSphere, count) * \
    0.5 * Yolk.radius + center + [0, 0, 1.3 * Yolk.radius]:
    Cell(p)

plt = sp.SphericalPlot(Cell.items(), yolk.position)

m.on_time(plt.update, period=0.01)

# run the simulator interactive
m.Simulator.run()
Example #4
0
            # velocity of the vertical (y) direction
            display_velocity[jj, ii] += avg_vel[i][1] / avg_bins

        display_velocity[:] = display_velocity / avg_bins

        Z = display_velocity

        plt.pause(0.01)
        plt.clf()
        #plt.contour(Z)

        yy = np.linspace(0, np.pi, num=100)
        xx = np.linspace(0, 2 * np.pi, num=200)
        c = plt.pcolormesh(xx, yy, Z, cmap='jet')
        plt.colorbar(c)
        plt.show(block=False)

        avg_pos[:] = 0
        avg_vel[:] = 0
        display_velocity_count[:] = 0
        display_velocity[:] = 0

    # bump counter where we store velocity info to be averaged
    avg_index = (avg_index + 1) % avg_bins


m.on_time(calc_avg_pos, period=0.01)

# run the simulator interactive
m.Simulator.run()
Example #5
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()
Example #6
0
import mechanica as m
import numpy as np

cutoff = 1

m.init(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))
Example #7
0
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

parts, bonds = m.bind_sphere(h,
                             type=B,
                             n=4,
                             phi=(0.6 * np.pi, np.pi),
                             radius=C.radius + B.radius)

[A(p) for p in pos_a]

# grab a vertical slice of the neighbors of the yolk:
slice_parts = [p for p in c.neighbors() if p.spherical()[1] > 0]

m.bind_pairwise(pab, slice_parts, cutoff=5 * A.radius, pairs=[(A, B)])

#A.style.visible = False

C.style.visible = False
B.style.visible = False
#A.style.visible = False


def update(e):
    print(B.items().center_of_mass())


m.on_time(update, period=0.01)

m.show()
Example #8
0
    radius = 0.1
    species = ['S1', 'S2', 'S3']
    style = {"colormap": {"species": "S1", "map": "rainbow", "range": "auto"}}

    def spew(self, event):

        print("spew...")

        # reset the value of the species
        # secrete consumes material...
        self.species.S1 = 500
        self.species.S1.secrete(250, distance=1)


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

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

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

# grap the particle at the top cornder
o = parts[24, 0, 24][0]

print("secreting pos: ", o.position)

# change type to B, since there is no flux rule between A and B
o.become(B)

m.on_time(B.spew, period=0.3)
m.show()
Example #9
0
# bind the potential with the *TYPES* of the particles
m.Universe.bind(pot, MyCell, MyCell)

# create a thermostat, coupling time constant determines how rapidly the
# thermostat operates, smaller numbers mean thermostat acts more rapidly
tstat = m.forces.berenderson_tstat(10)

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

# create a new particle every 0.05 time units. The 'on_time' event
# here binds the constructor of the MyCell object with the event, and
# calls at periodic intervals based on the exponential distribution,
# so the mean time between particle creation is 0.05
m.on_time(MyCell, period=0.05, distribution="exponential")


def write_data(time):
    print("time is now: ", time)

    positions = [list(p.position) for p in m.Universe.particles]

    print(positions)

    with open(fname, "a") as f:
        writer = csv.writer(f)
        writer.writerow([time, positions])

    print("wrote positions...")