Commit 34ac5e6c authored by Bharath Ramsundar's avatar Bharath Ramsundar
Browse files

yapf

parent 9e471925
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ from deepchem.utils.fragment_util import get_contact_atom_indices

logger = logging.getLogger(__name__)


def extract_active_site(protein_file, ligand_file, cutoff=4):
  """Extracts a box for the active site.

@@ -32,11 +33,11 @@ def extract_active_site(protein_file, ligand_file, cutoff=4):
  A tuple of `(CoordinateBox, np.ndarray)` where the second entry is
  of shape `(N, 3)` with `N` the number of atoms in the active site.
  """
  protein = rdkit_util.load_molecule(
      protein_file, add_hydrogens=False)
  protein = rdkit_util.load_molecule(protein_file, add_hydrogens=False)
  ligand = rdkit_util.load_molecule(
      ligand_file, add_hydrogens=True, calc_charges=True)
  protein_contacts, ligand_contacts = get_contact_atom_indices([protein, ligand], cutoff=cutoff)
  protein_contacts, ligand_contacts = get_contact_atom_indices(
      [protein, ligand], cutoff=cutoff)
  protein_coords = protein[0]
  pocket_coords = protein_coords[protein_contacts]

@@ -49,6 +50,7 @@ def extract_active_site(protein_file, ligand_file, cutoff=4):
  box = box_utils.CoordinateBox((x_min, x_max), (y_min, y_max), (z_min, z_max))
  return (box, pocket_coords)


class BindingPocketFinder(object):
  """Abstract superclass for binding pocket detectors

+10 −12
Original line number Diff line number Diff line
@@ -24,10 +24,7 @@ class Docker(object):
  generation and scoring classes that are provided to this class.
  """

  def __init__(self,
               pose_generator,
               featurizer=None,
               scoring_model=None):
  def __init__(self, pose_generator, featurizer=None, scoring_model=None):
    """Builds model.

    Parameters
@@ -75,7 +72,8 @@ class Docker(object):
      `True` if `self.featurizer` and `self.scoring_model` are set
      since those will be used to generate scores in that case. 
    """
    outputs = self.pose_generator.generate_poses(molecular_complex,
    outputs = self.pose_generator.generate_poses(
        molecular_complex,
        centroid=centroid,
        box_dims=box_dims,
        exhaustiveness=exhaustiveness,
+26 −18
Original line number Diff line number Diff line
@@ -110,7 +110,9 @@ class VinaPoseGenerator(PoseGenerator):
        filename = "autodock_vina_1_1_2_mac.tgz"
        dirname = "autodock_vina_1_1_2_mac"
    else:
      raise ValueError("This class can only run on Linux or Mac. If you are on Windows, please try using a cloud platform to run this code instead.")
      raise ValueError(
          "This class can only run on Linux or Mac. If you are on Windows, please try using a cloud platform to run this code instead."
      )
    self.vina_dir = os.path.join(data_dir, dirname)
    self.pocket_finder = pocket_finder
    if not os.path.exists(self.vina_dir):
@@ -177,11 +179,15 @@ class VinaPoseGenerator(PoseGenerator):
      out_dir = tempfile.mkdtemp()

    if num_pockets is not None and self.pocket_finder is None:
      raise ValueError("If num_pockets is specified, pocket_finder must have been provided at construction time.")
      raise ValueError(
          "If num_pockets is specified, pocket_finder must have been provided at construction time."
      )

    # Parse complex
    if len(molecular_complex) > 2:
      raise ValueError("Autodock Vina can only dock protein-ligand complexes and not more general molecular complexes.")
      raise ValueError(
          "Autodock Vina can only dock protein-ligand complexes and not more general molecular complexes."
      )

    (protein_file, ligand_file) = molecular_complex

@@ -208,14 +214,14 @@ class VinaPoseGenerator(PoseGenerator):
        centroids, dimensions = [protein_centroid], [box_dims]
      else:
        logger.info("About to find putative binding pockets")
        pockets = self.pocket_finder.find_pockets(
            protein_file)
        pockets = self.pocket_finder.find_pockets(protein_file)
        logger.info("%d pockets found in total" % len(pockets))
        logger.info("Computing centroid and size of proposed pockets.")
        centroids, dimensions = [], []
        for pocket in pockets:
          protein_centroid = pocket.center()
          (x_min, x_max), (y_min, y_max), (z_min, z_max) = pocket.x_range, pocket.y_range, pocket.z_range
          (x_min, x_max), (y_min, y_max), (
              z_min, z_max) = pocket.x_range, pocket.y_range, pocket.z_range
          # TODO(rbharath: Does vina divide box dimensions by 2?
          x_box = (x_max - x_min) / 2.
          y_box = (y_max - y_min) / 2.
@@ -225,7 +231,8 @@ class VinaPoseGenerator(PoseGenerator):
          dimensions.append(box_dims)

    if num_pockets is not None:
      logger.info("num_pockets = %d so selecting this many pockets for docking." % num_pockets)
      logger.info("num_pockets = %d so selecting this many pockets for docking."
                  % num_pockets)
      centroids = centroids[:num_pockets]
      dimensions = dimensions[:num_pockets]

@@ -239,7 +246,8 @@ class VinaPoseGenerator(PoseGenerator):

    docked_complexes = []
    all_scores = []
    for i, (protein_centroid, box_dims) in enumerate(zip(centroids, dimensions)):
    for i, (protein_centroid, box_dims) in enumerate(
        zip(centroids, dimensions)):
      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))
