def get_input_features(self, mol): """get input features Args: mol (Mol): Returns: """ type_check_num_atoms(mol, self.max_atoms) num_atoms = mol.GetNumAtoms() # Construct the atom array and adjacency matrix. atom_array = construct_atomic_number_array(mol, out_size=self.out_size) adj_array = construct_adj_matrix(mol, out_size=self.out_size) # Adjust the adjacency matrix. degree_vec = numpy.sum(adj_array[:num_atoms], axis=1) degree_sqrt_inv = 1. / numpy.sqrt(degree_vec) adj_array[:num_atoms, :num_atoms] *= numpy.broadcast_to( degree_sqrt_inv[:, None], (num_atoms, num_atoms)) adj_array[:num_atoms, :num_atoms] *= numpy.broadcast_to( degree_sqrt_inv[None, :], (num_atoms, num_atoms)) 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
def get_input_features(self, mol): """get input features Args: mol (Mol): Returns: """ type_check_num_atoms(mol, self.max_atoms) num_atoms = mol.GetNumAtoms() # Construct the atom array and adjacency matrix. atom_array = construct_atomic_number_array(mol, out_size=self.out_size) adj_array = construct_adj_matrix(mol, out_size=self.out_size) # Adjust the adjacency matrix. degree_vec = numpy.sum(adj_array[:num_atoms], axis=1) degree_sqrt_inv = 1. / numpy.sqrt(degree_vec) adj_array[:num_atoms, :num_atoms] *= numpy.broadcast_to( degree_sqrt_inv[:, None], (num_atoms, num_atoms)) adj_array[:num_atoms, :num_atoms] *= numpy.broadcast_to( degree_sqrt_inv[None, :], (num_atoms, num_atoms)) 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
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
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_adj_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
def test_construct_super_node_feature_adj_ndim2(sample_molecule): adj = common.construct_adj_matrix(sample_molecule) atom_array = common.construct_atomic_number_array(sample_molecule) s = common.construct_supernode_feature(sample_molecule, atom_array, adj) # print(s) assert s.shape == (MAX_ATOMIC_NUM * 2 + 4, ) assert s[0] == len(atom_array) assert s[1] == adj.sum() assert s[2] == 1 assert s[3] == 1 assert s[3 + 6] == 1 # C assert s[3 + 7] == 1 # N assert s[3 + 8] == 1 # O assert s[3 + MAX_ATOMIC_NUM] == 0 # other assert s[3 + MAX_ATOMIC_NUM + 6] == 2 / len(atom_array) assert s[3 + MAX_ATOMIC_NUM + 7] == 1 / len(atom_array) assert s[3 + MAX_ATOMIC_NUM + 8] == 1 / len(atom_array) assert s[3 + MAX_ATOMIC_NUM * 2] == 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
def get_input_features(self, mol): atom_array, adj_array = super(NFPGWMPreprocessor, self).get_input_features(mol) super_node_x = construct_supernode_feature(mol, atom_array, adj_array) return atom_array, adj_array, super_node_x