def run( self, chain=None, chargeType="bcc", chargeVal=None, guessCharge=False, multiplicity="1", atomType="gaff", force=False, basename=None, debug=False, outTopol="all", engine="tleap", allhdg=False, timeTol=36000, qprog="sqm", ekFlag=None, outType="mol2", ): ccpnProject = self.project if chain: other = [chain] else: other = self.getHeteroMols() if not other: print("WARN: no molecules entitled for ACPYPE") return None acpypeDict = {} for chain in other: if chargeVal is None and not guessCharge: chargeVal = chain.molecule.formalCharge # pdbCode = ccpnProject.name res = chain.findFirstResidue() resName = res.ccpCode.upper() if chargeVal is None: print("Running ACPYPE for '%s : %s' and trying to guess net charge" % (resName, chain.molecule.name)) else: print("Running ACPYPE for '%s : %s' with charge '%s'" % (resName, chain.molecule.name, chargeVal)) random.seed() d = [random.choice(letters) for x in range(10)] randString = "".join(d) randString = "test" dirTemp = "/tmp/ccpn2acpype_%s" % randString if not os.path.exists(dirTemp): os.mkdir(dirTemp) if outType == "mol2": resTempFile = os.path.join(dirTemp, "%s.mol2" % resName) else: resTempFile = os.path.join(dirTemp, "%s.pdb" % resName) entry = ccpnProject.currentNmrEntryStore.findFirstEntry() strucGen = entry.findFirstStructureGeneration() refStructure = strucGen.structureEnsemble.sortedModels()[0] if outType == "mol2": mol2Format = Mol2Format.Mol2Format(ccpnProject) mol2Format.writeChemComp( resTempFile, chemCompVar=chain.findFirstResidue().chemCompVar, coordSystem="pdb", minimalPrompts=True, forceNamingSystemName="XPLOR", ) else: pdbFormat = PdbFormat.PdbFormat(ccpnProject) pdbFormat.writeCoordinates( resTempFile, exportChains=[chain], structures=[refStructure], minimalPrompts=True, forceNamingSystemName="XPLOR", ) origCwd = os.getcwd() os.chdir(dirTemp) t0 = time.time() print(header) try: molecule = ACTopol( resTempFile, chargeType=chargeType, chargeVal=chargeVal, debug=debug, multiplicity=multiplicity, atomType=atomType, force=force, outTopol=outTopol, engine=engine, allhdg=allhdg, basename=basename, timeTol=timeTol, qprog=qprog, ekFlag='''"%s"''' % ekFlag, ) if not molecule.acExe: molecule.printError("no 'antechamber' executable... aborting!") hint1 = "HINT1: is 'AMBERHOME' or 'ACHOME' environment variable set?" hint2 = ( "HINT2: is 'antechamber' in your $PATH?" + " What 'which antechamber' in your terminal says?" + " 'alias' doesn't work for ACPYPE." ) molecule.printMess(hint1) molecule.printMess(hint2) sys.exit(1) molecule.createACTopol() molecule.createMolTopol() acpypeFailed = False except: raise _exceptionType, exceptionValue, exceptionTraceback = sys.exc_info() print("ACPYPE FAILED: %s" % exceptionValue) if debug: traceback.print_tb(exceptionTraceback, file=sys.stdout) acpypeFailed = True execTime = int(round(time.time() - t0)) if execTime == 0: msg = "less than a second" else: msg = elapsedTime(execTime) try: rmtree(molecule.tmpDir) except: raise print("Total time of execution: %s" % msg) if not acpypeFailed: acpypeDict[resName] = [x for x in dirWalk(os.path.join(dirTemp, "%s.acpype" % resName))] else: acpypeDict[resName] = [] # sys.exit(1) os.chdir(origCwd) self.acpypeDictFiles = acpypeDict
def run(self, chain = None, chargeType = 'bcc', chargeVal = None, guessCharge = False, multiplicity = '1', atomType = 'gaff', force = False, basename = None, debug = False, outTopol = 'all', engine = 'tleap', allhdg = False, timeTol = 36000, qprog = 'sqm', ekFlag = None, outType='mol2'): ccpnProject = self.project if chain: other = [chain] else: other = self.getHeteroMols() if not other: print("WARN: no molecules entitled for ACPYPE") return None acpypeDict = {} for chain in other: if chargeVal == None and not guessCharge: chargeVal = chain.molecule.formalCharge # pdbCode = ccpnProject.name res = chain.findFirstResidue() resName = res.ccpCode.upper() if chargeVal == None: print("Running ACPYPE for '%s : %s' and trying to guess net charge" % (resName, chain.molecule.name)) else: print("Running ACPYPE for '%s : %s' with charge '%s'" % (resName, chain.molecule.name, chargeVal)) random.seed() d = [random.choice(string.letters) for x in xrange(10)] randString = "".join(d) randString = 'test' dirTemp = '/tmp/ccpn2acpype_%s' % randString if not os.path.exists(dirTemp): os.mkdir(dirTemp) if outType == 'mol2': resTempFile = os.path.join(dirTemp, '%s.mol2' % resName) else: resTempFile = os.path.join(dirTemp, '%s.pdb' % resName) entry = ccpnProject.currentNmrEntryStore.findFirstEntry() strucGen = entry.findFirstStructureGeneration() refStructure = strucGen.structureEnsemble.sortedModels()[0] if outType == 'mol2': mol2Format = Mol2Format.Mol2Format(ccpnProject) mol2Format.writeChemComp(resTempFile, chemCompVar=chain.findFirstResidue().chemCompVar,coordSystem='pdb', minimalPrompts = True, forceNamingSystemName = 'XPLOR') else: pdbFormat = PdbFormat.PdbFormat(ccpnProject) pdbFormat.writeCoordinates(resTempFile, exportChains = [chain], structures = [refStructure], minimalPrompts = True, forceNamingSystemName = 'XPLOR') origCwd = os.getcwd() os.chdir(dirTemp) t0 = time.time() print(header) try: molecule = ACTopol(resTempFile, chargeType = chargeType, chargeVal = chargeVal, debug = debug, multiplicity = multiplicity, atomType = atomType, force = force, outTopol = outTopol, engine = engine, allhdg = allhdg, basename = basename, timeTol = timeTol, qprog = qprog, ekFlag = '''"%s"''' % ekFlag) if not molecule.acExe: molecule.printError("no 'antechamber' executable... aborting!") hint1 = "HINT1: is 'AMBERHOME' or 'ACHOME' environment variable set?" hint2 = "HINT2: is 'antechamber' in your $PATH?\n What 'which antechamber' in your terminal says?\n 'alias' doesn't work for ACPYPE." molecule.printMess(hint1) molecule.printMess(hint2) sys.exit(1) molecule.createACTopol() molecule.createMolTopol() acpypeFailed = False except: raise _exceptionType, exceptionValue, exceptionTraceback = sys.exc_info() print("ACPYPE FAILED: %s" % exceptionValue) if debug: traceback.print_tb(exceptionTraceback, file = sys.stdout) acpypeFailed = True execTime = int(round(time.time() - t0)) if execTime == 0: msg = "less than a second" else: msg = elapsedTime(execTime) try: rmtree(molecule.tmpDir) except: raise print("Total time of execution: %s" % msg) if not acpypeFailed: acpypeDict[resName] = [x for x in dirWalk(os.path.join(dirTemp, '%s.acpype' % resName))] else: acpypeDict[resName] = [] # sys.exit(1) os.chdir(origCwd) self.acpypeDictFiles = acpypeDict
# from ogpdb to amber pdb and top agpdb = 'ag%s.pdb' % res # output name agtop = 'ag%s.top' % res cmd = ' %s -f %s -o %s -p %s -ff amber99sb %s' % (pdb2gmx, apdb, agpdb, agtop, water) pdebug(cmd) out = _getoutput(cmd) #print(out) #parseOut(out) # acpype on agpdb file fixRes4Acpype(agpdb) cv = None #cmd = "%s -dfi %s -c %s -a %s" % (acpypeExe, agpdb, cType, ffType) if res in ['JJJ', 'RRR'] and cType == 'bcc': cv = 3 #cmd += ' -n 3' # acpype failed to get correct charge mol = ACTopol(agpdb, chargeType = cType, atomType = ffType, chargeVal = cv, debug = False, verbose = debug, gmx45 = True) mol.createACTopol() mol.createMolTopol() #out = commands.getstatusoutput(cmd) #parseOut(out[1]) print("Compare ACPYPE x GMX AMBER99SB topol & param") checkTopAcpype(res) # calc Pot Energy print("Compare ACPYPE x GMX AMBER99SB Pot. Energy (|ERROR|%)") # calc gmx amber energies dihAmb, dihAcp = calcGmxPotEnerDiff(res) # calc gmx acpype energies os.system('rm -f %s/\#* posre.itp tempScript.py' % tmpDir) os.system("find . -name 'ag*GMX*.itp' | xargs grep -v 'created by acpype on' > standard_ag_itp.txt")
cType = 'gas' #'gas' debug = False water = ' -water none' print('usePymol: %s, ffType: %s, cType: %s' % (usePymol, ffType, cType)) tmpDir = '/tmp/testAcpype' delList = ['topol.top', 'posre.itp'] #create Dummy PDB tpdb = '/tmp/tmp.pdb' dummyLine = 'ATOM 1 N ALA A 1 -1.188 -0.094 0.463 1.00 0.00 N\n' open(tpdb, 'w').writelines(dummyLine) tempObj = ACTopol(tpdb, chargeVal=0, verbose=False) # Binaries for ambertools acExe = tempObj.acExe tleapExe = tempObj.tleapExe sanderExe = os.path.join(os.path.dirname(acExe), 'sander') ambpdbExe = os.path.join(os.path.dirname(acExe), 'ambpdb') exePymol = '/sw/bin/pymol' # Binaries for gromacs gpath = '/sw/' gmxTopDir = gpath + "share" pdb2gmx = gpath + 'bin/pdb2gmx' grompp = gpath + 'bin/grompp' mdrun = gpath + 'bin/mdrun'