Commit 7041e3c3 authored by Bharath Ramsundar's avatar Bharath Ramsundar
Browse files

Changes

parent 00a0a416
Loading
Loading
Loading
Loading
+17 −8
Original line number Diff line number Diff line
@@ -68,16 +68,25 @@ class Docker(object):
      If specified, `self.pocket_finder` must be set. Will only
      generate poses for the first `num_pockets` returned by
      `self.pocket_finder`.
    out_dir: str, optional
    out_dir: str, optional (default None)
      If specified, write generated poses to this directory.
    use_pose_generator_scores: bool, optional (default False)
      If `True`, ask pose generator to generate scores. This cannot be
      `True` if `self.featurizer` and `self.scoring_model` are set
      since those will be used to generate scores in that case. 
    """
    complexes = self.pose_generator.generate_poses(molecular_complex,
    outputs = self.pose_generator.generate_poses(molecular_complex,
                                                 centroid=centroid,
                                                 box_dims=box_dims,
                                                 exhaustiveness=exhaustiveness,
                                                 num_modes=num_modes,
                                                 num_pockets=num_pockets,
                                                   out_dir=out_dir)
                                                 out_dir=out_dir,
                                                 generate_scores=use_pose_generator_scores)
    if use_pose_generator_scores:
      complexes, scores = outputs
    else:
      complexes = outputs
    for posed_complex in complexes:
      if self.featurizer is not None:
        # TODO: How to handle the failure here?
+9 −6
Original line number Diff line number Diff line
@@ -140,8 +140,6 @@ class VinaPoseGenerator(PoseGenerator):

    TODO: How can this work on Windows? We need to install a .msi file and invoke it correctly from Python for this to work.

    TODO: Can we extract the autodock vina computed binding free energy? Need to parse the output from Autodock vina.

    Parameters
    ----------
    molecular_complexes: list
@@ -166,7 +164,10 @@ class VinaPoseGenerator(PoseGenerator):

    Returns
    -------
    List of docked molecular complexes. Each entry in this list contains a `(protein_mol, ligand_mol)` pair of RDKit molecules.
    Tuple of `(docked_poses, scores)`. `docked_poses` is a list of
    docked molecular complexes. Each entry in this list contains a
    `(protein_mol, ligand_mol)` pair of RDKit molecules. `scores` is a
    list of binding free energies predicted by Vina.

    Raises
    ------
@@ -237,8 +238,9 @@ class VinaPoseGenerator(PoseGenerator):
    rdkit_util.write_molecule(ligand_mol[1], ligand_pdbqt)

    docked_complexes = []
    all_scores = []
    for i, (protein_centroid, box_dims) in enumerate(zip(centroids, dimensions)):
      logger.info("Docking in pocket %d/%d" % (i, len(centroids)))
      logger.info("Docking in pocket %d/%d" % (i+1, len(centroids)))
      logger.info("Docking with center: %s" % str(protein_centroid))
      logger.info("Box dimensions: %s" % str(box_dims))
      # Write Vina conf file
@@ -260,7 +262,8 @@ class VinaPoseGenerator(PoseGenerator):
          "%s --config %s --log %s --out %s" % (self.vina_cmd, conf_file,
                                                log_file, out_pdbqt),
          shell=True)
      ligands = vina_utils.load_docked_ligands(out_pdbqt)
      ligands, scores = vina_utils.load_docked_ligands(out_pdbqt)
      docked_complexes += [(protein_mol[1], ligand) for ligand in ligands]
      all_scores += scores

    return docked_complexes
    return docked_complexes, all_scores
+6 −3
Original line number Diff line number Diff line
@@ -41,13 +41,14 @@ class TestPoseGeneration(unittest.TestCase):
    ligand_file = os.path.join(current_dir, "1jld_ligand.sdf")

    vpg = dc.dock.VinaPoseGenerator(pocket_finder=None)
    poses = vpg.generate_poses(
    poses, scores = vpg.generate_poses(
        (protein_file, ligand_file),
        exhaustiveness=1,
        num_modes=1,
        out_dir="/tmp")

    assert len(poses) == 1
    assert len(scores) == 1
    protein, ligand = poses[0]
    from rdkit import Chem
    assert isinstance(protein, Chem.Mol)
@@ -69,7 +70,7 @@ class TestPoseGeneration(unittest.TestCase):
    centroid = np.array([56.21891368, 25.95862964, 3.58950065])
    box_dims = np.array([51.354, 51.243, 55.608])
    vpg = dc.dock.VinaPoseGenerator(pocket_finder=None)
    poses = vpg.generate_poses(
    poses, scores = vpg.generate_poses(
        (protein_file, ligand_file),
        centroid=centroid,
        box_dims=box_dims,
@@ -78,6 +79,7 @@ class TestPoseGeneration(unittest.TestCase):
        out_dir="/tmp")

    assert len(poses) == 1
    assert len(scores) == 1
    protein, ligand = poses[0]
    from rdkit import Chem
    assert isinstance(protein, Chem.Mol)
@@ -99,7 +101,7 @@ class TestPoseGeneration(unittest.TestCase):
    # Note this may download autodock Vina...
    convex_finder = dc.dock.ConvexHullPocketFinder()
    vpg = dc.dock.VinaPoseGenerator(pocket_finder=convex_finder)
    poses = vpg.generate_poses(
    poses, scores = vpg.generate_poses(
        (protein_file, ligand_file),
        exhaustiveness=1,
        num_modes=1,
@@ -107,6 +109,7 @@ class TestPoseGeneration(unittest.TestCase):
        out_dir="/tmp")

    assert len(poses) == 2
    assert len(scores) == 2
    from rdkit import Chem
    for pose in poses:
      protein, ligand = pose
+6 −3
Original line number Diff line number Diff line
@@ -52,7 +52,7 @@ def get_xyz_from_mol(mol):
    xyz[i, 2] = position.z
  return (xyz)

def add_hydrogens_to_mol(mol):
def add_hydrogens_to_mol(mol, is_protein=False):
  """
  Add hydrogens to a molecule object

