pKa/Design_pKa_help.py
def run_WI_pKa_calc(pdbfile,mutated_res,pKarun_params,do_matrix=None):
    """
    # Calculates the desolvation energy, the background interaction energy and all matrix interactions for
    # a single residue (mutated_res) which is given in the form :0000:RES (e.g. :0035:GLU)
    """
    # Create a temp dir
    #
    import tempfile, os, string
    tempfile.tempdir=os.getcwd()
    dirname=tempfile.mkdtemp(dir='/tmp')
    topdir=os.getcwd()
    os.chdir(dirname)
    if os.environ.has_key('HOSTNAME'):
       print 'Running pKa calculations in ',dirname,'on',os.environ['HOSTNAME']
    import sys
    sys.stdout.flush()
    #
    # Get pdbfile, topology.h and the charge files
    #
    # Are the files present in the pwd?
    #
    import os, shutil
    for filename in ['TOPOLOGY.H','DELRAD.DAT','DELCRG.DAT']:
        full_name=os.path.join(topdir,filename)
        destination=os.path.join(dirname,filename)
        if os.path.isfile(full_name):
            shutil.copyfile(full_name,destination)
    #
    # ----
    # Copy the pdb file 
    #
    shutil.copyfile(pdbfile,os.path.join(os.getcwd(),os.path.split(pdbfile)[1]))
    #
    # Find out which group we want to calculate for
    #
    group=None
    import pKarun
    Y=pKarun.pKa_general.pKatools()
    group_list=Y.get_titratable_residues(pdbfile)
    group=[]
    for residue,groupnum in group_list:
        if mutated_res==residue:
            group.append(str(groupnum))
    #
    if len(group)==1:
        #
        # For HIS it seems that we get erratic results for the background interaction energy if the calcs
        # are for only one residue. We therefore add the two previous groups to give more Hbond opt sampling
        #
        if mutated_res.find('HIS')!=-1:
            onlygroup=int(group[0])
            if onlygroup>1:
                group=['%d' %(onlygroup-1)]+group
            if onlygroup>2:
                group=['%d' %(onlygroup-2)]+group
    if group==[]:
        if mutated_res.split(':')[-1]=='CYS':
            # Probably a new SS bridge formed..
            return 'SS-bridge','SS-bridge'
        raise Exception('Could not find WHAT IF group number for mutated residue: %s' %mutated_res)
    #
    # Add this to the parameters
    #            
    pKarun_params['subset']=1
    pKarun_params['groups']=string.join(group,',')
    #
    # Link the pdb file
    #
    pdbfile=os.path.join(topdir,pdbfile)
    #
    # Start the pKa calculation
    #
    X=None
    import pKarun, os
    X=pKarun.pKarun_base.pKarun(os.getcwd(),pdbfile,pKarun_params)
    IO=pKaTool.pKaIO.pKaIO()
    X.clean()
    #
    # Are we do to do a matric calculation or a desolv/backgr calculation?
    #
    if not do_matrix:
        try:
            X.desolv(1)
            desolv=IO.read_desolv(X.desolvfile)
        except:
            desolv=None
        try:
            X.backgr(1)
            backgr=IO.read_backgr(X.backgrfile)
        except:
            backgr=None
    else:
        atomdata=X.matrix(1,style='pKD')
        matrix=IO.read_matrix(X.matrixfile)
        return matrix[mutated_res],atomdata
    #
    # If we cannot calculate one, then warn - this should be changed, and modelling optimised!
    #
    print 'D/B',desolv,backgr
    if desolv is None or backgr is None:
        print '\n\n\nWARNING: Modelling in pdbfile is imperfect - could not estimate intrinsic pKa or interactions\n\n\n'
        return 0.0,0.0
    else:
        #
        # Check that pKa_IO got NTERM and CTERM right
        #
        if not desolv.has_key(mutated_res):
            import pKD_tools
            group_type=pKD_tools.get_titgroup_type_from_titgroup(mutated_res)
            restype=pKD_tools.get_restype_from_titgroup(mutated_res)
            resid=pKD_tools.get_resid_from_res(mutated_res)
            fixed=False
            if group_type=='NTERM':
                newgroup='%s:%s' %(resid,'CTERM')
                if desolv.has_key(newgroup):
                    desolv[mutated_res]=desolv[newgroup]
                    del desolv[newgroup]
                    backgr[mutated_res]=backgr[newgroup]
                    del backgr[newgroup]
                    fixed=True
            elif group_type=='CTERM':
                newgroup='%s:%s' %(resid,'NTERM')
                if desolv.has_key(newgroup):
                    desolv[mutated_res]=desolv[newgroup]
                    del desolv[newgroup]
                    backgr[mutated_res]=backgr[newgroup]
                    del backgr[newgroup]
                    fixed=True
            else:
                pass
            #
            # Did we fix it?
            #
            if not fixed:
                print '!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
                print 'Something went wrong in the desolv and backgr calcs - cannot find residue in desolv file'
                print                                                                     
                desolv=None
                backgr=None
                raise Exception('This must not happen')
    #
    # Get the new pKa file
    #
    os.chdir(topdir)
    import pKarun.pKa_ostools as pKa_ostools
    pKa_ostools.rmr(dirname)
    print 'Returning',desolv,backgr
    return desolv, backgr

    # Calculates the desolvation energy, the background interaction energy and all matrix interactions for
    # a single residue (mutated_res) which is given in the form :0000:RES (e.g. :0035:GLU)
    
