Beispiel #1
0
def build_worker_charm22star(start_mol, idx, out="/tmp", saltconc=0.05):
    from random import randint
    topos22 = ['top/top_all22star_prot.rtf', 'top/top_water_ions.rtf']
    params22 = ['par/par_all22star_prot.prm', 'par/par_water_ions.prm']
    outdir = "{}{}_eq".format(out, idx)
    print(outdir)
    D = 41
    keep = True
    while keep:
        mol = start_mol.copy()
        if mol.numFrames > 1:
            x = randint(50, start_mol.numFrames - 1)
            mol.dropFrames(keep=[x])
        mol = proteinPrepare(mol)
        mol.set("segid", "P1")
        mol.filter(sel="protein")
        mol.center()
        mol_move = maxDistance(mol, 'all')
        if mol_move < D:
            keep = False
    smol = solvate(mol, minmax=[[-D, -D, -D], [D, D, D]])
    molbuilt = charmm.build(smol,
                            outdir=outdir,
                            caps=None,
                            topo=topos22,
                            param=params22,
                            saltconc=saltconc)
    return outdir
Beispiel #2
0
def rrt(mol, ligandsel, step=1, maxiter=int(1E6), ligcom=False, colldist=2, outdist=8):
    protcoor, ligcoor = _getCoordinates(mol, ligandsel, ligcom)
    viewer = _prepareViewer(mol, ligandsel)

    spherecoor = _pointsOnSphere(maxDistance(mol) + 5)

    tree = Tree(ligcoor)
    nocol = None

    for i in range(maxiter):
        print(i)
        if nocol is None:
            p_rand = spherecoor[np.random.randint(spherecoor.shape[0]), :]  # TODO: Make it clever. Discard failed points
        else:  # Reusing the same point that caused no collision
            p_rand = nocol
        parent_idx, p_near = _getNearest(tree.points, p_rand)
        p_new = _newPoint(p_rand, p_near, step)

        if _collision(protcoor, p_new, buffer=colldist):
            nocol = None
            continue
        nocol = p_rand

        print('no collision')
        tree.addPoint(p_new, parent_idx, step)

        _drawline(viewer, p_near, p_new)
        if _dist(p_rand, p_new) < 2:
            break
Beispiel #3
0
    def _prep_and_run(self, mol, rtf, prm, outdir, solvated):
        from htmd.builder.solvate import solvate
        from htmd.apps.acemdlocal import AcemdLocal
        # Do a simple solvation then run for 50ns
        ionize = True

        mol = Molecule(mol)
        mol.center()
        mol.set("segid", "L")
        d = maxDistance(mol, 'all') + 6

        if solvated:
            mol = solvate(mol, minmax=[[-d, -d, -d], [d, d, d]])

        if not solvated:
            ionize = False

        build_dir = os.path.join(outdir, "build")
        equil_dir = os.path.join(outdir, "equil")

        rtfs = ['top/top_water_ions.rtf', rtf]
        prms = ['par/par_water_ions.prm', prm]
        charmm.build(mol, topo=rtfs, param=prms, outdir=build_dir, ionize=ionize)
        md = Equilibration()
        md.runtime = 50
        md.timeunits = 'ns'
        md.temperature = 300
        md.write(build_dir, equil_dir)
        mdx = AcemdLocal()
        mdx.submit(equil_dir)
        mdx.wait()
Beispiel #4
0
   def _prep_and_run( self, mol, rtf, prm, outdir, solvated ):
      # Do a simple solvation then run for 50ns
      ionize = True 

      mol = Molecule(mol)
      mol.center()
      mol.set( "segid", "L" )
      D = maxDistance( mol, 'all' ) + 6

      if solvated:
          mol = solvate( mol, minmax=[[-D,-D,-D], [D,D,D]] )

      if not solvated:
          ionize=False    

      build_dir = os.path.join( outdir, "build" )
      equil_dir = os.path.join( outdir, "equil" )
      os.mkdir( build_dir, 0o700 )
      os.mkdir( equil_dir, 0o700 )

      rtfs = [ 'top/top_water_ions.rtf', rtf ]
      prms = [ 'par/par_water_ions.prm', prm ]
      mol  = charmm.build( mol, topo=rtfs, param=prms, outdir=build_dir, ionize=ionize )
      md = Equilibration()
      md.numsteps = 50 * 1000000 / 4 # 50ns simulation
      md.box = [ -D, -D, -D, D, D, D ]
      md.temperature = 300
      md.write( build_dir, equil_dir )
      mdx = AcemdLocal()
      mdx.submit( equil_dir )
      mdx.wait()
