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_bonds(): # TODO: deprecate this shit from chemlab.io import datafile bz = datafile("tests/data/benzene.mol").read('molecule') na = Molecule([Atom('O', [0.0, 0.0, 0.0]), Atom('H', [0.0, 0.0, 0.0]), Atom('H', [0.0, 0.0, 0.0]), ]) # Adding bonds s = System() with s.batch() as b: b.append(bz) assert_npequal(s.bonds, bz.bonds) assert_npequal(bz.bond_orders, [1, 2, 2, 1, 1, 2]) assert_npequal(s.bond_orders, bz.bond_orders) s.add(bz) assert_npequal(s.type_array, ['C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C']) eq_(s.dimensions['atom'], 12) assert_npequal(s.bonds, np.concatenate((bz.bonds, bz.bonds + 7))) # Reordering s.bonds = np.array([[0, 1], [6, 8]]) s.reorder_molecules([1, 0]) assert_eqbonds(s.bonds, np.array([[6, 7], [0, 2]])) # Selection ss = subsystem_from_molecules(s, [1]) assert_npequal(ss.bonds, np.array([[0, 1]]))
def test_random_lattice(): '''Testing random made box''' na = Molecule([Atom('Na', [0.0, 0.0, 0.0])]) cl = Molecule([Atom('Cl', [0.0, 0.0, 0.0])]) wat = Molecule.from_arrays(type_array=['O', 'H', 'H']) s = random_lattice_box([na, cl, wat], [160, 160, 160], [4, 4, 4]) eq_(s.dimensions['molecule'], 160 * 3) eq_(s.dimensions['atom'], 160 * 5)
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_npequal(tsys.type_array[:tsys.n_mol // 2], ['Cl'] * (tsys.n_mol // 2))
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]) eq_(tsys.r_array.min(), 0.0) eq_(tsys.r_array.max(), 12.5)
def test_serialization(): cl = Molecule([Atom.from_fields(type='Cl', r=[0.0, 0.0, 0.0])]) jsonstr = cl.to_json() m = Molecule.from_json(jsonstr) eq_(Molecule.from_json(jsonstr).to_json(), 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.to_json() eq_(System.from_json(jsonstr).to_json(), jsonstr)
def test_serialization(): cl = Molecule([Atom.from_fields(type="Cl", r=[0.0, 0.0, 0.0])]) jsonstr = cl.to_json() m = Molecule.from_json(jsonstr) eq_(Molecule.from_json(jsonstr).to_json(), 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.to_json() eq_(System.from_json(jsonstr).to_json(), jsonstr)
def test_init(self): a = Atom("O", [-4.99, 2.49, 0.0]) eq_(a.type_array, 'O') eq_(a.get_attribute('type_array').value, 'O') assert_npequal(a.r_array, [-4.99, 2.49, 0.0]) npeq_(a.get_attribute('r_array').value, [-4.99, 2.49, 0.0])
def test_init(self): a = Atom("O", [-4.99, 2.49, 0.0]) eq_(a.type_array, "O") eq_(a.get_attribute("type_array").value, "O") assert_npequal(a.r_array, [-4.99, 2.49, 0.0]) eq_(a.get_attribute("r_array").value, [-4.99, 2.49, 0.0])