Calculates the desolvation energy, the background interaction energy and all matrix interactions for
a single residue (mutated_res) which is given in the form :0000:RES
Calculates the desolvation energy the background interaction energy and all matrix interactions for a single residue ( mutated_res ) which is given in the form : 0000 : RES
def run_WI_pKa_calc(pdbfile,mutated_res,pKarun_params,do_matrix=None):
    import tempfile, os, string
    tempfile.tempdir=os.getcwd()
    dirname=tempfile.mkdtemp(dir='/tmp')
    topdir=os.getcwd()
    os.chdir(dirname)
    if os.environ.has_key('HOSTNAME'):
       print 'Running pKa calculations in ',dirname,'on',os.environ['HOSTNAME']
    import sys
    sys.stdout.flush()
     Get pdbfile, topology.h and the charge files
     Are the files present in the pwd?
    import os, shutil
    for filename in ['TOPOLOGY.H','DELRAD.DAT','DELCRG.DAT']:
        full_name=os.path.join(topdir,filename)
        destination=os.path.join(dirname,filename)
        if os.path.isfile(full_name):
            shutil.copyfile(full_name,destination)
     ----
     Copy the pdb file 
    shutil.copyfile(pdbfile,os.path.join(os.getcwd(),os.path.split(pdbfile)[1]))
     Find out which group we want to calculate for
    group=None
    import pKarun
    Y=pKarun.pKa_general.pKatools()
    group_list=Y.get_titratable_residues(pdbfile)
    group=[]
    for residue,groupnum in group_list:
        if mutated_res==residue:
            group.append(str(groupnum))
    if len(group)==1:
         For HIS it seems that we get erratic results for the background interaction energy if the calcs
         are for only one residue. We therefore add the two previous groups to give more Hbond opt sampling
        if mutated_res.find('HIS')!=-1:
            onlygroup=int(group[0])
            if onlygroup>1:
                group=['%d' %(onlygroup-1)]+group
            if onlygroup>2:
                group=['%d' %(onlygroup-2)]+group
    if group==[]:
        if mutated_res.split(':')[-1]=='CYS':
             Probably a new SS bridge formed..
            return 'SS-bridge','SS-bridge'
        raise Exception('Could not find WHAT IF group number for mutated residue: %s' %mutated_res)
     Add this to the parameters
    pKarun_params['subset']=1
    pKarun_params['groups']=string.join(group,',')
     Link the pdb file
    pdbfile=os.path.join(topdir,pdbfile)
     Start the pKa calculation
    X=None
    import pKarun, os
    X=pKarun.pKarun_base.pKarun(os.getcwd(),pdbfile,pKarun_params)
    IO=pKaTool.pKaIO.pKaIO()
    X.clean()
     Are we do to do a matric calculation or a desolv/backgr calculation?
    if not do_matrix:
        try:
            X.desolv(1)
            desolv=IO.read_desolv(X.desolvfile)
        except:
            desolv=None
        try:
            X.backgr(1)
            backgr=IO.read_backgr(X.backgrfile)
        except:
            backgr=None
    else:
        atomdata=X.matrix(1,style='pKD')
        matrix=IO.read_matrix(X.matrixfile)
        return matrix[mutated_res],atomdata
     If we cannot calculate one, then warn - this should be changed, and modelling optimised!
    print 'D/B',desolv,backgr
    if desolv is None or backgr is None:
        print '\n\n\nWARNING: Modelling in pdbfile is imperfect - could not estimate intrinsic pKa or interactions\n\n\n'
        return 0.0,0.0
    else:
         Check that pKa_IO got NTERM and CTERM right
        if not desolv.has_key(mutated_res):
            import pKD_tools
            group_type=pKD_tools.get_titgroup_type_from_titgroup(mutated_res)
            restype=pKD_tools.get_restype_from_titgroup(mutated_res)
            resid=pKD_tools.get_resid_from_res(mutated_res)
            fixed=False
            if group_type=='NTERM':
                newgroup='%s:%s' %(resid,'CTERM')
                if desolv.has_key(newgroup):
                    desolv[mutated_res]=desolv[newgroup]
                    del desolv[newgroup]
                    backgr[mutated_res]=backgr[newgroup]
                    del backgr[newgroup]
                    fixed=True
            elif group_type=='CTERM':
                newgroup='%s:%s' %(resid,'NTERM')
                if desolv.has_key(newgroup):
                    desolv[mutated_res]=desolv[newgroup]
                    del desolv[newgroup]
                    backgr[mutated_res]=backgr[newgroup]
                    del backgr[newgroup]
                    fixed=True
            else:
                pass
             Did we fix it?
            if not fixed:
                print '!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
                print 'Something went wrong in the desolv and backgr calcs - cannot find residue in desolv file'
                print                                                                     
                desolv=None
                backgr=None
                raise Exception('This must not happen')
     Get the new pKa file
    os.chdir(topdir)
    import pKarun.pKa_ostools as pKa_ostools
    pKa_ostools.rmr(dirname)
    print 'Returning',desolv,backgr
    return desolv, backgr
