示例#1
0
def test_4atoms():
    a = Atom("Ar", [0.5, 0.5, 0])
    b = Atom("Ar", [0.5, -0.5, 0])
    c = Atom("Ar", [-0.2, -0.5, 0])
    d = Atom("Ar", [-0.5, 0.5, 0.5])
    sys = MonatomicSystem([a, b, c, d], 6.0)

    v = Viewer()
    sr = v.add_renderer(SphereRenderer, sys.atoms)
    v.add_renderer(CubeRenderer, sys.boxsize)

    # evo takes times in picoseconds
    evo = evolve_generator(sys, t=1e3, tstep=0.002, periodic=True)

    def update_pos():
        try:
            for i in range(100):
                sys, t = evo.next()
            sr.update(sys.r_array)

        except StopIteration:
            pass
            #import pylab as pl
            #pl.plot(distances, pitentials, 'o')
            #pl.show()

    v.schedule(update_pos)
    v.run()
示例#2
0
def test_4atoms():
    a = Atom("Ar", [ 0.5, 0.5, 0])
    b = Atom("Ar", [ 0.5,-0.5, 0])
    c = Atom("Ar", [-0.2,-0.5, 0])
    d = Atom("Ar", [-0.5, 0.5, 0.5])
    sys = MonatomicSystem([a,b,c,d], 6.0)
    
    v = Viewer()
    sr = v.add_renderer(SphereRenderer, sys.atoms)
    v.add_renderer(CubeRenderer, sys.boxsize)
    
    # evo takes times in picoseconds
    evo = evolve_generator(sys, t=1e3, tstep=0.002, periodic=True)
    
    
    def update_pos():
        try:
            for i in range(100):
                sys, t = evo.next()
            sr.update(sys.r_array)
            
        except StopIteration:
            pass
            #import pylab as pl
            #pl.plot(distances, pitentials, 'o')
            #pl.show()


        
    v.schedule(update_pos)
    v.run()
def test_canonical():
    '''test for Canonical Ensemble'''
    # Liquid argon Near experimental density
    sys = MonatomicSystem.spaced_lattice('Ar', 100, 5.0) 
    
    energies = []
    pot = []
    kin = []
    times = []
    
    display_system(sys)
    gen = evolve_generator(sys, 100.0, 0.002)

    count = 0
    
    for sys, t in gen:
        v = cenergy.lennard_jones(sys.r_array*1e-9, sys.type, periodic=sys.boxsize*1e-9)
        
        m = typetomass['Ar'] * 1.660538921e-27
        k = (0.5 * m * sys.varray * sys.varray * 1e6).sum()
        
        count +=1
        if (count % 1000) == 0:
            pot.append(v)
            kin.append(k)
            energies.append((v + k))
            times.append(t)
    
    display_system(sys)
    pl.plot(times, energies, label="H")
    pl.plot(times, pot, label='V')
    pl.plot(times, kin, label='K')
    pl.legend()
    pl.show()
    
示例#4
0
def test_periodic():
    '''Now let's try to implement the periodic boundaries, we should
    try to put the molecules near the border and see if one molecule
    'passes' the wall.

    '''
    import pyglet
    pyglet.options['vsync'] = False

    # Let's say we have to store this in nm and picoseconds
    # I setup argon atoms pretty overlapping
    a = Atom("Ar", [0.5, 0.0, 0.0])
    b = Atom("Ar", [-1.4, 0.0, 0.0])
    sys = MonatomicSystem([a, b], 3.0)

    v = Viewer()

    sr = v.add_renderer(SphereRenderer, sys.atoms)
    v.add_renderer(CubeRenderer, sys.boxsize)

    # evo takes times in picoseconds
    evo = evolve_generator(sys, t=1e3, tstep=0.002, periodic=True)

    distances = [np.linalg.norm(sys.r_array[0] - sys.r_array[1])]
    pitentials = [
        cenergy.lennard_jones(sys.r_array * 1e-9, 'Ar', periodic=False)
    ]

    def update_pos():
        try:
            for i in range(100):
                sys, t = evo.next()

            dist = np.linalg.norm(sys.r_array[0] - sys.r_array[1])
            pot = cenergy.lennard_jones(sys.r_array * 1e-9,
                                        'Ar',
                                        periodic=False)
            distances.append(dist)
            pitentials.append(pot)
            sr.update(sys.r_array)

        except StopIteration:
            pass
            #import pylab as pl
            #pl.plot(distances, pitentials, 'o')
            #pl.show()

    v.schedule(update_pos)
    v.run()
