Commit 260581b8 authored by Bharath Ramsundar's avatar Bharath Ramsundar
Browse files

Starting to add tests for grid featurizers

parent dce38628
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -95,7 +95,7 @@ class ContactCircularFingerprint(ComplexFeaturizer):
    self.radius = radius
    self.size = size

  def _featurize(self, mol_pdb: str, complex_pdb: str):
  def _featurize(self, mol_pdb: str, protein_pdb: str):
    """
    Compute featurization for a molecular complex

@@ -103,11 +103,11 @@ class ContactCircularFingerprint(ComplexFeaturizer):
    ----------
    mol_pdb: str
      Filename for ligand molecule
    complex_pdb: str
    protein_pdb: str
      Filename for protein molecule
    """
    try:
      fragments = load_complex((mol_pdb, complex_pdb), add_hydrogens=False)
      fragments = load_complex((mol_pdb, protein_pdb), add_hydrogens=False)

    except MoleculeLoadException:
      logger.warning("This molecule cannot be loaded by Rdkit. Returning None")
@@ -183,7 +183,7 @@ class ContactCircularVoxelizer(ComplexFeaturizer):
    self.voxels_per_edge = int(self.box_width / self.voxel_width)
    self.flatten = flatten

  def _featurize(self, mol_pdb: str, complex_pdb: str):
  def _featurize(self, mol_pdb: str, protein_pdb: str):
    """
    Compute featurization for a molecular complex

@@ -191,10 +191,10 @@ class ContactCircularVoxelizer(ComplexFeaturizer):
    ----------
    mol_pdb: str
      Filename for ligand molecule
    complex_pdb: str
    protein_pdb: str
      Filename for protein molecule
    """
    molecular_complex = (mol_pdb, complex_pdb)
    molecular_complex = (mol_pdb, protein_pdb)
    try:
      fragments = load_complex(molecular_complex, add_hydrogens=False)

+30 −20
Original line number Diff line number Diff line
@@ -81,17 +81,20 @@ class ChargeVoxelizer(ComplexFeaturizer):
    self.voxel_width = voxel_width
    self.reduce_to_contacts = reduce_to_contacts

  def _featurize_complex(self, molecular_complex):
  def _featurize(self, mol_pdb: str, protein_pdb: str):
    """
    Compute featurization for a single mol/protein complex

    Parameters
    ----------
    molecular_complex: Object
      Some representation of a molecular complex.
    mol_pdb: str
      Filename for ligand molecule
    protein_pdb: str
      Filename for protein molecule
    """
    molecular_complex = (mol_pdb, protein_pdb)
    try:
      fragments = rdkit_util.load_complex(
      fragments = rdkit_utils.load_complex(
          molecular_complex, add_hydrogens=False)

    except MoleculeLoadException:
@@ -114,10 +117,10 @@ class ChargeVoxelizer(ComplexFeaturizer):
          sum([
              voxelize(
                  convert_atom_to_voxel,
                  self.box_width,
                  self.voxel_width,
                  None,
                  xyz,
                  hash_function=hash_ecfp_pair,
                  coordinates=xyz,
                  box_width=self.box_width,
                  voxel_width=self.voxel_width,
                  feature_dict=compute_charge_dictionary(mol),
                  nb_channel=1,
                  dtype="np.float16") for xyz, mol in zip(xyzs, rdks)
@@ -168,7 +171,7 @@ class SaltBridgeVoxelizer(ComplexFeaturizer):
    self.voxel_width = voxel_width
    self.reduce_to_contacts = reduce_to_contacts

  def _featurize_complex(self, molecular_complex):
  def _featurize(self, mol_pdb: str, protein_pdb: str):
    """
    Compute featurization for a single mol/protein complex

@@ -177,8 +180,9 @@ class SaltBridgeVoxelizer(ComplexFeaturizer):
    molecular_complex: Object
      Some representation of a molecular complex.
    """
    molecular_complex = (mol_pdb, protein_pdb)
    try:
      fragments = rdkit_util.load_complex(
      fragments = rdkit_utils.load_complex(
          molecular_complex, add_hydrogens=False)

    except MoleculeLoadException:
@@ -256,17 +260,20 @@ class CationPiVoxelizer(ComplexFeaturizer):
    self.box_width = box_width
    self.voxel_width = voxel_width

  def _featurize_complex(self, molecular_complex):
  def _featurize(self, mol_pdb: str, protein_pdb: str):
    """
    Compute featurization for a single mol/protein complex

    Parameters
    ----------
    molecular_complex: Object
      Some representation of a molecular complex.
    mol_pdb: str
      Filename for ligand molecule
    protein_pdb: str
      Filename for protein molecule
    """
    molecular_complex = (mol_pdb, protein_pdb)
    try:
      fragments = rdkit_util.load_complex(
      fragments = rdkit_utils.load_complex(
          molecular_complex, add_hydrogens=False)

    except MoleculeLoadException:
@@ -348,17 +355,20 @@ class PiStackVoxelizer(ComplexFeaturizer):
    self.box_width = box_width
    self.voxel_width = voxel_width

  def _featurize_complex(self, molecular_complex):
  def _featurize(self, mol_pdb: str, protein_pdb: str):
    """
    Compute featurization for a single mol/protein complex

    Parameters
    ----------
    molecular_complex: Object
      Some representation of a molecular complex.
    mol_pdb: str
      Filename for ligand molecule
    protein_pdb: str
      Filename for protein molecule
    """
    molecular_complex = (mol_pdb, protein_pdb)
    try:
      fragments = rdkit_util.load_complex(
      fragments = rdkit_utils.load_complex(
          molecular_complex, add_hydrogens=False)

    except MoleculeLoadException:
@@ -479,7 +489,7 @@ class HydrogenBondCounter(ComplexFeaturizer):
      Some representation of a molecular complex.
    """
    try:
      fragments = rdkit_util.load_complex(
      fragments = rdkit_utils.load_complex(
          molecular_complex, add_hydrogens=False)

    except MoleculeLoadException:
@@ -585,7 +595,7 @@ class HydrogenBondVoxelizer(ComplexFeaturizer):
      Some representation of a molecular complex.
    """
    try:
      fragments = rdkit_util.load_complex(
      fragments = rdkit_utils.load_complex(
          molecular_complex, add_hydrogens=False)

    except MoleculeLoadException:
+37 −0
Original line number Diff line number Diff line
import os
import unittest
import deepchem as dc


def test_charge_voxelizer():
  current_dir = os.path.dirname(os.path.realpath(__file__))
  protein_file = os.path.join(current_dir, 'data',
                              '3ws9_protein_fixer_rdkit.pdb')
  ligand_file = os.path.join(current_dir, 'data', '3ws9_ligand.sdf')

  cutoff = 4.5
  box_width = 16
  voxel_width = 1.0
  voxelizer = dc.feat.ChargeVoxelizer(
      cutoff=cutoff, box_width=box_width, voxel_width=voxel_width)
  features, failures = voxelizer.featurize([ligand_file], [protein_file])


def test_salt_bridge_voxelizer():
  pass


def test_cation_pi_voxelizer():
  pass


def test_pi_stack_voxelizer():
  pass


def test_hydrogen_bond_counter():
  pass


def test_hydrogen_bond_voxelizer():
  pass