Ejemplo n.º 1
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
Ejemplo n.º 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
Ejemplo n.º 3
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
Ejemplo n.º 4
0
from htmd.builder.amber import defaultParam, build

# Test protein ligand building with parametrized ligand
refdir = home(dataDir=join('test-amber-build', 'protLig'))
tmpdir = './protLig'

mol = Molecule(join(refdir, '3ptb_mod.pdb'))
mol.center()
lig = Molecule(join(refdir, 'benzamidine.pdb'),
               guess=('bonds', 'angles', 'dihedrals'))
prm, lig = fftype(lig, method='GAFF2')
writeFRCMOD(lig, prm, join(tmpdir, 'mol.frcmod'))
lig.segid[:] = 'L'
lig.center()

from moleculekit.util import maxDistance
D = maxDistance(mol, 'all')
D += 6
lig.moveBy([0, 0, D])

newmol = Molecule()
newmol.append(lig)
newmol.append(mol)
smol = solvate(newmol, posz=3)

params = defaultParam() + [
    join(tmpdir, 'mol.frcmod'),
]

_ = build(smol, outdir=tmpdir, param=params, ionize=False)
Ejemplo n.º 5
0
prot = autoSegment(prot, sel='protein')
prot.set('segid', 'W', sel='water')
prot.set('segid', 'CA', sel='resname CA')
prot.center()

#LIGAND
ligand = Molecule(
    '/home/alejandro/covid19/MDrun/melatonin_cov/parameters/GAFF2/mol.mol2')
ligand.center()
ligand.set('segid', 'L')
ligand.set('resname', 'MOL')
ligand.rotateBy(uniformRandomRotation())

from moleculekit.util import maxDistance
D = maxDistance(prot, 'all')
D += 5
ligand.moveBy([D, 0, 0])

mol = Molecule(name='combo')
mol.append(prot)
mol.append(ligand)
mol.reps.add(sel='protein', style='NewCartoon', color='Secondary Structure')
mol.reps.add(sel='resname MOL', style='Licorice')
mol.view()

# We solvate with a larger box to fully solvate the ligand
DW = D + 3
smol = solvate(mol, minmax=[[-DW, -DW, -DW], [DW, DW, DW]])
smol.reps.add(sel='water', style='Lines')
smol.view()