Commit c294a6e7 authored by Bharath Ramsundar's avatar Bharath Ramsundar
Browse files

changes

parent 2a72d8e1
Loading
Loading
Loading
Loading
+72 −0
Original line number Diff line number Diff line
import nglview
import tempfile
import os
import mdtraj as md
import numpy as np
import tempfile
from rdkit import Chem
from rdkit.Chem import Draw
from itertools import islice
from IPython.display import Image, HTML, display

def combine_mdtraj(protein, ligand):
  chain = protein.topology.add_chain()
  residue = protein.topology.add_residue("LIG", chain, resSeq=1)
  for atom in ligand.topology.atoms:
      protein.topology.add_atom(atom.name, atom.element, residue)
  protein.xyz = np.hstack([protein.xyz, ligand.xyz])
  protein.topology.create_standard_bonds()
  return protein

def visualize_complex(complex_mdtraj):
  ligand_atoms = [a.index for a in complex_mdtraj.topology.atoms if "LIG" in str(a.residue)]
  binding_pocket_atoms = md.compute_neighbors(complex_mdtraj, 0.5, ligand_atoms)[0]
  binding_pocket_residues = list(set([complex_mdtraj.topology.atom(a).residue.resSeq for a in binding_pocket_atoms]))
  binding_pocket_residues = [str(r) for r in binding_pocket_residues]
  binding_pocket_residues = " or ".join(binding_pocket_residues)

  traj = nglview.MDTrajTrajectory( complex_mdtraj ) # load file from RCSB PDB
  ngltraj = nglview.NGLWidget( traj )
  ngltraj.representations = [
  { "type": "cartoon", "params": {
  "sele": "protein", "color": "residueindex"
  } },
  { "type": "licorice", "params": {
  "sele": "(not hydrogen) and (%s)" %  binding_pocket_residues
  } },
  { "type": "ball+stick", "params": {
  "sele": "LIG"
  } }
  ]
  return ngltraj

def visualize_ligand(ligand_mdtraj):
  traj = nglview.MDTrajTrajectory( ligand_mdtraj ) # load file from RCSB PDB
  ngltraj = nglview.NGLWidget( traj )
  ngltraj.representations = [
    { "type": "ball+stick", "params": {"sele": "all" } } ]
  return ngltraj

def convert_lines_to_mdtraj(molecule_lines):
  tempdir = tempfile.mkdtemp()
  molecule_file = os.path.join(tempdir, "molecule.pdb")
  with open(molecule_file, "wb") as f:
    f.writelines(molecule_lines)
  molecule_mdtraj = md.load(molecule_file)
  return molecule_mdtraj

def display_images(filenames):
    """Helper to pretty-print images."""
    imagesList=''.join(
        ["<img style='width: 140px; margin: 0px; float: left; border: 1px solid black;' src='%s' />"
         % str(s) for s in sorted(filenames)])
    display(HTML(imagesList))

def mols_to_pngs(mols, basename="test"):
    """Helper to write RDKit mols to png files."""
    filenames = []
    for i, mol in enumerate(mols):
        filename = "%s%d.png" % (basename, i)
        Draw.MolToFile(mol, filename)
        filenames.append(filename)
    return filenames
+1 −1
Original line number Diff line number Diff line
import numpy as np
from deepchem.feat import Featurizer
from rdkit import Chem

zinc_charset = [
    ' ', '#', ')', '(', '+', '-', '/', '1', '3', '2', '5', '4', '7', '6', '8',
@@ -42,6 +41,7 @@ class OneHotFeaturizer(Featurizer):
    obj
      numpy array of features
    """
    from rdkit import Chem
    smiles = [Chem.MolToSmiles(mol) for mol in mols]
    if self.charset is None:
      self.charset = self._create_charset(smiles)
+0 −3
Original line number Diff line number Diff line
@@ -4,8 +4,6 @@ Tests for splitter objects.
from __future__ import division
from __future__ import unicode_literals

from rdkit.Chem.Fingerprints import FingerprintMols

__author__ = "Bharath Ramsundar, Aneesh Pappu"
__copyright__ = "Copyright 2016, Stanford University"
__license__ = "MIT"
@@ -16,7 +14,6 @@ import numpy as np
import deepchem as dc
from deepchem.data import NumpyDataset
from deepchem.splits import IndexSplitter
from rdkit import Chem, DataStructs


class TestSplitters(unittest.TestCase):
+1 −2
Original line number Diff line number Diff line
@@ -15,8 +15,6 @@ import tempfile
import tarfile
import zipfile

from rdkit import Chem
from rdkit.Chem.Scaffolds import MurckoScaffold

try:
  from urllib.request import urlretrieve  # Python 3
@@ -152,5 +150,6 @@ class ScaffoldGenerator(object):
    mols : array_like
        Molecules.
    """
    from rdkit.Chem.Scaffolds import MurckoScaffold
    return MurckoScaffold.MurckoScaffoldSmiles(
        mol=mol, includeChirality=self.include_chirality)
+5 −4
Original line number Diff line number Diff line
@@ -8,10 +8,6 @@ __license__ = "3-clause BSD"

import numpy as np

from rdkit import Chem
from rdkit.Chem import AllChem


class ConformerGenerator(object):
  """
  Generate molecule conformers.
@@ -106,6 +102,8 @@ class ConformerGenerator(object):
    mol : RDKit Mol
        Molecule.
    """
    from rdkit import Chem
    from rdkit.Chem import AllChem
    mol = Chem.AddHs(mol)  # add hydrogens
    n_confs = self.max_conformers * self.pool_multiplier
    AllChem.EmbedMultipleConfs(mol, numConfs=n_confs, pruneRmsThresh=-1.)
@@ -124,6 +122,7 @@ class ConformerGenerator(object):
    kwargs : dict, optional
        Keyword arguments for force field constructor.
    """
    from rdkit.Chem import AllChem
    if self.force_field == 'uff':
      ff = AllChem.UFFGetMoleculeForceField(
          mol, confId=conf_id, **kwargs)
@@ -218,6 +217,7 @@ class ConformerGenerator(object):

    # create a new molecule to hold the chosen conformers
    # this ensures proper conformer IDs and energy-based ordering
    from rdkit import Chem
    new = Chem.Mol(mol)
    new.RemoveAllConformers()
    conf_ids = [conf.GetId() for conf in mol.GetConformers()]
@@ -236,6 +236,7 @@ class ConformerGenerator(object):
    mol : RDKit Mol
        Molecule.
    """
    from rdkit.Chem import AllChem
    rmsd = np.zeros((mol.GetNumConformers(), mol.GetNumConformers()),
                    dtype=float)
    for i, ref_conf in enumerate(mol.GetConformers()):
Loading