Exemplo n.º 1
0
    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
Exemplo n.º 2
0
    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
Exemplo n.º 3
0
            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")
            #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"