def generateProteinDescriptor(pdb_file,voxel_size=64,mode='standard'): 
    # Remove HetAtoms
    pdb_id = os.path.basename(pdb_file).split('.')[0]
    # If your structure is fully protonated and contains all bond information in prot.bonds skip this step!
    if mode != 'scPDB':
        pdb_file_nonhet = removeHETAtoms(pdb_file,pdb_id)
        prot = Molecule(pdb_file_nonhet)
        prot = prepareProteinForAtomtyping(prot)
        prot.center()
        prot.write(pdb_file_nonhet)
        prot = Molecule(pdb_file_nonhet)
        prot.view(guessBonds=False)
    else:
        prot = SmallMol(pdb_file)     
    try:
        prot_vox, prot_centers, prot_N = getVoxelDescriptors(prot,voxelsize=1, buffer=1,center=(0,0,0),boxsize=(voxel_size,voxel_size,voxel_size))
    except:
        return False
    nchannels = prot_vox.shape[1]
    # Reshape Voxels
    prot_vox_t = prot_vox.transpose().reshape([1, nchannels, prot_N[0], prot_N[1], prot_N[2]]) 
    return prot_vox_t
Exemplo n.º 2
0
def buildMembrane(xysize, ratioupper, ratiolower, waterbuff=20, minimplatform='CPU', equilibrate=True, equilplatform='CUDA', outdir=None, lipidf=None):
    """ Construct a membrane containing arbitrary lipids and ratios of them.

    Parameters
    ----------
    xysize : list
        A list containing the size in x and y dimensions of the membrane in Angstroms
    ratioupper : dict
        A dict with keys the molecule names and the ratio of that molecule for the upper layer
    ratiolower : dict
        Same as ratioupper but for the lower layer
    waterbuff : float
        The z-dimension size of the water box above and below the membrane
    minimplatform : str
        The platform on which to run the minimization ('CUDA' or 'CPU')
    equilibrate : bool
        If True it equilibrates the membrane
    equilplatform : str
        The platform on which to run the equilibration ('CUDA' or 'CPU')
    outdir : str
        A folder in which to store the psf and pdb files
    lipidf : str
        The path to the folder containing the single-lipid PDB structures as well as the lipid DB file

    Returns
    -------
    mol : :class:`Molecule <moleculekit.molecule.Molecule`
        The resulting membrane including surrounding waters

    Examples
    --------
    >>> lipidratioupper = {'popc': 10, 'chl1': 1}
    >>> lipidratiolower = {'popc': 8, 'chl1': 2}
    >>> width = [50, 100]
    >>> res = buildMembrane(width, lipidratioupper, lipidratiolower)
    """
    from htmd.membranebuilder.ringpenetration import resolveRingPenetrations
    from htmd.builder.solvate import solvate
    from htmd.builder.charmm import build
    from htmd.util import tempname
    from moleculekit.molecule import Molecule
    from htmd.home import home
    import os
    import pandas as pd

    if lipidf is None:
        lipidf = os.path.join(home(shareDir=True), 'membranebuilder', 'lipids')
    lipiddb = pd.read_csv(os.path.join(lipidf, 'lipiddb.csv'), index_col='Name')

    uqlip = np.unique(list(ratioupper.keys()) + list(ratiolower.keys()))
    files = _locateLipidFiles(lipidf, uqlip)

    area = np.prod(xysize)
    lipids = _createLipids(ratioupper, area, lipiddb, files, leaflet='upper')
    lipids += _createLipids(ratiolower, area, lipiddb, files, leaflet='lower')

    _setPositionsLJSim(xysize, [l for l in lipids if l.xyz[2] > 0])
    _setPositionsLJSim(xysize, [l for l in lipids if l.xyz[2] < 0])

    _findNeighbours(lipids, xysize)

    _loadMolecules(lipids, files)

    # from globalminimization import minimize
    # newpos, newrot = minimize(lipids, xysize + [100], stepxy=0.5, steprot=50, contactthresh=1)
    # for i in range(len(lipids)):
    #     lipids[i].xyz[:2] = newpos[i]
    #     lipids[i].rot = newrot[i]

    resolveRingPenetrations(lipids, xysize)
    memb = _createMembraneMolecule(lipids)

    minc = memb.get('coords', 'name P').min(axis=0) - 5
    maxc = memb.get('coords', 'name P').max(axis=0) + 5

    mm = [[0, 0, maxc[2] - 2], [xysize[0], xysize[1], maxc[2] + waterbuff]]
    smemb = solvate(memb, minmax=mm)
    mm = [[0, 0, minc[2] - waterbuff], [xysize[0], xysize[1], minc[2] + 2]]
    smemb = solvate(smemb, minmax=mm)

    smemb.moveBy([0, 0, -smemb.coords[:, 2, 0].min()])

    if outdir is None:
        outdir = tempname()
        logger.info('Outdir {}'.format(outdir))
    res = build(smemb, ionize=False, stream=['str/lipid/toppar_all36_lipid_cholesterol_model_1.str'], outdir=outdir)

    if equilibrate:
        from htmd.membranebuilder.simulate_openmm import equilibrateSystem
        from shutil import copy, move
        outpdb = tempname(suffix='.pdb')
        charmmf = os.path.join(home(shareDir=True), 'membranebuilder', 'charmm-toppar')
        equilibrateSystem(os.path.join(outdir, 'structure.pdb'), os.path.join(outdir, 'structure.psf'), outpdb,
                          charmmfolder=charmmf, equilplatform=equilplatform, minimplatform=minimplatform)
        res = Molecule(outpdb)
        res.center()
        move(os.path.join(outdir, 'structure.pdb'), os.path.join(outdir, 'starting_structure.pdb'))
        copy(outpdb, os.path.join(outdir, 'structure.pdb'))

    return res
Exemplo n.º 3
0
from htmd.home import home
from os.path import join
from htmd.builder.solvate import solvate
from htmd.parameterization.fftype import fftype
from htmd.parameterization.writers import writeFRCMOD
from moleculekit.molecule import Molecule
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)