Unverified Commit bc2be073 authored by Bharath Ramsundar's avatar Bharath Ramsundar Committed by GitHub
Browse files

Merge pull request #2163 from nd-02110114/fix-import-error-msg

Fix position for throwing ModuleNotFoundError
parents 28d0e19b 1ee5932d
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -19,12 +19,13 @@ from deepchem.feat.atomic_coordinates import AtomicCoordinates
from deepchem.feat.atomic_coordinates import NeighborListComplexAtomicCoordinates

# molecule featurizers
from deepchem.feat.molecule_featurizers import MolGraphConvFeaturizer
from deepchem.feat.molecule_featurizers import BPSymmetryFunctionInput
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 MordredDescriptors
from deepchem.feat.molecule_featurizers import Mol2VecFingerprint
from deepchem.feat.molecule_featurizers import MolGraphConvFeaturizer
from deepchem.feat.molecule_featurizers import OneHotFeaturizer
from deepchem.feat.molecule_featurizers import RawFeaturizer
from deepchem.feat.molecule_featurizers import RDKitDescriptors
+6 −8
Original line number Diff line number Diff line
@@ -50,8 +50,13 @@ class ElementPropertyFingerprint(MaterialCompositionFeaturizer):
    data_source: str of "matminer", "magpie" or "deml" (default "matminer")
      Source for element property data.
    """
    try:
      from matminer.featurizers.composition import ElementProperty
    except ModuleNotFoundError:
      raise ValueError("This class requires matminer to be installed.")

    self.data_source = data_source
    self.ep_featurizer = ElementProperty.from_preset(self.data_source)

  def _featurize(self, composition: PymatgenComposition) -> np.ndarray:
    """
@@ -69,14 +74,7 @@ class ElementPropertyFingerprint(MaterialCompositionFeaturizer):
      stoichiometry. Some values may be NaN.
    """
    try:
      from matminer.featurizers.composition import ElementProperty
    except ModuleNotFoundError:
      raise ValueError("This class requires matminer to be installed.")

    ep = ElementProperty.from_preset(self.data_source)

    try:
      feats = ep.featurize(composition)
      feats = self.ep_featurizer.featurize(composition)
    except:
      feats = []

+6 −8
Original line number Diff line number Diff line
@@ -54,9 +54,14 @@ class SineCoulombMatrix(MaterialStructureFeaturizer):
    flatten: bool (default True)
      Return flattened vector of matrix eigenvalues.
    """
    try:
      from matminer.featurizers.structure import SineCoulombMatrix as SCM
    except ModuleNotFoundError:
      raise ValueError("This class requires matminer to be installed.")

    self.max_atoms = max_atoms
    self.flatten = flatten
    self.scm = SCM(flatten=False)

  def _featurize(self, struct: PymatgenStructure) -> np.ndarray:
    """
@@ -74,15 +79,8 @@ class SineCoulombMatrix(MaterialStructureFeaturizer):
      2D sine Coulomb matrix with shape (max_atoms, max_atoms),
      or 1D matrix eigenvalues with shape (max_atoms,).
    """

    try:
      from matminer.featurizers.structure import SineCoulombMatrix as SCM
    except ModuleNotFoundError:
      raise ValueError("This class requires matminer to be installed.")

    # Get full N x N SCM
    scm = SCM(flatten=False)
    sine_mat = scm.featurize(struct)
    sine_mat = self.scm.featurize(struct)

    if self.flatten:
      eigs, _ = np.linalg.eig(sine_mat)
+29 −5
Original line number Diff line number Diff line
@@ -54,6 +54,33 @@ class CircularFingerprint(MolecularFeaturizer):
               features: bool = False,
               sparse: bool = False,
               smiles: bool = False):
    """
    Parameters
    ----------
    radius: int, optional (default 2)
      Fingerprint radius.
    size: int, optional (default 2048)
      Length of generated bit vector.
    chiral: bool, optional (default False)
      Whether to consider chirality in fingerprint generation.
    bonds: bool, optional (default True)
      Whether to consider bond order in fingerprint generation.
    features: bool, optional (default False)
      Whether to use feature information instead of atom information; see
      RDKit docs for more info.
    sparse: bool, optional (default False)
      Whether to return a dict for each molecule containing the sparse
      fingerprint.
    smiles: bool, optional (default False)
      Whether to calculate SMILES strings for fragment IDs (only applicable
      when calculating sparse fingerprints).
    """
    try:
      from rdkit import Chem  # noqa
      from rdkit.Chem import rdMolDescriptors  # noqa
    except ModuleNotFoundError:
      raise ValueError("This class requires RDKit to be installed.")

    self.radius = radius
    self.size = size
    self.chiral = chiral
@@ -75,11 +102,8 @@ class CircularFingerprint(MolecularFeaturizer):
    np.ndarray
      A numpy array of circular fingerprint.
    """
    try:
    from rdkit import Chem
    from rdkit.Chem import rdMolDescriptors
    except ModuleNotFoundError:
      raise ValueError("This class requires RDKit to be installed.")

    if self.sparse:
      info: Dict = {}
+8 −5
Original line number Diff line number Diff line
@@ -63,6 +63,12 @@ class CoulombMatrix(MolecularFeaturizer):
    seed: int, optional (default None)
      Random seed to use.
    """
    try:
      from rdkit import Chem  # noqa
      from rdkit.Chem import AllChem  # noqa
    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
@@ -116,11 +122,8 @@ class CoulombMatrix(MolecularFeaturizer):
    np.ndarray
      The coulomb matrices of the given molecule
    """
    try:
    from rdkit import Chem
    from rdkit.Chem import AllChem
    except ModuleNotFoundError:
      raise ValueError("This class requires RDKit to be installed.")

    # Check whether num_confs >=1 or not
    num_confs = len(mol.GetConformers())
Loading