Beispiel #5
0
def rrtstarsmart(mol,
                 ligandsel,
                 step=1,
                 maxiter=int(1E6),
                 ligcom=False,
                 colldist=2,
                 outdist=8,
                 radius=2.5):
    protcoor, ligcoor = _getCoordinates(mol, ligandsel, ligcom)
    viewer = _prepareViewer(mol, ligandsel)

    mincoor = np.squeeze(np.min(mol.coords, axis=0) - 10)
    maxcoor = np.squeeze(np.max(mol.coords, axis=0) + 10)
    print(mincoor, maxcoor)

    spherecoor = _pointsOnSphere(maxDistance(mol) + 5)

    tree = Tree(ligcoor)
    nocol = None

    for i in range(maxiter):
        print(i)
        #p_rand = spherecoor[np.random.randint(spherecoor.shape[0]), :]
        p_rand = _randomPoint(mincoor, maxcoor)
        parent_idx, p_near = _getNearest(tree.points, p_rand)
        p_new = _newPoint(p_rand, p_near, step)

        if _collision(protcoor, p_new, buffer=colldist):
            continue

        print('no collision')
        near, neardist = _collisionFreeNeighbours(tree, p_new, radius,
                                                  protcoor, colldist, step)
        parent_idx, dist = _chooseParent(tree, near, neardist)
        tree.addPoint(p_new, parent_idx, dist)
        _rewire(tree, near, neardist, len(tree.points) - 1)

        if _endCondition(protcoor, p_rand, p_new, outdist, method='exited'):
            break

    for i in range(len(tree.points)):
        if tree.parent[i] is not None:
            _drawline(viewer, tree.points[i], tree.points[tree.parent[i]])

    print('optimizing')
    _pathOptimize(tree, len(tree.points) - 1, protcoor, colldist, step)
    print('finished optimization')
    # TODO: The algorithm is not finished. Normally you would get beacons and continue sampling around them to optimize
    # TODO: the path even more. However, we don't really need this in our case, unless I decide to make a real full impl
    # TODO: http://ieeexplore.ieee.org/xpls/icp.jsp?arnumber=6284384

    currnode = len(tree.points) - 1
    viewer.send('draw color green')
    while tree.parent[currnode] is not None:
        _drawline(viewer, tree.points[currnode],
                  tree.points[tree.parent[currnode]])
        currnode = tree.parent[currnode]

    return
def dockinit(protein_path, ligand_path):
    prot = Molecule(protein_path) 
    prot.filter('protein or water or resname CA')
    prot.set('segid', 'P', sel='protein and noh')
    prot.set('segid', 'W', sel='water')
    prot.set('segid', 'CA', sel='resname CA')
    D = maxDistance(prot, 'all')
    D = D + 15
    prot.center()
    lig = Molecule(ligand_path)
    poses, scores = dock(prot, lig)
    return (prot, poses, D)
def dockinit(protein_path, ligand_path):
    prot = Molecule(protein_path)
    prot.filter('protein or water or resname CA')
    prot.set('segid', 'P', sel='protein and noh')
    prot.set('segid', 'W', sel='water')
    prot.set('segid', 'CA', sel='resname CA')
    D = maxDistance(prot, 'all')
    D = D + 15
    prot.center()
    lig = Molecule(ligand_path)
    poses, scores = dock(prot, lig)
    return (prot, poses, D)
