Commit 91945985 authored by seyonechithrananda's avatar seyonechithrananda
Browse files

remove kwargs param

parent 01aadd66
Loading
Loading
Loading
Loading
+14 −18
Original line number Diff line number Diff line
@@ -25,8 +25,7 @@ class Featurizer(object):

  def featurize(self,
                datapoints: Iterable[Any],
                log_every_n: int = 1000,
                **kwargs) -> np.ndarray:
                log_every_n: int = 1000) -> np.ndarray:
    """Calculate features for datapoints.

    `**kwargs` will get passed directly to `Featurizer._featurize`
@@ -51,7 +50,7 @@ class Featurizer(object):
      if i % log_every_n == 0:
        logger.info("Featurizing datapoint %i" % i)
      try:
        features.append(self._featurize(point, **kwargs))
        features.append(self._featurize(point))
      except:
        logger.warning(
            "Failed to featurize datapoint %d. Appending empty array")
@@ -59,7 +58,7 @@ class Featurizer(object):

    return np.asarray(features)

  def __call__(self, datapoints: Iterable[Any], **kwargs):
  def __call__(self, datapoints: Iterable[Any]):
    """Calculate features for datapoints.

    `**kwargs` will get passed directly to `Featurizer.featurize`
@@ -69,9 +68,9 @@ class Featurizer(object):
    datapoints: Iterable[Any]
      Any blob of data you like. Subclasss should instantiate this.
    """
    return self.featurize(datapoints, **kwargs)
    return self.featurize(datapoints)

  def _featurize(self, datapoint: Any, **kwargs):
  def _featurize(self, datapoint: Any):
    """Calculate features for a single datapoint.

    Parameters
@@ -161,8 +160,7 @@ class ComplexFeaturizer(Featurizer):

  def featurize(self,
                complexes: Iterable[Tuple[str, str]],
                log_every_n: int = 100,
                **kwargs) -> np.ndarray:
                log_every_n: int = 100) -> np.ndarray:
    """
    Calculate features for mol/protein complexes.

@@ -186,7 +184,7 @@ class ComplexFeaturizer(Featurizer):
      if idx % log_every_n == 0:
        logger.info("Featurizing datapoint %i" % idx)
      try:
        features.append(self._featurize(point, **kwargs))
        features.append(self._featurize(point))
        successes.append(idx)
      except:
        logger.warning(
@@ -209,7 +207,7 @@ class ComplexFeaturizer(Featurizer):

    return np.asarray(features)

  def _featurize(self, complex: Tuple[str, str], **kwargs):
  def _featurize(self, complex: Tuple[str, str]):
    """
    Calculate features for single mol/protein complex.

@@ -239,7 +237,7 @@ class MolecularFeaturizer(Featurizer):
  The subclasses of this class require RDKit to be installed.
  """

  def featurize(self, molecules, log_every_n=1000, **kwargs) -> np.ndarray:
  def featurize(self, molecules, log_every_n=1000) -> np.ndarray:
    """Calculate features for molecules.

    Parameters
@@ -283,7 +281,7 @@ class MolecularFeaturizer(Featurizer):
          new_order = rdmolfiles.CanonicalRankAtoms(mol)
          mol = rdmolops.RenumberAtoms(mol, new_order)

        features.append(self._featurize(mol, **kwargs))
        features.append(self._featurize(mol))
      except Exception as e:
        if isinstance(mol, Chem.rdchem.Mol):
          mol = Chem.MolToSmiles(mol)
@@ -321,8 +319,7 @@ class MaterialStructureFeaturizer(Featurizer):

  def featurize(self,
                structures: Iterable[Union[Dict[str, Any], PymatgenStructure]],
                log_every_n: int = 1000,
                **kwargs) -> np.ndarray:
                log_every_n: int = 1000) -> np.ndarray:
    """Calculate features for crystal structures.

    Parameters
@@ -353,7 +350,7 @@ class MaterialStructureFeaturizer(Featurizer):
      try:
        if isinstance(structure, Dict):
          structure = Structure.from_dict(structure)
        features.append(self._featurize(structure, **kwargs))
        features.append(self._featurize(structure))
      except:
        logger.warning(
            "Failed to featurize datapoint %i. Appending empty array" % idx)
@@ -387,8 +384,7 @@ class MaterialCompositionFeaturizer(Featurizer):

  def featurize(self,
                compositions: Iterable[str],
                log_every_n: int = 1000,
                **kwargs) -> np.ndarray:
                log_every_n: int = 1000) -> np.ndarray:
    """Calculate features for crystal compositions.

    Parameters
@@ -416,7 +412,7 @@ class MaterialCompositionFeaturizer(Featurizer):
        logger.info("Featurizing datapoint %i" % idx)
      try:
        c = Composition(composition)
        features.append(self._featurize(c, **kwargs))
        features.append(self._featurize(c))
      except:
        logger.warning(
            "Failed to featurize datapoint %i. Appending empty array" % idx)
+6 −2
Original line number Diff line number Diff line
@@ -36,10 +36,12 @@ class RobertaFeaturizer(RobertaTokenizerFast, MolecularFeaturizer):
  """


  def __init__(self, **kwargs):
  #def __init__(self, **kwargs):
  def __init__(self, input_ids, attention_mask):
    super().__init__(**kwargs)
    return
  

  def _featurize(self, mol: RDKitMol, **kwargs) -> List[List[int]]:
    """Calculate encoding using HuggingFace's RobertaTokenizerFast

@@ -61,7 +63,9 @@ class RobertaFeaturizer(RobertaTokenizerFast, MolecularFeaturizer):
    smiles_string = Chem.MolToSmiles(mol)
    # the encoding is natively a dictionary with keys 'input_ids' and 'attention_mask'
    # -> make this a list of two lists to allow np to handle it
    encoding = list(self(smiles_string, **kwargs).values())
    # encoding = list(self(smiles_string, **kwargs).values())
    encoding = list(self(smiles_string, input_ids, attention_mask).values())

    return encoding

  def __call__(self, *args, **kwargs) -> Dict[str, List[int]]: