Commit 90ede031 authored by Nathan Frey's avatar Nathan Frey
Browse files

Test fixes

parent 3b3a06ad
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -155,7 +155,8 @@ class ComplexFeaturizer(Featurizer):
  Abstract class for calculating features for mol/protein complexes.
  """

  def featurize(self, complexes: Iterable[Tuple[str, str]],
  def featurize(self,
                complexes: Iterable[Tuple[str, str]],
                log_every_n: int = 100) -> np.ndarray:
    """
    Calculate features for mol/protein complexes.
@@ -164,13 +165,13 @@ class ComplexFeaturizer(Featurizer):
    ----------
    complexes: Iterable[Tuple[str, str]]
      List of filenames (PDB, SDF, etc.) for ligand molecules and proteins.
      Each element should be a tuple of the form (ligand_filename,
      protein_filename).

    Returns
    -------
    features: np.ndarray
      Array of features
    failures: List
      Indices of complexes that failed to featurize.
    """

    if not isinstance(complexes, Iterable):
+4 −4
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@ def test_charge_voxelizer():
  voxel_width = 1.0
  voxelizer = dc.feat.ChargeVoxelizer(
      cutoff=cutoff, box_width=box_width, voxel_width=voxel_width)
  features = voxelizer.featurize((ligand_file, protein_file))
  features = voxelizer.featurize([(ligand_file, protein_file)])
  assert features.shape == (1, box_width, box_width, box_width, 1)


@@ -28,7 +28,7 @@ def test_salt_bridge_voxelizer():
  voxel_width = 1.0
  voxelizer = dc.feat.SaltBridgeVoxelizer(
      cutoff=cutoff, box_width=box_width, voxel_width=voxel_width)
  features = voxelizer.featurize((ligand_file, protein_file))
  features = voxelizer.featurize([(ligand_file, protein_file)])
  assert features.shape == (1, box_width, box_width, box_width, 1)


@@ -43,7 +43,7 @@ def test_cation_pi_voxelizer():
  voxel_width = 1.0
  voxelizer = dc.feat.CationPiVoxelizer(
      cutoff=cutoff, box_width=box_width, voxel_width=voxel_width)
  features = voxelizer.featurize((ligand_file, protein_file))
  features = voxelizer.featurize([(ligand_file, protein_file)])
  assert features.shape == (1, box_width, box_width, box_width, 1)


@@ -58,7 +58,7 @@ def test_pi_stack_voxelizer():
  voxel_width = 1.0
  voxelizer = dc.feat.PiStackVoxelizer(
      cutoff=cutoff, box_width=box_width, voxel_width=voxel_width)
  features = voxelizer.featurize((ligand_file, protein_file))
  features = voxelizer.featurize([(ligand_file, protein_file)])
  assert features.shape == (1, box_width, box_width, box_width, 2)


+14 −8
Original line number Diff line number Diff line
@@ -471,7 +471,8 @@ class TestRdkitGridFeaturizer(unittest.TestCase):
    # test if default parameters work
    featurizer = rgf.RdkitGridFeaturizer()
    self.assertIsInstance(featurizer, rgf.RdkitGridFeaturizer)
    feature_tensor = featurizer.featurize((self.ligand_file, self.protein_file))
    feature_tensor = featurizer.featurize([(self.ligand_file,
                                            self.protein_file)])
    self.assertIsInstance(feature_tensor, np.ndarray)

  def test_example_featurizer(self):
@@ -482,7 +483,8 @@ class TestRdkitGridFeaturizer(unittest.TestCase):
        ecfp_power=9,
        splif_power=9,
        flatten=True)
    feature_tensor = featurizer.featurize((self.ligand_file, self.protein_file))
    feature_tensor = featurizer.featurize([(self.ligand_file,
                                            self.protein_file)])
    self.assertIsInstance(feature_tensor, np.ndarray)

  def test_force_flatten(self):
@@ -490,7 +492,8 @@ class TestRdkitGridFeaturizer(unittest.TestCase):
    featurizer = rgf.RdkitGridFeaturizer(
        feature_types=['ecfp_hashed'], flatten=False)
    featurizer.flatten = True  # False should be ignored with ecfp_hashed
    feature_tensor = featurizer.featurize((self.ligand_file, self.protein_file))
    feature_tensor = featurizer.featurize([(self.ligand_file,
                                            self.protein_file)])
    self.assertIsInstance(feature_tensor, np.ndarray)
    self.assertEqual(feature_tensor.shape, (1, 2 * 2**featurizer.ecfp_power))

@@ -506,7 +509,8 @@ class TestRdkitGridFeaturizer(unittest.TestCase):
        splif_power=splif_power,
        flatten=False,
        sanitize=True)
    feature_tensor = featurizer.featurize((self.ligand_file, self.protein_file))
    feature_tensor = featurizer.featurize([(self.ligand_file,
                                            self.protein_file)])
    self.assertIsInstance(feature_tensor, np.ndarray)
    voxel_total_len = (
        2**ecfp_power +
@@ -521,7 +525,8 @@ class TestRdkitGridFeaturizer(unittest.TestCase):
        ecfp_power=ecfp_power,
        splif_power=splif_power,
        sanitize=True)
    feature_tensor = featurizer.featurize((self.ligand_file, self.protein_file))
    feature_tensor = featurizer.featurize([(self.ligand_file,
                                            self.protein_file)])
    self.assertIsInstance(feature_tensor, np.ndarray)
    flat_total_len = (
        3 * 2**ecfp_power +
@@ -540,7 +545,8 @@ class TestRdkitGridFeaturizer(unittest.TestCase):

    self.assertTrue('pi_stack' not in featurizer.feature_types)
    self.assertTrue('cation_pi' not in featurizer.feature_types)
    feature_tensor = featurizer.featurize((self.ligand_file, self.protein_file))
    feature_tensor = featurizer.featurize([(self.ligand_file,
                                            self.protein_file)])
    self.assertIsInstance(feature_tensor, np.ndarray)
    total_len = voxel_total_len + flat_total_len - 3 - 2**ecfp_power
    self.assertEqual(feature_tensor.shape, (1, total_len))
@@ -567,8 +573,8 @@ class TestRdkitGridFeaturizer(unittest.TestCase):
        feature_types=['voxel_combined'],
        flatten=False,
        sanitize=True)
    feature_tensors = featurizer.featurize((self.ligand_file,
                                            self.protein_file))
    feature_tensors = featurizer.featurize([(self.ligand_file,
                                             self.protein_file)])
    self.assertEqual(feature_tensors.shape, (1, 4, 16, 16, 16, 40))

  def test_voxelize(self):
+1 −1
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@ class TestSplifFingerprints(unittest.TestCase):
    self.protein_file = os.path.join(current_dir, 'data',
                                     '3ws9_protein_fixer_rdkit.pdb')
    self.ligand_file = os.path.join(current_dir, 'data', '3ws9_ligand.sdf')
    self.complex_files = (self.ligand_file, self.protein_file)
    self.complex_files = [(self.ligand_file, self.protein_file)]

  def test_splif_shape(self):
    size = 8