Beispiel #8
0
def raytracing(mol, ligandsel, step=1, colldist=2, outdist=8, ligcom=False, numsamples=2000, ratioexposed=0, vmd=True):
    protcoor, ligcoor = _getCoordinates(mol, ligandsel, ligcom)

    spherecoor = _pointsOnSphere(maxDistance(mol) + 5, numsamples=numsamples)
    if vmd:
        _viewSphere(spherecoor)
        viewer = _prepareViewer(mol, ligandsel)

    distances = _dist(ligcoor, spherecoor)

    from joblib import Parallel, delayed
    results = Parallel(n_jobs=-2, verbose=11)(
        delayed(parallelfunc)(j, spherecoor[j, :], ligcoor, protcoor, step, colldist, outdist, distances[:, j])
        for j in range(spherecoor.shape[0]))

    points = []
    pointdist = []
    shortpoints = []
    for r in results:
        points += r[0]
        pointdist += r[1]
        shortpoints += r[2]

    if len(points) == 0:
        raise RuntimeError('No ligand atoms can exit the pocket without {}A clashes.'.format(colldist))

    points = np.array(points)
    numexposed = len(np.unique(points[:, 0]))
    percentexposed = (numexposed / ligcoor.shape[0]) * 100
    if numexposed < (ratioexposed * ligcoor.shape[0]):
        raise RuntimeError('Only {:.1f}% ligand atoms can exit the pocket without {}A clashes. '
                           'This collides with the user-defined required {:.1f}% exposed ligand atoms.'.format(
                            percentexposed, colldist, ratioexposed*100))
    print('{:.1f}% ligand atoms can exit the pocket without {}A clashes.'.format(percentexposed, colldist))


    from scipy.stats import mode
    modesphere = mode(points[:, 1]).mode[0]
    idx = points[:, 1] == modesphere
    meanlig = np.mean(ligcoor[points[idx, 0], :], axis=0)

    if vmd:
        viewer.send('draw color green')
        _drawline(viewer, meanlig, spherecoor[modesphere, :])

        for idx, p in enumerate(points.tolist()):
            if p[1] == modesphere:
                viewer.send('draw color red')
                _drawline(viewer, shortpoints[idx], spherecoor[p[1], :])
                viewer.send('draw color green')
                _drawline(viewer, ligcoor[p[0], :], shortpoints[idx])

    return spherecoor[modesphere, :] - meanlig
Beispiel #9
0
def maxDistance_calculator(infile):
    counter = 0
    mol = []
    distance_list = []
    for file in glob.glob(infile + '/*/*.pdb'):
        mol.append(Molecule(file))
        mol[counter].read(glob.glob(infile + '/*/*.xtc')[counter])
        distance_list.append(maxDistance(mol[counter], 'all'))
        counter += 1
        print(file + " Done!")
    maxdist = max(distance_list)
    maxdist = maxdist * 1.1
    return (maxdist, mol)
def maxDistance_calculator(infile):
    counter = 0
    mol = []
    distance_list=[]
    for file in glob.glob(infile +'/*/*.pdb'):
        mol.append(Molecule(file))
        mol[counter].read(glob.glob(infile+'/*/*.xtc')[counter])
        distance_list.append(maxDistance(mol[counter], 'all'))
        counter +=1
        print(file + " Done!")
    maxdist = max(distance_list)
    maxdist = maxdist*1.1
    return (maxdist, mol) 
