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

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


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


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

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

# constuct a particle for each position, make
# a list of particles
beads = [Bead(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, 1)

# run the model
m.run()
Exemple #2
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)
Exemple #3
0
    dynamics = m.Overdamped
    mass=1
    style={"color":"skyblue"}

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

C(m.Universe.center)

pos_a = m.random_points(m.Sphere, 12000) * (C.radius+A.radius)  + m.Universe.center
pos_b = m.random_points(m.Sphere, 4000) * (C.radius+B.radius + 1)  + m.Universe.center

# 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)