Exemplo n.º 1
0
def test_graph_from_adjacency_matrix(mol: molecule.Molecule, n_bonds: int) -> None:

    G = mol.to_graph()

    assert graph.num_vertices(G) == len(mol)
    assert graph.num_edges(G) == n_bonds

    for idx, atomicnum in enumerate(mol.atomicnums):
        assert graph.vertex_property(G, "atomicnum", idx) == atomicnum
Exemplo n.º 2
0
def test_adjacency_matrix_from_atomic_coordinates(mol: molecule.Molecule,
                                                  n_bonds: int) -> None:

    A = graph.adjacency_matrix_from_atomic_coordinates(mol.atomicnums,
                                                       mol.coordinates)

    G = graph.graph_from_adjacency_matrix(A)

    assert graph.num_vertices(G) == len(mol)
    assert graph.num_edges(G) == n_bonds
Exemplo n.º 3
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
Exemplo n.º 4
0
def test_graph_from_atomic_coordinates_perception(mol: molecule.Molecule,
                                                  n_bonds: int) -> None:

    m = copy.deepcopy(mol)

    delattr(m, "adjacency_matrix")
    m.G = None

    with pytest.warns(UserWarning):

        # Uses automatic bond perception
        G = m.to_graph()

        assert graph.num_vertices(G) == len(m)
        assert graph.num_edges(G) == n_bonds

        for idx, atomicnum in enumerate(mol.atomicnums):
            assert graph.vertex_property(G, "aprops", idx) == atomicnum
Exemplo n.º 5
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