Beispiel #11
0
def rrtstarsmart(mol, ligandsel, step=1, maxiter=int(1E6), ligcom=False, colldist=2, outdist=8, radius=2.5):
    protcoor, ligcoor = _getCoordinates(mol, ligandsel, ligcom)
    viewer = _prepareViewer(mol, ligandsel)

    mincoor = np.squeeze(np.min(mol.coords, axis=0) - 10)
    maxcoor = np.squeeze(np.max(mol.coords, axis=0) + 10)
    print(mincoor, maxcoor)

    spherecoor = _pointsOnSphere(maxDistance(mol) + 5)

    tree = Tree(ligcoor)
    nocol = None

    for i in range(maxiter):
        print(i)
        #p_rand = spherecoor[np.random.randint(spherecoor.shape[0]), :]
        p_rand = _randomPoint(mincoor, maxcoor)
        parent_idx, p_near = _getNearest(tree.points, p_rand)
        p_new = _newPoint(p_rand, p_near, step)

        if _collision(protcoor, p_new, buffer=colldist):
            continue

        print('no collision')
        near, neardist = _collisionFreeNeighbours(tree, p_new, radius, protcoor, colldist, step)
        parent_idx, dist = _chooseParent(tree, near, neardist)
        tree.addPoint(p_new, parent_idx, dist)
        _rewire(tree, near, neardist, len(tree.points)-1)

        if _endCondition(protcoor, p_rand, p_new, outdist, method='exited'):
            break

    for i in range(len(tree.points)):
        if tree.parent[i] is not None:
            _drawline(viewer, tree.points[i], tree.points[tree.parent[i]])

    print('optimizing')
    _pathOptimize(tree, len(tree.points)-1, protcoor, colldist, step)
    print('finished optimization')
    # TODO: The algorithm is not finished. Normally you would get beacons and continue sampling around them to optimize
    # TODO: the path even more. However, we don't really need this in our case, unless I decide to make a real full impl
    # TODO: http://ieeexplore.ieee.org/xpls/icp.jsp?arnumber=6284384

    currnode = len(tree.points)-1
    viewer.send('draw color green')
    while tree.parent[currnode] is not None:
        _drawline(viewer, tree.points[currnode], tree.points[tree.parent[currnode]])
        currnode = tree.parent[currnode]

    return
Beispiel #12
0
def dummy_leaflet(prot,name, sp =3):
    '''Returns a leaflet of dummy atoms, which represents a layer of the membrane. 
    Each dummy atom is placed at the xy plane separated from the other by a distance of sp Angstroms.'''
    pcenter = np.mean(prot.get('coords','protein'),axis=0)
    N = int(maxDistance(prot, 'all',pcenter))
    dl=Molecule()
    dl.empty(N*N) 
    dl.set("name",name)
    dl.set("record","HETATM")   
    resids=np.array(range(1,N*N+1))
    dl.set("resid",resids)
    dl.set("resname","DUM")    
    coords=[]
    for i in range(0,sp*N,sp):
        for j in range(0,sp*N,sp):
            coords.append([i,j,0])
    dl.set("coords",coords)        
    return (dl)
Beispiel #13
0
def rrt(mol,
        ligandsel,
        step=1,
        maxiter=int(1E6),
        ligcom=False,
        colldist=2,
        outdist=8):
    protcoor, ligcoor = _getCoordinates(mol, ligandsel, ligcom)
    viewer = _prepareViewer(mol, ligandsel)

    spherecoor = _pointsOnSphere(maxDistance(mol) + 5)

    tree = Tree(ligcoor)
    nocol = None

    for i in range(maxiter):
        print(i)
        if nocol is None:
            p_rand = spherecoor[np.random.randint(
                spherecoor.shape[0]
            ), :]  # TODO: Make it clever. Discard failed points
        else:  # Reusing the same point that caused no collision
            p_rand = nocol
        parent_idx, p_near = _getNearest(tree.points, p_rand)
        p_new = _newPoint(p_rand, p_near, step)

        if _collision(protcoor, p_new, buffer=colldist):
            nocol = None
            continue
        nocol = p_rand

        print('no collision')
        tree.addPoint(p_new, parent_idx, step)

        _drawline(viewer, p_near, p_new)
        if _dist(p_rand, p_new) < 2:
            break
Beispiel #14
0
def define_extremes(traj_wat):
    D = maxDistance(traj_wat)
    min_d = 0
    max_d = 2 * int(D + 1)
    return (min_d, max_d)