@@ -60,6 +60,9 @@ def add_hydrogens_to_mol(mol):
  ----------
  mol: Rdkit Mol
    Molecule to hydrogenate
  is_protein: bool, optional (default False)
    Whether this molecule is a protein.


  Returns
  -------
@@ -69,7 +72,7 @@ def add_hydrogens_to_mol(mol):
  ----
  This function requires RDKit and PDBFixer to be installed.
  """
  return apply_pdbfixer(mol, hydrogenate=True)
  return apply_pdbfixer(mol, hydrogenate=True, is_protein=is_protein)


def apply_pdbfixer(mol, add_missing=True, hydrogenate=True, pH=7.4,
@@ -80,7 +83,7 @@ def apply_pdbfixer(mol, add_missing=True, hydrogenate=True, pH=7.4,
  Parameters
  ----------
  mol: Rdkit Mol
    Molecule to hydrogenate
    Molecule to clean up.
  add_missing: bool, optional
    If true, add in missing residues and atoms
  hydrogenate: bool, optional
+19 −0
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ import unittest
import numpy as np
from deepchem.utils.geometry_utils import unit_vector
from deepchem.utils.geometry_utils import angle_between
from deepchem.utils.geometry_utils import compute_pairwise_distances
from deepchem.utils.geometry_utils import generate_random_unit_vector
from deepchem.utils.geometry_utils import generate_random_rotation_matrix
from deepchem.utils.geometry_utils import is_angle_within_cutoff
@@ -43,3 +44,21 @@ class TestGeometryUtils(unittest.TestCase):
    v2 = np.array([-1, 0, 0])
    angle_cutoff = 10
    assert is_angle_within_cutoff(v1, v2, angle_cutoff)

  def test_compute_pairwise_distances(self):
    n1 = 10
    n2 = 50
    coords1 = np.random.rand(n1, 3)
    coords2 = np.random.rand(n2, 3)

    distance = compute_pairwise_distances(coords1, coords2)
    self.assertEqual(distance.shape, (n1, n2))
    self.assertTrue((distance >= 0).all())
    # random coords between 0 and 1, so the max possible distance in sqrt(2)
    self.assertTrue((distance <= 2.0**0.5).all())

    # check if correct distance metric was used
    coords1 = np.array([[0, 0, 0], [1, 0, 0]])
    coords2 = np.array([[1, 0, 0], [2, 0, 0], [3, 0, 0]])
    distance = compute_pairwise_distances(coords1, coords2)
    self.assertTrue((distance == [[1, 2, 3], [0, 1, 2]]).all())
Loading