Commit 09225083 authored by Bharath Ramsundar's avatar Bharath Ramsundar Committed by GitHub
Browse files

Merge pull request #363 from rbharath/specific_pocket

Add ability to specify binding pocket to dc.dock
parents f9e847a7 9c77cc29
Loading
Loading
Loading
Loading
+16 −7
Original line number Diff line number Diff line
@@ -24,7 +24,8 @@ from subprocess import call
class Docker(object):
  """Abstract Class specifying API for Docking."""

  def dock(self, protein_file, ligand_file):
  def dock(self, protein_file, ligand_file, centroid=None, box_dims=None,
           dry_run=False):
    raise NotImplementedError

class VinaGridRFDocker(Docker):
@@ -47,11 +48,15 @@ class VinaGridRFDocker(Docker):
    self.pose_generator = VinaPoseGenerator(
        exhaustiveness=exhaustiveness, detect_pockets=detect_pockets) 

  def dock(self, protein_file, ligand_file):
  def dock(self, protein_file, ligand_file, centroid=None, box_dims=None,
           dry_run=False):
    """Docks using Vina and RF."""
    protein_docked, ligand_docked = self.pose_generator.generate_poses(
        protein_file, ligand_file)
        protein_file, ligand_file, centroid, box_dims, dry_run)
    if not dry_run:
      score = self.pose_scorer.score(protein_docked, ligand_docked)
    else:
      score = np.zeros((1,))
    return (score, (protein_docked, ligand_docked))

class VinaGridDNNDocker(object):
@@ -78,9 +83,13 @@ class VinaGridDNNDocker(object):
    self.pose_generator = VinaPoseGenerator(
        exhaustiveness=exhaustiveness, detect_pockets=detect_pockets) 

  def dock(self, protein_file, ligand_file):
  def dock(self, protein_file, ligand_file, centroid=None, box_dims=None,
           dry_run=False):
    """Docks using Vina and DNNs."""
    protein_docked, ligand_docked = self.pose_generator.generate_poses(
        protein_file, ligand_file)
        protein_file, ligand_file, centroid, box_dims, dry_run)
    if not dry_run:
      score = self.pose_scorer.score(protein_docked, ligand_docked)
    else:
      score = np.zeros((1,))
    return (score, (protein_docked, ligand_docked))
+27 −21
Original line number Diff line number Diff line
@@ -85,7 +85,9 @@ class VinaPoseGenerator(PoseGenerator):
    self.vina_cmd = os.path.join(self.vina_dir, "bin/vina")
      

  def generate_poses(self, protein_file, ligand_file, out_dir=None):
  def generate_poses(self, protein_file, ligand_file,
                     centroid=None, box_dims=None,
                     dry_run=False, out_dir=None):
    """Generates the docked complex and outputs files for docked complex."""
    if out_dir is None:
      out_dir = tempfile.mkdtemp()
@@ -102,6 +104,9 @@ class VinaPoseGenerator(PoseGenerator):
    receptor_pybel = next(pybel.readfile(str("pdb"), str(protein_hyd)))
    # TODO(rbharath): Need to add some way to identify binding pocket, or this is
    # going to be extremely slow!
    if centroid is not None and box_dims is not None:
      protein_centroid = centroid
    else:
      if not self.detect_pockets:
        protein_centroid, protein_range = get_molecule_data(receptor_pybel)
        box_dims = protein_range + 5.0
@@ -142,6 +147,7 @@ class VinaPoseGenerator(PoseGenerator):
    log_file = os.path.join(out_dir, "%s_log.txt" % ligand_name)
    out_pdbqt = os.path.join(out_dir, "%s_docked.pdbqt" % ligand_name)
    # TODO(rbharath): Let user specify the number of poses required.
    if not dry_run:
      print("About to call Vina")
      call("%s --config %s --log %s --out %s"
           % (self.vina_cmd, conf_file, log_file, out_pdbqt), shell=True)
+20 −12
Original line number Diff line number Diff line
@@ -62,12 +62,28 @@ class TestDocking(unittest.TestCase):
        protein_file, ligand_file)

    # Check returned files exist
    print("(score, (protein_docked, ligand_docked))")
    print((score, (protein_docked, ligand_docked)))
    assert score.shape == (1,)
    assert os.path.exists(protein_docked)
    assert os.path.exists(ligand_docked)

  def test_vina_grid_rf_docker_specified_pocket(self):
    """Test that VinaGridRFDocker can dock into spec. pocket."""
    if sys.version_info >= (3,0):
      return
    
    current_dir = os.path.dirname(os.path.realpath(__file__))
    protein_file = os.path.join(current_dir, "1jld_protein.pdb")
    ligand_file = os.path.join(current_dir, "1jld_ligand.sdf")

    docker = dc.dock.VinaGridRFDocker(
        exhaustiveness=1, detect_pockets=False)
    (score, (protein_docked, ligand_docked)) = docker.dock(
        protein_file, ligand_file, centroid=(10, 10, 10),
        box_dims=(1,1,1), dry_run=True)
  
    # Check returned files exist
    assert score.shape == (1,)

  def test_pocket_vina_grid_rf_docker_dock(self):
    """Test that VinaGridRFDocker can dock."""
    if sys.version_info >= (3,0):
@@ -80,15 +96,13 @@ class TestDocking(unittest.TestCase):
    docker = dc.dock.VinaGridRFDocker(
        exhaustiveness=1, detect_pockets=True)
    (score, (protein_docked, ligand_docked)) = docker.dock(
        protein_file, ligand_file)
        protein_file, ligand_file, dry_run=True)

    # Check returned files exist
    if sys.version_info >= (3,0):
      return
    
    assert score.shape == (1,)
    assert os.path.exists(protein_docked)
    assert os.path.exists(ligand_docked)

  def test_vina_grid_dnn_docker_dock(self):
    """Test that VinaGridDNNDocker can dock."""
@@ -102,8 +116,6 @@ class TestDocking(unittest.TestCase):
        protein_file, ligand_file)

    # Check returned files exist
    print("(score, (protein_docked, ligand_docked))")
    print((score, (protein_docked, ligand_docked)))
    assert score.shape == (1,)
    assert os.path.exists(protein_docked)
    assert os.path.exists(ligand_docked)
@@ -120,11 +132,7 @@ class TestDocking(unittest.TestCase):
    docker = dc.dock.VinaGridDNNDocker(
        exhaustiveness=1, detect_pockets=True)
    (score, (protein_docked, ligand_docked)) = docker.dock(
        protein_file, ligand_file)
        protein_file, ligand_file, dry_run=True)

    # Check returned files exist
    print("(score, (protein_docked, ligand_docked))")
    print((score, (protein_docked, ligand_docked)))
    assert score.shape == (1,)
    assert os.path.exists(protein_docked)
    assert os.path.exists(ligand_docked)