Commit 35288b8f authored by Nathan Frey's avatar Nathan Frey
Browse files

Fixing type errors

parent 6675474e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -211,10 +211,10 @@ class ContactCircularVoxelizer(ComplexFeaturizer):
          sum([
              voxelize(
                  convert_atom_to_voxel,
                  hash_ecfp,
                  xyz,
                  self.box_width,
                  self.voxel_width,
                  hash_function=hash_ecfp,
                  feature_dict=ecfp_dict,
                  nb_channel=self.size) for xyz, ecfp_dict in zip(
                      xyzs,
+29 −25
Original line number Diff line number Diff line
@@ -19,12 +19,12 @@ from deepchem.utils.geometry_utils import compute_pairwise_distances
from deepchem.utils.geometry_utils import subtract_centroid
from deepchem.utils.fragment_utils import get_partial_charge
from deepchem.utils.fragment_utils import reduce_molecular_complex_to_contacts
from typing import List, Tuple
from typing import List, Tuple, Optional

logger = logging.getLogger(__name__)

HBOND_DIST_BINS = [(2.2, 2.5), (2.5, 3.2), (3.2, 4.0)]
HBOND_ANGLE_CUTOFFS = [5, 50, 90]
HBOND_ANGLE_CUTOFFS = [5., 50., 90.]


def compute_charge_dictionary(molecule):
@@ -435,16 +435,21 @@ class HydrogenBondCounter(ComplexFeaturizer):
  that computes the total number of hydrogen bonds.
  """

  def __init__(self,
  def __init__(
      self,
      cutoff: float = 4.5,
               distance_bins: List[Tuple] = None,
               angle_cutoffs: List[float] = None,
               reduce_to_contacts: bool = True):
      reduce_to_contacts: bool = True,
      distance_bins: Optional[List[Tuple[float, float]]] = None,
      angle_cutoffs: Optional[List[float]] = None,
  ):
    """
    Parameters
    ----------
    cutoff: float (default 4.5)
      Distance cutoff in angstroms for molecules in complex.
    reduce_to_contacts: bool, optional
      If True, reduce the atoms in the complex to those near a contact
      region.
    distance_bins: list[tuple]
      List of hydgrogen bond distance bins. If not specified is
      set to default
@@ -454,9 +459,6 @@ class HydrogenBondCounter(ComplexFeaturizer):
      deviation from the ideal (180 deg) angle between
      hydrogen-atom1, hydrogen-atom2 vectors.If not specified
      is set to default `[5, 50, 90]`
    reduce_to_contacts: bool, optional
      If True, reduce the atoms in the complex to those near a contact
      region.
    """
    self.cutoff = cutoff
    if distance_bins is None:
@@ -533,18 +535,28 @@ class HydrogenBondVoxelizer(ComplexFeaturizer):
  of hydrogen bonds at each voxel.
  """

  def __init__(self,
  def __init__(
      self,
      cutoff: float = 4.5,
               distance_bins: List[Tuple] = None,
               angle_cutoffs: List[float] = None,
      box_width: float = 16.0,
      voxel_width: float = 1.0,
               reduce_to_contacts: bool = True):
      reduce_to_contacts: bool = True,
      distance_bins: Optional[List[Tuple[float, float]]] = None,
      angle_cutoffs: Optional[List[float]] = None,
  ):
    """
    Parameters
    ----------
    cutoff: float (default 4.5)
      Distance cutoff in angstroms for contact atoms in complex.
    box_width: float, optional (default 16.0)
      Size of a box in which voxel features are calculated. Box
      is centered on a ligand centroid.
    voxel_width: float, optional (default 1.0)
      Size of a 3D voxel in a grid.
    reduce_to_contacts: bool, optional
      If True, reduce the atoms in the complex to those near a contact
      region.
    distance_bins: list[tuple]
      List of hydgrogen bond distance bins. If not specified is
      set to default
@@ -554,14 +566,6 @@ class HydrogenBondVoxelizer(ComplexFeaturizer):
      deviation from the ideal (180 deg) angle between
      hydrogen-atom1, hydrogen-atom2 vectors.If not specified
      is set to default `[5, 50, 90]`
    box_width: float, optional (default 16.0)
      Size of a box in which voxel features are calculated. Box
      is centered on a ligand centroid.
    voxel_width: float, optional (default 1.0)
      Size of a 3D voxel in a grid.
    reduce_to_contacts: bool, optional
      If True, reduce the atoms in the complex to those near a contact
      region.
    """
    self.cutoff = cutoff
    if distance_bins is None:
+1 −1
Original line number Diff line number Diff line
@@ -172,7 +172,7 @@ def compute_charges(mol):
def load_complex(molecular_complex: OneOrMany[str],
                 add_hydrogens: bool = True,
                 calc_charges: bool = True,
                 sanitize: bool = True) -> List[Tuple]:
                 sanitize: bool = True) -> List[Tuple[np.ndarray, RDKitMol]]:
  """Loads a molecular complex.

  Given some representation of a molecular complex, returns a list of
+2 −2
Original line number Diff line number Diff line
@@ -40,10 +40,10 @@ class TestVoxelUtils(unittest.TestCase):
    nb_channel = 16
    features = voxel_utils.voxelize(
        get_voxels,
        hash_function,
        coordinates,
        box_width,
        voxel_width,
        hash_function,
        feature_dict,
        nb_channel=nb_channel)
    assert features.shape == (voxels_per_edge, voxels_per_edge, voxels_per_edge,
@@ -64,10 +64,10 @@ class TestVoxelUtils(unittest.TestCase):
    nb_channel = 16
    features = voxel_utils.voxelize(
        get_voxels,
        hash_function,
        coordinates,
        box_width,
        voxel_width,
        hash_function,
        feature_dict,
        nb_channel=nb_channel)
    assert features.shape == (voxels_per_edge, voxels_per_edge, voxels_per_edge,
+3 −3
Original line number Diff line number Diff line
@@ -77,10 +77,10 @@ def convert_atom_pair_to_voxel(coordinates_tuple: Tuple[np.ndarray, np.ndarray],


def voxelize(get_voxels: Callable[..., Any],
             hash_function: Callable[..., Any],
             coordinates: np.ndarray,
             box_width: float = 16.0,
             voxel_width: float = 1.0,
             hash_function: Optional[Callable[..., Any]] = None,
             feature_dict: Optional[Dict[Any, Any]] = None,
             feature_list: Optional[List[Union[int, Tuple[int]]]] = None,
             nb_channel: int = 16,
@@ -96,8 +96,6 @@ def voxelize(get_voxels: Callable[..., Any],
  ----------
  get_voxels: Function
    Function that voxelizes inputs
  hash_function: Function
    Used to map feature choices to voxel channels.
  coordinates: np.ndarray
    Contains the 3D coordinates of a molecular system.
  box_width: float, optional (default 16.0)
@@ -105,6 +103,8 @@ def voxelize(get_voxels: Callable[..., Any],
    is centered on a ligand centroid.
  voxel_width: float, optional (default 1.0)
    Size of a 3D voxel in a grid in Angstroms.
  hash_function: Function
    Used to map feature choices to voxel channels.
  feature_dict: Dict, optional (default None)
    Keys are atom indices or tuples of atom indices, the values are
    computed features. If `hash_function is not None`, then the values