pdb2pqr opal.py :  » Business-Application » PDB2PQR » pdb2pqr-1.6 » 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 » pdb2pqr-opal.py
#!@WHICHPYTHON@
"""
    Driver for interfacing pdb2pqr web form with OPAL SOAP job submission.
    
"""

__date__  = "5 April 2010"
__author__ = "Wes Goodman, Yong Huang"
__version__ = "1.6"

import string
import sys
import getopt
import os
import time
import re
from src import pdb
from src import utilities
from src import structures
from src import routines
from src import protein
from src import server
from src.pdb import *
from src.utilities import *
from src.structures import *
from src.definitions import *
from src.forcefield import *
from src.routines import *
from src.protein import *
from src.server import *
from src.hydrogens import *
from src.aconf import *
from StringIO import *

import httplib
from AppService_client import AppServiceLocator,getAppMetadataRequest,launchJobRequest,\
    launchJobBlockingRequest, getOutputAsBase64ByNameRequest
from AppService_types import ns0
from ZSI.TC import String
import cgi
import cgitb

def printheader(pagetitle,jobid=None):
  """
        Function to print html headers
  """
  if jobid:
    print "Location: querystatus.cgi?jobid=%s\n" % jobid
  print "Content-type: text/html\n"
  print "<HTML>"
  print "<HEAD>"
  print "\t<TITLE>%s</TITLE>" % pagetitle
  print "\t<link rel=\"stylesheet\" href=\"%s\" type=\"text/css\">\n" % STYLESHEET
  print "</HEAD>"
  return
   
def mainCGI():
    """
        Opal driver for running PDB2PQR from a web page
    """
    serviceURL = OPALURL
    
    cgitb.enable()
    form = cgi.FieldStorage()
    
    options = {}
 
    ff = form["FF"].value 
    options["ff"] = ff
    fffile = None
    input = 0
  
    if form.has_key("DEBUMP"): options["debump"] = 1
    else: options["debump"] = 0
    if form.has_key("OPT"): options["opt"] = 1
    else: options["opt"] = 0
    if form.has_key("PROPKA"):
        try:
            ph = float(form["PH"].value)
            if ph < 0.0 or ph > 14.0: raise ValueError
            options["ph"] = ph
        except ValueError:
             text = "The entered pH of %.2f is invalid!  " % form["PH"].value
             text += "Please choose a pH between 0.0 and 14.0."
#             print "Content-type: text/html\n"
             print text
             sys.exit(2)
    if form.has_key("PDBID"):
        filename = form["PDBID"].value
        infile = getPDBFile(form["PDBID"].value)
    elif form.has_key("PDB"):
        filename = form["PDB"].filename
        filename=re.split(r'[/\\]',filename)[-1]
        infile = StringIO(form["PDB"].value)
    if form.has_key("INPUT"):
        input = 1
        options["apbs"] = 1
    if form.has_key("USERFF"):
#        userff = StringIO(form["USERFF"].value)
#        ff = "user-defined"
#        options["userff"] = userff
        ffname = form["USERFF"].filename
        ffname = re.split(r'[/\\]',ffname)[-1]
        fffile = StringIO(form["USERFF"].value)
        options["ff"] = ffname
    if form.has_key("FFOUT"):
        if form["FFOUT"].value != "internal":
            options["ffout"] = form["FFOUT"].value
    if form.has_key("CHAIN"):
        options["chain"] = 1
    if form.has_key("WHITESPACE"):
        options["whitespace"] = 1
    if form.has_key("LIGAND"):
        ligandfilename=str(form["LIGAND"].filename)
        ligandfilename=re.split(r'[/\\]',ligandfilename)[-1]
        options["ligand"] = StringIO(form["LIGAND"].value)
        
    try:
#        starttime = time.time()
#        name = setID(starttime)
        name = filename
        ligandFile=None
        ffFile=None
        # begin SOAP changes
        # need to switch options from a dictionary to something resembling a command line query
        # such as --chain
        myopts=""
        for key in options:
            if key=="opt":
                if options[key]==0:
                    # user does not want optimization
                    key="noopt"
                else:
                    # pdb2pqr optimizes by default, don't bother with flag
                    continue
            elif key=="debump":
                if options[key]==0:
                    # user does not want debumping
                    key="nodebump"
                else:
                    # pdb2pqr debumps by default, so change this flag to --nodebump
                    continue
            elif key=="ph":
                val=options[key]
                key="with-ph=%s" % val
            elif key=="ffout":
                val=options[key]
                key="ffout=%s" % val
            elif key=="ligand":
                val=ligandfilename
                key="ligand=%s" % val
                ligandFile = ns0.InputFileType_Def('inputFile')
                ligandFile._name = val
                ligandFileTemp = open(options["ligand"], "r")
                ligandFileString = ligandFileTemp.read()
                ligandFileTemp.close()
                ligandFile._contents = ligandFileString
            elif key=="apbs":
                key="apbs-input"
            elif key=="chain":
                key="chain"
            elif key=="whitespace":
                key="whitespace"
            elif key=="ff":
                val=options[key]
                key="ff=%s" % val
                if fffile:
                  ffFile = ns0.InputFileType_Def('inputFile')
                  ffFile._name = val
                  ffFileTemp = open(fffile, "r")
                  ffFileString = ffFileTemp.read()
                  ffFileTemp.close()
                  ffFile._contents = ffFileString
            myopts+="--"+str(key)+" "
        myopts+=str(filename)+" "
        myopts+="%s.pqr" % str(name)
        appLocator = AppServiceLocator()
        appServicePort = appLocator.getAppServicePort(serviceURL)
        # launch job
        req = launchJobRequest()
        req._argList = myopts
        inputFiles = []
        pdbFile = ns0.InputFileType_Def('inputFile')
        pdbFile._name = filename
        pdbFile._contents = infile.read()
        infile.close()
        inputFiles.append(pdbFile)
        if ligandFile:
          inputFiles.append(ligandFile)
        if ffFile:
          inputFiles.append(ffFile)
        req._inputFile=inputFiles
        try:
          resp=appServicePort.launchJob(req)
        except Exception, e:
          printheader("PDB2PQR Job Submission - Error")
          print "<BODY>\n<P>"
          print "There was an error with your job submission<br>"
          print "</P>\n</BODY>"
          print "</HTML>"
          sys.exit(2)
        printheader("PDB2PQR Job Submission",resp._jobID)
        
    except StandardError, details:
        print details
        createError(name, details)

# File should only be called as CGI
mainCGI()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.