Commit 9f64f555 authored by nd-02110114's avatar nd-02110114
Browse files

🐛 fix bug

parent 14c5e53a
Loading
Loading
Loading
Loading
+3 −6
Original line number Diff line number Diff line
@@ -22,12 +22,6 @@ class AtomicCoordinates(MolecularFeaturizer):
    use_bohr: bool, optional (default False)
      Whether to use bohr or angstrom as a coordinate unit.
    """
    try:
      from rdkit import Chem  # noqa
      from rdkit.Chem import AllChem  # noqa
    except ModuleNotFoundError:
      raise ImportError("This class requires RDKit to be installed.")

    self.use_bohr = use_bohr

  def _featurize(self, mol: RDKitMol) -> np.ndarray:
@@ -43,8 +37,11 @@ class AtomicCoordinates(MolecularFeaturizer):
    np.ndarray
      A numpy array of atomic coordinates. The shape is `(n_atoms, 3)`.
    """
    try:
      from rdkit import Chem
      from rdkit.Chem import AllChem
    except ModuleNotFoundError:
      raise ImportError("This class requires RDKit to be installed.")

    # Check whether num_confs >=1 or not
    num_confs = len(mol.GetConformers())
+3 −6
Original line number Diff line number Diff line
@@ -55,12 +55,6 @@ class CircularFingerprint(MolecularFeaturizer):
      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 ImportError("This class requires RDKit to be installed.")

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

    if self.sparse:
      info: Dict = {}
+3 −6
Original line number Diff line number Diff line
@@ -63,12 +63,6 @@ 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 ImportError("This class requires RDKit to be installed.")

    self.max_atoms = int(max_atoms)
    self.remove_hydrogens = remove_hydrogens
    self.randomize = randomize
@@ -122,8 +116,11 @@ 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 ImportError("This class requires RDKit to be installed.")

    # Check whether num_confs >=1 or not
    num_confs = len(mol.GetConformers())
+8 −6
Original line number Diff line number Diff line
@@ -23,12 +23,7 @@ class MACCSKeysFingerprint(MolecularFeaturizer):

  def __init__(self):
    """Initialize this featurizer."""
    try:
      from rdkit.Chem.AllChem import GetMACCSKeysFingerprint  # noqa
    except ModuleNotFoundError:
      raise ImportError("This class requires RDKit to be installed.")

    self.calculator = GetMACCSKeysFingerprint
    self.calculator = None

  def _featurize(self, mol: RDKitMol) -> np.ndarray:
    """
@@ -44,4 +39,11 @@ class MACCSKeysFingerprint(MolecularFeaturizer):
    np.ndarray
      1D array of RDKit descriptors for `mol`. The length is 167.
    """
    if self.calculator is None:
      try:
        from rdkit.Chem.AllChem import GetMACCSKeysFingerprint
        self.calculator = GetMACCSKeysFingerprint
      except ModuleNotFoundError:
        raise ImportError("This class requires RDKit to be installed.")

    return self.calculator(mol)
+3 −5
Original line number Diff line number Diff line
@@ -158,11 +158,6 @@ class MolGraphConvFeaturizer(MolecularFeaturizer):
      Therefore, there is a possibility to fail to featurize for some molecules
      and featurization becomes slow.
    """
    try:
      from rdkit.Chem import AllChem  # noqa
    except ModuleNotFoundError:
      raise ImportError("This method requires RDKit to be installed.")

    self.use_edges = use_edges
    self.use_partial_charge = use_partial_charge
    self.use_chirality = use_chirality
@@ -185,8 +180,11 @@ class MolGraphConvFeaturizer(MolecularFeaturizer):
        mol.GetAtomWithIdx(0).GetProp('_GasteigerCharge')
      except:
        # If partial charges were not computed
        try:
          from rdkit.Chem import AllChem
          AllChem.ComputeGasteigerCharges(mol)
        except ModuleNotFoundError:
          raise ImportError("This method requires RDKit to be installed.")

    # construct atom (node) feature
    h_bond_infos = construct_hydrogen_bonding_info(mol)
Loading