def getEnergies(template):
     cmd = template % cmdDict
     pdebug(cmd)
     out = _getoutput(cmd)
     out = out.split('\n')[-nEner:]
     dictEner = {}
     for item in out:
         k, v = item.replace(' Dih.', '_Dih.').replace(
             ' (SR)', '_(SR)').replace('c En.', 'c_En.').replace(
                 ' (bar)', '_(bar)').replace('l E', 'l_E').split()[:2]
         v = eval(v)
         dictEner[k] = v
         if 'Dih.' in k or 'Bell.' in k:
             if 'Dihedral P+I' in list(dictEner.keys()):
                 dictEner['Dihedral P+I'] = dictEner['Dihedral P+I'] + v
             else:
                 dictEner['Dihedral P+I'] = v
         if 'Coulomb' in k or 'LJ' in k:
             if 'TotalNonBonded' in list(dictEner.keys()):
                 dictEner['TotalNonBonded'] = dictEner['TotalNonBonded'] + v
             else:
                 dictEner['TotalNonBonded'] = v
     dictEner['Total_Bonded'] = dictEner.get('Potential') - dictEner.get(
         'TotalNonBonded')
     return dictEner
Beispiel #2
0
 def getEnergies(template):
     cmd = template % cmdDict
     pdebug(cmd)
     out = _getoutput(cmd)
     out = out.split('\n')[-nEner:]
     dictEner = {}
     for item in out:
         k, v = item.replace(' Dih.', '_Dih.').replace(' (SR)', '_(SR)').replace('c En.', 'c_En.').replace(' (bar)', '_(bar)').replace('l E', 'l_E').split()[:2]
         v = eval(v)
         dictEner[k] = v
         if 'Dih.' in k or 'Bell.' in k:
             if 'Dihedral P+I' in list(dictEner.keys()):
                 dictEner['Dihedral P+I'] = dictEner['Dihedral P+I'] + v
             else:
                 dictEner['Dihedral P+I'] = v
         if 'Coulomb' in k or 'LJ' in k:
             if 'TotalNonBonded' in list(dictEner.keys()):
                 dictEner['TotalNonBonded'] = dictEner['TotalNonBonded'] + v
             else:
                 dictEner['TotalNonBonded'] = v
     dictEner['Total_Bonded'] = dictEner.get('Potential') - dictEner.get('TotalNonBonded')
     return dictEner
Beispiel #3
0
def build_residues_tleap():
    """Build residues tripeptides with tleap and minimise with sander"""
    mdin = '''Minimization\n&cntrl\nimin=1, maxcyc=200, ntmin=2, ntb=0, igb=0,cut=999,/\n'''
    open('mdin', 'w').writelines(mdin)
    seqi = aa_dict.keys()
    for aai in seqi:
        #if aai != 'H': continue
        aai3 = 3 * aai
        res = aa_dict.get(aai).upper()
        res1 = res
        leapDict = {'amberff' : amberff, 'res' : res, 'aai3' : aai3, 'res1':res1}
        tleapin = genPdbTemplate % leapDict
        open('tleap.in', 'w').writelines(tleapin)
        cmd = "%s -f tleap.in" % (tleapExe)
        _getoutput(cmd)
        #cmd = "%s -O; %s < restrt > %s.pdb; mv mdinfo %s.mdinfo" % (sanderExe, ambpdbExe, aai3, aai3) # -i mdin -o mdout -p prmtop -c inpcrd" % (sanderExe)
        cmd = "%s -O; %s < restrt > %s.pdb" % (sanderExe, ambpdbExe, aai3)
        _getoutput(cmd)
    _getoutput('rm -f mdout mdinfo mdin restrt tleap.in prmtop inpcrd leap.log')
