import mechanica as m import threading m.init(windowless=True, window_size=[1024, 1024]) print(m.system.gl_info()) class Na(m.Particle): radius = 0.4 style = {"color": "orange"} class Cl(m.Particle): radius = 0.25 style = {"color": "spablue"} uc = m.lattice.bcc(0.9, [Na, Cl]) m.lattice.create_lattice(uc, [10, 10, 10]) def threaded_steps(steps): print('thread start') print("thread, calling context_has_current()") m.Simulator.context_has_current()\ print("thread, calling context_make_current())")
import mechanica as m m.init() class A(m.Particle): radius = 0.2 uc = m.lattice.hex(1, A) print(uc) m.lattice.create_lattice(uc, [6, 4, 6]) m.show()
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()
import mechanica as m import numpy as np # dimensions of universe dim=np.array([30., 30., 30.]) dist = 3.9 offset = 6 m.init(dim=dim, cutoff=7, cells=[3,3,3], integrator=m.FORWARD_EULER, dt=0.01, bc={'z':'potential', 'x' : 'potential', 'y' : 'potential'}) class A(m.Particle): radius=1 dynamics = m.Newtonian mass=2.5 style={"color":"MediumSeaGreen"} class Sphere(m.Particle): radius=3 frozen = True style={"color":"orange"} class Test(m.Particle):
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 m.init(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 class Virus(m.Particle): mass = 1 radius = 0.5
import mechanica as m import numpy as np # dimensions of universe dim=np.array([30., 30., 30.]) m.init(dim=dim, 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])
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()
import mechanica as m import numpy as np m.init(dt=0.1, dim=[15, 12, 10], bc={'x':'no_slip', 'y':'periodic', 'bottom':'no_slip', '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)
import mechanica as m import numpy as np # potential cutoff distance cutoff = 3 # dimensions of universe dim = [10., 10., 10.] # new simulator m.init(dim=dim, window_size=[900, 900], perfcounter_period=100) # 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): radius = 0.1 mass = 39.4 # bind the potential with the *TYPES* of the particles m.Universe.bind(pot, Argon, Argon)
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 m.init(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
import mechanica as m import numpy as np # dimensions of universe dim = np.array([30., 30., 30.]) center = dim / 2 m.init(dim=dim, cutoff=10, integrator=m.FORWARD_EULER, dt=0.0005) class C(m.Cluster): radius = 3 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)
import mechanica as m import numpy as np m.init(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
import numpy as np # total number of cells A_count = 5000 B_count = 5000 # potential cutoff distance cutoff = 3 # dimensions of universe dim = np.array([20., 20., 20.]) center = dim / 2 # new simulator m.init(dim=dim, cutoff=cutoff, clip_planes=[([8, 8, 8], [1, 1, 0]), ([11, 11, 11], [-1, -1, 0])]) class A(m.Particle): mass = 40 radius = 0.4 dynamics = m.Overdamped class B(m.Particle): mass = 40 radius = 0.4 dynamics = m.Overdamped
import mechanica as m import numpy as np m.init(dim=[25., 25., 25.], cutoff=3, bc=m.BOUNDARY_NONE) class Blue(m.Particle): mass = 1 radius = 0.1 dynamics = m.Overdamped style = {'color': 'dodgerblue'} class Big(m.Particle): mass = 1 radius = 8 frozen = True style = {'color': 'orange'} # simple harmonic potential to pull particles pot = m.Potential.harmonic(k=1, r0=0.1, max=3) # make big cell in the middle Big(m.Universe.center) #Big.style.visible = False # create a uniform mesh of particles and bonds on the surface of a sphere parts, bonds = m.bind_sphere(pot, type=Blue,
# 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.init(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 radius = 1.2 target_temperature=0
import mechanica as m import numpy as np m.init(dt=0.1, dim=[15, 12, 10], bc={ '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)
import mechanica as m import numpy as np # dimensions of universe dim = np.array([30., 30., 30.]) m.init(dim=dim, cutoff=10, integrator=m.FORWARD_EULER, cells=[1, 1, 1], dt=0.005) class A(m.Particle): radius = 0.5 dynamics = m.Newtonian mass = 30 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"}
import mechanica as m import numpy as np # potential cutoff distance cutoff = 1 # new simulator m.init(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 events = [ m.on_time(m.Particle.fission, period=1, distribution='exponential') ] dynamics = m.Overdamped m.Universe.bind(pot, Cell, Cell) rforce = m.forces.random(0, 0.5)
import mechanica as m import numpy as np # potential cutoff distance cutoff = 1 # dimensions of universe dim=[10., 10., 10.] # new simulator m.init(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 ) pot = m.Potential.glj(e=0.1, min=0.5, max=3) # create a particle type # all new Particle derived types are automatically # registered with the universe class Argon(m.Particle): radius=0.19 mass = 39.4 # bind the potential with the *TYPES* of the particles m.Universe.bind(pot, Argon, Argon) # uniform random cube
import mechanica as m m.init(windowless=True, window_size=[1024, 1024], clip_planes=[([2, 2, 2], [1, 1, 0]), ([5, 5, 5], [-1, -1, 0])]) print(m.system.gl_info()) class Na(m.Particle): radius = 0.4 style = {"color": "orange"} class Cl(m.Particle): radius = 0.25 style = {"color": "spablue"} uc = m.lattice.bcc(0.9, [Na, Cl]) m.lattice.create_lattice(uc, [10, 10, 10]) # m.system.image_data() is a jpg byte stream of the # contents of the frame buffer. with open('system.jpg', 'wb') as f: f.write(m.system.image_data())
import mechanica as m m.init(window_size=[1000, 1000]) class Na(m.Particle): radius = 0.4 style = {"color": "orange"} class Cl(m.Particle): radius = 0.25 style = {"color": "spablue"} uc = m.lattice.bcc(0.9, [Na, Cl]) m.lattice.create_lattice(uc, [10, 10, 10]) m.show()
import mechanica as m m.init(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"}} class B(m.Particle): 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])
import mechanica as m import numpy as np m.init(dt=0.1, dim=[15, 12, 10]) #, bc=m.FREESLIP_FULL) # lattice spacing a = 0.65 class A(m.Particle): radius = 0.3 style = {"color": "seagreen"} dynamics = m.Overdamped 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)
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 m.init(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
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()
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))
import mechanica as m import numpy as np # dimensions of universe dim=np.array([30., 30., 30.]) center = dim / 2 m.init(dim=dim, cutoff=3, integrator=m.FORWARD_EULER, dt=0.001) class C(m.Cluster): 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):
import mechanica as m import numpy as np # dimensions of universe dim = np.array([30., 30., 30.]) center = dim / 2 m.init(dim=dim, cutoff=3, integrator=m.FORWARD_EULER, dt=0.001, cells=[6, 6, 6]) class C(m.Cluster): radius = 5 class B(m.Particle): radius = 0.25 dynamics = m.Overdamped mass = 15 style = {"color": "skyblue"} def split(self, event): print("splitting cluster, C.split(" + str(self) + ", event: " + str(event) + ")") axis = self.position - C.yolk_pos print("axis: " + str(axis)) m.Cluster.split(self, axis=axis) print("new cluster count: ", len(C.items()))
import mechanica as m import numpy as np m.init(dt=0.1, dim=[15, 12, 10], cells=[7, 6, 5], cutoff=0.5, bc={ 'x': 'periodic', 'y': 'periodic', 'top': { 'velocity': [0, 0, 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)
import mechanica as m import numpy as np # potential cutoff distance cutoff = 3 # dimensions of universe dim=[10., 10., 10.] # new simulator m.init(dim=dim, window_size=[900,900], perfcounter_period=100, clip_planes = [([2, 2, 2], [1, 1, 0.5]), ([8, 8, 8], [-1, -1, 0.9])]) # 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): radius=0.1 mass = 39.4 # bind the potential with the *TYPES* of the particles m.Universe.bind(pot, Argon, Argon)