Example #1
0
def test_loadall_sdf(molfile, natoms: int, nbonds: int) -> None:

    ms = io.loadall(os.path.join(molpath, molfile))

    assert len(ms) == 10

    for m in ms:
        assert io.numatoms(m) == natoms
        assert io.numbonds(m) == nbonds
Example #2
0
def test_loadall_mol2(molfile, natoms: int, nbonds: int) -> None:

    try:
        ms = io.loadall(os.path.join(molpath, molfile))

        assert len(ms) == 10

        for m in ms:
            assert io.numatoms(m) == natoms
            assert io.numbonds(m) == nbonds
    except NotImplementedError:  # Mol2MolSupplier in RDkit is not supported
        pass  # TODO: Warning
Example #3
0
def test_adjacency_matrix_from_mol(mol) -> None:

    natoms = io.numatoms(mol)
    nbonds = io.numbonds(mol)

    A = io.adjacency_matrix(mol)

    assert A.shape == (natoms, natoms)
    assert np.alltrue(A == A.T)
    assert np.sum(A) == nbonds * 2

    for i, j in io.bonds(mol):

        assert A[i, j] == 1
Example #4
0
def test_loadall_pdb_single_model() -> None:
    """
    Test load_all function for PDB files when only a single model is present.
    """

    try:
        ms = io.loadall(os.path.join(molpath, "1a99_ligand.pdb"))

        assert len(ms) == 1

        assert io.numatoms(ms[0]) == 20
        assert io.numbonds(ms[0]) == 19

    except NotImplementedError:  # PDBMolSupplier in RDkit is not supported
        pass  # TODO: Warning
Example #5
0
def test_graph_from_adjacency_matrix(mol) -> None:

    natoms = io.numatoms(mol)
    nbonds = io.numbonds(mol)

    A = io.adjacency_matrix(mol)

    assert A.shape == (natoms, natoms)
    assert np.alltrue(A == A.T)
    assert np.sum(A) == nbonds * 2

    G = graph.graph_from_adjacency_matrix(A)

    assert graph.num_vertices(G) == natoms
    assert graph.num_edges(G) == nbonds
Example #6
0
def test_graph_from_adjacency_matrix_atomicnums(rawmol, mol) -> None:

    natoms = io.numatoms(rawmol)
    nbonds = io.numbonds(rawmol)

    A = io.adjacency_matrix(rawmol)

    assert len(mol) == natoms
    assert mol.adjacency_matrix.shape == (natoms, natoms)
    assert np.alltrue(mol.adjacency_matrix == A)
    assert np.sum(mol.adjacency_matrix) == nbonds * 2

    G = mol.to_graph()

    assert graph.num_vertices(G) == natoms
    assert graph.num_edges(G) == nbonds

    for idx, atomicnum in enumerate(mol.atomicnums):
        assert graph.vertex_property(G, "atomicnum", idx) == atomicnum
Example #7
0
def test_load_pdb(molfile, natoms: int, nbonds: int) -> None:

    m = io.load(os.path.join(molpath, molfile))

    assert io.numatoms(m) == natoms
    assert io.numbonds(m) == nbonds