def test_mol_read_xyz():

    file = 'tests/test_store/ethane.xyz'
    pmol = next(pyb.readfile('xyz', file))
    mol = get_ethane_mol()

    assert np.array_equal(mol.xyz, pread.mol_read_xyz(pmol))
示例#2
0
def test_get_dummy_features():

    mol = get_ethane_mol()

    mols = [mol]

    x, y, r = get_dummy_features(mols, targetflag='CCS')
    assert x == []
    assert np.array_equal(y, mol.shift[np.where(mol.types == 6)])
    assert np.array_equal(r, [['ethane', 0], ['ethane', 1]])

    x, y, r = get_dummy_features(mols, targetflag='HCS')
    assert x == []
    assert np.array_equal(y, mol.shift[np.where(mol.types == 1)])
    assert np.array_equal(r, [['ethane', 2], ['ethane', 3], ['ethane', 4],
                              ['ethane', 5], ['ethane', 6], ['ethane', 7]])

    x, y, r = get_dummy_features(mols, targetflag='1JCH')
    for i, index in enumerate(r):
        assert y[i] == mol.coupling[index[1]][index[2]]
    assert np.array_equal(
        r, [['ethane', 0, 2], ['ethane', 0, 3], ['ethane', 0, 4],
            ['ethane', 1, 5], ['ethane', 1, 6], ['ethane', 1, 7]])

    x, y, r = get_dummy_features(mols, targetflag='3JHH')
    for i, index in enumerate(r):
        assert y[i] == mol.coupling[index[1]][index[2]]
    assert np.array_equal(
        r, [['ethane', 2, 5], ['ethane', 2, 6], ['ethane', 2, 7],
            ['ethane', 3, 5], ['ethane', 3, 6], ['ethane', 3, 7],
            ['ethane', 4, 5], ['ethane', 4, 6], ['ethane', 4, 7]])
def test_mol_getatoms():

    file = 'tests/test_store/ethane.xyz'
    pmol = next(pyb.readfile('xyz', file))
    mol = get_ethane_mol()
    size = len(mol.types)
    assert size == pread.mol_getatoms(pmol)
def test_mol_iswhole():

    file = 'tests/test_store/ethane.xyz'
    pmol = next(pyb.readfile('xyz', file))
    mol = get_ethane_mol()
    size = len(mol.types)

    assert psplit.mol_iswhole(pmol)
示例#5
0
def test_mol_isequal():

    mol1 = get_ethane_mol()
    mol2 = get_random_mol()
    # Different molecules are different
    assert mol_isequal(mol1, mol2) == False
    # Identical molecules are identical
    assert mol_isequal(mol1, mol1) == True
def test_get_coupling_lengths():

    file = 'tests/test_store/ethane.xyz'
    pmol = next(pyb.readfile('xyz', file))
    mol = get_ethane_mol()
    size = len(mol.types)

    coupling_len = pbonds.get_coupling_lengths(pmol, mol.types, maxlen=4)
    assert np.array_equal(coupling_len, mol.coupling_len)
def test_mol_get_bond_table():

    file = 'tests/test_store/ethane.xyz'
    pmol = next(pyb.readfile('xyz', file))
    mol = get_ethane_mol()
    size = len(mol.types)

    bond_table = pbonds.mol_get_bond_table(pmol)
    assert np.array_equal(bond_table, mol.conn)
示例#8
0
def test_get_FCHL_features():

    mol = get_ethane_mol()

    mols = [mol]

    x, y, r = get_dummy_features(mols, targetflag='CCS')
    assert x == []
    assert np.array_equal(y, mol.shift[np.where(mol.types == 6)])
def test_mol_read_dist():

    file = 'tests/test_store/ethane.xyz'
    pmol = next(pyb.readfile('xyz', file))
    mol = get_ethane_mol()
    size = len(mol.types)
    d_array = pread.mol_read_dist(pmol)
    for i in range(size):
        for j in range(size):
            assert d_array[i][j] == np.absolute(
                np.linalg.norm(mol.xyz[i] - mol.xyz[j]))
示例#10
0
def test_mol_splitmol():

    file = 'tests/test_store/ethane.xyz'
    pmol = next(pyb.readfile('xyz', file))
    mol = get_ethane_mol()
    size = len(mol.types)

    print(psplit.mol_splitmol(pmol))

    assert len(psplit.mol_splitmol(pmol)[0]) == size
    assert len(psplit.mol_splitmol(pmol)[1]) == 0
    assert len(psplit.mol_splitmol(pmol)) == 2
示例#11
0
def test_mol_read_type():

    file = 'tests/test_store/ethane.xyz'
    pmol = next(pyb.readfile('xyz', file))
    mol = get_ethane_mol()
    size = len(mol.types)

    type_list, type_array = pread.mol_read_type(pmol)
    assert np.array_equal(mol.types, type_array)
    assert np.array_equal(
        np.asarray([x for x, type in enumerate(type_list) if "H" == type]),
        np.where(type_array == 1)[0])
    assert np.array_equal(
        np.asarray([x for x, type in enumerate(type_list) if "C" == type]),
        np.where(type_array == 6)[0])