def run_WI_pKa_calc ( pdbfile , mutated_res , pKarun_params , do_matrix = None ) : import tempfile , os , string tempfile . tempdir = os . getcwd ( ) dirname = tempfile . mkdtemp ( dir = '/tmp' ) topdir = os . getcwd ( ) os . chdir ( dirname ) if os . environ . has_key ( 'HOSTNAME' ) : print 'Running pKa calculations in ' , dirname , 'on' , os . environ [ 'HOSTNAME' ] import sys sys . stdout . flush ( ) import os , shutil for filename in [ 'TOPOLOGY.H' , 'DELRAD.DAT' , 'DELCRG.DAT' ] : full_name = os . path . join ( topdir , filename ) destination = os . path . join ( dirname , filename ) if os . path . isfile ( full_name ) : shutil . copyfile ( full_name , destination ) shutil . copyfile ( pdbfile , os . path . join ( os . getcwd ( ) , os . path . split ( pdbfile ) [ 1 ] ) ) group = None import pKarun Y = pKarun . pKa_general . pKatools ( ) group_list = Y . get_titratable_residues ( pdbfile ) group = [ ] for residue , groupnum in group_list : if mutated_res == residue : group . append ( str ( groupnum ) ) if len ( group ) == 1 : if mutated_res . find ( 'HIS' ) != - 1 : onlygroup = int ( group [ 0 ] ) if onlygroup > 1 : group = [ '%d' % ( onlygroup - 1 ) ] + group if onlygroup > 2 : group = [ '%d' % ( onlygroup - 2 ) ] + group if group == [ ] : if mutated_res . split ( ':' ) [ - 1 ] == 'CYS' : return 'SS-bridge' , 'SS-bridge' raise Exception ( 'Could not find WHAT IF group number for mutated residue: %s' % mutated_res ) pKarun_params [ 'subset' ] = 1 pKarun_params [ 'groups' ] = string . join ( group , ',' ) pdbfile = os . path . join ( topdir , pdbfile ) X = None import pKarun , os X = pKarun . pKarun_base . pKarun ( os . getcwd ( ) , pdbfile , pKarun_params ) IO = pKaTool . pKaIO . pKaIO ( ) X . clean ( ) if not do_matrix : try : X . desolv ( 1 ) desolv = IO . read_desolv ( X . desolvfile ) except : desolv = None try : X . backgr ( 1 ) backgr = IO . read_backgr ( X . backgrfile ) except : backgr = None else : atomdata = X . matrix ( 1 , style = 'pKD' ) matrix = IO . read_matrix ( X . matrixfile ) return matrix [ mutated_res ] , atomdata print 'D/B' , desolv , backgr if desolv is None or backgr is None : print '\n\n\nWARNING: Modelling in pdbfile is imperfect - could not estimate intrinsic pKa or interactions\n\n\n' return 0.0 , 0.0 else : if not desolv . has_key ( mutated_res ) : import pKD_tools group_type = pKD_tools . get_titgroup_type_from_titgroup ( mutated_res ) restype = pKD_tools . get_restype_from_titgroup ( mutated_res ) resid = pKD_tools . get_resid_from_res ( mutated_res ) fixed = False if group_type == 'NTERM' : newgroup = '%s:%s' % ( resid , 'CTERM' ) if desolv . has_key ( newgroup ) : desolv [ mutated_res ] = desolv [ newgroup ] del desolv [ newgroup ] backgr [ mutated_res ] = backgr [ newgroup ] del backgr [ newgroup ] fixed = True elif group_type == 'CTERM' : newgroup = '%s:%s' % ( resid , 'NTERM' ) if desolv . has_key ( newgroup ) : desolv [ mutated_res ] = desolv [ newgroup ] del desolv [ newgroup ] backgr [ mutated_res ] = backgr [ newgroup ] del backgr [ newgroup ] fixed = True else : pass if not fixed : print '!!!!!!!!!!!!!!!!!!!!!!!!!!!!' print 'Something went wrong in the desolv and backgr calcs - cannot find residue in desolv file' print desolv = None backgr = None raise Exception ( 'This must not happen' ) os . chdir ( topdir ) import pKarun . pKa_ostools as pKa_ostools pKa_ostools . rmr ( dirname ) print 'Returning' , desolv , backgr return desolv , backgr
Calculates the desolvation energy, the background interaction energy and all matrix interactions for
 a single residue (mutated_res) which is given in the form :0000:RES (e.g.
Calculates the desolvation energy the background interaction energy and all matrix interactions for a single residue ( mutated_res ) which is given in the form : 0000 : RES ( e . g .
"""
    # Calculates the desolvation energy, the background interaction energy and all matrix interactions for
    # a single residue (mutated_res) which is given in the form :0000:RES (e.g. :0035:GLU)
    """ # Create a temp dir # # # Get pdbfile, topology.h and the charge files # # Are the files present in the pwd? # # # ---- # Copy the pdb file  # # # Find out which group we want to calculate for # # # # For HIS it seems that we get erratic results for the background interaction energy if the calcs # are for only one residue. We therefore add the two previous groups to give more Hbond opt sampling # # Probably a new SS bridge formed.. # # Add this to the parameters #             # # Link the pdb file # # # Start the pKa calculation # # # Are we do to do a matric calculation or a desolv/backgr calculation? # # # If we cannot calculate one, then warn - this should be changed, and modelling optimised! # # # Check that pKa_IO got NTERM and CTERM right # # # Did we fix it? # # # Get the new pKa file #
pdbfile
mutated_res
pKarun_params
do_matrix