示例#5
0
def test_forces():
    '''This test simply shows two atoms that are subject to a lennard
    jones potential. you can modulate the distance between atoms and
    see if this physically makes sense. For example two atoms at a
    distance of about 1.5sigma should bounce.

    '''
    import pyglet
    pyglet.options['vsync'] = False

    # Let's say we have to store this in nm and picoseconds
    # I setup argon atoms pretty overlapping
    a = Atom("Ar", [0.0, 0.0, 0.0])
    b = Atom("Ar", [1.00, 0.0, 0.0])
    sys = MonatomicSystem([a, b], 3.0)

    v = Viewer()

    sr = v.add_renderer(SphereRenderer, sys.atoms)
    v.add_renderer(CubeRenderer, sys.boxsize)

    # evo takes times in picoseconds
    evo = evolve_generator(sys, t=1e2, tstep=0.002, periodic=False)
    distances = [np.linalg.norm(sys.r_array[0] - sys.r_array[1])]
    pitentials = [
        cenergy.lennard_jones(sys.r_array * 1e-9, 'Ar', periodic=False)
    ]

    def update_pos():
        try:
            for i in range(100):
                sys, t = evo.next()

            dist = np.linalg.norm(sys.r_array[0] - sys.r_array[1])
            pot = cenergy.lennard_jones(sys.r_array * 1e-9,
                                        'Ar',
                                        periodic=False)
            distances.append(dist)
            pitentials.append(pot)
            sr.update(sys.r_array)

        except StopIteration:
            import pylab as pl
            pl.plot(distances, pitentials, 'o')
            pl.show()

    v.schedule(update_pos)
    v.run()
示例#6
0
def test_periodic():
    '''Now let's try to implement the periodic boundaries, we should
    try to put the molecules near the border and see if one molecule
    'passes' the wall.

    '''
    import pyglet
    pyglet.options['vsync'] = False
    
    # Let's say we have to store this in nm and picoseconds
    # I setup argon atoms pretty overlapping
    a = Atom("Ar", [ 0.5, 0.0, 0.0])
    b = Atom("Ar", [ -1.4, 0.0, 0.0])
    sys = MonatomicSystem([a,b], 3.0)
    
    v = Viewer()
    
    sr = v.add_renderer(SphereRenderer, sys.atoms)
    v.add_renderer(CubeRenderer, sys.boxsize)
    
    # evo takes times in picoseconds
    evo = evolve_generator(sys, t=1e3, tstep=0.002, periodic=True)
    
    distances = [np.linalg.norm(sys.r_array[0] - sys.r_array[1])]
    pitentials = [cenergy.lennard_jones( sys.r_array * 1e-9, 'Ar', periodic=False)]
    
    def update_pos():
        try:
            for i in range(100):
                sys, t = evo.next()
                
            dist = np.linalg.norm(sys.r_array[0] - sys.r_array[1])
            pot = cenergy.lennard_jones( sys.r_array * 1e-9, 'Ar', periodic=False)            
            distances.append(dist)
            pitentials.append(pot)
            sr.update(sys.r_array)
            
        except StopIteration:
            pass
            #import pylab as pl
            #pl.plot(distances, pitentials, 'o')
            #pl.show()


        
    v.schedule(update_pos)
    v.run()
示例#7
0
def test_forces():
    '''This test simply shows two atoms that are subject to a lennard
    jones potential. you can modulate the distance between atoms and
    see if this physically makes sense. For example two atoms at a
    distance of about 1.5sigma should bounce.

    '''
    import pyglet
    pyglet.options['vsync'] = False
    
    # Let's say we have to store this in nm and picoseconds
    # I setup argon atoms pretty overlapping
    a = Atom("Ar", [ 0.0, 0.0, 0.0])
    b = Atom("Ar", [ 1.00, 0.0, 0.0])
    sys = MonatomicSystem([a,b], 3.0)
    
    v = Viewer()
    
    sr = v.add_renderer(SphereRenderer, sys.atoms)
    v.add_renderer(CubeRenderer, sys.boxsize)
    
    # evo takes times in picoseconds
    evo = evolve_generator(sys, t=1e2, tstep=0.002, periodic=False)
    distances = [np.linalg.norm(sys.r_array[0] - sys.r_array[1])]
    pitentials = [cenergy.lennard_jones( sys.r_array * 1e-9, 'Ar', periodic=False)]
    
    def update_pos():
        try:
            for i in range(100):
                sys, t = evo.next()
                
            dist = np.linalg.norm(sys.r_array[0] - sys.r_array[1])
            pot = cenergy.lennard_jones( sys.r_array * 1e-9, 'Ar', periodic=False)            
            distances.append(dist)
            pitentials.append(pot)
            sr.update(sys.r_array)
            
        except StopIteration:
            import pylab as pl
            pl.plot(distances, pitentials, 'o')
            pl.show()


        
    v.schedule(update_pos)
    v.run()
示例#8
0
def test_2():
    boxsize = 15.0 #nm
    nmol = 400
    sys = MonatomicSystem.random("Ar", nmol, boxsize)
    
    v = Viewer()
    pr = v.add_renderer(SphereRenderer, sys.atoms)
    v.add_renderer(CubeRenderer, boxsize)
    
    sys.varray = (np.random.rand(nmol, 3).astype(np.float32) - 0.5)
    
    gen = evolve_generator(sys, t=1000, tstep=0.002, periodic=True)
    
    def iterate(dt):
        for i in range(10):
            sys, t = gen.next()
        pr.update(sys.r_array)
    
    import pyglet
    pyglet.clock.schedule(iterate)
    pyglet.app.run()