示例#12
0
def test_qml_features():

    import qml

    mol = get_ethane_mol()
    mbtypes = [[1], [1, 1], [1, 1, 1], [1, 1, 6], [1, 1, 7], [1, 1, 8],
               [1, 1, 9], [1, 6], [1, 6, 1], [1, 6, 6], [1, 6, 7], [1, 6, 8],
               [1, 6, 9], [1, 7], [1, 7, 1], [1, 7, 6], [1, 7, 7], [1, 7, 8],
               [1, 7, 9], [1, 8], [1, 8, 1], [1, 8, 6], [1, 8, 7], [1, 8, 8],
               [1, 8, 9], [1, 9], [1, 9, 1], [1, 9, 6], [1, 9, 7], [1, 9, 8],
               [1, 9, 9], [6], [6, 1], [6, 1, 1], [6, 1, 6], [6, 1, 7],
               [6, 1, 8], [6, 1, 9], [6, 6], [6, 6, 1], [6, 6, 6], [6, 6, 7],
               [6, 6, 8], [6, 6, 9], [6, 7], [6, 7, 1], [6, 7, 6], [6, 7, 7],
               [6, 7, 8], [6, 7, 9], [6, 8], [6, 8, 1], [6, 8, 6], [6, 8, 7],
               [6, 8, 8], [6, 8, 9], [6, 9], [6, 9, 1], [6, 9, 6], [6, 9, 7],
               [6, 9, 8], [6, 9, 9], [7], [7, 1], [7, 1, 1], [7, 1, 6],
               [7, 1, 7], [7, 1, 8], [7, 1, 9], [7, 6], [7, 6, 1], [7, 6, 6],
               [7, 6, 7], [7, 6, 8], [7, 6, 9], [7, 7], [7, 7, 1], [7, 7, 6],
               [7, 7, 7], [7, 7, 8], [7, 7, 9], [7, 8], [7, 8, 1], [7, 8, 6],
               [7, 8, 7], [7, 8, 8], [7, 8, 9], [7, 9], [7, 9, 1], [7, 9, 6],
               [7, 9, 7], [7, 9, 8], [7, 9, 9], [8], [8, 1], [8, 1, 1],
               [8, 1, 6], [8, 1, 7], [8, 1, 8], [8, 1, 9], [8, 6], [8, 6, 1],
               [8, 6, 6], [8, 6, 7], [8, 6, 8], [8, 6, 9], [8, 7], [8, 7, 1],
               [8, 7, 6], [8, 7, 7], [8, 7, 8], [8, 7, 9], [8, 8], [8, 8, 1],
               [8, 8, 6], [8, 8, 7], [8, 8, 8], [8, 8, 9], [8, 9], [8, 9, 1],
               [8, 9, 6], [8, 9, 7], [8, 9, 8], [8, 9, 9], [9], [9, 1],
               [9, 1, 1], [9, 1, 6], [9, 1, 7], [9, 1, 8], [9, 1, 9], [9, 6],
               [9, 6, 1], [9, 6, 6], [9, 6, 7], [9, 6, 8], [9, 6, 9], [9, 7],
               [9, 7, 1], [9, 7, 6], [9, 7, 7], [9, 7, 8], [9, 7, 9], [9, 8],
               [9, 8, 1], [9, 8, 6], [9, 8, 7], [9, 8, 8], [9, 8, 9], [9, 9],
               [9, 9, 1], [9, 9, 6], [9, 9, 7], [9, 9, 8], [9, 9, 9]]
    reps = qml.representations.generate_slatm(mol.xyz, mol.types, mbtypes)
    x = np.asarray(reps)
    reps = qml.representations.generate_atomic_coulomb_matrix(
        mol.types, mol.xyz)
    x = np.asarray(reps)
    reps = qml.fchl.generate_representation(mol.xyz, mol.types)
    x = np.asarray(reps)
    try:
        reps = qml.representations.generate_acsf(mol.types, mol.xyz)
    except:
        print('Warning: not using qml version with ACSF rep')
示例#13
0
def test_mol_find_all_paths():

    file = 'tests/test_store/ethane.xyz'
    pmol = next(pyb.readfile('xyz', file))
    mol = get_ethane_mol()
    size = len(mol.types)

    for i in range(size):
        for j in range(size):
            for k in range(size):
                paths = pbonds.mol_find_all_paths(pmol, i, j, k)

                if i == j:
                    assert len(paths) == 0
                else:
                    for path in paths:
                        if len(path) == 0:
                            continue
                        assert path[0] == i
                        assert path[-1] == j
                        assert len(set(path)) == len(path)

                    if mol.coupling_len[i][j] == k:
                        assert len(paths[0]) == k + 1