def testProteinLigand(self): from htmd.builder.solvate import solvate from htmd.parameterization.fftype import fftype, FFTypeMethod from htmd.parameterization.writers import writeFRCMOD # Test protein ligand building with parametrized ligand refdir = home(dataDir=join('test-amber-build', 'protLig')) tmpdir = os.path.join(self.testDir, 'protLig') os.makedirs(tmpdir) mol = Molecule(join(refdir, '3ptb_mod.pdb')) lig = Molecule(join(refdir, 'benzamidine.pdb'), guess=('bonds', 'angles', 'dihedrals')) prm, lig = fftype(lig, method=FFTypeMethod.GAFF2) writeFRCMOD(lig, prm, join(tmpdir, 'mol.frcmod')) lig.segid[:] = 'L' # params = newmol = Molecule() newmol.append(lig) newmol.append(mol) smol = solvate(newmol) params = defaultParam() + [join(tmpdir, 'mol.frcmod'),] _ = build(smol, outdir=tmpdir, param=params, ionize=False) refdir = home(dataDir=join('test-amber-build', 'protLig', 'results')) TestAmberBuild._compareResultFolders(refdir, tmpdir, '3PTB')
def test_disulfideWithInsertion(self): from htmd.molecule.molecule import Molecule from htmd.builder.solvate import solvate from htmd.home import home from htmd.util import tempname, assertSameAsReferenceDir import os import numpy as np # Use pre-prepared files so we can tell whether the error is in prepare or in build # Inputs are reference outputs of proteinprepare. preparedInputDir = home(dataDir='test-proteinprepare') pdb = '3PTB' print('Building {}'.format(pdb)) inFile = os.path.join(preparedInputDir, pdb, "{}-prepared.pdb".format(pdb)) mol = Molecule(inFile) mol.filter('protein') # Fix for bad proteinPrepare hydrogen placing np.random.seed(1) # Needed for ions smol = solvate(mol) topos = ['top/top_all36_prot.rtf', 'top/top_water_ions.rtf'] params = ['par/par_all36_prot_mod.prm', 'par/par_water_ions.prm'] smol.insertion[ smol.resid == 42] = 'A' # Adding an insertion to test that disulfide bonds with insertions work tmpdir = tempname() _ = build(smol, topo=topos, param=params, outdir=tmpdir) compareDir = home( dataDir=os.path.join('test-charmm-build', '3PTB_insertion')) assertSameAsReferenceDir(compareDir, tmpdir)
def test_build(self): from moleculekit.molecule import Molecule from htmd.builder.solvate import solvate from htmd.home import home from htmd.util import tempname, assertSameAsReferenceDir import os import numpy as np # Use pre-prepared files so we can tell whether the error is in prepare or in build # Inputs are reference outputs of proteinprepare. preparedInputDir = home(dataDir="test-proteinprepare") pdbids = ["3PTB", "1A25", "1GZM", "1U5U"] for pdb in pdbids: with self.subTest(pdb=pdb): print("Building {}".format(pdb)) inFile = os.path.join(preparedInputDir, pdb, "{}-prepared.pdb".format(pdb)) mol = Molecule(inFile) mol.filter( "protein") # Fix for bad proteinPrepare hydrogen placing np.random.seed(1) # Needed for ions smol = solvate(mol) topos = ["top/top_all36_prot.rtf", "top/top_water_ions.rtf"] params = ["par/par_all36_prot.prm", "par/par_water_ions.prm"] tmpdir = tempname() _ = build(smol, topo=topos, param=params, outdir=tmpdir) compareDir = home( dataDir=os.path.join("test-charmm-build", pdb)) assertSameAsReferenceDir(compareDir, tmpdir)
def test_disulfideWithInsertion(self): from htmd.molecule.molecule import Molecule from htmd.builder.solvate import solvate from htmd.home import home from htmd.util import tempname, assertSameAsReferenceDir import os import numpy as np # Use pre-prepared files so we can tell whether the error is in prepare or in build # Inputs are reference outputs of proteinprepare. preparedInputDir = home(dataDir='test-proteinprepare') pdb = '3PTB' print('Building {}'.format(pdb)) inFile = os.path.join(preparedInputDir, pdb, "{}-prepared.pdb".format(pdb)) mol = Molecule(inFile) mol.filter('protein') # Fix for bad proteinPrepare hydrogen placing np.random.seed(1) # Needed for ions smol = solvate(mol) topos = ['top/top_all36_prot.rtf', 'top/top_water_ions.rtf'] params = ['par/par_all36_prot_mod.prm', 'par/par_water_ions.prm'] smol.insertion[smol.resid == 42] = 'A' # Adding an insertion to test that disulfide bonds with insertions work tmpdir = tempname() _ = build(smol, topo=topos, param=params, outdir=tmpdir) compareDir = home(dataDir=os.path.join('test-charmm-build', '3PTB_insertion')) assertSameAsReferenceDir(compareDir, tmpdir)
def test_build(self): from htmd.molecule.molecule import Molecule from htmd.builder.solvate import solvate from htmd.home import home from htmd.util import tempname, assertSameAsReferenceDir import os import numpy as np # Use pre-prepared files so we can tell whether the error is in prepare or in build # Inputs are reference outputs of proteinprepare. preparedInputDir = home(dataDir='test-proteinprepare') pdbids = ['3PTB', '1A25', '1GZM', '1U5U'] for pdb in pdbids: with self.subTest(pdb=pdb): print('Building {}'.format(pdb)) inFile = os.path.join(preparedInputDir, pdb, "{}-prepared.pdb".format(pdb)) mol = Molecule(inFile) mol.filter( 'protein') # Fix for bad proteinPrepare hydrogen placing np.random.seed(1) # Needed for ions smol = solvate(mol) topos = ['top/top_all36_prot.rtf', 'top/top_water_ions.rtf'] params = [ 'par/par_all36_prot_mod.prm', 'par/par_water_ions.prm' ] tmpdir = tempname() _ = build(smol, topo=topos, param=params, outdir=tmpdir) compareDir = home( dataDir=os.path.join('test-charmm-build', pdb)) assertSameAsReferenceDir(compareDir, tmpdir)
def test_build(self): from htmd.molecule.molecule import Molecule from htmd.builder.solvate import solvate from htmd.home import home from htmd.util import tempname, assertSameAsReferenceDir import os import numpy as np # Use pre-prepared files so we can tell whether the error is in prepare or in build # Inputs are reference outputs of proteinprepare. preparedInputDir = home(dataDir='test-proteinprepare') pdbids = ['3PTB', '1A25', '1GZM', '1U5U'] for pdb in pdbids: with self.subTest(pdb=pdb): print('Building {}'.format(pdb)) inFile = os.path.join(preparedInputDir, pdb, "{}-prepared.pdb".format(pdb)) mol = Molecule(inFile) mol.filter('protein') # Fix for bad proteinPrepare hydrogen placing np.random.seed(1) # Needed for ions smol = solvate(mol) topos = ['top/top_all36_prot.rtf', 'top/top_water_ions.rtf'] params = ['par/par_all36_prot_mod.prm', 'par/par_water_ions.prm'] tmpdir = tempname() _ = build(smol, topo=topos, param=params, outdir=tmpdir) compareDir = home(dataDir=os.path.join('test-charmm-build', pdb)) assertSameAsReferenceDir(compareDir, tmpdir)
def test_customDisulfideBonds(self): from htmd.builder.solvate import solvate # Test without proteinPrepare pdbids = [ '1GZM', ] for pid in pdbids: np.random.seed(1) mol = Molecule(pid) mol.filter('protein') smol = solvate(mol) ffs = defaultFf() disu = [['segid 1 and resid 110', 'segid 1 and resid 187'], ['segid 0 and resid 110', 'segid 0 and resid 187']] tmpdir = os.path.join(self.testDir, 'withoutProtPrep', pid) _ = build(smol, ff=ffs, outdir=tmpdir, disulfide=disu) refdir = home(dataDir=join('test-amber-build', 'nopp', pid)) TestAmberBuild._compareResultFolders(refdir, tmpdir, pid) np.random.seed(1) tmpdir = os.path.join(self.testDir, 'withoutProtPrep', pid) _ = build(smol, ff=ffs, outdir=tmpdir) refdir = home(dataDir=join('test-amber-build', 'nopp', pid)) TestAmberBuild._compareResultFolders(refdir, tmpdir, pid)
def test_customDisulfideBonds(self): from htmd.builder.solvate import solvate # Test without proteinPrepare pdbids = [ "1GZM", ] for pid in pdbids: np.random.seed(1) mol = Molecule(pid) mol.filter("protein") smol = solvate(mol) ffs = defaultFf() disu = [ ["segid 1 and resid 110", "segid 1 and resid 187"], ["segid 0 and resid 110", "segid 0 and resid 187"], ] tmpdir = os.path.join(self.testDir, "withoutProtPrep", pid) _ = build(smol, ff=ffs, outdir=tmpdir, disulfide=disu) refdir = home(dataDir=join("test-amber-build", "nopp", pid)) _TestAmberBuild._compareResultFolders(refdir, tmpdir, pid) np.random.seed(1) tmpdir = os.path.join(self.testDir, "withoutProtPrep", pid) _ = build(smol, ff=ffs, outdir=tmpdir) refdir = home(dataDir=join("test-amber-build", "nopp", pid)) _TestAmberBuild._compareResultFolders(refdir, tmpdir, pid)
def testProteinLigand(self): from htmd.builder.solvate import solvate # Test protein ligand building with parametrized ligand refdir = home(dataDir=join("test-amber-build", "protLig")) tmpdir = os.path.join(self.testDir, "protLig") os.makedirs(tmpdir) mol = Molecule(join(refdir, "3ptb_mod.pdb")) lig = Molecule(join(refdir, "benzamidine.mol2")) lig.segid[:] = "L" # params = newmol = Molecule() newmol.append(lig) newmol.append(mol) smol = solvate(newmol) params = defaultParam() + [ join(refdir, "benzamidine.frcmod"), ] _ = build(smol, outdir=tmpdir, param=params, ionize=False) refdir = home(dataDir=join("test-amber-build", "protLig", "results")) _TestAmberBuild._compareResultFolders(refdir, tmpdir, "3PTB")
def test_customDisulfideBonds(self): from moleculekit.molecule import Molecule from htmd.builder.solvate import solvate from htmd.home import home from htmd.util import tempname, assertSameAsReferenceDir import os import numpy as np # Use pre-prepared files so we can tell whether the error is in prepare or in build # Inputs are reference outputs of proteinprepare. preparedInputDir = home(dataDir="test-proteinprepare") pdb = "1GZM" inFile = os.path.join(preparedInputDir, pdb, "{}-prepared.pdb".format(pdb)) mol = Molecule(inFile) mol.filter("protein") # Fix for bad proteinPrepare hydrogen placing np.random.seed(1) # Needed for ions smol = solvate(mol) topos = ["top/top_all36_prot.rtf", "top/top_water_ions.rtf"] params = ["par/par_all36_prot.prm", "par/par_water_ions.prm"] disu = [ ["segid 1 and resid 110", "segid 1 and resid 187"], ["segid 0 and resid 110", "segid 0 and resid 187"], ] tmpdir = tempname() _ = build(smol, topo=topos, param=params, outdir=tmpdir, disulfide=disu) compareDir = home(dataDir=os.path.join("test-charmm-build", pdb)) assertSameAsReferenceDir(compareDir, tmpdir)
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()
def testProteinLigand(self): from htmd.builder.solvate import solvate from htmd.parameterization.fftype import fftype, FFTypeMethod from htmd.parameterization.writers import writeFRCMOD # Test protein ligand building with parametrized ligand refdir = home(dataDir=join('test-amber-build', 'protLig')) tmpdir = os.path.join(self.testDir, 'protLig') os.makedirs(tmpdir) mol = Molecule(join(refdir, '3ptb_mod.pdb')) lig = Molecule(join(refdir, 'benzamidine.pdb'), guess=('bonds', 'angles', 'dihedrals')) prm, lig = fftype(lig, method=FFTypeMethod.GAFF2) writeFRCMOD(lig, prm, join(tmpdir, 'mol.frcmod')) lig.segid[:] = 'L' # params = newmol = Molecule() newmol.append(lig) newmol.append(mol) smol = solvate(newmol) params = defaultParam() + [ join(tmpdir, 'mol.frcmod'), ] _ = build(smol, outdir=tmpdir, param=params, ionize=False) refdir = home(dataDir=join('test-amber-build', 'protLig', 'results')) TestAmberBuild._compareResultFolders(refdir, tmpdir, '3PTB')
def test_customDisulfideBonds(self): from htmd.molecule.molecule import Molecule from htmd.builder.solvate import solvate from htmd.home import home from htmd.util import tempname, assertSameAsReferenceDir import os import numpy as np # Use pre-prepared files so we can tell whether the error is in prepare or in build # Inputs are reference outputs of proteinprepare. preparedInputDir = home(dataDir='test-proteinprepare') pdb = '1GZM' inFile = os.path.join(preparedInputDir, pdb, "{}-prepared.pdb".format(pdb)) mol = Molecule(inFile) mol.filter('protein') # Fix for bad proteinPrepare hydrogen placing np.random.seed(1) # Needed for ions smol = solvate(mol) topos = ['top/top_all36_prot.rtf', 'top/top_water_ions.rtf'] params = ['par/par_all36_prot_mod.prm', 'par/par_water_ions.prm'] disu = [['segid 1 and resid 110', 'segid 1 and resid 187'], ['segid 0 and resid 110', 'segid 0 and resid 187']] tmpdir = tempname() _ = build(smol, topo=topos, param=params, outdir=tmpdir, disulfide=disu) compareDir = home(dataDir=os.path.join('test-charmm-build', pdb)) assertSameAsReferenceDir(compareDir, tmpdir) # TODO: Remove this after deprecation from htmd.builder.builder import DisulfideBridge np.random.seed(1) # Needed for ions disu = [ DisulfideBridge('1', 110, '1', 187), DisulfideBridge('0', 110, '0', 187) ] tmpdir = tempname() _ = build(smol, topo=topos, param=params, outdir=tmpdir, disulfide=disu) compareDir = home(dataDir=os.path.join('test-charmm-build', pdb)) assertSameAsReferenceDir(compareDir, tmpdir)
def testWithoutProteinPrepare(self): from htmd.builder.solvate import solvate # Test without proteinPrepare pdbids = ['3PTB'] # pdbids = ['3PTB', '1A25', '1GZM', '1U5U'] for pid in pdbids: np.random.seed(1) mol = Molecule(pid) mol.filter('protein') smol = solvate(mol) ffs = defaultFf() tmpdir = os.path.join(self.testDir, 'withoutProtPrep', pid) _ = build(smol, ff=ffs, outdir=tmpdir) refdir = home(dataDir=join('test-amber-build', 'nopp', pid)) TestAmberBuild._compareResultFolders(refdir, tmpdir, pid)
def testWithProteinPrepare(self): from htmd.builder.preparation import proteinPrepare from htmd.builder.solvate import solvate # Test with proteinPrepare pdbids = ['3PTB'] # pdbids = ['3PTB', '1A25', '1GZM'] # '1U5U' out because it has AR0 (no parameters) for pid in pdbids: np.random.seed(1) mol = Molecule(pid) mol.filter('protein') mol = proteinPrepare(mol) mol.filter('protein') # Fix for bad proteinPrepare hydrogen placing smol = solvate(mol) ffs = defaultFf() tmpdir = os.path.join(self.testDir, 'withProtPrep', pid) _ = build(smol, ff=ffs, outdir=tmpdir) refdir = home(dataDir=join('test-amber-build', 'pp', pid)) TestAmberBuild._compareResultFolders(refdir, tmpdir, pid)
def test_customTeLeapImports(self): from htmd.builder.solvate import solvate # Test without proteinPrepare pdbids = ['3PTB'] # pdbids = ['3PTB', '1A25', '1GZM', '1U5U'] for pid in pdbids: np.random.seed(1) mol = Molecule(pid) mol.filter('protein') smol = solvate(mol) ffs = defaultFf() tmpdir = os.path.join(self.testDir, 'withoutProtPrep', pid) amberhome = defaultAmberHome() teleapimports = [] teleapimports.append( os.path.join(amberhome, _defaultAmberSearchPaths['lib'])) teleapimports.append( os.path.join(amberhome, _defaultAmberSearchPaths['param'])) _ = build(smol, ff=ffs, outdir=tmpdir, teleapimports=teleapimports) refdir = home(dataDir=join('test-amber-build', 'nopp', pid)) _TestAmberBuild._compareResultFolders(refdir, tmpdir, pid)
def test_customDisulfideBonds(self): from htmd.builder.solvate import solvate # Test without proteinPrepare pdbids = ['1GZM', ] for pid in pdbids: np.random.seed(1) mol = Molecule(pid) mol.filter('protein') smol = solvate(mol) ffs = defaultFf() disu = [['segid 1 and resid 110', 'segid 1 and resid 187'], ['segid 0 and resid 110', 'segid 0 and resid 187']] tmpdir = os.path.join(self.testDir, 'withoutProtPrep', pid) _ = build(smol, ff=ffs, outdir=tmpdir, disulfide=disu) refdir = home(dataDir=join('test-amber-build', 'nopp', pid)) TestAmberBuild._compareResultFolders(refdir, tmpdir, pid) np.random.seed(1) tmpdir = os.path.join(self.testDir, 'withoutProtPrep', pid) _ = build(smol, ff=ffs, outdir=tmpdir) refdir = home(dataDir=join('test-amber-build', 'nopp', pid)) TestAmberBuild._compareResultFolders(refdir, tmpdir, pid)
def test_customDisulfideBonds(self): from htmd.molecule.molecule import Molecule from htmd.builder.solvate import solvate from htmd.home import home from htmd.util import tempname, assertSameAsReferenceDir import os import numpy as np # Use pre-prepared files so we can tell whether the error is in prepare or in build # Inputs are reference outputs of proteinprepare. preparedInputDir = home(dataDir='test-proteinprepare') pdb = '1GZM' inFile = os.path.join(preparedInputDir, pdb, "{}-prepared.pdb".format(pdb)) mol = Molecule(inFile) mol.filter('protein') # Fix for bad proteinPrepare hydrogen placing np.random.seed(1) # Needed for ions smol = solvate(mol) topos = ['top/top_all36_prot.rtf', 'top/top_water_ions.rtf'] params = ['par/par_all36_prot_mod.prm', 'par/par_water_ions.prm'] disu = [['segid 1 and resid 110', 'segid 1 and resid 187'], ['segid 0 and resid 110', 'segid 0 and resid 187']] tmpdir = tempname() _ = build(smol, topo=topos, param=params, outdir=tmpdir, disulfide=disu) compareDir = home(dataDir=os.path.join('test-charmm-build', pdb)) assertSameAsReferenceDir(compareDir, tmpdir) # TODO: Remove this after deprecation from htmd.builder.builder import DisulfideBridge np.random.seed(1) # Needed for ions disu = [DisulfideBridge('1', 110, '1', 187), DisulfideBridge('0', 110, '0', 187)] tmpdir = tempname() _ = build(smol, topo=topos, param=params, outdir=tmpdir, disulfide=disu) compareDir = home(dataDir=os.path.join('test-charmm-build', pdb)) assertSameAsReferenceDir(compareDir, tmpdir)
if len(mismatch) != 0 or len(error) != 0 or len(match) != len(files): raise RuntimeError( 'Different results produced by amber.build for test {} between {} and {} in files {}.'.format(pid, compare, tmpdir, mismatch)) for f in deletefiles: os.remove(f) # Test with proteinPrepare pdbids = ['3PTB', '1A25', '1GZM'] # '1U5U' out because it has AR0 (no parameters) for pid in pdbids: np.random.seed(1) mol = Molecule(pid) mol.filter('protein') mol = proteinPrepare(mol) mol.filter('protein') # Fix for bad proteinPrepare hydrogen placing smol = solvate(mol) ffs = ['leaprc.lipid14', 'leaprc.ff14SB', 'leaprc.gaff'] tmpdir = tempname() bmol = build(smol, ff=ffs, outdir=tmpdir) refdir = home(dataDir=os.path.join('test-amber-build', pid)) _compareResultFolders(refdir, tmpdir, pid) shutil.rmtree(tmpdir) # Test without proteinPrepare pdbids = ['3PTB', '1A25', '1GZM', '1U5U'] for pid in pdbids: np.random.seed(1) mol = Molecule(pid) mol.filter('protein') smol = solvate(mol)
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
for f in deletefiles: os.remove(f) # Test with proteinPrepare pdbids = ['3PTB'] # pdbids = ['3PTB', '1A25', '1GZM'] # '1U5U' out because it has AR0 (no parameters) for pid in pdbids: np.random.seed(1) mol = Molecule(pid) mol.filter('protein') if mol._checkInsertions(): mol.renumberResidues() mol = proteinPrepare(mol) mol.filter('protein') # Fix for bad proteinPrepare hydrogen placing smol = solvate(mol) ffs = defaultFf() tmpdir = tempname() bmol = build(smol, ff=ffs, outdir=tmpdir) refdir = home(dataDir=join('test-amber-build', pid)) _compareResultFolders(refdir, tmpdir, pid) shutil.rmtree(tmpdir) # Test without proteinPrepare pdbids = ['3PTB'] # pdbids = ['3PTB', '1A25', '1GZM', '1U5U'] for pid in pdbids: np.random.seed(1) mol = Molecule(pid) mol.filter('protein')
def buildMembrane(xysize, ratioupper, ratiolower, waterbuff=20, equilibrate=True, outdir='./buildmemb/', 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 : list of lists A list containing sublists indicating the molecule name and the ratio of that molecule for the upper layer ratiolower : list of lists Same as ratioupper but for the lower layer waterbuff : float The z-dimension size of the water box above and below the membrane equilibrate : bool If True it equilibrates the membrane outdir : str A folder in which to store the psf and pdb files lipidf : str The path to the starting lipid conformations Returns ------- mol : :class:`Molecule <htmd.molecule.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 htmd.molecule.molecule import Molecule from htmd.home import home import os import pandas as pd if lipidf is None: lipidf = os.path.join(home(), 'membranebuilder', 'lipids') lipiddb = pd.read_csv(os.path.join(home(), 'membranebuilder', 'lipiddb.csv'), index_col='Name') uqlip = np.unique([x[0] for x in ratioupper] + [x[0] for x in ratiolower]) 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) resolveRingPenetrations(lipids, xysize) memb = _createMembraneMolecule(lipids) # 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) # endmemb = _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() print('Outdir ', 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(), 'membranebuilder', 'charmm-toppar') equilibrateSystem(os.path.join(outdir, 'structure.pdb'), os.path.join(outdir, 'structure.psf'), outpdb, charmmfolder=charmmf) 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
import numpy as np # Use pre-prepared files so we can tell whether the error is in prepare or in build # Inputs are reference outputs of proteinprepare. preparedInputDir = home(dataDir='test-proteinprepare') pdbids = ['3PTB', '1A25', '1GZM', '1U5U'] for pdb in pdbids: inFile = os.path.join(preparedInputDir, pdb, "{}-prepared.pdb".format(pdb)) mol = Molecule(inFile) mol.filter('protein') # Fix for bad proteinPrepare hydrogen placing if mol._checkInsertions(): mol.renumberResidues() np.random.seed(1) # Needed for ions smol = solvate(mol) topos = ['top/top_all36_prot.rtf', 'top/top_water_ions.rtf'] params = ['par/par_all36_prot_mod.prm', 'par/par_water_ions.prm'] tmpdir = tempname() bmol = build(smol, topo=topos, param=params, outdir=tmpdir) compareDir = home(dataDir=os.path.join('test-charmm-build', pdb)) assertSameAsReferenceDir(compareDir, tmpdir) # shutil.rmtree(tmpdir) from htmd.ui import * import doctest doctest.testmod()
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)