Commit ad62142f authored by nd-02110114's avatar nd-02110114
Browse files

🚧 wip molecule featurizer

parent e0fb7785
Loading
Loading
Loading
Loading
+0 −11
Original line number Diff line number Diff line
from collections import deque

import sys
import tensorflow as tf
import pickle

import os
import fnmatch
import numpy as np
from scipy.spatial.distance import pdist, squareform
import pandas as pd

from deepchem.feat.base_classes import Featurizer
from deepchem.feat.graph_features import atom_features
from scipy.sparse import csr_matrix


def get_atom_type(atom):
+11 −50
Original line number Diff line number Diff line
@@ -4,7 +4,6 @@ Generate coulomb matrices for molecules.
See Montavon et al., _New Journal of Physics_ __15__ (2013) 095003.
"""
import numpy as np
import deepchem as dc
from deepchem.feat.base_classes import MolecularFeaturizer
from deepchem.utils import pad_array
from deepchem.feat.atomic_coordinates import AtomicCoordinates
@@ -54,23 +53,6 @@ class CoulombMatrix(MolecularFeaturizer):
  Coulomb matrices provide a representation of the electronic structure of a
  molecule. This method is described in [1]_.

  Parameters
  ----------
  max_atoms : int
      Maximum number of atoms for any molecule in the dataset. Used to
      pad the Coulomb matrix.
  remove_hydrogens : bool, optional (default False)
      Whether to remove hydrogens before constructing Coulomb matrix.
  randomize : bool, optional (default False)
      Whether to randomize Coulomb matrices to remove dependence on atom
      index order.
  upper_tri : bool, optional (default False)
      Whether to return the upper triangular portion of the Coulomb matrix.
  n_samples : int, optional (default 1)
      Number of random Coulomb matrices to generate if randomize is True.
  seed : int, optional
      Random seed.

  Example
  -------
  >>> featurizers = dc.feat.CoulombMatrix(max_atoms=23)
@@ -90,8 +72,6 @@ class CoulombMatrix(MolecularFeaturizer):
  ----
  This class requires RDKit to be installed.
  """
  conformers = True
  name = 'coulomb_matrix'

  def __init__(self,
               max_atoms,
@@ -118,10 +98,6 @@ class CoulombMatrix(MolecularFeaturizer):
    seed: int, optional (default None)
      Random seed to use.
    """
    try:
      from rdkit import Chem
    except ModuleNotFoundError:
      raise ValueError("This class requires RDKit to be installed.")
    self.max_atoms = int(max_atoms)
    self.remove_hydrogens = remove_hydrogens
    self.randomize = randomize
@@ -142,8 +118,8 @@ class CoulombMatrix(MolecularFeaturizer):

    Parameters
    ----------
    mol : RDKit Mol
        Molecule.
    mol: rdkit.Chem.rdchem.Mol
      RDKit Mol object
    """
    features = self.coulomb_matrix(mol)
    if self.upper_tri:
@@ -157,10 +133,14 @@ class CoulombMatrix(MolecularFeaturizer):

    Parameters
    ----------
    mol : RDKit Mol
        Molecule.
    mol: rdkit.Chem.rdchem.Mol
      RDKit Mol object
    """
    try:
      from rdkit import Chem
    except ModuleNotFoundError:
      raise ValueError("This class requires RDKit to be installed.")

    if self.remove_hydrogens:
      mol = Chem.RemoveHs(mol)
    n_atoms = mol.GetNumAtoms()
@@ -191,12 +171,8 @@ class CoulombMatrix(MolecularFeaturizer):

    Parameters
    ----------
    m : ndarray
    m: np.ndarray
      Coulomb matrix.
    n_samples : int, optional (default 1)
        Number of random matrices to generate.
    seed : int, optional
        Random seed.

    References
    ----------
@@ -240,21 +216,6 @@ class CoulombMatrixEig(CoulombMatrix):
  This featurizer computes the eigenvalues of the Coulomb matrices for provided
  molecules. Coulomb matrices are described in [1]_.

  Parameters
  ----------
  max_atoms : int
      Maximum number of atoms for any molecule in the dataset. Used to
      pad the Coulomb matrix.
  remove_hydrogens : bool, optional (default False)
      Whether to remove hydrogens before constructing Coulomb matrix.
  randomize : bool, optional (default False)
      Whether to randomize Coulomb matrices to remove dependence on atom
      index order.
  n_samples : int, optional (default 1)
      Number of random Coulomb matrices to generate if randomize is True.
  seed : int, optional
      Random seed.

  Example
  -------
  >>> featurizers = dc.feat.CoulombMatrixEig(max_atoms=23)
@@ -311,8 +272,8 @@ class CoulombMatrixEig(CoulombMatrix):

    Parameters
    ----------
    mol : RDKit Mol
        Molecule.
    mol: rdkit.Chem.rdchem.Mol
      RDKit Mol object
    """
    cmat = self.coulomb_matrix(mol)
    features = []
+0 −1
Original line number Diff line number Diff line
@@ -40,7 +40,6 @@ class CircularFingerprint(MolecularFeaturizer):
  ----
  This class requires RDKit to be installed.
  """
  name = 'circular'

  def __init__(self,
               radius=2,