Ejemplo n.º 1
0
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])
Ejemplo n.º 2
0
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])
Ejemplo n.º 3
0
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')
Ejemplo n.º 4
0
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
Ejemplo n.º 5
0
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)
Ejemplo n.º 6
0
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
Ejemplo n.º 7
0
def test_system():
    wat = 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])], export={'hello': 1.0})

    wat.r_array *= 0.1
    # Initialization from empty
    s = System.empty(4, 4*3)
    
    mols = []
    for i in xrange(s.n_mol):
        wat.r_array += 0.1
        s.add(wat)
        m  = wat.copy()
        mols.append(wat.copy())
        
    # Printing just to test if there aren't any exception    
    print "Init from Empty"
    print "*" * 72
    _print_sysinfo(s)
    
    print "Init Normal"
    print "*" * 72
    s = System(mols)
    _print_sysinfo(s)
    
    # 3 water molecules
    r_array = np.random.random((9, 3))
    type_array = ['O', 'H', 'H', 'O', 'H', 'H', 'O', 'H', 'H']
    mol_indices = [0, 3, 6]
    mol_n_atoms = [3, 3, 3]
    s2 = System.from_arrays(r_array=r_array, type_array=type_array,
                       mol_indices=mol_indices, mol_n_atoms=mol_n_atoms)
    

    print 'bonds', s2._mol_bonds
    sub2 = subsystem_from_molecules(s2, np.array([0, 2]))
    assert sub2.n_mol == 2
    
    
    sub = subsystem_from_atoms(s2, np.array([True, True, False,
                                             False, False, False,
                                             False, False, False]))
    assert sub.n_mol == 1
Ejemplo n.º 8
0
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
Ejemplo n.º 9
0
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')