def build_residues_tleap():
    """Build residues tripeptides with tleap and minimise with sander"""
    mdin = '''Minimization\n&cntrl\nimin=1, maxcyc=200, ntmin=2, ntb=0, igb=0,cut=999,/\n'''
    open('mdin', 'w').writelines(mdin)
    seqi = aa_dict.keys()
    for aai in seqi:
        #if aai != 'H': continue
        aai3 = 3 * aai
        res = aa_dict.get(aai).upper()
        res1 = res
        leapDict = {'amberff': amberff, 'res': res, 'aai3': aai3, 'res1': res1}
        tleapin = genPdbTemplate % leapDict
        open('tleap.in', 'w').writelines(tleapin)
        cmd = "%s -f tleap.in" % (tleapExe)
        _getoutput(cmd)
        #cmd = "%s -O; %s < restrt > %s.pdb; mv mdinfo %s.mdinfo" % (sanderExe, ambpdbExe, aai3, aai3) # -i mdin -o mdout -p prmtop -c inpcrd" % (sanderExe)
        cmd = "%s -O; %s < restrt > %s.pdb" % (sanderExe, ambpdbExe, aai3)
        _getoutput(cmd)
    _getoutput(
        'rm -f mdout mdinfo mdin restrt tleap.in prmtop inpcrd leap.log')
Beispiel #5
0
def calcGmxPotEnerDiff(res):
    def getEnergies(template):
        cmd = template % cmdDict
        pdebug(cmd)
        out = _getoutput(cmd)
        out = out.split('\n')[-nEner:]
        dictEner = {}
        for item in out:
            k, v = item.replace(' Dih.', '_Dih.').replace(' (SR)', '_(SR)').replace('c En.', 'c_En.').replace(' (bar)', '_(bar)').replace('l E', 'l_E').split()[:2]
            v = eval(v)
            dictEner[k] = v
            if 'Dih.' in k or 'Bell.' in k:
                if 'Dihedral P+I' in list(dictEner.keys()):
                    dictEner['Dihedral P+I'] = dictEner['Dihedral P+I'] + v
                else:
                    dictEner['Dihedral P+I'] = v
            if 'Coulomb' in k or 'LJ' in k:
                if 'TotalNonBonded' in list(dictEner.keys()):
                    dictEner['TotalNonBonded'] = dictEner['TotalNonBonded'] + v
                else:
                    dictEner['TotalNonBonded'] = v
        dictEner['Total_Bonded'] = dictEner.get('Potential') - dictEner.get('TotalNonBonded')
        return dictEner

    os.chdir(tmpDir)
    nEner = 9 # number of energy entries from g_energy
    tEner = ' '.join([str(x) for x in range(1, nEner + 1)])
    open('SPE.mdp', 'w').writelines(spe_mdp)
    cmdDict = {'pdb2gmx':pdb2gmx, 'grompp':grompp, 'mdrun':mdrun, 'res':res,
               'g_energy':g_energy, 'tEner':tEner, 'water':water, 'gmxdump':gmxdump}

    # calc Pot Ener for aXXX.pdb (AMB_GMX)
    template = '''%(pdb2gmx)s -ff amber99sb -f a%(res)s.pdb -o a%(res)s_.pdb -p a%(res)s.top %(water)s
    %(grompp)s -c a%(res)s_.pdb -p a%(res)s.top -f SPE.mdp -o a%(res)s.tpr -pp a%(res)sp.top
    %(mdrun)s -v -deffnm a%(res)s
    echo %(tEner)s | %(g_energy)s -f a%(res)s.edr
    '''
    dictEnerAMB = getEnergies(template)
    #print(dictEnerAMB)

    #calc Pot Ener for agXXX.acpype/agXXX.pdb (ACPYPE_GMX)
    template = '''%(grompp)s -c ag%(res)s.acpype/ag%(res)s_NEW.pdb -p ag%(res)s.acpype/ag%(res)s_GMX.top -f SPE.mdp -o ag%(res)s.tpr -pp ag%(res)sp.top
    %(mdrun)s -v -deffnm ag%(res)s
    echo %(tEner)s | %(g_energy)s -f ag%(res)s.edr
    '''
    dictEnerACPYPE = getEnergies(template)
    #print(dictEnerACPYPE)

    order = ['LJ-14', 'LJ_(SR)', 'Coulomb-14', 'Coulomb_(SR)', 'TotalNonBonded', 'Potential', 'Angle', 'Bond', 'Proper_Dih.', 'Improper_Dih.', 'Dihedral P+I', 'Total_Bonded'] #sorted(dictEnerAMB.items())
    for k in order:
        v = dictEnerAMB.get(k)
        v2 = dictEnerACPYPE.get(k)
        rerror = error(v2, v)
        if rerror > 0.1:
            print("%15s   %.3f   %5.6f x %5.6f" % (k, rerror, v2, v))
        else:
            print("%15s   %.3f" % (k, rerror))

    cmd = "%(gmxdump)s -s a%(res)s.tpr" % cmdDict
    amb = _getoutput(cmd)
    cmd = "%(gmxdump)s -s ag%(res)s.tpr" % cmdDict
    acp = _getoutput(cmd)

    #dihAmb = [x.split(']=')[-1] for x in amb.splitlines() if ('PIDIHS' in x or 'PDIHS' in x) and 'functype' in x ]
    #dihAcp = [x.split(']=')[-1] for x in acp.splitlines() if ('PIDIHS' in x or 'PDIHS' in x) and 'functype' in x ]

    dihAmb = [x.split('PIDIHS')[-1][2:] for x in amb.splitlines() if ('PIDIHS' in x)]
    dihAcp = [x.split('PIDIHS')[-1][2:] for x in acp.splitlines() if ('PIDIHS' in x)]

    dAcp = set(dihAcp).difference(set(dihAmb))
    dAmb = set(dihAmb).difference(set(dihAcp))
    rAcp = [' '.join(reversed(x.split())) for x in dAcp]
    rAmb = [' '.join(reversed(x.split())) for x in dAmb]
    ddAmb = sorted(dAmb.difference(rAcp))
    ddAcp = sorted(dAcp.difference(rAmb))
    if ddAmb: print('IDIH: Amb diff Acp', ddAmb)
    if ddAcp: print('IDIH: Acp diff Amb', ddAcp)

    return dihAmb, dihAcp
