Ejemplo n.º 1
0
    def get_input_features(self, mol):

        type_check_num_atoms(mol, self.max_atoms)

        atoms = self.create_atoms(mol)
        i_jbond_dict = self.create_ijbonddict(mol)

        subgraph_array = self.extract_subgraph(atoms, i_jbond_dict,
                                               self.radius)
        adj_array = construct_discrete_edge_matrix(mol)

        return subgraph_array, adj_array
Ejemplo n.º 2
0
    def get_input_features(self, mol):
        """get input features

        Args:
            mol (Mol):

        Returns:

        """
        type_check_num_atoms(mol, self.max_atoms)
        atom_array = construct_atomic_number_array(mol, out_size=self.out_size)
        adj_array = construct_discrete_edge_matrix(mol, out_size=self.out_size)
        return atom_array, adj_array
Ejemplo n.º 3
0
    def get_input_features(self, mol):
        """get input features

        Args:
            mol (Mol): Molecule input

        Returns:

        """
        type_check_num_atoms(mol, self.max_atoms)
        atom_array = construct_atomic_number_array(mol, out_size=self.out_size)
        adj_array = construct_discrete_edge_matrix(mol, out_size=self.out_size)
        return atom_array, adj_array
Ejemplo n.º 4
0
    def get_input_features(self, mol):
        """get input features

        Args:
            mol (Mol): Molecule input

        Returns:

        """
        type_check_num_atoms(mol, self.max_atoms)
        atom_array = construct_atomic_number_array(mol, out_size=self.out_size)
        adj_array = construct_discrete_edge_matrix(mol, out_size=self.out_size)
        super_node_x = construct_supernode_feature(
            mol, atom_array, adj_array, out_size=self.out_size_super)
        return atom_array, adj_array, super_node_x
Ejemplo n.º 5
0
def test_construct_super_node_feature_adj_ndim3(sample_molecule):
    adj = common.construct_discrete_edge_matrix(sample_molecule)
    atom_array = common.construct_atomic_number_array(sample_molecule)
    s = common.construct_supernode_feature(sample_molecule, atom_array, adj)
    assert s.shape == (MAX_ATOMIC_NUM * 2 + 10, )
    assert s[0] == len(atom_array)
    assert s[1] == adj.sum()
    assert s[2] == 1
    assert s[3] == 1
    assert s[4] == 0
    assert s[5] == 0
    assert pytest.approx(s[6], 1 * 2 / adj.sum())  # symmetric
    assert pytest.approx(s[7], 2 * 2 / adj.sum())  # symmetric
    assert s[8] == 0
    assert s[9] == 0
    assert s[9 + 6] == 1  # C
    assert s[9 + 6] == 1  # N
    assert s[9 + 7] == 1  # O
    assert s[9 + MAX_ATOMIC_NUM] == 0  # other
    assert s[9 + MAX_ATOMIC_NUM + 6] == 2 / len(atom_array)
    assert s[9 + MAX_ATOMIC_NUM + 7] == 1 / len(atom_array)
    assert s[9 + MAX_ATOMIC_NUM + 8] == 1 / len(atom_array)
    assert s[9 + MAX_ATOMIC_NUM * 2] == 0
Ejemplo n.º 6
0
    def get_input_features(self, mol):
        """get input features

        Args:
            mol (Mol):

        Returns: (atom, feature_dim)

        """
        # type_check_num_atoms(mol, self.max_atoms)
        # atom_array = construct_atomic_number_array(mol, out_size=self.out_size)
        # adj_array = construct_adj_matrix(mol, out_size=self.out_size)
        # return atom_array, adj_array
        graph = MolGraph()
        atoms_by_rd_idx = {}
        for atom in mol.GetAtoms():
            new_atom_node = graph.new_node('atom',
                                           features=atom_features(atom),
                                           rdkit_ix=atom.GetIdx())
            atoms_by_rd_idx[atom.GetIdx()] = new_atom_node

        for bond in mol.GetBonds():
            atom1_node = atoms_by_rd_idx[bond.GetBeginAtom().GetIdx()]
            atom2_node = atoms_by_rd_idx[bond.GetEndAtom().GetIdx()]
            new_bond_node = graph.new_node('bond',
                                           features=bond_features(bond))
            new_bond_node.add_neighbors((atom1_node, atom2_node))
            atom1_node.add_neighbors((atom2_node, ))

        mol_node = graph.new_node('molecule')
        mol_node.add_neighbors(graph.nodes['atom'])

        atom_array = graph.feature_array('atom')
        atom_array = atom_array.astype(dtype=np.float32)
        adj_array = construct_discrete_edge_matrix(mol, out_size=self.out_size)
        return atom_array, adj_array
Ejemplo n.º 7
0
 def test_truncated(self, sample_molecule_2):
     with pytest.raises(ValueError):
         adj = common.construct_discrete_edge_matrix(sample_molecule_2,
                                                     6)  # NOQA
Ejemplo n.º 8
0
    def test_padding(self, sample_molecule_2):
        adj = common.construct_discrete_edge_matrix(sample_molecule_2, 8)

        assert adj.shape == (4, 8, 8)
        expect = extend_adj(self.expect_adj, out_size=8, axis=[-1, -2])
        numpy.testing.assert_equal(adj, expect)
Ejemplo n.º 9
0
 def test_add_self_connection_channel(self, sample_molecule_2):
     adj = common.construct_discrete_edge_matrix(
         sample_molecule_2, add_self_connection_channel=True)
     assert adj.shape == (5, 7, 7)
     numpy.testing.assert_equal(adj[:4], self.expect_adj)
     numpy.testing.assert_equal(adj[4], numpy.eye(7, 7))
Ejemplo n.º 10
0
 def test_default(self, sample_molecule_2):
     adj = common.construct_discrete_edge_matrix(sample_molecule_2)
     assert adj.shape == (4, 7, 7)
     numpy.testing.assert_equal(adj, self.expect_adj)
Ejemplo n.º 11
0
 def test_truncated(self, sample_molecule_2):
     with pytest.raises(ValueError):
         adj = common.construct_discrete_edge_matrix(sample_molecule_2, 6)  # NOQA
Ejemplo n.º 12
0
    def test_padding(self, sample_molecule_2):
        adj = common.construct_discrete_edge_matrix(sample_molecule_2, 8)

        assert adj.shape == (4, 8, 8)
        expect = extend_adj(self.expect_adj, out_size=8, axis=[-1, -2])
        numpy.testing.assert_equal(adj, expect)
Ejemplo n.º 13
0
 def test_default(self, sample_molecule_2):
     adj = common.construct_discrete_edge_matrix(sample_molecule_2)
     assert adj.shape == (4, 7, 7)
     numpy.testing.assert_equal(adj, self.expect_adj)