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_1(): a = Atom("Ne", [-1.0, 0.0, 0.0]) b = Atom("Ne", [1.0, 0.0, 0.0]) am = Molecule([a, b]) # Force vector exterted on the first atom TODO, for optimization # purposes, this function should not take atom objects but coords. f = lennard_jones(a, b)
def _make_water(): mol = Molecule([ Atom("O", [-4.99, 2.49, 0.0]), Atom("H", [-4.02, 2.49, 0.0]), Atom("H", [-5.32, 1.98, 1.0]) ], bonds=[[0, 1], [0, 2]], export={'hello': 1.0}) return mol
def test_random(): '''Testing random made box''' from chemlab.db import ChemlabDB cdb = ChemlabDB() na = Molecule([Atom('Na', [0.0, 0.0, 0.0])]) cl = Molecule([Atom('Cl', [0.0, 0.0, 0.0])]) wat = cdb.get("molecule", 'gromacs.spce') s = random_lattice_box([na, cl, wat], [160, 160, 160], [4, 4, 4])
def test_crystal(): '''Building a crystal by using spacegroup module''' na = Molecule([Atom('Na', [0.0, 0.0, 0.0])]) cl = Molecule([Atom('Cl', [0.0, 0.0, 0.0])]) # Fract position of Na and Cl, space group 255 tsys = crystal([[0.0, 0.0, 0.0], [0.5, 0.5, 0.5]], [na, cl], 225, repetitions=[13, 13, 13])
def test_sort(): na = Molecule([Atom('Na', [0.0, 0.0, 0.0])]) cl = Molecule([Atom('Cl', [0.0, 0.0, 0.0])]) # Fract position of Na and Cl, space group 255 tsys = crystal([[0.0, 0.0, 0.0], [0.5, 0.5, 0.5]], [na, cl], 225, repetitions=[3, 3, 3]) tsys.sort() assert np.all(tsys.type_array[:tsys.n_mol / 2] == 'Cl')
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()
def test_serialization(): cl = Molecule([Atom.from_fields(type='Cl', r=[0.0, 0.0, 0.0])]) jsonstr = cl.tojson() assert Molecule.from_json(jsonstr).tojson() == jsonstr na = Molecule([Atom('Na', [0.0, 0.0, 0.0])]) cl = Molecule([Atom('Cl', [0.0, 0.0, 0.0])]) # Fract position of Na and Cl, space group 255 tsys = crystal([[0.0, 0.0, 0.0], [0.5, 0.5, 0.5]], [na, cl], 225, repetitions=[3, 3, 3]) jsonstr = tsys.tojson() assert System.from_json(jsonstr).tojson() == jsonstr
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()
def test_serialization(): cl = Molecule([Atom.from_fields(type='Cl', r=[0.0, 0.0, 0.0])]) jsonstr = cl.tojson() assert Molecule.from_json(jsonstr).tojson() == jsonstr na = Molecule([Atom('Na', [0.0, 0.0, 0.0])]) cl = Molecule([Atom('Cl', [0.0, 0.0, 0.0])]) # Fract position of Na and Cl, space group 255 tsys = crystal([[0.0, 0.0, 0.0],[0.5, 0.5, 0.5]], [na, cl], 225, repetitions=[3,3,3]) jsonstr = tsys.tojson() assert System.from_json(jsonstr).tojson() == jsonstr
def test_bonds(): from chemlab.io import datafile bz = datafile("tests/data/benzene.mol").read('molecule') na = Molecule([Atom('Na', [0.0, 0.0, 0.0])]) # Adding bonds s = System.empty(2, 2 * bz.n_atoms) s.add(bz) assert_npequal(s.bonds, bz.bonds) s.add(bz) assert_npequal(s.bonds, np.concatenate((bz.bonds, bz.bonds + 6))) # Reordering orig = np.array([[0, 1], [6, 8]]) s.bonds = orig s.reorder_molecules([1, 0]) assert_npequal(s.bonds, np.array([[6, 7], [0, 2]])) # Selection ss = subsystem_from_molecules(s, [1]) assert_npequal(ss.bonds, np.array([[0, 1]])) ss2 = System.from_arrays(**ss.__dict__) ss2.r_array += 10.0 ms = merge_systems(ss, ss2) assert_npequal(ms.bonds, np.array([[0, 1], [6, 7]])) # From_arrays s = System.from_arrays(mol_indices=[0], **bz.__dict__) assert_npequal(s.bonds, bz.bonds) # Get molecule entry # Test the bonds when they're 0 s.bonds = np.array([]) assert_equals(s.get_derived_molecule_array('formula'), 'C6')