Beispiel #6
0
    listRes.sort()
    for resFile in listRes:
        res, ext = os.path.splitext(resFile) # eg. res = 'AAA'
        #if res != 'RRR': continue
        if len(resFile) == 7 and ext == ".pdb" and resFile[:3].isupper():
            print("\nFile %s : residue %s" % (resFile, aa_dict[res[0]].upper()))

            _pdb = createOldPdb2(resFile) # using my own dict
            apdb = createAmberPdb3(_pdb) # create file aAAA.pdb with NXXX, CXXX

            # 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])
def calcGmxPotEnerDiff(res):
    def getEnergies(template):
        cmd = template % cmdDict
        pdebug(cmd)
        out = _getoutput(cmd)
        out = out.split('\n')[-nEner:]
        dictEner = {}
        for item in out:
            k, v = item.replace(' Dih.', '_Dih.').replace(
                ' (SR)', '_(SR)').replace('c En.', 'c_En.').replace(
                    ' (bar)', '_(bar)').replace('l E', 'l_E').split()[:2]
            v = eval(v)
            dictEner[k] = v
            if 'Dih.' in k or 'Bell.' in k:
                if 'Dihedral P+I' in list(dictEner.keys()):
                    dictEner['Dihedral P+I'] = dictEner['Dihedral P+I'] + v
                else:
                    dictEner['Dihedral P+I'] = v
            if 'Coulomb' in k or 'LJ' in k:
                if 'TotalNonBonded' in list(dictEner.keys()):
                    dictEner['TotalNonBonded'] = dictEner['TotalNonBonded'] + v
                else:
                    dictEner['TotalNonBonded'] = v
        dictEner['Total_Bonded'] = dictEner.get('Potential') - dictEner.get(
            'TotalNonBonded')
        return dictEner

    os.chdir(tmpDir)
    nEner = 9  # number of energy entries from g_energy
    tEner = ' '.join([str(x) for x in range(1, nEner + 1)])
    open('SPE.mdp', 'w').writelines(spe_mdp)
    cmdDict = {
        'pdb2gmx': pdb2gmx,
        'grompp': grompp,
        'mdrun': mdrun,
        'res': res,
        'g_energy': g_energy,
        'tEner': tEner,
        'water': water,
        'gmxdump': gmxdump
    }

    # calc Pot Ener for aXXX.pdb (AMB_GMX)
    template = '''%(pdb2gmx)s -ff amber99sb -f a%(res)s.pdb -o a%(res)s_.pdb -p a%(res)s.top %(water)s
    %(grompp)s -c a%(res)s_.pdb -p a%(res)s.top -f SPE.mdp -o a%(res)s.tpr -pp a%(res)sp.top
    %(mdrun)s -v -deffnm a%(res)s
    echo %(tEner)s | %(g_energy)s -f a%(res)s.edr
    '''
    dictEnerAMB = getEnergies(template)
    #print(dictEnerAMB)

    #calc Pot Ener for agXXX.acpype/agXXX.pdb (ACPYPE_GMX)
    template = '''%(grompp)s -c ag%(res)s.acpype/ag%(res)s_NEW.pdb -p ag%(res)s.acpype/ag%(res)s_GMX.top -f SPE.mdp -o ag%(res)s.tpr -pp ag%(res)sp.top
    %(mdrun)s -v -deffnm ag%(res)s
    echo %(tEner)s | %(g_energy)s -f ag%(res)s.edr
    '''
    dictEnerACPYPE = getEnergies(template)
    #print(dictEnerACPYPE)

    order = [
        'LJ-14', 'LJ_(SR)', 'Coulomb-14', 'Coulomb_(SR)', 'TotalNonBonded',
        'Potential', 'Angle', 'Bond', 'Proper_Dih.', 'Improper_Dih.',
        'Dihedral P+I', 'Total_Bonded'
    ]  #sorted(dictEnerAMB.items())
    for k in order:
        v = dictEnerAMB.get(k)
        v2 = dictEnerACPYPE.get(k)
        rerror = error(v2, v)
        if rerror > 0.1:
            print("%15s   %.3f   %5.6f x %5.6f" % (k, rerror, v2, v))
        else:
            print("%15s   %.3f" % (k, rerror))

    cmd = "%(gmxdump)s -s a%(res)s.tpr" % cmdDict
    amb = _getoutput(cmd)
    cmd = "%(gmxdump)s -s ag%(res)s.tpr" % cmdDict
    acp = _getoutput(cmd)

    #dihAmb = [x.split(']=')[-1] for x in amb.splitlines() if ('PIDIHS' in x or 'PDIHS' in x) and 'functype' in x ]
    #dihAcp = [x.split(']=')[-1] for x in acp.splitlines() if ('PIDIHS' in x or 'PDIHS' in x) and 'functype' in x ]

    dihAmb = [
        x.split('PIDIHS')[-1][2:] for x in amb.splitlines() if ('PIDIHS' in x)
    ]
    dihAcp = [
        x.split('PIDIHS')[-1][2:] for x in acp.splitlines() if ('PIDIHS' in x)
    ]

    dAcp = set(dihAcp).difference(set(dihAmb))
    dAmb = set(dihAmb).difference(set(dihAcp))
    rAcp = [' '.join(reversed(x.split())) for x in dAcp]
    rAmb = [' '.join(reversed(x.split())) for x in dAmb]
    ddAmb = sorted(dAmb.difference(rAcp))
    ddAcp = sorted(dAcp.difference(rAmb))
    if ddAmb: print('IDIH: Amb diff Acp', ddAmb)
    if ddAcp: print('IDIH: Acp diff Amb', ddAcp)

    return dihAmb, dihAcp
        #if res != 'RRR': continue
        if len(resFile) == 7 and ext == ".pdb" and resFile[:3].isupper():
            print("\nFile %s : residue %s" %
                  (resFile, aa_dict[res[0]].upper()))

            _pdb = createOldPdb2(resFile)  # using my own dict
            apdb = createAmberPdb3(
                _pdb)  # create file aAAA.pdb with NXXX, CXXX

            # 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,