pKa_utility_functions_compat.py :  » Business-Application » PDB2PQR » pdb2pqr-1.6 » pdb2pka » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Business Application » PDB2PQR 
PDB2PQR » pdb2pqr 1.6 » pdb2pka » pKa_utility_functions_compat.py
#
# $Id: pKa_utility_functions.py 361 2007-05-06 11:44:10Z nielsen $
#
# pKa utility functions
#
# Copyright (C) Jens Erik Nielsen, EMBL 2000, UCSD/HHMI 2002-2003
# University College Dublin 2003 -
# All rights reserved
#

#
# Routines for getting WHAT IF residue identifiers
#

def getWI_resid(line):
    #
    # Take a WHAT IF line of the form:
    # Residue:     1 LYS  (   1  )      (Prp= 1.00)
    #
    # and return a unique resid
    #
    import string
    split=string.split(line)
    residuename=split[2]
    last=string.split(line,'(')[1]
    number=string.split(last,')')[0]
    if len(string.strip(string.split(last,')')[1]))>0:
        chainID=string.split(string.split(last,')')[1])[0]
    else:
        chainID=''
    number=string.strip(number)
    resid='%s:%4s:%3s' %(chainID,string.zfill(number,4),residuename)
    return resid

def getWI_resid2(line,format=None):
    """
     Convert a WHAT IF line of the form:
     43 ASP  (  43  )         xxxxxx
     or
     182 SER  ( 182  ) A   
     and return a unique resid
    

    If format is pdb2pka, then just return the line"""
    import string
    if format=='pdb2pka':
        return string.strip(line.split(' ')[0])
    #
    # WHAT IF format
    #

    split=string.split(line)[:-1]
    line=string.join(split)
    #
    # Line reformatted
    #
    residuename=split[1]
    last=string.split(line,'(')[1]
    number=string.split(last,')')[0]
    last_part=string.strip(string.split(last,')')[1])
    last_split=string.split(last_part)
    if len(last_split)==1:
        chainID=last_split[0]
    else:
        chainID=''
    number=string.strip(number)
    resid='%s:%4s:%3s' %(chainID,string.zfill(number,4),residuename)
    return resid

def getWI_resid3(line):
    #
    # Take a WHAT IF line of the form:
    # Residue:     1 THR      1    A     Prp= 0.00
    # and return a unique resid
    #
    import string
    split=string.split(line)
    residuename=split[2]
    number=split[3]
    cid=split[4]
    chainID=''
    if len(cid)==1:
        chainID=cid
    else:
        chainID=''
    number=string.strip(number)
    resid='%s:%4s:%3s' %(chainID,string.zfill(number,4),residuename)
    return resid

def getWI_resid4(line):
    #
    # Take a WHAT IF line of the form:
    #   1 THR  (   1  )       N   xxxxxxx
    # and return a unique resid
    #
    import string
    #
    # First trim the string
    #
    line=string.join(string.split(string.strip(line))[:-1])
    #
    # Now the line looks like: 1 THR ( 1 ) N
    #
    split=string.split(line)
    atomname=split[-1]
    residuename=split[1]
    last=string.split(line,'(')[1]
    number=string.strip(string.split(last,')')[0])
    # Chain ID
    laststrip=string.strip(last)
    lastsplit=string.split(last,')')[1]
    split_lastsplit=string.split(lastsplit)
    if len(split_lastsplit)>1:
        chainID=split_lastsplit[0]
    else:
        chainID=''
    resid='%s:%4s:%3s:%s' %(chainID,string.zfill(number,4),residuename,atomname)
    return resid

#
# -----
#

def get_resid(uniqueid):
    import string
    return string.join(string.split(uniqueid,':')[:2],':')

def get_resnum(uniqueid):
    import string
    # Given a uniqueid this function returns the residue number
    return string.split(uniqueid,':')[1]

def get_resname(uniqueid):
    import string
    return string.split(uniqueid,':')[2]

def get_chainid(self,uniqueid):
    import string
    return string.split(uniqueid,':')[0]

def is_terminal(uniqueid):
    #
    # Is this residue a terminal titratable group?
    #
    if string.split(uniqueid,':')[-1]=='TERM':
        return 1
    return None

acidbase={'ARG':1,'HIS':1,'LYS':1,'TYR':-1,'ASP':-1,'GLU':-1,'CYS':-1,'CTERM':-1,'NTERM':1,'SER':-1,'THR':-1}

charged=['ARG','LYS','HIS','ASP','GLU']

def is_normally_titratable(uniqueid):
    """Does this group have a pKa value in the range 2-12"""
    type=uniqueid.split(':')[-1]
    if istitratable(uniqueid) and type!='SER' and type!='THR':
        return 1
    return None

def is_titratable(uniqueid):
    return istitratable(uniqueid)

def istitratable(uniqueid):
    import string
    type=string.split(uniqueid,':')[-1]
    if acidbase.has_key(type):
        return 1
    else:
        return None

def is_charged(uniqueid):
    import string
    type=string.split(uniqueid,':')[-1]
    if type in charged:
        return 1
    return None

def isacid(uniqueid):
    #
    # Is the residue a base or an acid?
    #
    import string
    type=string.split(uniqueid,':')[-1]
    val=acidbase[type]
    if val==-1:
        return 1
    return None

def acibas(uniqueid):
    #
    # Return -1 (acid) or 1 (base)
    #
    if isacid(uniqueid):
        return -1
    return 1

def reformat_name(oldname,Nterm=None,format='WHAT IF'):
    #
    # Reformat the residue names 
    #
    if format=='WHAT IF':
        import copy
        residue=copy.copy(oldname)
        newname=''
        Tflag=None
        if residue[0]=='T':
            Tflag=1
            residue=residue[1:]
        number=residue[:4]
        name=residue[4:7]
        chainID=''
        if len(residue)==8:
            chainID=residue[7]
        newname='%s:%4s:%3s' %(chainID,number,name)
        if Tflag:
            #
            # Nterm is 1 for an Nterm and 0 for a Cterm
            #
            if Nterm==1:
                newname=newname+':NTERM'
            else:
                newname=newname+':CTERM'
    else:
        import string
        return string.strip(oldname)
    return newname
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.