Commit 7ccc4d59 authored by nd-02110114's avatar nd-02110114
Browse files

🚧 create molecule featurizer directory

parent ad62142f
Loading
Loading
Loading
Loading
+10 −6
Original line number Diff line number Diff line
"""
Making it easy to import in classes.
"""
# flake8: noqa
from deepchem.feat.base_classes import Featurizer
from deepchem.feat.base_classes import MolecularFeaturizer
from deepchem.feat.base_classes import MaterialStructureFeaturizer
from deepchem.feat.base_classes import MaterialCompositionFeaturizer
from deepchem.feat.base_classes import ComplexFeaturizer
from deepchem.feat.base_classes import UserDefinedFeaturizer

from deepchem.feat.graph_features import ConvMolFeaturizer
from deepchem.feat.graph_features import WeaveFeaturizer
from deepchem.feat.fingerprints import CircularFingerprint
from deepchem.feat.rdkit_descriptors import RDKitDescriptors
from deepchem.feat.coulomb_matrices import CoulombMatrix
from deepchem.feat.coulomb_matrices import CoulombMatrixEig
from deepchem.feat.coulomb_matrices import BPSymmetryFunctionInput
from deepchem.feat.rdkit_grid_featurizer import RdkitGridFeaturizer
from deepchem.feat.binding_pocket_features import BindingPocketFeaturizer
from deepchem.feat.one_hot import OneHotFeaturizer
from deepchem.feat.raw_featurizer import RawFeaturizer
from deepchem.feat.atomic_coordinates import AtomicCoordinates
from deepchem.feat.atomic_coordinates import NeighborListComplexAtomicCoordinates
from deepchem.feat.adjacency_fingerprints import AdjacencyFingerprint
from deepchem.feat.smiles_featurizers import SmilesToSeq, SmilesToImage

from deepchem.feat.molecule_featurizers import AdjacencyFingerprint
from deepchem.feat.molecule_featurizers import CircularFingerprint
from deepchem.feat.molecule_featurizers import CoulombMatrix
from deepchem.feat.molecule_featurizers import CoulombMatrixEig
from deepchem.feat.molecule_featurizers import OneHotFeaturizer
from deepchem.feat.molecule_featurizers import RDKitDescriptors

from deepchem.feat.material_featurizers import ElementPropertyFingerprint
from deepchem.feat.material_featurizers import SineCoulombMatrix
from deepchem.feat.material_featurizers import CGCNNFeaturizer
+13 −13
Original line number Diff line number Diff line
@@ -2,10 +2,9 @@
Feature calculations.
"""
import logging
import types
import numpy as np
import multiprocessing
from typing import Any, Dict, List, Iterable, Sequence, Tuple, Union
from typing import Any, Dict, List, Iterable, Sequence, Tuple

logger = logging.getLogger(__name__)

@@ -169,7 +168,7 @@ class MolecularFeaturizer(Featurizer):
  In general, subclasses of this class will require RDKit to be installed.
  """

  def featurize(self, molecules, log_every_n=1000):
  def featurize(self, molecules, log_every_n=1000, canonical=False):
    """Calculate features for molecules.

    Parameters
@@ -177,6 +176,10 @@ class MolecularFeaturizer(Featurizer):
    molecules: RDKit Mol / SMILES string / iterable
        RDKit Mol, or SMILES string or iterable sequence of RDKit mols/SMILES
        strings.
    log_every_n: int, default 1000
      Logging messages reported every `log_every_n` samples.
    canonical: bool, default False
      Whether to use a canonical order of atoms returned by RDKit

    Returns
    -------
@@ -185,33 +188,30 @@ class MolecularFeaturizer(Featurizer):
    """
    try:
      from rdkit import Chem
      from rdkit.Chem import rdmolfiles
      from rdkit.Chem import rdmolops
      from rdkit.Chem.rdchem import Mol
    except ModuleNotFoundError:
      raise ValueError("This class requires RDKit to be installed.")

    # Special case handling of single molecule
    if isinstance(molecules, str) or isinstance(molecules, Mol):
      molecules = [molecules]
    else:
      # Convert iterables to list
      molecules = list(molecules)

    features = []
    for i, mol in enumerate(molecules):
      if i % log_every_n == 0:
        logger.info("Featurizing datapoint %i" % i)
      try:
        # Process only case of SMILES strings.
        if isinstance(mol, str):
          # mol must be a SMILES string so parse
          mol = Chem.MolFromSmiles(mol)
          # TODO (ytz) this is a bandage solution to reorder the atoms
          # so that they're always in the same canonical order.
          # Presumably this should be correctly implemented in the
          # future for graph mols.
          if mol:
            new_order = rdmolfiles.CanonicalRankAtoms(mol)
            mol = rdmolops.RenumberAtoms(mol, new_order)
        # canonicalize
        if canonical:
          canonical_smiles = Chem.MolToSmiles(mol, isomericSmiles=False, canonical=True)
          mol = Chem.MolFromSmiles(canonical_smiles)

        features.append(self._featurize(mol))
      except:
        logger.warning(
+3 −4
Original line number Diff line number Diff line
@@ -109,8 +109,7 @@ class GraphData:
    return Data(
      x=torch.from_numpy(self.node_features),
      edge_index=torch.from_numpy(self.edge_index).long(),
      edge_attr=None if self.edge_features is None \
        else torch.from_numpy(self.edge_features),
      edge_attr=None if self.edge_features is None else torch.from_numpy(self.edge_features),
    )

  def to_dgl_graph(self):
@@ -194,8 +193,8 @@ class BatchGraphData(GraphData):
    # create new edge index
    num_nodes_list = [graph.num_nodes for graph in graph_list]
    batch_edge_index = np.hstack(
      [graph.edge_index + prev_num_node for prev_num_node, graph \
        in zip([0] + num_nodes_list[:-1], graph_list)]
      [graph.edge_index + prev_num_node
       for prev_num_node, graph in zip([0] + num_nodes_list[:-1], graph_list)]
    )

    # graph_index indicates which nodes belong to which graph
+1 −0
Original line number Diff line number Diff line
"""
Featurizers for inorganic crystals.
"""
# flake8: noqa
from deepchem.feat.material_featurizers.element_property_fingerprint import ElementPropertyFingerprint
from deepchem.feat.material_featurizers.sine_coulomb_matrix import SineCoulombMatrix
from deepchem.feat.material_featurizers.cgcnn_featurizer import CGCNNFeaturizer
+7 −0
Original line number Diff line number Diff line
# flake8: noqa
from deepchem.feat.molecule_featurizers.adjacency_fingerprint import AdjacencyFingerprint
from deepchem.feat.molecule_featurizers.morgan_fingerprint import CircularFingerprint
from deepchem.feat.molecule_featurizers.coulomb_matrices import CoulombMatrix
from deepchem.feat.molecule_featurizers.coulomb_matrices import CoulombMatrixEig
from deepchem.feat.molecule_featurizers.one_hot_featurizer import OneHotFeaturizer
from deepchem.feat.molecule_featurizers.rdkit_descriptors import RDKitDescriptors
Loading