Commit 13259b56 authored by nd-02110114's avatar nd-02110114
Browse files

🚧 wip commit

parent bb2737cf
Loading
Loading
Loading
Loading
+9 −23
Original line number Diff line number Diff line
@@ -73,24 +73,6 @@ class Featurizer(object):
    raise NotImplementedError('Featurizer is not defined.')


def _featurize_callback(
    featurizer,
    mol_pdb_file,
    protein_pdb_file,
    log_message,
):
  """Callback function for apply_async in ComplexFeaturizer.

  This callback function must be defined globally
  because `apply_async` doesn't execute a nested function.

  See the details from the following link.
  https://stackoverflow.com/questions/56533827/pool-apply-async-nested-function-is-not-executed
  """
  logging.info(log_message)
  return featurizer._featurize(mol_pdb_file, protein_pdb_file)


class ComplexFeaturizer(object):
  """"
  Abstract class for calculating features for mol/protein complexes.
@@ -121,7 +103,7 @@ class ComplexFeaturizer(object):
    for i, (mol_file, protein_pdb) in enumerate(zip(mol_files, protein_pdbs)):
      log_message = "Featurizing %d / %d" % (i, len(mol_files))
      results.append(
          pool.apply_async(_featurize_callback,
          pool.apply_async(ComplexFeaturizer._featurize_callback,
                           (self, mol_file, protein_pdb, log_message)))
    pool.close()
    features = []
@@ -149,6 +131,12 @@ class ComplexFeaturizer(object):
    """
    raise NotImplementedError('Featurizer is not defined.')

  @staticmethod
  def _featurize_callback(featurizer, mol_pdb_file, protein_pdb_file,
                          log_message):
    logging.info(log_message)
    return featurizer._featurize(mol_pdb_file, protein_pdb_file)


class MolecularFeaturizer(Featurizer):
  """Abstract class for calculating a set of features for a
@@ -183,8 +171,8 @@ class MolecularFeaturizer(Featurizer):

    Returns
    -------
    A numpy array containing a featurized representation of
    `datapoints`.
    features: np.ndarray
      A numpy array containing a featurized representation of `datapoints`.
    """
    try:
      from rdkit import Chem
@@ -266,7 +254,6 @@ class MaterialStructureFeaturizer(Featurizer):
    features: np.ndarray
      A numpy array containing a featurized representation of
      `structures`.

    """

    structures = list(structures)
@@ -332,7 +319,6 @@ class MaterialCompositionFeaturizer(Featurizer):
    features: np.ndarray
      A numpy array containing a featurized representation of
      `compositions`.

    """

    compositions = list(compositions)
+0 −1
Original line number Diff line number Diff line
@@ -101,6 +101,5 @@ class BindingPocketFeaturizer(Featurizer):
        if residue not in res_map:
          logger.info("Warning: Non-standard residue in PDB file")
          continue
        atomtype = atom_name.split("-")[1]
        all_features[pocket_num, res_map[residue]] += 1
    return all_features
+3 −0
Original line number Diff line number Diff line
# flake8: noqa
from deepchem.feat.complex_featurizers.atomic_coordinates import NeighborListComplexAtomicCoordinates
from deepchem.feat.complex_featurizers.atomic_coordinates import ComplexNeighborListFragmentAtomicCoordinates
+4 −3
Original line number Diff line number Diff line
# flake8: noqa
from deepchem.feat.molecule_featurizers.adjacency_fingerprint import AdjacencyFingerprint
from deepchem.feat.molecule_featurizers.coulomb_matrices import BPSymmetryFunctionInput
from deepchem.feat.molecule_featurizers.bp_symmetry_function_input import BPSymmetryFunctionInput
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.atom_coordinates import NeighborListAtomicCoordinates
from deepchem.feat.molecule_featurizers.one_hot_featurizer import OneHotFeaturizer
from deepchem.feat.molecule_featurizers.raw_featurizer import RawFeaturizer
from deepchem.feat.molecule_featurizers.rdkit_descriptors import RDKitDescriptors
from deepchem.feat.molecule_featurizers.smiles_featurizers import SmilesToSeq
from deepchem.feat.molecule_featurizers.smiles_featurizers import SmilesToImage
from deepchem.feat.molecule_featurizers.smiles_to_image import SmilesToImage
from deepchem.feat.molecule_featurizers.smiles_to_seq import SmilesToSeq
+42 −0
Original line number Diff line number Diff line
import numpy as np

from deepchem.utils.typing import RDKitMol
from deepchem.utils.rdkit_utils import get_coordinates_from_mol
from deepchem.feat.base_classes import MolecularFeaturizer


class BPSymmetryFunctionInput(MolecularFeaturizer):
  """Calculate Symmetry Function for each atom in the molecules

  This method is described in [1]_

  References
  ----------
  .. [1] Behler, Jörg, and Michele Parrinello. "Generalized neural-network
     representation of high-dimensional potential-energy surfaces." Physical
     review letters 98.14 (2007): 146401.

  Notes
  -----
  This class requires RDKit to be installed.
  """

  def __init__(self, max_atoms: int):
    """Initialize this featurizer.

    Parameters
    ----------
    max_atoms: int
      The maximum number of atoms expected for molecules this featurizer will
      process.
    """
    self.max_atoms = max_atoms

  def _featurize(self, mol: RDKitMol) -> np.ndarray:
    coordinates = get_coordinates_from_mol(mol, unit='bohr')
    atom_numbers = np.array([atom.GetAtomicNum() for atom in mol.GetAtoms()])
    atom_numbers = np.expand_dims(atom_numbers, axis=1)
    assert atom_numbers.shape[0] == coordinates.shape[0]
    n_atoms = atom_numbers.shape[0]
    features = np.concatenate([atom_numbers, coordinates], axis=1)
    return np.pad(features, ((0, self.max_atoms - n_atoms), (0, 0)), 'constant')
Loading