Commit 1fd3b05a authored by Nathan Frey's avatar Nathan Frey
Browse files

AtomicConvFeaturizer test fixes

parent 6e5ca359
Loading
Loading
Loading
Loading
+2 −5
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@
Atomic coordinate featurizer.
"""
import logging
import warnings

import numpy as np

@@ -242,10 +243,6 @@ class AtomicConvFeaturizer(ComplexFeaturizer):
    neighbor_list = compute_neighbor_list(coords, self.neighbor_cutoff,
                                          self.max_num_neighbors, None)
    # pad outputs
    if len(neighbor_list.keys()) < max_num_atoms:
      s = range(max_num_atoms) - neighbor_list.keys()
      for k in s:
        neighbor_list[k] = []
    z = self.get_Z_matrix(mol, max_num_atoms)
    z = pad_array(z, max_num_atoms)
    coords = pad_array(coords, (max_num_atoms, 3))
@@ -285,7 +282,7 @@ class AtomicConvFeaturizer(ComplexFeaturizer):
    return coords, mol


#################### Deprecation warnings for old atomic conv featurizer name ####################
# Deprecation warnings for old atomic conv featurizer name #

ATOMICCONV_DEPRECATION = "{} is deprecated and has been renamed to {} and will be removed in DeepChem 3.0."

+2876 −0

File added.

Preview size limit exceeded, changes collapsed.

+16 −7
Original line number Diff line number Diff line
@@ -5,6 +5,8 @@ Test atomic conv featurizer.
import os
import logging

import numpy as np

from deepchem.feat import AtomicConvFeaturizer

logger = logging.getLogger(__name__)
@@ -14,12 +16,12 @@ def test_atomic_conv_featurization():
  """Unit test for AtomicConvFeaturizer."""
  dir_path = os.path.dirname(os.path.realpath(__file__))
  ligand_file = os.path.join(dir_path, "data/3zso_ligand_hyd.pdb")
  protein_file = os.path.join(dir_path, "data/3zso_protein.pdb")
  protein_file = os.path.join(dir_path, "data/3zso_protein_noH.pdb")
  # Pulled from PDB files. For larger datasets with more PDBs, would use
  # max num atoms instead of exact.
  frag1_num_atoms = 44  # for ligand atoms
  frag2_num_atoms = 2336  # for protein atoms
  complex_num_atoms = 2380  # in total
  frag2_num_atoms = 2334  # for protein atoms
  complex_num_atoms = 2378  # in total
  max_num_neighbors = 4
  # Cutoff in angstroms
  neighbor_cutoff = 4
@@ -30,20 +32,27 @@ def test_atomic_conv_featurization():
   frag2_neighbor_list, frag2_z, complex_coords, complex_neighbor_list,
   complex_z) = complex_featurizer._featurize((ligand_file, protein_file))

  # Coords are padded, neighbor list and Z are not
  assert frag1_coords.shape == (frag1_num_atoms, 3)
  assert (sorted(list(frag1_neighbor_list.keys())) == list(
      range(frag1_num_atoms)))
  assert frag1_neighbor_list[0] == [1, 2, 14, 3]
  assert frag1_z.shape == (frag1_num_atoms,)
  assert np.array_equal(
      frag1_z,
      np.array([
          6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
          6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8
      ]))

  assert frag2_coords.shape == (frag2_num_atoms, 3)

  assert (sorted(list(frag2_neighbor_list.keys())) == list(
      range(frag2_num_atoms)))

  assert frag2_neighbor_list[0] == [1, 2, 4, 3]
  assert frag2_z.shape == (frag2_num_atoms,)
  assert complex_coords.shape == (complex_num_atoms, 3)

  assert complex_coords.shape == (complex_num_atoms, 3)
  assert (sorted(list(complex_neighbor_list.keys())) == list(
      range(complex_num_atoms)))

  assert complex_neighbor_list[0] == [1, 2, 14, 3]
  assert (complex_z.shape == (complex_num_atoms,))