Beispiel #15
0
def raytracing(mol,
               ligandsel,
               step=1,
               colldist=2,
               outdist=8,
               ligcom=False,
               numsamples=2000,
               ratioexposed=0,
               vmd=True):
    protcoor, ligcoor = _getCoordinates(mol, ligandsel, ligcom)

    spherecoor = _pointsOnSphere(maxDistance(mol) + 5, numsamples=numsamples)
    if vmd:
        _viewSphere(spherecoor)
        viewer = _prepareViewer(mol, ligandsel)

    distances = _dist(ligcoor, spherecoor)

    from joblib import Parallel, delayed
    results = Parallel(n_jobs=-2, verbose=11)(
        delayed(parallelfunc)(j, spherecoor[j, :], ligcoor, protcoor, step,
                              colldist, outdist, distances[:, j])
        for j in range(spherecoor.shape[0]))

    points = []
    pointdist = []
    shortpoints = []
    for r in results:
        points += r[0]
        pointdist += r[1]
        shortpoints += r[2]

    if len(points) == 0:
        raise RuntimeError(
            'No ligand atoms can exit the pocket without {}A clashes.'.format(
                colldist))

    points = np.array(points)
    numexposed = len(np.unique(points[:, 0]))
    percentexposed = (numexposed / ligcoor.shape[0]) * 100
    if numexposed < (ratioexposed * ligcoor.shape[0]):
        raise RuntimeError(
            'Only {:.1f}% ligand atoms can exit the pocket without {}A clashes. '
            'This collides with the user-defined required {:.1f}% exposed ligand atoms.'
            .format(percentexposed, colldist, ratioexposed * 100))
    print(
        '{:.1f}% ligand atoms can exit the pocket without {}A clashes.'.format(
            percentexposed, colldist))

    from scipy.stats import mode
    modesphere = mode(points[:, 1]).mode[0]
    idx = points[:, 1] == modesphere
    meanlig = np.mean(ligcoor[points[idx, 0], :], axis=0)

    if vmd:
        viewer.send('draw color green')
        _drawline(viewer, meanlig, spherecoor[modesphere, :])

        for idx, p in enumerate(points.tolist()):
            if p[1] == modesphere:
                viewer.send('draw color red')
                _drawline(viewer, shortpoints[idx], spherecoor[p[1], :])
                viewer.send('draw color green')
                _drawline(viewer, ligcoor[p[0], :], shortpoints[idx])

    return spherecoor[modesphere, :] - meanlig
def define_extremes(traj_wat):
    D = maxDistance(traj_wat)
    min_d = 0
    max_d = 2*int(D+1)    
    return(min_d,max_d)
Beispiel #17
0
def get_descriptors(path, ligands, boxSize):
    batch = len(ligands) / 100
    cont = batch
    descriptors = []
    labels = np.empty(shape=[0, 1])

    contFails = 0
    maxSize = 0
    if boxSize != "Null":
        maxSize = int(boxSize)

    else:
        print("Calculating box size descriptors ...")
        maxSize = 0
        for i, ligand in enumerate(ligands):
            cont -= 1
            if cont < 0:
                cont = batch
                print(str((i / len(ligands)) * 100) + "%")
            try:
                mol = Molecule(path + ligand[0] + ".pdbqt")
                dist = u.maxDistance(mol, sel='all', origin=[0, 0, 0])
                if maxSize < dist:
                    maxSize = dist
            except:
                continue

    print("Box Size = " + str(maxSize))
    print("Bulding descriptors ...")

    bindingCount = 0
    noBindingCount = 0
    cont = batch

    for i, ligand in enumerate(ligands):
        cont -= 1
        if cont < 0:
            cont = batch
            print(str((i / len(ligands)) * 100) + "%")
        try:
            mol = Molecule(path + ligand[0] + ".pdbqt")
            point = np.squeeze(mol.coords).mean(axis=0)
            desc = vd.getPointDescriptors(mol, point, size=[int(maxSize)] * 3)
            dist = u.maxDistance(mol, sel='all', origin=[0, 0, 0])
            if dist > int(maxSize):
                continue
        except:
            contFails += 1
            print("pdb " + str(ligand[0]) + " not found : " + str(contFails))
            continue

        if ligand[2] == "0":
            noBindingCount += 1
        elif ligand[2] == "1":
            bindingCount += 1

        labels = np.append(labels, ligand[2])
        descriptors.append(desc)
    print("Final binding " + str(bindingCount))
    print("Final no binding " + str(noBindingCount))
    return np.array(descriptors), labels, int(maxSize)