+9 −1
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ def pairwise_distances(coords1, coords2):
  """
  return np.sum((coords1[None, :] - coords2[:, None])**2, -1)**0.5


def cutoff_filter(d, x, cutoff=8.0):
  """Applies a cutoff filter on pairwise distances

@@ -39,6 +40,7 @@ def cutoff_filter(d, x, cutoff=8.0):
  """
  return np.where(d < cutoff, x, np.zeros_like(x))


def vina_nonlinearity(c, w, Nrot):
  """Computes non-linearity used in Vina.

@@ -58,6 +60,7 @@ def vina_nonlinearity(c, w, Nrot):
  out_tensor = c / (1 + w * Nrot)
  return out_tensor


def vina_repulsion(d):
  """Computes Autodock Vina's repulsion interaction term.

@@ -72,6 +75,7 @@ def vina_repulsion(d):
  """
  return np.where(d >= 0, d**2, np.zeros_like(d))


def vina_hydrophobic(d):
  """Computes Autodock Vina's hydrophobic interaction term.

@@ -108,6 +112,7 @@ def vina_hbond(d):
      np.where(d < 0, (1.0 / 0.7) * (0 - d), np.zeros_like(d)))
  return out_tensor


def vina_gaussian_first(d):
  """Computes Autodock Vina's first Gaussian interaction term.

@@ -123,6 +128,7 @@ def vina_gaussian_first(d):
  out_tensor = np.exp(-(d / 0.5)**2)
  return out_tensor


def vina_gaussian_second(d):
  """Computes Autodock Vina's second Gaussian interaction term.

@@ -138,6 +144,7 @@ def vina_gaussian_second(d):
  out_tensor = np.exp(-((d - 3) / 2)**2)
  return out_tensor


def weighted_linear_sum(w, x):
  """Computes weighted linear sum.

@@ -150,6 +157,7 @@ def weighted_linear_sum(w, x):
  """
  return np.sum(np.dot(w, x))


def vina_energy_term(coords1, coords2, weights, wrot, Nrot):
  """Computes the Vina Energy function for two molecular conformations

+8 −7
Original line number Diff line number Diff line
@@ -32,7 +32,8 @@ class TestDocking(unittest.TestCase):
    # We provide no scoring model so the docker won't score
    vpg = dc.dock.VinaPoseGenerator()
    docker = dc.dock.Docker(vpg)
    docked_outputs = docker.dock((self.protein_file, self.ligand_file),
    docked_outputs = docker.dock(
        (self.protein_file, self.ligand_file),
        exhaustiveness=1,
        num_modes=1,
        out_dir="/tmp")
Loading