示例#1
0
def displayResults(jobID):
	""" Displays URLs of resulting files, if they are not to be fetched automatically. """
	global service_url
	appServicePort = AppServiceLocator().getAppServicePort(service_url)
	resp = appServicePort.getOutputs(getOutputsRequest(jobID))
	
	# Retrieve a listing of all output files
	stdout.write("\tStandard Output:  %s\n" % resp._stdOut, "\n")
	stdout.write("\tStandard Error:  %s\n", resp._stdErr)
	if (resp._outputFile != None):
		for i in range(0, resp._outputFile.__len__()):
			stdout.write("\t%s:  %s\n" % (resp._outputFile[i]._name, resp._outputFile[i]._url))
		stdout.write("\tStandard Error:  %s\n" % resp._stdErr)
示例#2
0
def displayResults(jobID):
    """ Displays URLs of resulting files, if they are not to be fetched automatically. """
    global service_url
    appServicePort = AppServiceLocator().getAppServicePort(service_url)
    resp = appServicePort.getOutputs(getOutputsRequest(jobID))

    # Retrieve a listing of all output files
    stdout.write("\tStandard Output:  %s\n" % resp._stdOut, "\n")
    stdout.write("\tStandard Error:  %s\n", resp._stdErr)
    if (resp._outputFile != None):
        for i in range(0, resp._outputFile.__len__()):
            stdout.write("\t%s:  %s\n" %
                         (resp._outputFile[i]._name, resp._outputFile[i]._url))
        stdout.write("\tStandard Error:  %s\n" % resp._stdErr)
示例#3
0
class OpalService:

	def __init__(self, serviceName=None,
		opalURL="http://webservices.rbvi.ucsf.edu/opal/services/",
		sessionData=None):

		from AppService_client import AppServiceLocator
		from AppService_client import getAppMetadataRequest
		self.busy = False
		self.appLocator = AppServiceLocator()
		if sessionData:
			self.serviceURL, self.jobID, self.status = sessionData
			try:
				from cPickle import loads
			except ImportError:
				from pickle import loads
		else:
			self.serviceURL = opalURL + serviceName
			self.jobID = None
			self.status = None
		self.appServicePort = self.appLocator.getAppServicePort(
							self.serviceURL)
		if not sessionData:
			req = getAppMetadataRequest()
			resp = self.appServicePort.getAppMetadata(req)
			#print resp._usage

	def sessionData(self):
		return self.serviceURL, self.jobID, self.status

	def _saveStatus(self, status):
		self.status = (status._code, status._message, status._baseURL)

	def currentStatus(self):
		if self.status:
			return self.status[1]
		elif self.busy:
			return "waiting for response from Opal server"
		else:
			return "no Opal job running"

	def launchJob(self, cmdLine, **kw):
		if self.jobID is not None or self.busy:
			raise RuntimeError("Job has been launched already")
		import chimera
		from AppService_client import launchJobRequest
		import socket
		req = launchJobRequest()
		req._argList = cmdLine
		for key, value in kw.iteritems():
			setattr(req, key, value)
		if chimera.nogui:
			try:
				resp = self.appServicePort.launchJob(req)
			except socket.error, e:
				from chimera import NonChimeraError
				raise NonChimeraError(str(e))
			self.jobID = resp._jobID
			self._saveStatus(resp._status)
		else:
示例#4
0
def pollStatus(jobID,outputDirectory):
	""" Determines current status of run and executes fetching of results if the run is completed. """
	global service_url
	appServicePort = AppServiceLocator().getAppServicePort(service_url)
	status = appServicePort.queryStatus(queryStatusRequest(jobID))
	
	if status._code == 4:
		stderr.write("Error!  The calculation failed!\n")
		stderr.write("Message:  %s\n" % status._message)
		sys.exit(13)
	elif status._code != 8:
		stderr.write("Sorry, the calculation hasn't been completed yet. Please wait a short while and attempt to fetch the files again.\n")
		sys.exit(13)
	else:
		resp = appServicePort.getOutputs(getOutputsRequest(jobID))
		fetchResults(jobID, outputDirectory, resp._outputFile, status._code==4)
示例#5
0
class OpalService:
    def __init__(self,
                 serviceName=None,
                 opalURL="http://webservices.rbvi.ucsf.edu/opal/services/",
                 sessionData=None):

        from AppService_client import AppServiceLocator
        from AppService_client import getAppMetadataRequest
        self.busy = False
        self.appLocator = AppServiceLocator()
        if sessionData:
            self.serviceURL, self.jobID, self.status = sessionData
            try:
                from cPickle import loads
            except ImportError:
                from pickle import loads
        else:
            self.serviceURL = opalURL + serviceName
            self.jobID = None
            self.status = None
        self.appServicePort = self.appLocator.getAppServicePort(
            self.serviceURL)
        if not sessionData:
            req = getAppMetadataRequest()
            resp = self.appServicePort.getAppMetadata(req)
            #print resp._usage

    def sessionData(self):
        return self.serviceURL, self.jobID, self.status

    def _saveStatus(self, status):
        self.status = (status._code, status._message, status._baseURL)

    def currentStatus(self):
        if self.status:
            return self.status[1]
        elif self.busy:
            return "waiting for response from Opal server"
        else:
            return "no Opal job running"

    def launchJob(self, cmdLine, **kw):
        if self.jobID is not None or self.busy:
            raise RuntimeError("Job has been launched already")
        import chimera
        from AppService_client import launchJobRequest
        import socket
        req = launchJobRequest()
        req._argList = cmdLine
        for key, value in kw.iteritems():
            setattr(req, key, value)
        if chimera.nogui:
            try:
                resp = self.appServicePort.launchJob(req)
            except socket.error, e:
                from chimera import NonChimeraError
                raise NonChimeraError(str(e))
            self.jobID = resp._jobID
            self._saveStatus(resp._status)
        else:
示例#6
0
def pollStatus(jobID, outputDirectory):
    """ Determines current status of run and executes fetching of results if the run is completed. """
    global service_url
    appServicePort = AppServiceLocator().getAppServicePort(service_url)
    status = appServicePort.queryStatus(queryStatusRequest(jobID))

    if status._code == 4:
        stderr.write("Error!  The calculation failed!\n")
        stderr.write("Message:  %s\n" % status._message)
        sys.exit(13)
    elif status._code != 8:
        stderr.write(
            "Sorry, the calculation hasn't been completed yet. Please wait a short while and attempt to fetch the files again.\n"
        )
        sys.exit(13)
    else:
        resp = appServicePort.getOutputs(getOutputsRequest(jobID))
        fetchResults(jobID, outputDirectory, resp._outputFile,
                     status._code == 4)
示例#7
0
def initVars():
    #global serviceURL

    if not form.has_key("jobid"):
        pass  # add code to redirect to PDB2PQR input page here
    else:
        jobid = form['jobid'].value

        #aspFile = open('./tmp/%s/%s-asp' % (logTime, logTime))
        #appServicePort = pickle.load(aspFile)
        #aspFile.close()

        #jobInfoFile = open('./tmp/%s/%s-jobinfo' % (logTime, logTime))
        #jobID = jobInfoFile.read()
        #jobInfoFile.close()

        aoFile = open('%s%s%s/%s-ao' % (INSTALLDIR, TMPDIR, jobid, jobid))
        apbsOptions = pickle.load(aoFile)
        aoFile.close()

        if APBS_OPAL_URL != "":
            from AppService_client import AppServiceLocator, getOutputsRequest
            apbsOpalJobIDFile = open('%s%s%s/apbs_opal_job_id' %
                                     (INSTALLDIR, TMPDIR, jobid))
            apbsOpalJobID = apbsOpalJobIDFile.read()
            apbsOpalJobIDFile.close()

            appLocator = AppServiceLocator()
            resp = appLocator.getAppServicePort(APBS_OPAL_URL).getOutputs(
                getOutputsRequest(apbsOpalJobID))
            if not os.access('%s%s%s' % (INSTALLDIR, TMPDIR, jobid), os.F_OK):
                os.mkdir('%s%s%s' % (INSTALLDIR, TMPDIR, jobid))
            for file in resp._outputFile:
                fileName = file._name
                if fileName != "Standard Output" and fileName != "Standard Error":
                    urllib.urlretrieve(
                        file._url,
                        '%s%s%s/%s' % (INSTALLDIR, TMPDIR, jobid, fileName))

        return apbsOptions
示例#8
0
def initVars():
    #global serviceURL

    if not form.has_key("jobid"):
        pass # add code to redirect to PDB2PQR input page here
    else:
        jobid = form['jobid'].value

        #aspFile = open('./tmp/%s/%s-asp' % (logTime, logTime))
        #appServicePort = pickle.load(aspFile)
        #aspFile.close()

        #jobInfoFile = open('./tmp/%s/%s-jobinfo' % (logTime, logTime))
        #jobID = jobInfoFile.read()
        #jobInfoFile.close()

        aoFile = open('%s%s%s/%s-ao' % (INSTALLDIR, TMPDIR, jobid, jobid))
        apbsOptions = pickle.load(aoFile)
        aoFile.close()

        if APBS_OPAL_URL!="":
            from AppService_client import AppServiceLocator, getOutputsRequest
            apbsOpalJobIDFile = open('%s%s%s/apbs_opal_job_id' % (INSTALLDIR, TMPDIR, jobid))
            apbsOpalJobID = apbsOpalJobIDFile.read()
            apbsOpalJobIDFile.close()
            
            appLocator = AppServiceLocator()
            resp = appLocator.getAppServicePort(APBS_OPAL_URL).getOutputs(getOutputsRequest(apbsOpalJobID))
            if not os.access('%s%s%s' % (INSTALLDIR, TMPDIR, jobid), os.F_OK):
                os.mkdir('%s%s%s' % (INSTALLDIR, TMPDIR, jobid))
            for file in resp._outputFile:
                fileName = file._name
                if fileName!="Standard Output" and fileName!="Standard Error":
                    urllib.urlretrieve(file._url, '%s%s%s/%s' % (INSTALLDIR, TMPDIR, jobid, fileName))

        return apbsOptions
示例#9
0
    def __init__(self,
                 serviceName=None,
                 opalURL="http://webservices.rbvi.ucsf.edu/opal/services/",
                 sessionData=None):

        from AppService_client import AppServiceLocator
        from AppService_client import getAppMetadataRequest
        self.busy = False
        self.appLocator = AppServiceLocator()
        if sessionData:
            self.serviceURL, self.jobID, self.status = sessionData
            try:
                from cPickle import loads
            except ImportError:
                from pickle import loads
        else:
            self.serviceURL = opalURL + serviceName
            self.jobID = None
            self.status = None
        self.appServicePort = self.appLocator.getAppServicePort(
            self.serviceURL)
        if not sessionData:
            req = getAppMetadataRequest()
            resp = self.appServicePort.getAppMetadata(req)
示例#10
0
	def __init__(self, serviceName=None,
		opalURL="http://webservices.rbvi.ucsf.edu/opal/services/",
		sessionData=None):

		from AppService_client import AppServiceLocator
		from AppService_client import getAppMetadataRequest
		self.busy = False
		self.appLocator = AppServiceLocator()
		if sessionData:
			self.serviceURL, self.jobID, self.status = sessionData
			try:
				from cPickle import loads
			except ImportError:
				from pickle import loads
		else:
			self.serviceURL = opalURL + serviceName
			self.jobID = None
			self.status = None
		self.appServicePort = self.appLocator.getAppServicePort(
							self.serviceURL)
		if not sessionData:
			req = getAppMetadataRequest()
			resp = self.appServicePort.getAppMetadata(req)
示例#11
0
def mainCGI():
    """
        Main driver for running PDB2PQR from a web page
    """
    print "Content-type: text/html\n"
    import cgi
    import cgitb

    cgitb.enable()
    form = cgi.FieldStorage()
    ff = form["FF"].value
    input = 0

    apbs_input = form.has_key("INPUT")
    typemap = form.has_key("TYPEMAP")
    neutraln = form.has_key("NEUTRALN")
    neutralc = form.has_key("NEUTRALC")

    if HAVE_PDB2PQR_OPAL == "1":
        have_opal = True
        # Opal-specific import statments
        from AppService_client import AppServiceLocator, getAppMetadataRequest, launchJobRequest, launchJobBlockingRequest, getOutputAsBase64ByNameRequest
        from AppService_types import ns0
        from ZSI.TC import String
    else:
        have_opal = False

    if have_opal:
        options = {}
        options["ff"] = ff
        fffile = None
        namesfile = None
    else:
        options = {"extensions": {}}

    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"):
        pdbfile = getPDBFile(form["PDBID"].value)
        pdbfilename = form["PDBID"].value
    elif form.has_key("PDB"):
        pdbfile = StringIO(form["PDB"].value)
        pdbfilename = form["PDB"].filename
        pdbfilename = re.split(r'[/\\]', pdbfilename)[-1]
    if form.has_key("INPUT"):
        input = 1
        options["apbs"] = 1
    if form.has_key("USERFF"):
        if have_opal:
            ffname = form["USERFF"].filename
            ffname = re.split(r'[/\\]', ffname)[-1]
            if ffname[-4:] == ".DAT":
                ffname = ffname[:-4]
            fffile = StringIO(form["USERFF"].value)
            namesfile = StringIO(form["USERNAMES"].value)
            options["ff"] = ffname
            options["userff"] = fffile
            options["usernames"] = namesfile
        else:
            userff = StringIO(form["USERFF"].value)
            usernames = StringIO(form["USERNAMES"].value)
            options["ff"] = "user-defined"
            options["userff"] = userff
            options["usernames"] = usernames
    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("TYPEMAP"):
        options["typemap"] = 1
    if form.has_key("NEUTRALN"):
        options["neutraln"] = 1
    if form.has_key("NEUTRALC"):
        options["neutralc"] = 1
    if form.has_key("LIGAND"):
        if have_opal:
            ligandfilename = str(form["LIGAND"].filename)
            ligandfilename = re.split(r'[/\\]', ligandfilename)[-1]

        # for Windows-style newline compatibility
        templigandfilename = tempfile.mkstemp()[1]
        templigandfile = open(templigandfilename, 'w')
        templigandfile.write(form["LIGAND"].value)
        templigandfile.close()
        templigandfile = open(templigandfilename, 'rU')
        if have_opal:
            options["ligand"] = templigandfile.read()
        else:
            templigandstring = templigandfile.read(
            )  # this variable is used again later to write this file to output
            options["ligand"] = StringIO(templigandstring)

        templigandfile.close()

    if not have_opal:
        pdbfilestring = pdbfile.read()
        pdblist, errlist = readPDB(StringIO(pdbfilestring))
        dummydef = Definition()
        dummyprot = Protein(pdblist, dummydef)
        if len(pdblist) == 0 and len(errlist) == 0:
            text = "Unable to find PDB file - Please make sure this is "
            text += "a valid PDB file ID!"
            #print "Content-type: text/html\n"
            print text
            sys.exit(2)
        elif dummyprot.numAtoms() > MAXATOMS and "opt" in options:
            text = "<HTML><HEAD>"
            text += "<TITLE>PDB2PQR Error</title>"
            text += "<link rel=\"stylesheet\" href=\"%s\" type=\"text/css\">" % STYLESHEET
            text += "</HEAD><BODY><H2>PDB2PQR Error</H2><P>"
            text += "Due to server limits, we are currently unable to optimize "
            text += "proteins of greater than MAXATOMS atoms on the server (PDB2PQR "
            text += "found %s atoms in the selected PDB file).  If you " % dummyprot.numAtoms(
            )
            text += "want to forgo optimization please try the server again.<P>"
            text += "Otherwise you may use the standalone version of PDB2PQR that "
            text += "is available from the <a href=\"http://pdb2pqr.sourceforge.net\">"
            text += "PDB2PQR SourceForge project page</a>."
            text += "<script type=\"text/javascript\">"
            text += "var gaJsHost = ((\"https:\" == document.location.protocol) ? \"https://ssl.\" : \"http://www.\");"
            text += "document.write(unescape(\"%3Cscript src=\'\" + gaJsHost + \"google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E\"));"
            text += "</script>"
            text += "<script type=\"text/javascript\">"
            text += "try {"
            text += "var pageTracker = _gat._getTracker(\"UA-11026338-3\");"
            for key in options:
                text += "pageTracker._trackPageview(\"/main_cgi/has_%s_%s.html\");" % (
                    key, options[key])
            text += "pageTracker._trackPageview();"
            text += "} catch(err) {}</script>"
            text += "</BODY></HTML>"
            #print "Content-type: text/html\n"
            print text
            sys.exit(2)

    try:
        if have_opal:
            ligandFile = None
            ffFile = None
            namesFile = None
        #else:
        starttime = time.time()
        name = setID(starttime)

        os.makedirs('%s%s%s' % (INSTALLDIR, TMPDIR, name))
        apbsInputFile = open('%s%s%s/apbs_input' % (INSTALLDIR, TMPDIR, name),
                             'w')
        apbsInputFile.write(str(apbs_input))
        apbsInputFile.close()
        typemapInputFile = open('%s%s%s/typemap' % (INSTALLDIR, TMPDIR, name),
                                'w')
        typemapInputFile.write(str(typemap))
        typemapInputFile.close()

        if have_opal:
            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
                    ligandFile._contents = options["ligand"]
                elif key == "apbs":
                    key = "apbs-input"
                elif key == "chain":
                    key = "chain"
                elif key == "whitespace":
                    key = "whitespace"
                elif key == "typemap":
                    key = "typemap"
                elif key == "ff":
                    val = options[key]
                    key = "ff=%s" % val
                    if fffile:
                        ffFile = ns0.InputFileType_Def('inputFile')
                        ffFile._name = val + ".DAT"
                        ffFileString = fffile.read()
                        ffFile._contents = ffFileString
                    if namesfile:
                        namesFile = ns0.InputFileType_Def('inputFile')
                        namesFile._name = val + ".names"
                        namesFileString = namesfile.read()
                        namesFile._contents = namesFileString
                if key not in ["userff", "usernames"]:
                    myopts += "--" + str(key) + " "
            myopts += str(pdbfilename) + " "
            if pdbfilename[-4:] == ".pdb":
                myopts += "%s.pqr" % str(pdbfilename[:-4])
            else:
                myopts += "%s.pqr" % str(pdbfilename)
            appLocator = AppServiceLocator()
            appServicePort = appLocator.getAppServicePort(PDB2PQR_OPAL_URL)
            # launch job
            req = launchJobRequest()
            req._argList = myopts
            inputFiles = []
            pdbOpalFile = ns0.InputFileType_Def('inputFile')
            pdbOpalFile._name = pdbfilename
            pdbOpalFile._contents = pdbfile.read()
            pdbfile.close()
            inputFiles.append(pdbOpalFile)
            if ligandFile:
                inputFiles.append(ligandFile)
            if ffFile:
                inputFiles.append(ffFile)
            if namesFile:
                inputFiles.append(namesFile)
            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>"
                print "<script type=\"text/javascript\">"
                print "var gaJsHost = ((\"https:\" == document.location.protocol) ? \"https://ssl.\" : \"http://www.\");"
                print "document.write(unescape(\"%3Cscript src=\'\" + gaJsHost + \"google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E\"));"
                print "</script>"
                print "<script type=\"text/javascript\">"
                print "try {"
                print "var pageTracker = _gat._getTracker(\"UA-11026338-3\");"
                for key in options:
                    print "pageTracker._trackPageview(\"/main_cgi/has_%s_%s.html\");" % (
                        key, options[key])
                print "pageTracker._trackPageview();"
                print "} catch(err) {}</script>"
                print "</BODY>"
                print "</HTML>"
                sys.exit(2)
            #printHeader("PDB2PQR Job Submission",have_opal,jobid=resp._jobID)
            pdb2pqrOpalJobIDFile = open(
                '%s%s%s/pdb2pqr_opal_job_id' % (INSTALLDIR, TMPDIR, name), 'w')
            pdb2pqrOpalJobIDFile.write(resp._jobID)
            pdb2pqrOpalJobIDFile.close()
            print redirector(name)
            if options.has_key("userff"):
                options["userff"] = ffFileString
            if options.has_key("usernames"):
                options["usernames"] = namesFileString
            # Recording CGI run information for PDB2PQR Opal
            pdb2pqrOpalLogFile = open(
                '%s%s%s/pdb2pqr_opal_log' % (INSTALLDIR, TMPDIR, name), 'w')
            pdb2pqrOpalLogFile.write(
                str(options) + '\n' + str(ff) + '\n' +
                str(os.environ["REMOTE_ADDR"]))
            pdb2pqrOpalLogFile.close()

        else:
示例#12
0
 def __init__(self, url):
     self.url = url
     appLocator = AppServiceLocator()
     self.appServicePort = appLocator.getAppServicePort(self.url)
示例#13
0
def execApbs(vars=None, argv=None):
    """ Executes APBS and regulates checking of job status and retrieval of data if job is successfully completed. """
    if argv is None:
        # i.e. if it is a local run
        argv = sys.argv
        webRun = False
    else:
        webRun = True
        custom_service_url = None
        if vars != None:
            if vars.has_key('service_url'):
                custom_service_url = vars['service_url']
        vars = initRemoteVars(argv)
        if custom_service_url != None:
            vars['service_url'] = custom_service_url
    global service_url
    #*argument parser
    # command-line arguments
    vars['inFile'] = argv[-1]

    # parses input file
    if (vars['inFile'].find("/") == -1):
        directory = ""
    else:
        directory = os.path.dirname(vars['inFile']) + '/'
        vars['inFile'] = os.path.basename(vars['inFile'])

    nprocs = 1
    if not vars.has_key('service_url'):
        # find out if it's sequential or parallel
        tempFile = open(directory + vars['inFile'], 'r')
        version_check_flag = True
        for line in tempFile:
            # remove whitespace
            line = line.strip()
            if (line[:5] == 'pdime'):
                dimension_array = line.split()
                nprocs = int(dimension_array[1]) * int(
                    dimension_array[2]) * int(dimension_array[3])
                global parallel_service_url
                vars['service_url'] = parallel_service_url
                version_check_flag = False
            if (line[:5] == 'async'):
                vars['service_url'] = service_url
                version_check_flag = True
                break
        if version_check_flag:
            vars['service_url'] = service_url

        tempFile.close()
    else:
        version_check_flag = True  # Enable version checking for custom defined Opal service as well
        service_url = vars['service_url']
    # Retrieve a reference to the AppServicePort
    #*this is also from the path to the service
    appServicePort = AppServiceLocator().getAppServicePort(vars['service_url'])

    # Set up remote job launch
    req = launchJobRequest()
    # Checks version compatibility (but currently only works for sequential calculations)
    if version_check_flag:
        opal_version = AppServicePortTypeSoapBindingSOAP(
            vars['service_url']).getAppMetadata(
                getAppMetadataRequest())._usage.split()[-1]
        if opal_version != local_version:
            stderr.write(
                "WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING!\n"
            )
            stderr.write(
                "It appears that the remote server version of APBS (%s) does not match\nthe local version (%s)!\n"
                % (opal_version, local_version))
            stderr.write("Proceed at your own risk!!\n")
            stderr.write(
                "WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING!\n"
            )
            if webRun:
                return False

    if (vars.has_key('argList')):
        vars['argList'] = vars['argList'] + " " + vars['inFile']
    else:
        vars['argList'] = vars['inFile']

    req._argList = vars['argList']
    req._numProcs = nprocs
    # append all input files in this manner - in this case we have two of them

    inputFiles = []
    #*this is where apbs.in is read in
    inputFiles.append(ns0.InputFileType_Def('inputFile'))
    #*this must be the same as req._argList is defined to be
    inputFiles[-1]._name = vars['inFile']
    tempFile = open(directory + vars['inFile'], 'r')
    inputFiles[-1]._contents = tempFile.read()
    tempFile.close()

    # this is where the rest of the files to read in are determined
    start = False
    tempFile = open(directory + vars['inFile'], 'r')
    for line in tempFile:
        # remove whitespace
        line = line.strip()
        if (line == "end"):
            break
        if (start and line.find("#") != 0):
            # eliminates lines with just comments
            # remove comment
            if (line.find("#") != -1):
                line = line[:line.find("#")]
            # re-remove whitespace (left after comment removal)
            line = line.strip()
            # remove everything except file name
            count = -1
            while line[count] != ' ':
                count = count - 1
            fileName = line[count + 1:]
            inputFiles.append(ns0.InputFileType_Def('inputFile'))
            inputFiles[-1]._name = fileName
            tempFile2 = open(directory + fileName, "r")
            inputFiles[-1]._contents = tempFile2.read()
            tempFile2.close()
        if (line == "read"):
            start = True

    tempFile.close()

    # req's inputFile variable is the array of input files created in the lines directly above
    req._inputFile = inputFiles

    if vars['typeOfRun'] == 'remote':
        appServicePort.launchJob(req)
        return [appServicePort, appServicePort.launchJob(req)]

    # Launch job, and retrieve job ID
    print "Launching remote APBS job"
    try:
        resp = appServicePort.launchJob(req)
    except ZSI.FaultException, errstr:
        stderr.write(
            "Error! Failed to execute Opal job. Please send the entire output to the APBS development team.\n"
        )
        stderr.write("%s\n" % errstr.fault.AsSoap())
        sys.exit(13)
示例#14
0
# Import the Opal libraries
from AppService_client import \
     AppServiceLocator, getAppMetadataRequest, launchJobRequest, \
     queryStatusRequest, getOutputsRequest, \
     launchJobBlockingRequest, getOutputAsBase64ByNameRequest
from AppService_types import ns0
from os import mkdir
from time import sleep
from ZSI.TC import String

# Set the location of our service
# A list of NBCR services can be found at http://ws.nbcr.net/opal2/dashboard?command=serviceList
serviceURL = "http://ws.nbcr.net/opal2/services/MEME_4.4.0"

# Instantiate a new service object to interact with.  Pass it the service location
appLocator = AppServiceLocator()
appServicePort = appLocator.getAppServicePort(serviceURL)
    
# Instantiate a new non-blocking job request
req = launchJobRequest()

# Set the command-line arguments for the job.
# Use DNA alphabet, and find 3 motifs.
req._argList = "meme crp0.fasta -dna -mod zoops -nmotifs 3"

# Get contents of local file to be used as input
fastaFile = open("./crp0.fasta", "r")
fastaFileContents = fastaFile.read()
fastaFile.close()

# Set name and content of remote input file.
示例#15
0
def mainCGI():
    """
        Main method for determining the query page output
    """
    logopts = {}
    print "Content-type: text/html\n\n"
    calctype = form["calctype"].value

    # prints version error, if it exists
    if form["jobid"].value == 'False':
        print printheader("%s Job Status Page" % calctype.upper())
        progress = "version_mismatch"
        runtime = 0
    elif form["jobid"].value == 'notenoughmem':
        print printheader("%s Job Status Page" % calctype.upper())
        progress = "not_enough_memory"
        runtime = 0
    else:
        progress = None

    #Check for error html
    errorpath = '%s%s%s.html' % (INSTALLDIR, TMPDIR, form["jobid"].value)
    if os.path.isfile(errorpath):
        string = ""
        string+= "<html>\n"
        string+= "\t<head>\n"
        string+= "\t\t<meta http-equiv=\"Refresh\" content=\"0; url=%s%s%s.html\">\n" % (WEBSITE, TMPDIR, form["jobid"].value)
        string+= "\t</head>\n"
        string+= "</html>\n"
        print string
        return

    # prepares for Opal query, if necessary
    if have_opal:
        if calctype=="pdb2pqr":
            opal_url = PDB2PQR_OPAL_URL
        elif calctype=="apbs":
            opal_url = APBS_OPAL_URL
        appLocator = AppServiceLocator()
        appServicePort = appLocator.getAppServicePort(opal_url)
    else:
        appServicePort = None

    # if PDB2PQR, determines if link to APBS calculation should be shown
    if calctype=="pdb2pqr":
        #if(form["apbsinput"].value=="True"): # change to use a file
        #    apbs_input = True
        #else:
        #    apbs_input = False
        apbsInputFile = open('%s%s%s/apbs_input' % (INSTALLDIR, TMPDIR, form["jobid"].value))
        apbs_input = apbsInputFile.read()
        apbsInputFile.close()
        if apbs_input=="True":
            apbs_input = True
        else:
            apbs_input = False

        typemapInputFile = open('%s%s%s/typemap' % (INSTALLDIR, TMPDIR, form["jobid"].value))
        typemap = typemapInputFile.read()
        typemapInputFile.close()
        if typemap=="True":
            typemap = True
        else:
            typemap = False

    if have_opal and progress == None:
        if form["calctype"].value=="pdb2pqr":
            pdb2pqrJobIDFile = open('%s%s%s/pdb2pqr_opal_job_id' % (INSTALLDIR, TMPDIR, form["jobid"].value))
            jobid = pdb2pqrJobIDFile.read()
            pdb2pqrJobIDFile.close()
        elif form["calctype"].value=="apbs":
            apbsJobIDFile = open('%s%s%s/apbs_opal_job_id' % (INSTALLDIR, TMPDIR, form["jobid"].value))
            jobid = apbsJobIDFile.read()
            apbsJobIDFile.close()
    else:
        jobid = form["jobid"].value

    if progress == None:
        cp = checkprogress(jobid,appServicePort,calctype) # finds out status of job
        progress = cp[0]

    #initialize with bogus value just in case
    starttime = time.time()

    if progress == "running" or progress == "complete":
        timefile = open('%s%s%s/%s_start_time' % (INSTALLDIR, TMPDIR, form["jobid"].value, form["calctype"].value))
        starttime = float(timefile.read())
        timefile.close()

    if progress == "running" or (have_opal and progress not in ("version_mismatch",
                                                                "not_enough_memory",
                                                                "error",
                                                                "complete")):
        runtime = time.time()-starttime
        runtime = int(runtime)

    elif progress == "complete":
        endTimeFileString = '%s%s%s/%s_end_time' % (INSTALLDIR, TMPDIR, form["jobid"].value, form["calctype"].value)
        if have_opal and not os.path.isfile(endTimeFileString):
            runtime = time.time()-starttime
            with open(endTimeFileString, 'w') as endTimeFile:
                endTimeFile.write(str(time.time()))
        else:
            with open(endTimeFileString, 'r') as endTimeFile:
                runtime = float(endTimeFile.read())-starttime
    else:
        runtime = -1

    if progress == "running":
        #if have_opal:
        #    resultsurl = cp[1]._baseURL
        #else:
        if calctype=="pdb2pqr":
            resultsurl = '%squerystatus.cgi?jobid=%s&apbsinput=%s&calctype=pdb2pqr' % (WEBSITE, form["jobid"].value, apbs_input)
        else:
            resultsurl = '%squerystatus.cgi?jobid=%s&calctype=apbs' % (WEBSITE, form["jobid"].value)

    if progress == "complete":
        print printheader("%s Job Status Page" % calctype.upper(), jobid=form["jobid"].value)

    elif progress == "error":
        print printheader("%s Job Status Page - Error" % calctype.upper(),0, jobid=form["jobid"].value)

    elif progress == "running": # job is not complete, refresh in 30 seconds
        print printheader("%s Job Status Page" % calctype.upper(), refresh, jobid=form["jobid"].value)

    print "<BODY>\n<P>"
    print "<p></p>"
    print '<div id="content">'
    print "<h3>Status:"

    color = "FA3434"
    image = WEBSITE+"images/red_x.png"

    if progress == "complete":
        color = "2CDE56"
        image = WEBSITE+"images/green_check.png"
    elif progress == "running":
        color = "ffcc00"
        image = WEBSITE+"images/yellow_exclamation.png"

    print "<strong style=\"color:#%s;\">%s</strong>" % (color, progress)
    print "<img src=\"%s\"><br />" % image
    print "</h3>"
    print "Run time: " + str(timedelta(seconds=round(runtime))) + '<br />'
    print "Current time: %s<br />" % time.asctime()
    print "</P>\n<HR>\n<P>"

    if progress == "complete":
        if calctype=="pdb2pqr":
            nexturl = 'apbs_cgi.cgi?jobid=%s' % form["jobid"].value
        else:
            url_3dmol = 'visualize.cgi?jobid=%s&tool=%s' % (form["jobid"].value,'tool_3dmol')
            url_jmol = 'visualize.cgi?jobid=%s&tool=%s' % (form["jobid"].value,'tool_jmol')


        if have_opal:
            resp = appServicePort.getOutputs(getOutputsRequest(jobid))
            filelist = resp._outputFile

        print "Here are the results:<ul>"
        print "<li>Input files<ul>"

        if calctype=="pdb2pqr":
            # this code should be cleaned up once local PDB2PQR runs output the PDB file with the .pdb extension
            if have_opal:
                for i in range(0,len(filelist)):
                    file_name = filelist[i]._name
                    if ((len(file_name) == 4 and '.' not in file_name) or
                        (file_name.lower().endswith(".pdb") and "pdb2pka_output" not in file_name)):
                        print "<li><a href=%s>%s</a></li>" % (filelist[i]._url, filelist[i]._name)

                    if file_name.lower().endswith((".mol", ".mol2", ".names", ".dat")) and "pdb2pka_output" not in file_name:
                        print "<li><a href=%s>%s</a></li>" % (filelist[i]._url, filelist[i]._name)


            else:
                print "<li><a href=%s%s%s/%s.pdb>%s.pdb</a></li>" % (WEBSITE, TMPDIR, jobid, jobid, jobid)

        elif calctype=="apbs":
            if have_opal:
                for i in range(0,len(filelist)):
                    if filelist[i]._name == "apbsinput.in" or filelist[i]._name[-4:] == ".pqr":
                        print "<li><a href=%s>%s</a></li>" % (filelist[i]._url, filelist[i]._name)
            else:
                print "<li><a href=%s%s%s/apbsinput.in>apbsinput.in</a></li>" % (WEBSITE, TMPDIR, jobid)
                print "<li><a href=%s%s%s/%s.pqr>%s.pqr</a></li>" % (WEBSITE, TMPDIR, jobid, jobid, jobid)

        print "</ul></li>"
        print "<li>Output files<ul>"

        queryString = [str(os.environ["REMOTE_ADDR"])]
        # Getting PDB2PQR run log info
        if os.path.isfile('%s%s%s/pdb2pqr_log' % (INSTALLDIR, TMPDIR, jobid)):
            pdb2pqrLogFile=open('%s%s%s/pdb2pqr_log' % (INSTALLDIR, TMPDIR, jobid), 'r')
            logstr=pdb2pqrLogFile.read().split('\n')
            templogopts = eval(logstr[0])
            pdb2pqrLogFile.close()
            queryString.insert(0, templogopts.get('pdb',''))

        if calctype=="pdb2pqr":
            if have_opal:
                for i in range(0,len(filelist)):
                    if filelist[i]._name.endswith((".propka", "-typemap.html")):
                        print "<li><a href=%s>%s</a></li>" % (filelist[i]._url, filelist[i]._name)

                    if filelist[i]._name.endswith(".in") and "pdb2pka_output" not in filelist[i]._name:
                        print "<li><a href=%s>%s</a></li>" % (filelist[i]._url, filelist[i]._name)

                    if filelist[i]._name.endswith(".pqr") and not filelist[i]._name.endswith("background_input.pqr"):
                        print "<li><a href=%s>%s</a></li>" % (filelist[i]._url, filelist[i]._name)

                    #Get the first line of the summary file.
                    if filelist[i]._name.endswith(".summary"):
                        f=urllib.urlopen(filelist[i]._url)
                        summaryLine = f.readline().strip()
                        #logopts["pdb"]=logopts.get("pdb", "") + "|" + summaryLine
                        queryString.append(summaryLine)
                        f.close()
#                logRun(logopts, runtime, pqrOpalFileLength, logff, REMOTE_ADDR)
            else:
                #Get the first line of the summary file.
                summaryFile = '%s%s%s/%s%s' % (INSTALLDIR, TMPDIR, jobid, jobid, ".summary")
                if os.path.isfile(summaryFile):
                    with open(summaryFile) as f:
                        summaryLine = f.readline().strip()
                        #logopts["pdb"]=logopts.get("pdb", "") + "|" + summaryLine
                        queryString.append(summaryLine)

                outputfilelist = glob.glob('%s%s%s/*.propka' % (INSTALLDIR, TMPDIR, jobid))
                for i in range(0,len(outputfilelist)):
                    outputfilelist[i] = os.path.basename(outputfilelist[i])
                for extension in ["-typemap.html", ".pqr", ".in"]:
                    if extension != ".in" or apbs_input != False:
                        if extension == "-typemap.html" and typemap == False:
                            continue
                        outputfilelist.append('%s%s' % (jobid, extension))
                for outputfile in outputfilelist:
                    print "<li><a href=%s%s%s/%s>%s</a></li>" % (WEBSITE, TMPDIR, jobid, outputfile, outputfile)

            logopts['queryPDB2PQR'] = '|'.join(queryString)

                #for extension in ["-typemap.html", ".pqr", ".in"]:
                #    print "<li><a href=%s%s%s/%s%s>%s%s</a></li>" % (WEBSITE, TMPDIR, jobid, jobid, extension, jobid, extension)
        elif calctype=="apbs":
            if have_opal:
                for i in range(0,len(filelist)):
                    if filelist[i]._name[-3:]==".dx":
                        # compressing APBS OpenDX output files
                        currentpath = os.getcwd()
                        zipjobid = filelist[i]._name.split("-")[0]
                        dxfilename = '%s%s%s/%s' % (INSTALLDIR, TMPDIR, zipjobid, filelist[i]._name)
                        urllib.urlretrieve(filelist[i]._url, dxfilename)
                        os.chdir('%s%s%s' % (INSTALLDIR, TMPDIR, zipjobid))
                        # making both the dx file and the compressed file (.gz) available in the directory
                        syscommand = 'cp %s dxbkupfile' % (filelist[i]._name)
                        os.system(syscommand)
                        syscommand = 'gzip -9 ' + filelist[i]._name
                        os.system(syscommand)
                        syscommand = 'mv dxbkupfile %s' % (filelist[i]._name)
                        os.system(syscommand)
                        outputfilezip = filelist[i]._name + '.gz'

                        pqrfilename = '%s%s%s/%s.pqr' % (INSTALLDIR, TMPDIR, zipjobid, zipjobid)
                        cubefilename = '%s%s%s/%s.cube' % (INSTALLDIR, TMPDIR, zipjobid, zipjobid)

                        # making both the cube file and the compressed file (.gz) available in the directory
                        createcube(dxfilename, pqrfilename, cubefilename)
                        cubefilebasename = os.path.basename(cubefilename)

                        syscommand = 'cp %s cubebkupfile' % cubefilebasename
                        os.system(syscommand)
                        syscommand = 'gzip -9 ' + cubefilebasename
                        os.system(syscommand)
                        syscommand = 'mv cubebkupfile %s' % cubefilebasename
                        os.system(syscommand)
                        os.chdir(currentpath)
                        outputcubefilezip = cubefilebasename+".gz"

                        print "<li><a href=%s%s%s/%s>%s</a></li>" % (WEBSITE, TMPDIR, zipjobid, outputfilezip, outputfilezip)
                        print "<li><a href=%s%s%s/%s>%s</a></li>" % (WEBSITE, TMPDIR, zipjobid, outputcubefilezip, outputcubefilezip)

            else:
                outputfilelist = glob.glob('%s%s%s/%s-*.dx' % (INSTALLDIR, TMPDIR, jobid, jobid))
                for dxfile in outputfilelist:
                    # compressing APBS OpenDX output files
                    currentpath = os.getcwd()
                    workingpath = os.path.dirname(dxfile)
                    os.chdir(workingpath)
                    # making both the dx file and the compressed file (.gz) available in the directory
                    syscommand = 'cp %s dxbkupfile' % (os.path.basename(dxfile))
                    os.system(syscommand)
                    syscommand = 'gzip -9 ' + os.path.basename(dxfile)
                    os.system(syscommand)
                    syscommand = 'mv dxbkupfile %s' % (os.path.basename(dxfile))
                    os.system(syscommand)
                    os.chdir(currentpath)
                    outputfilezip = dxfile+".gz"



                    cubefilename = '%s%s%s/%s.cube' % (INSTALLDIR, TMPDIR, jobid, jobid)
                    pqrfilename = '%s%s%s/%s.pqr' % (INSTALLDIR, TMPDIR, jobid, jobid)


                    createcube(dxfile, pqrfilename, cubefilename)

                    print "<li><a href=%s%s%s/%s>%s</a></li>" % (WEBSITE, TMPDIR, jobid, os.path.basename(outputfilezip), os.path.basename(outputfilezip))

                outputcubefilelist = glob.glob('%s%s%s/%s.cube' % (INSTALLDIR, TMPDIR, jobid, jobid))
                for cubefile in outputcubefilelist:
                    # compressing cube output file
                    currentpath = os.getcwd()
                    os.chdir(workingpath)
                    # making both the cube file and the compressed file (.gz) available in the directory
                    syscommand = 'cp %s cubebkupfile' % (os.path.basename(cubefile))
                    os.system(syscommand)
                    syscommand = 'gzip -9 ' + os.path.basename(cubefile)
                    os.system(syscommand)
                    syscommand = 'mv cubebkupfile %s' % (os.path.basename(cubefile))
                    os.system(syscommand)
                    os.chdir(currentpath)
                    outputcubefilezip = cubefile+".gz"

                    print "<li><a href=%s%s%s/%s>%s</a></li>" % (WEBSITE, TMPDIR, jobid, os.path.basename(outputcubefilezip), os.path.basename(outputcubefilezip))

            logopts['queryAPBS'] = '|'.join(queryString)

        if calctype=="pdb2pqr":
            if have_opal:
                outputfilelist = []
                for i in range(0,len(filelist)):
                    if filelist[i]._name.endswith((".DAT", ".txt")):
                        outputfilelist.append((filelist[i]._url, os.path.basename(filelist[i]._name)))
                        #print "<li><a href=%s>%s</a></li>" % (filelist[i]._url, filelist[i]._name)
                if outputfilelist:
                    print "</ul></li>"
                    print "<li>PDB2PKA files<ul>"
                    for outputfile in outputfilelist:
                        print "<li><a href=%s>%s</a></li>" % (outputfile[0], outputfile[1])
            else:
                outputfilelist = glob.glob('%s%s%s/pdb2pka_output/*.DAT' % (INSTALLDIR, TMPDIR, jobid))
                outputfilelist.extend(glob.glob('%s%s%s/pdb2pka_output/*.txt' % (INSTALLDIR, TMPDIR, jobid)))
                outputfilelist = [os.path.basename(outputfile) for outputfile in outputfilelist]
                if outputfilelist:
                    print "</ul></li>"
                    print "<li>PDB2PKA files<ul>"
                    for outputfile in outputfilelist:
                        print "<li><a href=%s%s%s/pdb2pka_output/%s>%s</a></li>" % (WEBSITE, TMPDIR, jobid, outputfile, outputfile)

        print "</ul></li>"
        print "<li>Runtime and debugging information<ul>"

        if have_opal:
            stdouturl = resp._stdOut
            stderrurl = resp._stdErr
        else:
            stdouturl = "%s%s%s/%s_stdout.txt" % (WEBSITE, TMPDIR, jobid, calctype)
            stderrurl = "%s%s%s/%s_stderr.txt" % (WEBSITE, TMPDIR, jobid, calctype)

        print "<li><a href=%s>Program output (stdout)</a></li>" % stdouturl
        print "<li><a href=%s>Program errors and warnings (stderr)</a></li>" % stderrurl


        print "</ul></li></ul>"


        #if have_opal:
        #    resp = appServicePort.getOutputs(getOutputsRequest(jobid))
        #    for opalfile in resp._outputFile:
        #        if opalfile._name[-8:]!="-input.p":
        #            print "<li><a href=%s>%s</a></li>" % (opalfile._url, opalfile._name)
        #    print "<li><a href=%s>Standard output</a></li>" % (resp._stdOut)
        #    print "<li><a href=%s>Standard error</a></li>" % (resp._stdErr)
        #else:
        #    for line in cp[1:]:
        #        line = os.path.basename(line)
        #        if line[-8:]!="-input.p":
        #            if line[-11:]=="_stdout.txt":
        #                printname = "Standard output"
        #            elif line[-11:]=="_stderr.txt":
        #                printname = "Standard error"
        #            else:
        #                printname = line
        #            print "<li><a href=%s>%s</a></li>" % (WEBSITE+TMPDIR+jobid+"/"+line,printname)

        if calctype=="pdb2pqr" and apbs_input and HAVE_APBS:
            print "</ul></p><hr><p><b><a href=%s>Click here</a> to run APBS with your results.</b></p>" % nexturl
        elif calctype=="apbs":
            #print "</ul></p><hr><p><b><a href=%s>Click here</a> to visualize your results in Jmol.</b></p>" % nexturl
            print "</ul></p><hr><p><b>Visualize your results online:"
            print "<ul> <li><a href=%s>3Dmol</a></li><li><a href=%s>Jmol</a></li></ul>" % (url_3dmol, url_jmol)

    elif progress == "error":
        print "There was an error with your query request. This page will not refresh."

        print "</ul></li>"
        print "<li>Runtime and debugging information<ul>"

        if have_opal:
            resp = appServicePort.getOutputs(getOutputsRequest(jobid))
            stdouturl = resp._stdOut
            stderrurl = resp._stdErr

        else:
            stdouturl = "%s%s%s/%s_stdout.txt" % (WEBSITE, TMPDIR, jobid, calctype)
            stderrurl = "%s%s%s/%s_stderr.txt" % (WEBSITE, TMPDIR, jobid, calctype)

        print "<li><a href=%s>Program output (stdout)</a></li>" % stdouturl
        print "<li><a href=%s>Program errors and warnings (stderr)</a></li>" % stderrurl

        print "</ul></li></ul>"

        if have_opal:
            print " <br />If your job has been running for a prolonged period of time and failed with no reason listed in the standard out or standard error, then the job probably timed out and was terminated by the system.<br />"

        print '<br />If you are having trouble running PDB2PQR on the webserver, please download the <a href="http://www.poissonboltzmann.org/docs/downloads/">command line version of PDB2PQR</a> and run the job from there.'



    elif progress == "running":
        print "Page will refresh in %d seconds<br />" % refresh
        print "<HR>"

        if not have_opal:
            print "</ul></li>"
            print "<li>Runtime and debugging information<ul>"
            stdouturl = "%s%s%s/%s_stdout.txt" % (WEBSITE, TMPDIR, jobid, calctype)
            stderrurl = "%s%s%s/%s_stderr.txt" % (WEBSITE, TMPDIR, jobid, calctype)
            print "<li><a href=%s>Program output (stdout)</a></li>" % stdouturl
            print "<li><a href=%s>Program errors and warnings (stderr)</a></li>" % stderrurl
            print "</ul></li></ul>"

        print "<small>Your results will appear at <a href=%s>this page</a>. If you want, you can bookmark it and come back later (note: results are only stored for approximately 12-24 hours).</small>" % resultsurl
    elif progress == "version_mismatch":
        print "The versions of APBS on the local server and on the Opal server do not match, so the calculation could not be completed"

    print "</P>"
    print "<script type=\"text/javascript\">"
    for key in logopts:
        print getEventTrackingString('queryData', key, logopts[key]),
        #print "_gaq.push(['_trackPageview', '/main_cgi/has_%s_%s.html']);" % (key, logopts[key])
    print "</script>"
    print "</div> <!--end content div-->"
    print "</BODY>"
    print "</HTML>"
示例#16
0
def handleOpal(weboptions):
    '''
        Handle opal based run.
    '''
    # Opal-specific import statements
    from AppService_client import AppServiceLocator, launchJobRequest
    from AppService_types import ns0

    inputFiles = []

    if 'userff' in weboptions:
        ffFile = ns0.InputFileType_Def('inputFile')
        ffFile._name = weboptions.userfffilename
        ffFile._contents = weboptions.userffstring
        inputFiles.append(ffFile)

    if 'usernames' in weboptions:
        namesFile = ns0.InputFileType_Def('inputFile')
        namesFile._name = weboptions.usernamesfilename
        namesFile._contents = weboptions.usernamesstring
        inputFiles.append(namesFile)

    if 'ligand' in weboptions:
        ligandFile = ns0.InputFileType_Def('inputFile')
        ligandFile._name = weboptions.ligandfilename
        ligandFile._contents = weboptions.ligandfilestring
        inputFiles.append(ligandFile)

    pdbOpalFile = ns0.InputFileType_Def('inputFile')
    pdbOpalFile._name = weboptions.pdbfilename
    pdbOpalFile._contents = weboptions.pdbfilestring
    inputFiles.append(pdbOpalFile)

    # launch job
    appLocator = AppServiceLocator()
    appServicePort = appLocator.getAppServicePort(PDB2PQR_OPAL_URL)

    req = launchJobRequest()
    req._argList = weboptions.getCommandLine()
    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>"
        print "<script type=\"text/javascript\">"
        print "var gaJsHost = ((\"https:\" == document.location.protocol) ? \"https://ssl.\" : \"http://www.\");"
        print "document.write(unescape(\"%3Cscript src=\'\" + gaJsHost + \"google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E\"));"
        print "</script>"
        print "<script type=\"text/javascript\">"
        print "try {"
        print "var pageTracker = _gat._getTracker(\"UA-11026338-3\");"
        for key in weboptions:
            print "pageTracker._trackPageview(\"/main_cgi/has_%s_%s.html\");" % (
                key, weboptions[key])
        print "pageTracker._trackPageview();"
        print "} catch(err) {}</script>"
        print "</BODY>"
        print "</HTML>"
        sys.exit(2)
示例#17
0
def handleOpal(weboptions):
    '''
        Handle opal based run.
    '''
    # Opal-specific import statements
    from AppService_client import AppServiceLocator, launchJobRequest
    from AppService_types import ns0

    inputFiles = []
    
    if 'userff' in weboptions:
        ffFile = ns0.InputFileType_Def('inputFile')
        ffFile._name = weboptions.userfffilename
        ffFile._contents = weboptions.userffstring
        inputFiles.append(ffFile)
        
    if 'usernames' in weboptions:
        namesFile = ns0.InputFileType_Def('inputFile')
        namesFile._name = weboptions.usernamesfilename
        namesFile._contents = weboptions.usernamesstring
        inputFiles.append(namesFile)
        
    if 'ligand' in weboptions:
        ligandFile = ns0.InputFileType_Def('inputFile')
        ligandFile._name = weboptions.ligandfilename
        ligandFile._contents = weboptions.ligandfilestring
        inputFiles.append(ligandFile)
        
    pdbOpalFile = ns0.InputFileType_Def('inputFile')
    pdbOpalFile._name = weboptions.pdbfilename
    pdbOpalFile._contents = weboptions.pdbfilestring
    inputFiles.append(pdbOpalFile)
     
    # launch job   
    appLocator = AppServiceLocator()
    appServicePort = appLocator.getAppServicePort(PDB2PQR_OPAL_URL)
    
    req = launchJobRequest()
    req._argList = weboptions.getCommandLine()
    req._inputFile=inputFiles

    try:
        resp=appServicePort.launchJob(req)
    except Exception as e:
        printHeader("PDB2PQR Job Submission - Error")
        print("<BODY>\n<P>")
        print("There was an error with your job submission<br>")
        print("</P>")
        print("<script type=\"text/javascript\">")
        print("var gaJsHost = ((\"https:\" == document.location.protocol) ? \"https://ssl.\" : \"http://www.\");")
        print("document.write(unescape(\"%3Cscript src=\'\" + gaJsHost + \"google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E\"));")
        print("</script>")
        print("<script type=\"text/javascript\">")
        print("try {")
        print("var pageTracker = _gat._getTracker(\"UA-11026338-3\");")
        for key in weboptions:
            print("pageTracker._trackPageview(\"/main_cgi/has_%s_%s.html\");" % (key, weboptions[key]))
        print("pageTracker._trackPageview();")
        print("} catch(err) {}</script>")
        print("</BODY>")
        print("</HTML>")
        sys.exit(2)
    
    try:
        starttime = time.time()
        name = setID(starttime)
        
        #Some job parameters logging.
        os.makedirs('%s%s%s' % (INSTALLDIR, TMPDIR, name))
        apbsInputFile = open('%s%s%s/apbs_input' % (INSTALLDIR, TMPDIR, name),'w')
        apbsInputFile.write(str(weboptions["apbs"]))
        apbsInputFile.close()
        
        typemapInputFile = open('%s%s%s/typemap' % (INSTALLDIR, TMPDIR, name),'w')
        typemapInputFile.write(str(weboptions["typemap"]))
        typemapInputFile.close()
        
        pdb2pqrOpalJobIDFile = open('%s%s%s/pdb2pqr_opal_job_id' % (INSTALLDIR, TMPDIR, name), 'w')
        pdb2pqrOpalJobIDFile.write(resp._jobID)
        pdb2pqrOpalJobIDFile.close()
        
        print(redirector(name, weboptions))
        
        # Recording CGI run information for PDB2PQR Opal
        pdb2pqrOpalLogFile = open('%s%s%s/pdb2pqr_log' % (INSTALLDIR, TMPDIR, name), 'w')
        pdb2pqrOpalLogFile.write(str(weboptions.getOptions())+'\n'+
                                 str(os.environ["REMOTE_ADDR"]))
        pdb2pqrOpalLogFile.close()

    except Exception as details:
        print(details)
        createError(name, details)
示例#18
0
def execApbs(vars=None, argv=None):
	""" Executes APBS and regulates checking of job status and retrieval of data if job is successfully completed. """
	if argv is None:
		# i.e. if it is a local run
		argv = sys.argv
		webRun = False
	else:
		webRun = True
		custom_service_url = None
		if vars != None:
			if vars.has_key('service_url'):
				custom_service_url = vars['service_url']
		vars = initRemoteVars(argv)
		if custom_service_url != None:
			vars['service_url'] = custom_service_url
	global service_url	
	#*argument parser
	# command-line arguments
	vars['inFile'] = argv[-1]
	
	# parses input file
	if(vars['inFile'].find("/")==-1):
		directory=""
	else:
		directory = os.path.dirname(vars['inFile'])+'/'
		vars['inFile'] = os.path.basename(vars['inFile'])
		
	nprocs = 1
	if not vars.has_key('service_url'):
		# find out if it's sequential or parallel
		tempFile = open(directory+vars['inFile'], 'r')
		version_check_flag = True
		for line in tempFile:
			# remove whitespace
			line=line.strip()
			if(line[:5]=='pdime'):
				dimension_array = line.split()
				nprocs = int(dimension_array[1])*int(dimension_array[2])*int(dimension_array[3])
				global parallel_service_url
				vars['service_url'] = parallel_service_url
				version_check_flag = False
			if(line[:5]=='async'):
				vars['service_url'] = service_url
				version_check_flag = True
				break
		if version_check_flag:
			vars['service_url'] = service_url
			
		tempFile.close()
	else:
		version_check_flag = True     # Enable version checking for custom defined Opal service as well 
		service_url = vars['service_url']
	# Retrieve a reference to the AppServicePort
	#*this is also from the path to the service
	appServicePort = AppServiceLocator().getAppServicePort(vars['service_url'])
	
	# Set up remote job launch
	req = launchJobRequest()
	# Checks version compatibility (but currently only works for sequential calculations)
	if version_check_flag:
		opal_version = AppServicePortTypeSoapBindingSOAP(vars['service_url']).getAppMetadata(getAppMetadataRequest())._usage.split()[-1]
		if opal_version != local_version:
			stderr.write("WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING!\n")
			stderr.write("It appears that the remote server version of APBS (%s) does not match\nthe local version (%s)!\n" % (opal_version,local_version))
			stderr.write("Proceed at your own risk!!\n")
			stderr.write("WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING!\n")
			if webRun:
				return False
	
	if(vars.has_key('argList')):
		vars['argList'] = vars['argList'] + " " + vars['inFile']
	else:
		vars['argList']=vars['inFile']
		
	req._argList = vars['argList']
	req._numProcs = nprocs
	# append all input files in this manner - in this case we have two of them
	
	inputFiles = []
	#*this is where apbs.in is read in
	inputFiles.append(ns0.InputFileType_Def('inputFile'))
	#*this must be the same as req._argList is defined to be
	inputFiles[-1]._name = vars['inFile']
	tempFile = open(directory+vars['inFile'], 'r')
	inputFiles[-1]._contents = tempFile.read()
	tempFile.close()
    
	# this is where the rest of the files to read in are determined
	start = False
	tempFile = open(directory+vars['inFile'], 'r')
	for line in tempFile:
		# remove whitespace
		line=line.strip()
		if(line=="end"):
			break
		if(start and line.find("#")!=0):
			# eliminates lines with just comments
			# remove comment
			if(line.find("#")!=-1):
				line = line[:line.find("#")]
			# re-remove whitespace (left after comment removal)
			line=line.strip()
			# remove everything except file name
			count = -1
			while line[count]!=' ':
				count = count-1
			fileName=line[count+1:]
			inputFiles.append(ns0.InputFileType_Def('inputFile'))
			inputFiles[-1]._name=fileName
			tempFile2 = open(directory+fileName, "r")
			inputFiles[-1]._contents = tempFile2.read()
			tempFile2.close()
		if(line=="read"):
			start = True
	
	tempFile.close()
	
	# req's inputFile variable is the array of input files created in the lines directly above
	req._inputFile = inputFiles
	
	if vars['typeOfRun']=='remote':
		appServicePort.launchJob(req)
		return [appServicePort, appServicePort.launchJob(req)]
	
	# Launch job, and retrieve job ID
	print "Launching remote APBS job"
	try:
		resp = appServicePort.launchJob(req)
	except ZSI.FaultException, errstr:
		stderr.write("Error! Failed to execute Opal job. Please send the entire output to the APBS development team.\n")
		stderr.write("%s\n" % errstr.fault.AsSoap())
		sys.exit(13)
示例#19
0
def mainCGI():
    """
        Main method for determining the query page output
    """
    logopts = {}
    print "Content-type: text/html\n\n"
    calctype = form["calctype"].value

    # prints version error, if it exists
    if form["jobid"].value == 'False':
        print printheader("%s Job Status Page" % calctype.upper())
        progress = "version_mismatch"
        runtime = 0
    else:
        progress = None

    # prepares for Opal query, if necessary
    if have_opal:
        if calctype == "pdb2pqr":
            opal_url = PDB2PQR_OPAL_URL
        elif calctype == "apbs":
            opal_url = APBS_OPAL_URL
        appLocator = AppServiceLocator()
        appServicePort = appLocator.getAppServicePort(opal_url)
    else:
        appServicePort = None

    # if PDB2PQR, determines if link to APBS calculation should be shown
    if calctype == "pdb2pqr":
        #if(form["apbsinput"].value=="True"): # change to use a file
        #    apbs_input = True
        #else:
        #    apbs_input = False
        apbsInputFile = open('%s%s%s/apbs_input' %
                             (INSTALLDIR, TMPDIR, form["jobid"].value))
        apbs_input = apbsInputFile.read()
        apbsInputFile.close()
        if apbs_input == "True":
            apbs_input = True
        else:
            apbs_input = False

        typemapInputFile = open('%s%s%s/typemap' %
                                (INSTALLDIR, TMPDIR, form["jobid"].value))
        typemap = typemapInputFile.read()
        typemapInputFile.close()
        if typemap == "True":
            typemap = True
        else:
            typemap = False

    if have_opal and progress == None:
        if form["calctype"].value == "pdb2pqr":
            pdb2pqrJobIDFile = open('%s%s%s/pdb2pqr_opal_job_id' %
                                    (INSTALLDIR, TMPDIR, form["jobid"].value))
            jobid = pdb2pqrJobIDFile.read()
            pdb2pqrJobIDFile.close()
        elif form["calctype"].value == "apbs":
            apbsJobIDFile = open('%s%s%s/apbs_opal_job_id' %
                                 (INSTALLDIR, TMPDIR, form["jobid"].value))
            jobid = apbsJobIDFile.read()
            apbsJobIDFile.close()
    else:
        jobid = form["jobid"].value

    if progress == None:
        cp = checkprogress(jobid, appServicePort,
                           calctype)  # finds out status of job
        progress = cp[0]

    if progress == "running" or progress == "complete":
        timefile = open(
            '%s%s%s/%s_start_time' %
            (INSTALLDIR, TMPDIR, form["jobid"].value, form["calctype"].value))
        starttime = float(timefile.read())
        timefile.close()
    if progress == "running" or (have_opal and progress != "version_mismatch"):
        runtime = time.time() - starttime
    elif progress == "complete":
        endtimefile = open(
            '%s%s%s/%s_end_time' %
            (INSTALLDIR, TMPDIR, form["jobid"].value, form["calctype"].value))
        runtime = float(endtimefile.read()) - starttime

    if progress == "running":
        #if have_opal:
        #    resultsurl = cp[1]._baseURL
        #else:
        if calctype == "pdb2pqr":
            resultsurl = '%squerystatus.cgi?jobid=%s&apbsinput=%s&calctype=pdb2pqr' % (
                WEBSITE, form["jobid"].value, apbs_input)
        else:
            resultsurl = '%squerystatus.cgi?jobid=%s&calctype=apbs' % (
                WEBSITE, form["jobid"].value)

    if progress == "complete":
        print printheader("%s Job Status Page" % calctype.upper())

    elif progress == "error":
        print printheader("%s Job Status Page - Error" % calctype.upper(), 0)

    elif progress == "running":  # job is not complete, refresh in 30 seconds
        print printheader("%s Job Status Page" % calctype.upper(), refresh)

    print "<BODY>\n<P>"
    print "<h3>Status"
    print "</h3>"
    print "Message: %s<br />" % progress
    print "Run time: %s seconds<br />" % int(runtime)
    print "Current time: %s<br />" % time.asctime()
    print "</P>\n<HR>\n<P>"

    if progress == "complete":
        if calctype == "pdb2pqr":
            nexturl = 'apbs_cgi.cgi?jobid=%s' % form["jobid"].value
        else:
            nexturl = 'visualize.cgi?jobid=%s' % form["jobid"].value

        if have_opal:
            resp = appServicePort.getOutputs(getOutputsRequest(jobid))
            filelist = resp._outputFile

        print "Here are the results:<ul>"
        print "<li>Input files<ul>"

        if calctype == "pdb2pqr":
            # this code should be cleaned up once local PDB2PQR runs output the PDB file with the .pdb extension
            if have_opal:
                for i in range(0, len(filelist)):
                    if len(filelist[i]._name) == 4:
                        print "<li><a href=%s>%s</a></li>" % (
                            filelist[i]._url, filelist[i]._name)
            else:
                print "<li><a href=%s%s%s/%s.pdb>%s.pdb</a></li>" % (
                    WEBSITE, TMPDIR, jobid, jobid, jobid)

        elif calctype == "apbs":
            if have_opal:
                for i in range(0, len(filelist)):
                    if filelist[i]._name == "apbsinput.in" or filelist[
                            i]._name[-4:] == ".pqr":
                        print "<li><a href=%s>%s</a></li>" % (
                            filelist[i]._url, filelist[i]._name)
            else:
                print "<li><a href=%s%s%s/apbsinput.in>apbsinput.in</a></li>" % (
                    WEBSITE, TMPDIR, jobid)
                print "<li><a href=%s%s%s/%s.pqr>%s.pqr</a></li>" % (
                    WEBSITE, TMPDIR, jobid, jobid, jobid)

        print "</ul></li>"
        print "<li>Output files<ul>"

        if calctype == "pdb2pqr":
            if have_opal:
                # Getting PDB2PQR Opal run log info
                if os.path.isfile('%s%s%s/pdb2pqr_opal_log' %
                                  (INSTALLDIR, TMPDIR, form["jobid"].value)):
                    pdb2pqrOpalLogFile = open(
                        '%s%s%s/pdb2pqr_opal_log' %
                        (INSTALLDIR, TMPDIR, form["jobid"].value), 'r')
                    logstr = pdb2pqrOpalLogFile.read().split('\n')
                    logopts = eval(logstr[0])
                    logff = logstr[1]
                    REMOTE_ADDR = logstr[2]
                    pdb2pqrOpalLogFile.close()
                for i in range(0, len(filelist)):
                    if filelist[i]._name[-7:] == ".propka" or (
                            filelist[i]._name[-13:] == "-typemap.html"
                            and typemap == True
                    ) or filelist[i]._name[-4:] == ".pqr" or filelist[i]._name[
                            -3:] == ".in":
                        if filelist[i]._name[-4:] == ".pqr":
                            # Getting pqr file length for PDB2PQR Opal run
                            f = urllib.urlopen(filelist[i]._url)
                            pqrOpalFileLength = len(f.readlines())
                            f.close()
                        print "<li><a href=%s>%s</a></li>" % (
                            filelist[i]._url, filelist[i]._name)
                logRun(logopts, runtime, pqrOpalFileLength, logff, REMOTE_ADDR)
            else:
                outputfilelist = glob.glob('%s%s%s/*.propka' %
                                           (INSTALLDIR, TMPDIR, jobid))
                for i in range(0, len(outputfilelist)):
                    outputfilelist[i] = os.path.basename(outputfilelist[i])
                for extension in ["-typemap.html", ".pqr", ".in"]:
                    if extension != ".in" or apbs_input != False:
                        if extension == "-typemap.html" and typemap == False:
                            continue
                        outputfilelist.append('%s%s' % (jobid, extension))
                for outputfile in outputfilelist:
                    print "<li><a href=%s%s%s/%s>%s</a></li>" % (
                        WEBSITE, TMPDIR, jobid, outputfile, outputfile)

                #for extension in ["-typemap.html", ".pqr", ".in"]:
                #    print "<li><a href=%s%s%s/%s%s>%s%s</a></li>" % (WEBSITE, TMPDIR, jobid, jobid, extension, jobid, extension)
        elif calctype == "apbs":
            if have_opal:
                for i in range(0, len(filelist)):
                    if filelist[i]._name[-3:] == ".dx":
                        # compressing APBS OpenDX output files
                        currentpath = os.getcwd()
                        zipjobid = filelist[i]._name.split("-")[0]
                        urllib.urlretrieve(
                            filelist[i]._url, '%s%s%s/%s' %
                            (INSTALLDIR, TMPDIR, zipjobid, filelist[i]._name))
                        os.chdir('%s%s%s' % (INSTALLDIR, TMPDIR, zipjobid))
                        syscommand = 'zip -9 ' + filelist[
                            i]._name + '.zip ' + filelist[i]._name
                        os.system(syscommand)
                        os.chdir(currentpath)
                        outputfilezip = filelist[i]._name + '.zip'
                        print "<li><a href=%s%s%s/%s>%s</a></li>" % (
                            WEBSITE, TMPDIR, zipjobid, outputfilezip,
                            outputfilezip)
            else:
                outputfilelist = glob.glob('%s%s%s/%s-*.dx' %
                                           (INSTALLDIR, TMPDIR, jobid, jobid))
                for outputfile in outputfilelist:
                    # compressing APBS OpenDX output files
                    currentpath = os.getcwd()
                    workingpath = os.path.dirname(outputfile)
                    os.chdir(workingpath)
                    syscommand = 'zip -9 ' + os.path.basename(
                        outputfile) + '.zip ' + os.path.basename(outputfile)
                    os.system(syscommand)
                    os.chdir(currentpath)
                    outputfilezip = outputfile + ".zip"
                    print "<li><a href=%s%s%s/%s>%s</a></li>" % (
                        WEBSITE, TMPDIR, jobid,
                        os.path.basename(outputfilezip),
                        os.path.basename(outputfilezip))

        print "</ul></li>"
        print "<li>Runtime and debugging information<ul>"

        if have_opal:
            stdouturl = resp._stdOut
            stderrurl = resp._stdErr
        else:
            stdouturl = "%s%s%s/%s_stdout.txt" % (WEBSITE, TMPDIR, jobid,
                                                  calctype)
            stderrurl = "%s%s%s/%s_stderr.txt" % (WEBSITE, TMPDIR, jobid,
                                                  calctype)

        print "<li><a href=%s>Program output (stdout)</a></li>" % stdouturl
        print "<li><a href=%s>Program errors and warnings (stderr)</a></li>" % stderrurl

        print "</ul></li></ul>"

        #if have_opal:
        #    resp = appServicePort.getOutputs(getOutputsRequest(jobid))
        #    for opalfile in resp._outputFile:
        #        if opalfile._name[-8:]!="-input.p":
        #            print "<li><a href=%s>%s</a></li>" % (opalfile._url, opalfile._name)
        #    print "<li><a href=%s>Standard output</a></li>" % (resp._stdOut)
        #    print "<li><a href=%s>Standard error</a></li>" % (resp._stdErr)
        #else:
        #    for line in cp[1:]:
        #        line = os.path.basename(line)
        #        if line[-8:]!="-input.p":
        #            if line[-11:]=="_stdout.txt":
        #                printname = "Standard output"
        #            elif line[-11:]=="_stderr.txt":
        #                printname = "Standard error"
        #            else:
        #                printname = line
        #            print "<li><a href=%s>%s</a></li>" % (WEBSITE+TMPDIR+jobid+"/"+line,printname)

        if calctype == "pdb2pqr" and apbs_input and HAVE_APBS != "":
            print "</ul></p><hr><p><a href=%s>Click here</a> to run APBS with your results.</p>" % nexturl
        elif calctype == "apbs":
            print "</ul></p><hr><p><a href=%s>Click here</a> to visualize your results.</p>" % nexturl

    elif progress == "error":
        print "There was an error with your query request. This page will not refresh."
    elif progress == "running":
        print "Page will refresh in %d seconds<br />" % refresh
        print "<HR>"
        print "<small>Your results will appear at <a href=%s>this page</a>. If you want, you can bookmark it and come back later (note: results are only stored for approximately 12-24 hours).</small>" % resultsurl
    elif progress == "version_mismatch":
        print "The versions of APBS on the local server and on the Opal server do not match, so the calculation could not be completed"

    print "</P>"
    print "<script type=\"text/javascript\">"
    print "var gaJsHost = ((\"https:\" == document.location.protocol) ? \"https://ssl.\" : \"http://www.\");"
    print "document.write(unescape(\"%3Cscript src=\'\" + gaJsHost + \"google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E\"));"
    print "</script>"
    print "<script type=\"text/javascript\">"
    print "try {"
    print "var pageTracker = _gat._getTracker(\"UA-11026338-3\");"
    if logopts != {}:
        for key in logopts:
            print "pageTracker._trackPageview(\"/main_cgi/has_%s_%s.html\");" % (
                key, logopts[key])
    print "pageTracker._trackPageview();"
    print "} catch(err) {}</script>"
    print "</BODY>"
    print "</HTML>"
示例#20
0
 def __init__(self, url):
     """ A OpalService can be contructed passing a string containing a valid Opal URL """
     self.url = url
     appLocator = AppServiceLocator()
     self.appServicePort = appLocator.getAppServicePort(self.url)
示例#21
0
# set the locations for the X509 certificate and key
#cert = "/Users/sriramkrishnan/certs/apbs_service.cert.pem"
#key = "/Users/sriramkrishnan/certs/apbs_service.privkey"

# If you are using a proxy cert, set both the cert 
# and key to the location of the proxy
# Proxies have to be RFC 3820 compliant (use grid-proxy-init -rfc)
cert = "/tmp/x509up_u1000"
key = "/tmp/x509up_u1000"

# Host and port for remote services
baseURL = proto + "://rocks-171.sdsc.edu:8443/"
#baseURL = proto + "://localhost:8080/"

# Retrieve a reference to the AppServicePort
appLocator = AppServiceLocator()
if proto == "http":
    appServicePort = appLocator.getAppServicePort(baseURL + "opal2/services/BabelServicePort")
else:
    if proto == "https":
	# example of ssl invocation
	appServicePort = appLocator.getAppServicePort(
	    baseURL + "opal2/services/cat",
	    ssl=1,
        transdict={'cert_file': cert, 'key_file': key},
	    transport=httplib.HTTPSConnection)
        print "setting cert to: " + cert
    else:
	print "Unknown protocol: ", proto
	sys.exit(1)
	
示例#22
0
def handleOpal(weboptions):
    '''
        Handle opal based run.
    '''
    # Opal-specific import statements
    from AppService_client import AppServiceLocator, getAppMetadataRequest, launchJobRequest, launchJobBlockingRequest, getOutputAsBase64ByNameRequest
    from AppService_types import ns0

    inputFiles = []
    
    if 'userff' in weboptions:
        ffFile = ns0.InputFileType_Def('inputFile')
        ffFile._name = weboptions.userfffilename
        ffFile._contents = weboptions.userffstring
        inputFiles.append(ffFile)
        
    if 'usernames' in weboptions:
        namesFile = ns0.InputFileType_Def('inputFile')
        namesFile._name = weboptions.usernamesfilename
        namesFile._contents = weboptions.usernamesstring
        inputFiles.append(namesFile)
        
    if 'ligand' in weboptions:
        ligandFile = ns0.InputFileType_Def('inputFile')
        ligandFile._name = weboptions.ligandfilename
        ligandFile._contents = weboptions.ligandfilestring
        inputFiles.append(ligandFile)
        
    pdbOpalFile = ns0.InputFileType_Def('inputFile')
    pdbOpalFile._name = weboptions.pdbfilename
    pdbOpalFile._contents = weboptions.pdbfilestring
    inputFiles.append(pdbOpalFile)
     
    # launch job   
    appLocator = AppServiceLocator()
    appServicePort = appLocator.getAppServicePort(PDB2PQR_OPAL_URL)
    
    req = launchJobRequest()
    req._argList = weboptions.getCommandLine()
    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>"
        print "<script type=\"text/javascript\">"
        print "var gaJsHost = ((\"https:\" == document.location.protocol) ? \"https://ssl.\" : \"http://www.\");"
        print "document.write(unescape(\"%3Cscript src=\'\" + gaJsHost + \"google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E\"));"
        print "</script>"
        print "<script type=\"text/javascript\">"
        print "try {"
        print "var pageTracker = _gat._getTracker(\"UA-11026338-3\");"
        for key in weboptions:
            print "pageTracker._trackPageview(\"/main_cgi/has_%s_%s.html\");" % (key, weboptions[key])
        print "pageTracker._trackPageview();"
        print "} catch(err) {}</script>"
        print "</BODY>"
        print "</HTML>"
        sys.exit(2)
示例#23
0
def mainCGI():
    """
        Main driver for running PDB2PQR from a web page
    """
    global ligandFile, pdbfilestring, templigandstring, ffFileString, name, pdblist, namesFileString, launchJobRequest, AppServiceLocator, pdbfilename, namesfile, fffile, ns0, ligandfilename, pdbfile, namesFile, ffFile
    print("Content-type: text/html\n")
    import cgi
    import cgitb

    cgitb.enable()
    form = cgi.FieldStorage()
    ff = form["FF"].value
    input = 0

    apbs_input = "INPUT" in form
    typemap = "TYPEMAP" in form
    neutraln = "NEUTRALN" in form
    neutralc = "NEUTRALC" in form

    if HAVE_PDB2PQR_OPAL == "1":
        have_opal = True
        # Opal-specific import statments
        from AppService_client import AppServiceLocator, launchJobRequest
        from AppService_types import ns0
        from ZSI.TC import String
    else:
        have_opal = False

    if have_opal:
        options = {"ff": ff}
        fffile = None
        namesfile = None
    else:
        options = {"extensions": {}}

    if "DEBUMP" in form:
        options["debump"] = 1
    else:
        options["debump"] = 0
    if "OPT" in form:
        options["opt"] = 1
    else:
        options["opt"] = 0
    if "PROPKA" in form:
        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 "PDBID" in form:
        pdbfile = getPDBFile(form["PDBID"].value)
        pdbfilename = form["PDBID"].value
    elif "PDB" in form:
        pdbfile = StringIO(form["PDB"].value)
        pdbfilename = form["PDB"].filename
        pdbfilename = pdbfilename.split(r'[/\\]')[-1]
    if "INPUT" in form:
        input = 1
        options["apbs"] = 1
    if "USERFF" in form:
        if have_opal:
            ffname = form["USERFF"].filename
            ffname = ffname.split(r'[/\\]')[-1]
            if ffname[-4:] == ".DAT":
                ffname = ffname[:-4]
            fffile = StringIO(form["USERFF"].value)
            namesfile = StringIO(form["USERNAMES"].value)
            options["ff"] = ffname
            options["userff"] = fffile
            options["usernames"] = namesfile
        else:
            userff = StringIO(form["USERFF"].value)
            usernames = StringIO(form["USERNAMES"].value)
            options["ff"] = "user-defined"
            options["userff"] = userff
            options["usernames"] = usernames
    if "FFOUT" in form:
        if form["FFOUT"].value != "internal":
            options["ffout"] = form["FFOUT"].value
    if "CHAIN" in form:
        options["chain"] = 1
    if "WHITESPACE" in form:
        options["whitespace"] = 1
    if "TYPEMAP" in form:
        options["typemap"] = 1
    if "NEUTRALN" in form:
        options["neutraln"] = 1
    if "NEUTRALC" in form:
        options["neutralc"] = 1
    if "LIGAND" in form:
        if have_opal:
            ligandfilename = str(form["LIGAND"].filename)
            ligandfilename = ligandfilename.split(r'[/\\]')[-1]

        # for Windows-style newline compatibility
        templigandfilename = tempfile.mkstemp()[1]
        templigandfile = open(templigandfilename, 'w')
        templigandfile.write(form["LIGAND"].value)
        templigandfile.close()
        templigandfile = open(templigandfilename, 'rU')
        if have_opal:
            options["ligand"] = templigandfile.read()
        else:
            templigandstring = templigandfile.read()  # this variable is used again later to write this file to output
            options["ligand"] = StringIO(templigandstring)

        templigandfile.close()

    if not have_opal:
        pdbfilestring = pdbfile.read()
        pdblist, errlist = readPDB(StringIO(pdbfilestring))
        dummydef = Definition()
        dummyprot = Protein(pdblist, dummydef)
        if len(pdblist) == 0 and len(errlist) == 0:
            text = "Unable to find PDB file - Please make sure this is "
            text += "a valid PDB file ID!"
            # print "Content-type: text/html\n"
            print(text)
            sys.exit(2)
        elif dummyprot.numAtoms() > MAXATOMS and "opt" in options:
            text = "<HTML><HEAD>"
            text += "<TITLE>PDB2PQR Error</title>"
            text += "<link rel=\"stylesheet\" href=\"%s\" type=\"text/css\">" % STYLESHEET
            text += "</HEAD><BODY><H2>PDB2PQR Error</H2><P>"
            text += "Due to server limits, we are currently unable to optimize "
            text += "proteins of greater than MAXATOMS atoms on the server (PDB2PQR "
            text += "found %s atoms in the selected PDB file).  If you " % dummyprot.numAtoms()
            text += "want to forgo optimization please try the server again.<P>"
            text += "Otherwise you may use the standalone version of PDB2PQR that "
            text += "is available from the <a href=\"http://pdb2pqr.sourceforge.net\">"
            text += "PDB2PQR SourceForge project page</a>."
            text += "<script type=\"text/javascript\">"
            text += "var gaJsHost = ((\"https:\" == document.location.protocol) ? \"https://ssl.\" : \"http://www.\");"
            text += "document.write(unescape(\"%3Cscript src=\'\" + gaJsHost + \"google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E\"));"
            text += "</script>"
            text += "<script type=\"text/javascript\">"
            text += "try {"
            text += "var pageTracker = _gat._getTracker(\"UA-11026338-3\");"
            for key in options:
                text += "pageTracker._trackPageview(\"/main_cgi/has_%s_%s.html\");" % (key, options[key])
            text += "pageTracker._trackPageview();"
            text += "} catch(err) {}</script>"
            text += "</BODY></HTML>"
            # print "Content-type: text/html\n"
            print(text)
            sys.exit(2)

    try:
        if have_opal:
            ligandFile = None
            ffFile = None
            namesFile = None
        # else:
        starttime = time.time()
        name = setID(starttime)

        os.makedirs('%s%s%s' % (INSTALLDIR, TMPDIR, name))
        apbsInputFile = open('%s%s%s/apbs_input' % (INSTALLDIR, TMPDIR, name), 'w')
        apbsInputFile.write(str(apbs_input))
        apbsInputFile.close()
        typemapInputFile = open('%s%s%s/typemap' % (INSTALLDIR, TMPDIR, name), 'w')
        typemapInputFile.write(str(typemap))
        typemapInputFile.close()

        if have_opal:
            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
                    ligandFile._contents = options["ligand"]
                elif key == "apbs":
                    key = "apbs-input"
                elif key == "chain":
                    key = "chain"
                elif key == "whitespace":
                    key = "whitespace"
                elif key == "typemap":
                    key = "typemap"
                elif key == "ff":
                    val = options[key]
                    key = "ff=%s" % val
                    if fffile:
                        ffFile = ns0.InputFileType_Def('inputFile')
                        ffFile._name = val + ".DAT"
                        ffFileString = fffile.read()
                        ffFile._contents = ffFileString
                    if namesfile:
                        namesFile = ns0.InputFileType_Def('inputFile')
                        namesFile._name = val + ".names"
                        namesFileString = namesfile.read()
                        namesFile._contents = namesFileString
                if key not in ["userff", "usernames"]:
                    myopts += "--" + str(key) + " "
            myopts += str(pdbfilename) + " "
            if pdbfilename[-4:] == ".pdb":
                myopts += "%s.pqr" % str(pdbfilename[:-4])
            else:
                myopts += "%s.pqr" % str(pdbfilename)
            appLocator = AppServiceLocator()
            appServicePort = appLocator.getAppServicePort(PDB2PQR_OPAL_URL)
            # launch job
            req = launchJobRequest()
            req._argList = myopts
            inputFiles = []
            pdbOpalFile = ns0.InputFileType_Def('inputFile')
            pdbOpalFile._name = pdbfilename
            pdbOpalFile._contents = pdbfile.read()
            pdbfile.close()
            inputFiles.append(pdbOpalFile)
            if ligandFile:
                inputFiles.append(ligandFile)
            if ffFile:
                inputFiles.append(ffFile)
            if namesFile:
                inputFiles.append(namesFile)
            req._inputFile = inputFiles
            try:
                resp = appServicePort.launchJob(req)
            except Exception as e:
                printHeader("PDB2PQR Job Submission - Error")
                print("<BODY>\n<P>")
                print("There was an error with your job submission<br>")
                print("</P>")
                print("<script type=\"text/javascript\">")
                print(
                    "var gaJsHost = ((\"https:\" == document.location.protocol) ? \"https://ssl.\" : \"http://www.\");")
                print(
                    "document.write(unescape(\"%3Cscript src=\'\" + gaJsHost + \"google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E\"));")
                print("</script>")
                print("<script type=\"text/javascript\">")
                print("try {")
                print("var pageTracker = _gat._getTracker(\"UA-11026338-3\");")
                for key in options:
                    print("pageTracker._trackPageview(\"/main_cgi/has_%s_%s.html\");" % (key, options[key]))
                print("pageTracker._trackPageview();")
                print("} catch(err) {}</script>")
                print("</BODY>")
                print("</HTML>")
                sys.exit(2)
            # printHeader("PDB2PQR Job Submission",have_opal,jobid=resp._jobID)
            pdb2pqrOpalJobIDFile = open('%s%s%s/pdb2pqr_opal_job_id' % (INSTALLDIR, TMPDIR, name), 'w')
            pdb2pqrOpalJobIDFile.write(resp._jobID)
            pdb2pqrOpalJobIDFile.close()
            print(redirector(name))
            if "userff" in options:
                options["userff"] = ffFileString
            if "usernames" in options:
                options["usernames"] = namesFileString
            # Recording CGI run information for PDB2PQR Opal
            pdb2pqrOpalLogFile = open('%s%s%s/pdb2pqr_opal_log' % (INSTALLDIR, TMPDIR, name), 'w')
            pdb2pqrOpalLogFile.write(str(options) + '\n' + str(ff) + '\n' + str(os.environ["REMOTE_ADDR"]))
            pdb2pqrOpalLogFile.close()

        else:
            # pqrpath = startServer(name)
            statusfile = open('%s%s%s/pdb2pqr_status' % (INSTALLDIR, TMPDIR, name), 'w')
            statusfile.write('running')
            statusfile.close()

            pid = os.fork()
            if pid:
                print(redirector(name))
                sys.exit()
            else:
                currentdir = os.getcwd()
                os.chdir("/")
                os.setsid()
                os.umask(0)
                os.chdir(currentdir)
                os.close(1)  # not sure if these
                os.close(2)  # two lines are necessary
                pqrpath = '%s%s%s/%s.pqr' % (INSTALLDIR, TMPDIR, name, name)
                options["outname"] = pqrpath
                options["verbose"] = ""
                orig_stdout = sys.stdout
                orig_stderr = sys.stderr
                sys.stdout = open('%s%s%s/pdb2pqr_stdout.txt' % (INSTALLDIR, TMPDIR, name), 'w')
                sys.stderr = open('%s%s%s/pdb2pqr_stderr.txt' % (INSTALLDIR, TMPDIR, name), 'w')
                header, lines, missedligands = runPDB2PQR(pdblist, ff, options)
                sys.stdout.close()
                sys.stderr.close()
                sys.stdout = orig_stdout
                sys.stderr = orig_stderr

                endtimefile = open('%s%s%s/pdb2pqr_end_time' % (INSTALLDIR, TMPDIR, name), 'w')
                endtimefile.write(str(time.time()))
                endtimefile.close()

                pqrfile = open(pqrpath, "w")
                pqrfile.write(header)
                for line in lines:  # type: object
                    # Adding whitespaces if --whitespace is in the options
                    if "whitespace" in options.keys() and options["whitespace"] == 1:
                        if line[0:4] == 'ATOM':
                            newline = line[0:16] + ' ' + line[16:38] + ' ' + line[38:46] + ' ' + line[46:]
                            pqrfile.write("%s\n" % newline.strip())
                        elif line[0:6] == 'HETATM':
                            newline = line[0:16] + ' ' + line[16:38] + ' ' + line[38:46] + ' ' + line[46:]
                            pqrfile.write("%s\n" % newline.strip())
                    else:
                        pqrfile.write("%s\n" % line.strip())
                pqrfile.close()

                if input:
                    from src import inputgen as Inp
                    from src import psize as Pz
                    method = "mg-auto"
                    size = Pz.Psize()
                    size.parseInput(pqrpath)
                    size.runPsize(pqrpath)
                    async = 0  # No async files here!
                    myinput = Inp.Input(pqrpath, size, method, async)
                    myinput.printInputFiles()
                    myinput.dumpPickle()

                endtime = time.time() - starttime
                # createResults(header, input, name, endtime, missedligands)
                logRun(options, endtime, len(lines), ff, os.environ["REMOTE_ADDR"])
                # printHeader("PDB2PQR Job Submission",have_opal,jobid=name)
                if "LIGAND" in form:
                    outputligandfile = open('%s%s%s/%s.mol2' % (INSTALLDIR, TMPDIR, name, name), 'w')
                    outputligandfile.write(templigandstring)
                    outputligandfile.close()
                outputpdbfile = open('%s%s%s/%s.pdb' % (INSTALLDIR, TMPDIR, name, name), 'w')
                outputpdbfile.write(pdbfilestring)
                outputpdbfile.close()

                statusfile = open('%s%s%s/pdb2pqr_status' % (INSTALLDIR, TMPDIR, name), 'w')
                statusfile.write('complete\n')
                filelist = glob.glob('%s%s%s/%s*' % (INSTALLDIR, TMPDIR, name, name))
                for filename in filelist:
                    statusfile.write(filename + '\n')
                statusfile.close()


    except SystemError.StandardError as details:
        print(details)
        createError(name, details)
示例#24
0
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)
示例#25
0
def mainCGI():
    """
        Main driver for running PDB2PQR from a web page
    """
    print "Content-type: text/html\n"
    import cgi
    import cgitb

    cgitb.enable()
    form = cgi.FieldStorage()
    ff = form["FF"].value 
    input = 0

    apbs_input = form.has_key("INPUT")
    typemap = form.has_key("TYPEMAP")
    neutraln = form.has_key("NEUTRALN")
    neutralc = form.has_key("NEUTRALC")

    if HAVE_PDB2PQR_OPAL=="1":
        have_opal = True
        # Opal-specific import statments
        from AppService_client import AppServiceLocator, getAppMetadataRequest, launchJobRequest, launchJobBlockingRequest, getOutputAsBase64ByNameRequest
        from AppService_types import ns0
        from ZSI.TC import String
    else:
        have_opal = False

    if have_opal:
        options = {}
        options["ff"] = ff
        fffile = None
        namesfile = None
    else:
        options = {"extensions":{}}
 
  
    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"):
        pdbfile = getPDBFile(form["PDBID"].value)
        pdbfilename = form["PDBID"].value
    elif form.has_key("PDB"):
        pdbfile = StringIO(form["PDB"].value)
        pdbfilename = form["PDB"].filename
        pdbfilename = re.split(r'[/\\]',pdbfilename)[-1]
    if form.has_key("INPUT"):
        input = 1
        options["apbs"] = 1
    if form.has_key("USERFF"):
        if have_opal:
            ffname = form["USERFF"].filename
            ffname = re.split(r'[/\\]',ffname)[-1]
            if ffname[-4:] == ".DAT":
               ffname = ffname[:-4]
            fffile = StringIO(form["USERFF"].value)
            namesfile = StringIO(form["USERNAMES"].value)
            options["ff"] = ffname
            options["userff"] = fffile
            options["usernames"] = namesfile
        else:
            userff = StringIO(form["USERFF"].value)
            usernames = StringIO(form["USERNAMES"].value)
            options["ff"] = "user-defined"
            options["userff"] = userff
            options["usernames"] = usernames
    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("TYPEMAP"):
        options["typemap"] = 1
    if form.has_key("NEUTRALN"):
        options["neutraln"] = 1
    if form.has_key("NEUTRALC"):
        options["neutralc"] = 1
    if form.has_key("LIGAND"):
        if have_opal:
            ligandfilename=str(form["LIGAND"].filename)
            ligandfilename=re.split(r'[/\\]',ligandfilename)[-1]

        # for Windows-style newline compatibility
        templigandfilename = tempfile.mkstemp()[1]
        templigandfile = open(templigandfilename,'w')
        templigandfile.write(form["LIGAND"].value)
        templigandfile.close()
        templigandfile = open(templigandfilename,'rU')
        if have_opal:
            options["ligand"] = templigandfile.read()
        else:
            templigandstring = templigandfile.read() # this variable is used again later to write this file to output
            options["ligand"] = StringIO(templigandstring)
            
        templigandfile.close()
        
    if not have_opal:
        pdbfilestring = pdbfile.read()
        pdblist, errlist = readPDB(StringIO(pdbfilestring))
        dummydef = Definition()
        dummyprot = Protein(pdblist, dummydef)
        if len(pdblist) == 0 and len(errlist) == 0:
            text = "Unable to find PDB file - Please make sure this is "
            text += "a valid PDB file ID!"
            #print "Content-type: text/html\n"
            print text
            sys.exit(2)
        elif dummyprot.numAtoms() > MAXATOMS and "opt" in options:
            text = "<HTML><HEAD>"
            text += "<TITLE>PDB2PQR Error</title>"
            text += "<link rel=\"stylesheet\" href=\"%s\" type=\"text/css\">" % STYLESHEET
            text += "</HEAD><BODY><H2>PDB2PQR Error</H2><P>"
            text += "Due to server limits, we are currently unable to optimize "
            text += "proteins of greater than MAXATOMS atoms on the server (PDB2PQR "
            text += "found %s atoms in the selected PDB file).  If you " % dummyprot.numAtoms()
            text += "want to forgo optimization please try the server again.<P>"
            text += "Otherwise you may use the standalone version of PDB2PQR that "
            text += "is available from the <a href=\"http://pdb2pqr.sourceforge.net\">"
            text += "PDB2PQR SourceForge project page</a>."
            text += "<script type=\"text/javascript\">"
            text += "var gaJsHost = ((\"https:\" == document.location.protocol) ? \"https://ssl.\" : \"http://www.\");"
            text += "document.write(unescape(\"%3Cscript src=\'\" + gaJsHost + \"google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E\"));"
            text += "</script>"
            text += "<script type=\"text/javascript\">"
            text += "try {"
            text += "var pageTracker = _gat._getTracker(\"UA-11026338-3\");"
            for key in options:
                text += "pageTracker._trackPageview(\"/main_cgi/has_%s_%s.html\");" % (key, options[key])
            text += "pageTracker._trackPageview();"
            text += "} catch(err) {}</script>"
            text += "</BODY></HTML>"
            #print "Content-type: text/html\n"
            print text
            sys.exit(2)

    try:
        if have_opal:
            ligandFile=None
            ffFile=None
            namesFile=None
        #else:
        starttime = time.time()
        name = setID(starttime)

        os.makedirs('%s%s%s' % (INSTALLDIR, TMPDIR, name))
        apbsInputFile = open('%s%s%s/apbs_input' % (INSTALLDIR, TMPDIR, name),'w')
        apbsInputFile.write(str(apbs_input))
        apbsInputFile.close()
        typemapInputFile = open('%s%s%s/typemap' % (INSTALLDIR, TMPDIR, name),'w')
        typemapInputFile.write(str(typemap))
        typemapInputFile.close()

        if have_opal:
            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
                    ligandFile._contents = options["ligand"]
                elif key=="apbs":
                    key="apbs-input"
                elif key=="chain":
                    key="chain"
                elif key=="whitespace":
                    key="whitespace"
                elif key=="typemap":
                    key="typemap"
                elif key=="ff":
                    val=options[key]
                    key="ff=%s" % val
                    if fffile:
                      ffFile = ns0.InputFileType_Def('inputFile')
                      ffFile._name = val + ".DAT"
                      ffFileString = fffile.read()
                      ffFile._contents = ffFileString
                    if namesfile:
                      namesFile = ns0.InputFileType_Def('inputFile')
                      namesFile._name = val + ".names"
                      namesFileString = namesfile.read()
                      namesFile._contents = namesFileString
                if key not in ["userff", "usernames"]:
                    myopts+="--"+str(key)+" "
            myopts+=str(pdbfilename)+" "
            if pdbfilename[-4:]==".pdb":
                myopts+="%s.pqr" % str(pdbfilename[:-4])
            else:
                myopts+="%s.pqr" % str(pdbfilename)
            appLocator = AppServiceLocator()
            appServicePort = appLocator.getAppServicePort(PDB2PQR_OPAL_URL)
            # launch job
            req = launchJobRequest()
            req._argList = myopts
            inputFiles = []
            pdbOpalFile = ns0.InputFileType_Def('inputFile')
            pdbOpalFile._name = pdbfilename
            pdbOpalFile._contents = pdbfile.read()
            pdbfile.close()
            inputFiles.append(pdbOpalFile)
            if ligandFile:
              inputFiles.append(ligandFile)
            if ffFile:
              inputFiles.append(ffFile)
            if namesFile:
              inputFiles.append(namesFile)
            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>"
                print "<script type=\"text/javascript\">"
                print "var gaJsHost = ((\"https:\" == document.location.protocol) ? \"https://ssl.\" : \"http://www.\");"
                print "document.write(unescape(\"%3Cscript src=\'\" + gaJsHost + \"google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E\"));"
                print "</script>"
                print "<script type=\"text/javascript\">"
                print "try {"
                print "var pageTracker = _gat._getTracker(\"UA-11026338-3\");"
                for key in options:
                    print "pageTracker._trackPageview(\"/main_cgi/has_%s_%s.html\");" % (key, options[key])
                print "pageTracker._trackPageview();"
                print "} catch(err) {}</script>"
                print "</BODY>"
                print "</HTML>"
                sys.exit(2)
            #printHeader("PDB2PQR Job Submission",have_opal,jobid=resp._jobID)
            pdb2pqrOpalJobIDFile = open('%s%s%s/pdb2pqr_opal_job_id' % (INSTALLDIR, TMPDIR, name), 'w')
            pdb2pqrOpalJobIDFile.write(resp._jobID)
            pdb2pqrOpalJobIDFile.close()
            print redirector(name)
            if options.has_key("userff"):
                options["userff"] = ffFileString
            if options.has_key("usernames"):
                options["usernames"] = namesFileString
            # Recording CGI run information for PDB2PQR Opal
            pdb2pqrOpalLogFile = open('%s%s%s/pdb2pqr_opal_log' % (INSTALLDIR, TMPDIR, name), 'w')
            pdb2pqrOpalLogFile.write(str(options)+'\n'+str(ff)+'\n'+str(os.environ["REMOTE_ADDR"]))
            pdb2pqrOpalLogFile.close()

        else:
示例#26
0
cert = "/Users/sriramkrishnan/certs/apbs_service.cert.pem"
key = "/Users/sriramkrishnan/certs/apbs_service.privkey"

# If you are using a proxy cert, set both the cert 
# and key to the location of the proxy
# Proxies have to be RFC 3820 compliant (use grid-proxy-init -rfc)
# cert = "/tmp/x509up_u506"
# key = "/tmp/x509up_u506"

# Host and port for remote services
# baseURL = proto + "://localhost:8080/"
baseURL = proto + "://ws.nbcr.net/"
# baseURL = proto + "://ws.nbcr.net:8443/"

# Retrieve a reference to the AppServicePort
appLocator = AppServiceLocator()
if proto == "http":
    appServicePort = appLocator.getAppServicePort(
	baseURL + "opal2/services/Pdb2pqrOpalService")
else:
    if proto == "https":
	# example of ssl invocation
	appServicePort = appLocator.getAppServicePort(
	    baseURL + "opal2/services/Pdb2pqrOpalService",
	    ssl=1,
	    transdict=dict(cert_file=cert, key_file=key),
	    transport=httplib.HTTPSConnection)
    else:
	print "Unknown protocol: ", proto
	sys.exit(1)
	
示例#27
0
    queryStatusRequest,
    getOutputsRequest,
    launchJobBlockingRequest,
    getOutputAsBase64ByNameRequest,
)
from AppService_types import ns0
from os import mkdir
from time import sleep
from ZSI.TC import String

# Set the location of our service
# A list of NBCR services can be found at http://ws.nbcr.net/opal2/dashboard?command=serviceList
serviceURL = "http://ws.nbcr.net/opal2/services/MEME_4.4.0"

# Instantiate a new service object to interact with.  Pass it the service location
appLocator = AppServiceLocator()
appServicePort = appLocator.getAppServicePort(serviceURL)

# Instantiate a new non-blocking job request
req = launchJobRequest()

# Set the command-line arguments for the job.
# Use DNA alphabet, and find 3 motifs.
req._argList = "meme crp0.fasta -dna -mod zoops -nmotifs 3"

# Get contents of local file to be used as input
fastaFile = open("./crp0.fasta", "r")
fastaFileContents = fastaFile.read()
fastaFile.close()

# Set name and content of remote input file.
示例#28
0
def handleOpal(weboptions):
    '''
        Handle opal based run.
    '''
    # Opal-specific import statements
    from AppService_client import AppServiceLocator, launchJobRequest
    from AppService_types import ns0

    inputFiles = []

    if 'userff' in weboptions:
        ffFile = ns0.InputFileType_Def('inputFile')
        ffFile._name = weboptions.userfffilename
        ffFile._contents = weboptions.userffstring
        inputFiles.append(ffFile)

    if 'usernames' in weboptions:
        namesFile = ns0.InputFileType_Def('inputFile')
        namesFile._name = weboptions.usernamesfilename
        namesFile._contents = weboptions.usernamesstring
        inputFiles.append(namesFile)

    if 'ligand' in weboptions:
        ligandFile = ns0.InputFileType_Def('inputFile')
        ligandFile._name = weboptions.ligandfilename
        ligandFile._contents = weboptions.ligandfilestring
        inputFiles.append(ligandFile)

    pdbOpalFile = ns0.InputFileType_Def('inputFile')
    pdbOpalFile._name = weboptions.pdbfilename
    pdbOpalFile._contents = weboptions.pdbfilestring
    inputFiles.append(pdbOpalFile)

    # launch job
    appLocator = AppServiceLocator()
    appServicePort = appLocator.getAppServicePort(PDB2PQR_OPAL_URL)

    req = launchJobRequest()
    req._argList = weboptions.getCommandLine()
    req._inputFile = inputFiles

    try:
        resp = appServicePort.launchJob(req)
    except Exception as e:
        printHeader("PDB2PQR Job Submission - Error")
        print("<BODY>\n<P>")
        print("There was an error with your job submission<br>")
        print("</P>")
        print("<script type=\"text/javascript\">")
        print(
            "var gaJsHost = ((\"https:\" == document.location.protocol) ? \"https://ssl.\" : \"http://www.\");"
        )
        print(
            "document.write(unescape(\"%3Cscript src=\'\" + gaJsHost + \"google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E\"));"
        )
        print("</script>")
        print("<script type=\"text/javascript\">")
        print("try {")
        print("var pageTracker = _gat._getTracker(\"UA-11026338-3\");")
        for key in weboptions:
            print("pageTracker._trackPageview(\"/main_cgi/has_%s_%s.html\");" %
                  (key, weboptions[key]))
        print("pageTracker._trackPageview();")
        print("} catch(err) {}</script>")
        print("</BODY>")
        print("</HTML>")
        sys.exit(2)

    try:
        starttime = time.time()
        name = setID(starttime)

        #Some job parameters logging.
        os.makedirs('%s%s%s' % (INSTALLDIR, TMPDIR, name))
        apbsInputFile = open('%s%s%s/apbs_input' % (INSTALLDIR, TMPDIR, name),
                             'w')
        apbsInputFile.write(str(weboptions["apbs"]))
        apbsInputFile.close()

        typemapInputFile = open('%s%s%s/typemap' % (INSTALLDIR, TMPDIR, name),
                                'w')
        typemapInputFile.write(str(weboptions["typemap"]))
        typemapInputFile.close()

        pdb2pqrOpalJobIDFile = open(
            '%s%s%s/pdb2pqr_opal_job_id' % (INSTALLDIR, TMPDIR, name), 'w')
        pdb2pqrOpalJobIDFile.write(resp._jobID)
        pdb2pqrOpalJobIDFile.close()

        print(redirector(name, weboptions))

        # Recording CGI run information for PDB2PQR Opal
        pdb2pqrOpalLogFile = open(
            '%s%s%s/pdb2pqr_log' % (INSTALLDIR, TMPDIR, name), 'w')
        pdb2pqrOpalLogFile.write(
            str(weboptions.getOptions()) + '\n' +
            str(os.environ["REMOTE_ADDR"]))
        pdb2pqrOpalLogFile.close()

    except Exception as details:
        print(details)
        createError(name, details)
def mainCGI():
    """
        Main method for determining the query page output
    """
    logopts = {}
    print "Content-type: text/html\n\n"
    calctype = form["calctype"].value

    # prints version error, if it exists
    if form["jobid"].value == "False":
        print printheader("%s Job Status Page" % calctype.upper())
        progress = "version_mismatch"
        runtime = 0
    elif form["jobid"].value == "notenoughmem":
        print printheader("%s Job Status Page" % calctype.upper())
        progress = "not_enough_memory"
        runtime = 0
    else:
        progress = None

    # Check for error html
    errorpath = "%s%s%s.html" % (INSTALLDIR, TMPDIR, form["jobid"].value)
    if os.path.isfile(errorpath):
        string = ""
        string += "<html>\n"
        string += "\t<head>\n"
        string += '\t\t<meta http-equiv="Refresh" content="0; url=%s%s%s.html">\n' % (
            WEBSITE,
            TMPDIR,
            form["jobid"].value,
        )
        string += "\t</head>\n"
        string += "</html>\n"
        print string
        return

    # prepares for Opal query, if necessary
    if have_opal:
        if calctype == "pdb2pqr":
            opal_url = PDB2PQR_OPAL_URL
        elif calctype == "apbs":
            opal_url = APBS_OPAL_URL
        appLocator = AppServiceLocator()
        appServicePort = appLocator.getAppServicePort(opal_url)
    else:
        appServicePort = None

    # if PDB2PQR, determines if link to APBS calculation should be shown
    if calctype == "pdb2pqr":
        # if(form["apbsinput"].value=="True"): # change to use a file
        #    apbs_input = True
        # else:
        #    apbs_input = False
        apbsInputFile = open("%s%s%s/apbs_input" % (INSTALLDIR, TMPDIR, form["jobid"].value))
        apbs_input = apbsInputFile.read()
        apbsInputFile.close()
        if apbs_input == "True":
            apbs_input = True
        else:
            apbs_input = False

        typemapInputFile = open("%s%s%s/typemap" % (INSTALLDIR, TMPDIR, form["jobid"].value))
        typemap = typemapInputFile.read()
        typemapInputFile.close()
        if typemap == "True":
            typemap = True
        else:
            typemap = False

    if have_opal and progress == None:
        if form["calctype"].value == "pdb2pqr":
            pdb2pqrJobIDFile = open("%s%s%s/pdb2pqr_opal_job_id" % (INSTALLDIR, TMPDIR, form["jobid"].value))
            jobid = pdb2pqrJobIDFile.read()
            pdb2pqrJobIDFile.close()
        elif form["calctype"].value == "apbs":
            apbsJobIDFile = open("%s%s%s/apbs_opal_job_id" % (INSTALLDIR, TMPDIR, form["jobid"].value))
            jobid = apbsJobIDFile.read()
            apbsJobIDFile.close()
    else:
        jobid = form["jobid"].value

    if progress == None:
        cp = checkprogress(jobid, appServicePort, calctype)  # finds out status of job
        progress = cp[0]

    # initialize with bogus value just in case
    starttime = time.time()

    if progress == "running" or progress == "complete":
        timefile = open("%s%s%s/%s_start_time" % (INSTALLDIR, TMPDIR, form["jobid"].value, form["calctype"].value))
        starttime = float(timefile.read())
        timefile.close()
    if progress == "running" or (
        have_opal and progress != "version_mismatch" and progress != "not_enough_memory" and progress != "error"
    ):
        runtime = time.time() - starttime
    elif progress == "complete":
        endtimefile = open("%s%s%s/%s_end_time" % (INSTALLDIR, TMPDIR, form["jobid"].value, form["calctype"].value))
        runtime = float(endtimefile.read()) - starttime
    else:
        runtime = -1

    if progress == "running":
        # if have_opal:
        #    resultsurl = cp[1]._baseURL
        # else:
        if calctype == "pdb2pqr":
            resultsurl = "%squerystatus.cgi?jobid=%s&apbsinput=%s&calctype=pdb2pqr" % (
                WEBSITE,
                form["jobid"].value,
                apbs_input,
            )
        else:
            resultsurl = "%squerystatus.cgi?jobid=%s&calctype=apbs" % (WEBSITE, form["jobid"].value)

    if progress == "complete":
        print printheader("%s Job Status Page" % calctype.upper())

    elif progress == "error":
        print printheader("%s Job Status Page - Error" % calctype.upper(), 0)

    elif progress == "running":  # job is not complete, refresh in 30 seconds
        print printheader("%s Job Status Page" % calctype.upper(), refresh)

    print "<BODY>\n<P>"
    print "<h3>Status"
    print "</h3>"
    print "Message: %s<br />" % progress
    print "Run time: %s seconds<br />" % int(runtime)
    print "Current time: %s<br />" % time.asctime()
    print "</P>\n<HR>\n<P>"

    if progress == "complete":
        if calctype == "pdb2pqr":
            nexturl = "apbs_cgi.cgi?jobid=%s" % form["jobid"].value
        else:
            nexturl = "visualize.cgi?jobid=%s" % form["jobid"].value

        if have_opal:
            resp = appServicePort.getOutputs(getOutputsRequest(jobid))
            filelist = resp._outputFile

        print "Here are the results:<ul>"
        print "<li>Input files<ul>"

        if calctype == "pdb2pqr":
            # this code should be cleaned up once local PDB2PQR runs output the PDB file with the .pdb extension
            if have_opal:
                for i in range(0, len(filelist)):
                    if len(filelist[i]._name) == 4:
                        print "<li><a href=%s>%s</a></li>" % (filelist[i]._url, filelist[i]._name)
            else:
                print "<li><a href=%s%s%s/%s.pdb>%s.pdb</a></li>" % (WEBSITE, TMPDIR, jobid, jobid, jobid)

        elif calctype == "apbs":
            if have_opal:
                for i in range(0, len(filelist)):
                    if filelist[i]._name == "apbsinput.in" or filelist[i]._name[-4:] == ".pqr":
                        print "<li><a href=%s>%s</a></li>" % (filelist[i]._url, filelist[i]._name)
            else:
                print "<li><a href=%s%s%s/apbsinput.in>apbsinput.in</a></li>" % (WEBSITE, TMPDIR, jobid)
                print "<li><a href=%s%s%s/%s.pqr>%s.pqr</a></li>" % (WEBSITE, TMPDIR, jobid, jobid, jobid)

        print "</ul></li>"
        print "<li>Output files<ul>"

        if calctype == "pdb2pqr":
            if have_opal:
                # Getting PDB2PQR Opal run log info
                if os.path.isfile("%s%s%s/pdb2pqr_opal_log" % (INSTALLDIR, TMPDIR, form["jobid"].value)):
                    pdb2pqrOpalLogFile = open(
                        "%s%s%s/pdb2pqr_opal_log" % (INSTALLDIR, TMPDIR, form["jobid"].value), "r"
                    )
                    logstr = pdb2pqrOpalLogFile.read().split("\n")
                    logopts = eval(logstr[0])
                    #                    logff = logstr[1]
                    #                    REMOTE_ADDR = logstr[2]
                    pdb2pqrOpalLogFile.close()
                for i in range(0, len(filelist)):
                    if (
                        filelist[i]._name[-7:] == ".propka"
                        or (filelist[i]._name[-13:] == "-typemap.html" and typemap == True)
                        or filelist[i]._name[-4:] == ".pqr"
                        or filelist[i]._name[-3:] == ".in"
                    ):
                        if filelist[i]._name[-4:] == ".pqr":
                            # Getting pqr file length for PDB2PQR Opal run
                            f = urllib.urlopen(filelist[i]._url)
                            pqrOpalFileLength = len(f.readlines())
                            f.close()
                        print "<li><a href=%s>%s</a></li>" % (filelist[i]._url, filelist[i]._name)
            #                logRun(logopts, runtime, pqrOpalFileLength, logff, REMOTE_ADDR)
            else:
                outputfilelist = glob.glob("%s%s%s/*.propka" % (INSTALLDIR, TMPDIR, jobid))
                for i in range(0, len(outputfilelist)):
                    outputfilelist[i] = os.path.basename(outputfilelist[i])
                for extension in ["-typemap.html", ".pqr", ".in"]:
                    if extension != ".in" or apbs_input != False:
                        if extension == "-typemap.html" and typemap == False:
                            continue
                        outputfilelist.append("%s%s" % (jobid, extension))
                for outputfile in outputfilelist:
                    print "<li><a href=%s%s%s/%s>%s</a></li>" % (WEBSITE, TMPDIR, jobid, outputfile, outputfile)

                # for extension in ["-typemap.html", ".pqr", ".in"]:
                #    print "<li><a href=%s%s%s/%s%s>%s%s</a></li>" % (WEBSITE, TMPDIR, jobid, jobid, extension, jobid, extension)
        elif calctype == "apbs":
            if have_opal:
                for i in range(0, len(filelist)):
                    if filelist[i]._name[-3:] == ".dx":
                        # compressing APBS OpenDX output files
                        currentpath = os.getcwd()
                        zipjobid = filelist[i]._name.split("-")[0]
                        urllib.urlretrieve(
                            filelist[i]._url, "%s%s%s/%s" % (INSTALLDIR, TMPDIR, zipjobid, filelist[i]._name)
                        )
                        os.chdir("%s%s%s" % (INSTALLDIR, TMPDIR, zipjobid))
                        # making both the dx file and the compressed file (.gz) available in the directory
                        syscommand = "cp %s dxbkupfile" % (filelist[i]._name)
                        os.system(syscommand)
                        syscommand = "gzip -9 " + filelist[i]._name
                        os.system(syscommand)
                        syscommand = "mv dxbkupfile %s" % (filelist[i]._name)
                        os.system(syscommand)
                        os.chdir(currentpath)
                        outputfilezip = filelist[i]._name + ".gz"
                        print "<li><a href=%s%s%s/%s>%s</a></li>" % (
                            WEBSITE,
                            TMPDIR,
                            zipjobid,
                            outputfilezip,
                            outputfilezip,
                        )
            else:
                outputfilelist = glob.glob("%s%s%s/%s-*.dx" % (INSTALLDIR, TMPDIR, jobid, jobid))
                for outputfile in outputfilelist:
                    # compressing APBS OpenDX output files
                    currentpath = os.getcwd()
                    workingpath = os.path.dirname(outputfile)
                    os.chdir(workingpath)
                    # making both the dx file and the compressed file (.gz) available in the directory
                    syscommand = "cp %s dxbkupfile" % (os.path.basename(outputfile))
                    os.system(syscommand)
                    syscommand = "gzip -9 " + os.path.basename(outputfile)
                    os.system(syscommand)
                    syscommand = "mv dxbkupfile %s" % (os.path.basename(outputfile))
                    os.system(syscommand)
                    os.chdir(currentpath)
                    outputfilezip = outputfile + ".gz"
                    print "<li><a href=%s%s%s/%s>%s</a></li>" % (
                        WEBSITE,
                        TMPDIR,
                        jobid,
                        os.path.basename(outputfilezip),
                        os.path.basename(outputfilezip),
                    )

        print "</ul></li>"
        print "<li>Runtime and debugging information<ul>"

        if have_opal:
            stdouturl = resp._stdOut
            stderrurl = resp._stdErr
        else:
            stdouturl = "%s%s%s/%s_stdout.txt" % (WEBSITE, TMPDIR, jobid, calctype)
            stderrurl = "%s%s%s/%s_stderr.txt" % (WEBSITE, TMPDIR, jobid, calctype)

        print "<li><a href=%s>Program output (stdout)</a></li>" % stdouturl
        print "<li><a href=%s>Program errors and warnings (stderr)</a></li>" % stderrurl

        print "</ul></li></ul>"

        # if have_opal:
        #    resp = appServicePort.getOutputs(getOutputsRequest(jobid))
        #    for opalfile in resp._outputFile:
        #        if opalfile._name[-8:]!="-input.p":
        #            print "<li><a href=%s>%s</a></li>" % (opalfile._url, opalfile._name)
        #    print "<li><a href=%s>Standard output</a></li>" % (resp._stdOut)
        #    print "<li><a href=%s>Standard error</a></li>" % (resp._stdErr)
        # else:
        #    for line in cp[1:]:
        #        line = os.path.basename(line)
        #        if line[-8:]!="-input.p":
        #            if line[-11:]=="_stdout.txt":
        #                printname = "Standard output"
        #            elif line[-11:]=="_stderr.txt":
        #                printname = "Standard error"
        #            else:
        #                printname = line
        #            print "<li><a href=%s>%s</a></li>" % (WEBSITE+TMPDIR+jobid+"/"+line,printname)

        if calctype == "pdb2pqr" and apbs_input and HAVE_APBS != "":
            print "</ul></p><hr><p><a href=%s>Click here</a> to run APBS with your results.</p>" % nexturl
        elif calctype == "apbs":
            print "</ul></p><hr><p><a href=%s>Click here</a> to visualize your results.</p>" % nexturl

    elif progress == "error":
        print "There was an error with your query request. This page will not refresh."
    elif progress == "running":
        print "Page will refresh in %d seconds<br />" % refresh
        print "<HR>"
        print "<small>Your results will appear at <a href=%s>this page</a>. If you want, you can bookmark it and come back later (note: results are only stored for approximately 12-24 hours).</small>" % resultsurl
    elif progress == "version_mismatch":
        print "The versions of APBS on the local server and on the Opal server do not match, so the calculation could not be completed"

    print "</P>"
    print '<script type="text/javascript">'
    print 'var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");'
    print "document.write(unescape(\"%3Cscript src='\" + gaJsHost + \"google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E\"));"
    print "</script>"
    print '<script type="text/javascript">'
    print "try {"
    print 'var pageTracker = _gat._getTracker("UA-11026338-3");'
    if logopts != {}:
        for key in logopts:
            print 'pageTracker._trackPageview("/main_cgi/has_%s_%s.html");' % (key, logopts[key])
    print "pageTracker._trackPageview();"
    print "} catch(err) {}</script>"
    print "</BODY>"
    print "</HTML>"
示例#30
0
def initialize():
    global _modules

    if configuration.check('urlList'):
        urlList = configuration.urlList.split(";")
    else:
        return

    module_descs = []

    opal_url = urlList[0]

    if not opal_url:
        print "ERROR: No Opal URL provided"
        return
    
    services = []

    for opal_url in urlList:
        if opal_url.find("/opal2") != -1:
            service_list_url = opal_url + "/opalServices.xml"
            opener = urllib.FancyURLopener({})
            socket = opener.open(service_list_url)
            text = socket.read()
            feed = xml.dom.minidom.parseString(text)
            for entry in feed.getElementsByTagName('entry'):
                link = entry.getElementsByTagName('link')[0]
                service = link.getAttribute('href')
                services.append(str(service))
        else:
            print "ERROR: No opal2 contained in URL"
            return

    for url in services:
        namespace = os.path.dirname(os.path.dirname(url))
        servername = urlparse.urlparse(url)[1]
        servername = servername.replace('.','_')
        servername = servername.split(':')[0]
        node_name = os.path.basename(url) + '_' + servername
        appLocator = AppServiceLocator()
        appServicePort = appLocator.getAppServicePort(url)
        req = getAppMetadataRequest()
        metadata = appServicePort.getAppMetadata(req)

        if url == 'http://ws.nbcr.net/opal2/services/Pdb2pqrOpalService':
            print "------------------------\n"
            print metadata
            print "------------------------\n"

        ip_list = []
        pdesc_dic = {}

        try:
            separator = metadata._types._taggedParams._separator

            if separator == None:
                separator = " "
        except AttributeError:
            separator = " "
            
        try:
            rawlist = metadata._types._flags._flag

            for i in rawlist:
                pdesc_dic[str(i._id)] = str(i._textDesc)
                meta = {'url': url, 'type': 'FLAG', 'file': False, 'arg': str(i._tag), 'default': None, 'adv': True}
                if i._default and str(i._default) == 'True':
                    meta['default'] = 'True'
                    ip_list.append((str(i._id), "basic:Boolean", {"defaults": str([str('True')]), "labels": str([str(i._textDesc)]), "optional": True}, meta))
                else:
                    ip_list.append((str(i._id), "basic:Boolean", {"labels": str([str(i._textDesc)]), "optional": True}, meta))
        except AttributeError:
            flaglist = []
            
        try:
            rawlist = metadata._types._taggedParams._param

            for i in rawlist:
                #print "TAGID is " + str(i._tag)
                meta = {'url': url, 'type': 'TAGGED', 'file': False, 'default': None, 'adv': True}
                meta['arg'] = str(i._tag) + str(separator)
                pdesc_dic[str(i._id)] = str(i._textDesc)
                tagged_object = getTaggedParam(metadata, str(i._id))

                if (tagged_object._paramType == 'FILE') and (tagged_object._ioType == 'INPUT'):
                    meta['file'] = True
                    
                    if i._default:
                        meta['default'] = str(i._default)
                        ip_list.append((str(i._id), "basic:File", {"defaults": str([str(i._default)]), "labels": str([str(i._textDesc)]), "optional": True}, meta))
                    else:
                        ip_list.append((str(i._id), "basic:File", {"labels": str([str(i._textDesc)]), "optional": True}, meta))
                else:
                    meta['file'] = False

                    if i._default:
                        meta['default'] = str(i._default)
                        ip_list.append((str(i._id), "basic:String", {"defaults": str([str(i._default)]), "labels": str([str(i._textDesc)]), "optional": True}, meta))
                    else:
                        ip_list.append((str(i._id), "basic:String", {"labels": str([str(i._textDesc)]), "optional": True}, meta))
        except AttributeError:
            taglist = []

        try:
            rawlist = metadata._types._untaggedParams._param
            #untaglist = [str(i._id) for i in rawlist]
            for i in rawlist:
                meta = {'url': url, 'type': 'UNTAGGED', 'file': False, 'default': None, 'adv': True}
                meta['arg'] = str(i._id) 
                pdesc_dic[str(i._id)] = str(i._textDesc)                
                untagged_object = getUntaggedParam(metadata, meta['arg'])

                if (untagged_object._paramType=='FILE') and (untagged_object._ioType=='INPUT'):
                    meta['file'] = True
                    ip_list.append((str(i._id), "basic:File", {"labels": str([str(i._textDesc)]), "optional": True}, meta))
                else:
                    if i._default:
                        meta['default'] = str(i._default)
                        ip_list.append((str(i._id), "basic:String", {"defaults": str([str(i._default)]), "labels": str([str(i._textDesc)]), "optional": True}, meta))
                    else:
                        ip_list.append((str(i._id), "basic:String", {"labels": str([str(i._textDesc)]), "optional": True}, meta))
        except AttributeError:
            untaglist = []

        pdesc_keys = pdesc_dic.keys()
        pdesc_keys.sort()

        mod_doc = metadata._usage + "\n"
        mod_doc += "\n***************** Input Parameters ****************\n\n"

        for pk in pdesc_keys:
            mod_doc += pk + ": " + pdesc_dic[pk] + "\n"

        if ip_list == []:
            meta = {'url': url, 'type': 'simple', 'default': None, 'adv': False}
            ip_list.append(("commandLine", "basic:String", {"labels": str(["Command line arguments"]), "optional": True}, meta))
            ip_list.append(("inFiles", "basic:List", {"labels": str(["Input file list"]), "optional": True}, meta))
            ip_list.append(("numProcs", "basic:Integer", {"labels": str(["Number of processors"]), "optional": True}, meta))

        def ws_compute(self):
            if self._port_list[0][3]['url'] != None:
                url = self._port_list[0][3]['url']
                adv = self._port_list[0][3]['adv']
            else:
                url = ""
                print "ERROR: There are no input arguments provided for this web service"

            cmdline = ""
            numProcs = None
            tagged = []
            untagged = []
            flags = []
            files = []

            for i in self._port_list:
                pn = i[0]
                meta = i[3]

                if ((self.hasInputFromPort(pn) and self.getInputFromPort(pn) != "") or meta['default'] != None) and adv == True:
#                    print "META"
#                    print meta

                    if meta['type'] == 'FLAG':
                        if self.hasInputFromPort(pn):
                            if self.getInputFromPort(pn) == True:
                                flags.append(meta['arg'])
                        elif meta['default'] == 'True':
                            flags.append(meta['arg'])
                    elif meta['type'] == 'TAGGED':
                        if self.hasInputFromPort(pn):
                            val = self.getInputFromPort(pn)
                        elif meta['default'] != None:
                            val = meta['default']

                        if meta['file'] == True:
                            file_an = core.modules.basic_modules.File.translate_to_string(val)
                            file_bn = os.path.basename(file_an)
                            tagged.append(meta['arg'] + file_bn)
                            files.append(file_an)
                        else:
                            tagged.append(meta['arg'] + val)
                    elif meta['type'] == 'UNTAGGED':
                        if self.hasInputFromPort(pn):
                            val = self.getInputFromPort(pn)
                        elif meta['default'] != None:
                            val = meta['default']

                        if meta['file'] == True:
                            file_an = core.modules.basic_modules.File.translate_to_string(val)
                            file_bn = os.path.basename(file_an)
                            untagged.append(file_bn)
                            files.append(file_an)
                        else:
                            untagged.append(val)
                            
                    cmdline = ""

                    for i in flags:
                        cmdline += i + " "
                    for i in tagged:
                        cmdline += i + " "
                    for i in untagged:
                        cmdline += i + " "

            inputFiles = []

            for i in files:
                inputFile = ns0.InputFileType_Def('inputFile')
                inputFile._name = os.path.basename(i)                     
                inputFile._attachment = open(i, "r")
                inputFiles.append(inputFile)

            if cmdline == "":
                if self.hasInputFromPort('commandLine'):
                    cmdline = self.getInputFromPort('commandLine')
                if self.hasInputFromPort('numProcs'):
                    numProcs = self.getInputFromPort('numProcs')
                if self.hasInputFromPort("inFiles"):
                    inFilesPath = self.getInputFromPort("inFiles")
                    if inFilesPath != None:
                        for i in inFilesPath:
                            inputFile = ns0.InputFileType_Def('inputFile')
                            inputFile._name = os.path.basename(i)                     
                            inputFile._attachment = open(i, "r")
                            inputFiles.append(inputFile)
            
            print os.path.basename(url) + " from " + os.path.dirname(url) + " is going to run with arguments:\n     " + cmdline 

            appLocator = AppServiceLocator()
            appServicePort = appLocator.getAppServicePort(url)
            req = launchJobRequest()
            req._argList = cmdline
            req._inputFile = inputFiles
            if numProcs != None:
                req._numProcs = numProcs
            resp = appServicePort.launchJob(req)
            self.jobID = resp._jobID
            print "Job outputs URL: " + resp._status._baseURL # urlparse.urljoin(url, '/' + self.jobID)
            status = resp._status._code

            while (status != 4 and status != 8):
                status = appServicePort.queryStatus(queryStatusRequest(self.jobID))._code
                time.sleep(5)
             
            if (status == 8):
                resp = appServicePort.getOutputs(getOutputsRequest(self.jobID))
                outurls = [str(resp._stdOut), str(resp._stdErr)]
                if (resp._outputFile != None):
                    for i in resp._outputFile:
                        outurls.append(str(i._url))
                    print "Opal job completed successfully"
            else:
                print "ERROR: Opal job failed"
                resp = appServicePort.getOutputs(getOutputsRequest(self.jobID))
                outurls = [str(resp._stdOut), str(resp._stdErr)]

            self.setResult("outurls", tuple(outurls))

        module_descs.append((node_name, 
                             {"_inputs": get_ports(ip_list),                        
                              "_outputs": [("outurls", "basic:List")],
                              "_doc": mod_doc,
                              "namespace": namespace},
                             {"compute": ws_compute,            
                              "_port_list": ip_list,
                              }))

              
#    if configuration.use_b:
    _modules = build_modules(module_descs)
示例#31
0
def mainCGI():
    """
        Main method for determining the query page output
    """
    logopts = {}
    print "Content-type: text/html\n\n"
    calctype = form["calctype"].value

    # prints version error, if it exists
    if form["jobid"].value == 'False':
        print printheader("%s Job Status Page" % calctype.upper())
        progress = "version_mismatch"
        runtime = 0
    elif form["jobid"].value == 'notenoughmem':
        print printheader("%s Job Status Page" % calctype.upper())
        progress = "not_enough_memory"
        runtime = 0
    else:
        progress = None

    #Check for error html
    errorpath = '%s%s%s.html' % (INSTALLDIR, TMPDIR, form["jobid"].value)
    if os.path.isfile(errorpath):
        string = ""
        string += "<html>\n"
        string += "\t<head>\n"
        string += "\t\t<meta http-equiv=\"Refresh\" content=\"0; url=%s%s%s.html\">\n" % (
            WEBSITE, TMPDIR, form["jobid"].value)
        string += "\t</head>\n"
        string += "</html>\n"
        print string
        return

    # prepares for Opal query, if necessary
    if have_opal:
        if calctype == "pdb2pqr":
            opal_url = PDB2PQR_OPAL_URL
        elif calctype == "apbs":
            opal_url = APBS_OPAL_URL
        appLocator = AppServiceLocator()
        appServicePort = appLocator.getAppServicePort(opal_url)
    else:
        appServicePort = None

    # if PDB2PQR, determines if link to APBS calculation should be shown
    if calctype == "pdb2pqr":
        #if(form["apbsinput"].value=="True"): # change to use a file
        #    apbs_input = True
        #else:
        #    apbs_input = False
        apbsInputFile = open('%s%s%s/apbs_input' %
                             (INSTALLDIR, TMPDIR, form["jobid"].value))
        apbs_input = apbsInputFile.read()
        apbsInputFile.close()
        if apbs_input == "True":
            apbs_input = True
        else:
            apbs_input = False

        typemapInputFile = open('%s%s%s/typemap' %
                                (INSTALLDIR, TMPDIR, form["jobid"].value))
        typemap = typemapInputFile.read()
        typemapInputFile.close()
        if typemap == "True":
            typemap = True
        else:
            typemap = False

    if have_opal and progress == None:
        if form["calctype"].value == "pdb2pqr":
            pdb2pqrJobIDFile = open('%s%s%s/pdb2pqr_opal_job_id' %
                                    (INSTALLDIR, TMPDIR, form["jobid"].value))
            jobid = pdb2pqrJobIDFile.read()
            pdb2pqrJobIDFile.close()
        elif form["calctype"].value == "apbs":
            apbsJobIDFile = open('%s%s%s/apbs_opal_job_id' %
                                 (INSTALLDIR, TMPDIR, form["jobid"].value))
            jobid = apbsJobIDFile.read()
            apbsJobIDFile.close()
    else:
        jobid = form["jobid"].value

    if progress == None:
        cp = checkprogress(jobid, appServicePort,
                           calctype)  # finds out status of job
        progress = cp[0]

    #initialize with bogus value just in case
    starttime = time.time()

    if progress == "running" or progress == "complete":
        timefile = open(
            '%s%s%s/%s_start_time' %
            (INSTALLDIR, TMPDIR, form["jobid"].value, form["calctype"].value))
        starttime = float(timefile.read())
        timefile.close()
    if progress == "running" or (have_opal and progress not in (
            "version_mismatch", "not_enough_memory", "error", "complete")):
        runtime = time.time() - starttime
    elif progress == "complete":
        endTimeFileString = '%s%s%s/%s_end_time' % (
            INSTALLDIR, TMPDIR, form["jobid"].value, form["calctype"].value)
        if have_opal and not os.path.isfile(endTimeFileString):
            runtime = time.time() - starttime
            with open(endTimeFileString, 'w') as endTimeFile:
                endTimeFile.write(str(time.time()))
        else:
            with open(endTimeFileString, 'r') as endTimeFile:
                runtime = float(endTimeFile.read()) - starttime
    else:
        runtime = -1

    if progress == "running":
        #if have_opal:
        #    resultsurl = cp[1]._baseURL
        #else:
        if calctype == "pdb2pqr":
            resultsurl = '%squerystatus.cgi?jobid=%s&apbsinput=%s&calctype=pdb2pqr' % (
                WEBSITE, form["jobid"].value, apbs_input)
        else:
            resultsurl = '%squerystatus.cgi?jobid=%s&calctype=apbs' % (
                WEBSITE, form["jobid"].value)

    if progress == "complete":
        print printheader("%s Job Status Page" % calctype.upper(),
                          jobid=form["jobid"].value)

    elif progress == "error":
        print printheader("%s Job Status Page - Error" % calctype.upper(),
                          0,
                          jobid=form["jobid"].value)

    elif progress == "running":  # job is not complete, refresh in 30 seconds
        print printheader("%s Job Status Page" % calctype.upper(),
                          refresh,
                          jobid=form["jobid"].value)

    print "<BODY>\n<P>"
    print "<h3>Status"
    print "</h3>"
    print "Message: %s<br />" % progress
    print "Run time: %s seconds<br />" % int(runtime)
    print "Current time: %s<br />" % time.asctime()
    print "</P>\n<HR>\n<P>"

    if progress == "complete":
        if calctype == "pdb2pqr":
            nexturl = 'apbs_cgi.cgi?jobid=%s' % form["jobid"].value
        else:
            nexturl = 'visualize.cgi?jobid=%s' % form["jobid"].value

        if have_opal:
            resp = appServicePort.getOutputs(getOutputsRequest(jobid))
            filelist = resp._outputFile

        print "Here are the results:<ul>"
        print "<li>Input files<ul>"

        if calctype == "pdb2pqr":
            # this code should be cleaned up once local PDB2PQR runs output the PDB file with the .pdb extension
            if have_opal:
                for i in range(0, len(filelist)):
                    if len(filelist[i]._name) == 4:
                        print "<li><a href=%s>%s</a></li>" % (
                            filelist[i]._url, filelist[i]._name)
            else:
                print "<li><a href=%s%s%s/%s.pdb>%s.pdb</a></li>" % (
                    WEBSITE, TMPDIR, jobid, jobid, jobid)

        elif calctype == "apbs":
            if have_opal:
                for i in range(0, len(filelist)):
                    if filelist[i]._name == "apbsinput.in" or filelist[
                            i]._name[-4:] == ".pqr":
                        print "<li><a href=%s>%s</a></li>" % (
                            filelist[i]._url, filelist[i]._name)
            else:
                print "<li><a href=%s%s%s/apbsinput.in>apbsinput.in</a></li>" % (
                    WEBSITE, TMPDIR, jobid)
                print "<li><a href=%s%s%s/%s.pqr>%s.pqr</a></li>" % (
                    WEBSITE, TMPDIR, jobid, jobid, jobid)

        print "</ul></li>"
        print "<li>Output files<ul>"

        queryString = [str(os.environ["REMOTE_ADDR"])]
        # Getting PDB2PQR run log info
        if os.path.isfile('%s%s%s/pdb2pqr_log' % (INSTALLDIR, TMPDIR, jobid)):
            pdb2pqrLogFile = open(
                '%s%s%s/pdb2pqr_log' % (INSTALLDIR, TMPDIR, jobid), 'r')
            logstr = pdb2pqrLogFile.read().split('\n')
            templogopts = eval(logstr[0])
            pdb2pqrLogFile.close()
            queryString.insert(0, templogopts.get('pdb', ''))

        if calctype == "pdb2pqr":
            if have_opal:
                for i in range(0, len(filelist)):
                    if filelist[i]._name.endswith(
                        (".propka", "-typemap.html", ".pqr", ".in")):
                        #                        if filelist[i]._name[-4:]==".pqr":
                        #                            # Getting pqr file length for PDB2PQR Opal run
                        #                            f=urllib.urlopen(filelist[i]._url)
                        #                            #pqrOpalFileLength = len(f.readlines())
                        #                            f.close()
                        print "<li><a href=%s>%s</a></li>" % (
                            filelist[i]._url, filelist[i]._name)

                    #Get the first line of the summary file.
                    if filelist[i]._name.endswith(".summary"):
                        f = urllib.urlopen(filelist[i]._url)
                        summaryLine = f.readline().strip()
                        #logopts["pdb"]=logopts.get("pdb", "") + "|" + summaryLine
                        queryString.append(summaryLine)
                        f.close()


#                logRun(logopts, runtime, pqrOpalFileLength, logff, REMOTE_ADDR)
            else:
                #Get the first line of the summary file.
                summaryFile = '%s%s%s/%s%s' % (INSTALLDIR, TMPDIR, jobid,
                                               jobid, ".summary")
                if os.path.isfile(summaryFile):
                    with open(summaryFile) as f:
                        summaryLine = f.readline().strip()
                        #logopts["pdb"]=logopts.get("pdb", "") + "|" + summaryLine
                        queryString.append(summaryLine)

                outputfilelist = glob.glob('%s%s%s/*.propka' %
                                           (INSTALLDIR, TMPDIR, jobid))
                for i in range(0, len(outputfilelist)):
                    outputfilelist[i] = os.path.basename(outputfilelist[i])
                for extension in ["-typemap.html", ".pqr", ".in"]:
                    if extension != ".in" or apbs_input != False:
                        if extension == "-typemap.html" and typemap == False:
                            continue
                        outputfilelist.append('%s%s' % (jobid, extension))
                for outputfile in outputfilelist:
                    print "<li><a href=%s%s%s/%s>%s</a></li>" % (
                        WEBSITE, TMPDIR, jobid, outputfile, outputfile)

            logopts['queryPDB2PQR'] = '|'.join(queryString)

            #for extension in ["-typemap.html", ".pqr", ".in"]:
            #    print "<li><a href=%s%s%s/%s%s>%s%s</a></li>" % (WEBSITE, TMPDIR, jobid, jobid, extension, jobid, extension)
        elif calctype == "apbs":
            if have_opal:
                for i in range(0, len(filelist)):
                    if filelist[i]._name[-3:] == ".dx":
                        # compressing APBS OpenDX output files
                        currentpath = os.getcwd()
                        zipjobid = filelist[i]._name.split("-")[0]
                        urllib.urlretrieve(
                            filelist[i]._url, '%s%s%s/%s' %
                            (INSTALLDIR, TMPDIR, zipjobid, filelist[i]._name))
                        os.chdir('%s%s%s' % (INSTALLDIR, TMPDIR, zipjobid))
                        # making both the dx file and the compressed file (.gz) available in the directory
                        syscommand = 'cp %s dxbkupfile' % (filelist[i]._name)
                        os.system(syscommand)
                        syscommand = 'gzip -9 ' + filelist[i]._name
                        os.system(syscommand)
                        syscommand = 'mv dxbkupfile %s' % (filelist[i]._name)
                        os.system(syscommand)
                        os.chdir(currentpath)
                        outputfilezip = filelist[i]._name + '.gz'
                        print "<li><a href=%s%s%s/%s>%s</a></li>" % (
                            WEBSITE, TMPDIR, zipjobid, outputfilezip,
                            outputfilezip)
            else:
                outputfilelist = glob.glob('%s%s%s/%s-*.dx' %
                                           (INSTALLDIR, TMPDIR, jobid, jobid))
                for outputfile in outputfilelist:
                    # compressing APBS OpenDX output files
                    currentpath = os.getcwd()
                    workingpath = os.path.dirname(outputfile)
                    os.chdir(workingpath)
                    # making both the dx file and the compressed file (.gz) available in the directory
                    syscommand = 'cp %s dxbkupfile' % (
                        os.path.basename(outputfile))
                    os.system(syscommand)
                    syscommand = 'gzip -9 ' + os.path.basename(outputfile)
                    os.system(syscommand)
                    syscommand = 'mv dxbkupfile %s' % (
                        os.path.basename(outputfile))
                    os.system(syscommand)
                    os.chdir(currentpath)
                    outputfilezip = outputfile + ".gz"
                    print "<li><a href=%s%s%s/%s>%s</a></li>" % (
                        WEBSITE, TMPDIR, jobid,
                        os.path.basename(outputfilezip),
                        os.path.basename(outputfilezip))

            logopts['queryAPBS'] = '|'.join(queryString)

        print "</ul></li>"
        print "<li>Runtime and debugging information<ul>"

        if have_opal:
            stdouturl = resp._stdOut
            stderrurl = resp._stdErr
        else:
            stdouturl = "%s%s%s/%s_stdout.txt" % (WEBSITE, TMPDIR, jobid,
                                                  calctype)
            stderrurl = "%s%s%s/%s_stderr.txt" % (WEBSITE, TMPDIR, jobid,
                                                  calctype)

        print "<li><a href=%s>Program output (stdout)</a></li>" % stdouturl
        print "<li><a href=%s>Program errors and warnings (stderr)</a></li>" % stderrurl

        print "</ul></li></ul>"

        #if have_opal:
        #    resp = appServicePort.getOutputs(getOutputsRequest(jobid))
        #    for opalfile in resp._outputFile:
        #        if opalfile._name[-8:]!="-input.p":
        #            print "<li><a href=%s>%s</a></li>" % (opalfile._url, opalfile._name)
        #    print "<li><a href=%s>Standard output</a></li>" % (resp._stdOut)
        #    print "<li><a href=%s>Standard error</a></li>" % (resp._stdErr)
        #else:
        #    for line in cp[1:]:
        #        line = os.path.basename(line)
        #        if line[-8:]!="-input.p":
        #            if line[-11:]=="_stdout.txt":
        #                printname = "Standard output"
        #            elif line[-11:]=="_stderr.txt":
        #                printname = "Standard error"
        #            else:
        #                printname = line
        #            print "<li><a href=%s>%s</a></li>" % (WEBSITE+TMPDIR+jobid+"/"+line,printname)

        if calctype == "pdb2pqr" and apbs_input and HAVE_APBS != "":
            print "</ul></p><hr><p><b><a href=%s>Click here</a> to run APBS with your results.</b></p>" % nexturl
        elif calctype == "apbs":
            print "</ul></p><hr><p><b><a href=%s>Click here</a> to visualize your results.</b></p>" % nexturl

    elif progress == "error":
        print "There was an error with your query request. This page will not refresh."
    elif progress == "running":
        print "Page will refresh in %d seconds<br />" % refresh
        print "<HR>"
        print "<small>Your results will appear at <a href=%s>this page</a>. If you want, you can bookmark it and come back later (note: results are only stored for approximately 12-24 hours).</small>" % resultsurl
    elif progress == "version_mismatch":
        print "The versions of APBS on the local server and on the Opal server do not match, so the calculation could not be completed"

    print "</P>"
    print "<script type=\"text/javascript\">"
    for key in logopts:
        print getEventTrackingString('queryData', key, logopts[key]),
        #print "_gaq.push(['_trackPageview', '/main_cgi/has_%s_%s.html']);" % (key, logopts[key])
    print "</script>"
    print "</BODY>"
    print "</HTML>"
示例#32
0
        def ws_compute(self):
            if self._port_list[0][3]['url'] != None:
                url = self._port_list[0][3]['url']
                adv = self._port_list[0][3]['adv']
            else:
                url = ""
                print "ERROR: There are no input arguments provided for this web service"

            cmdline = ""
            numProcs = None
            tagged = []
            untagged = []
            flags = []
            files = []

            for i in self._port_list:
                pn = i[0]
                meta = i[3]

                if ((self.hasInputFromPort(pn) and self.getInputFromPort(pn) != "") or meta['default'] != None) and adv == True:
#                    print "META"
#                    print meta

                    if meta['type'] == 'FLAG':
                        if self.hasInputFromPort(pn):
                            if self.getInputFromPort(pn) == True:
                                flags.append(meta['arg'])
                        elif meta['default'] == 'True':
                            flags.append(meta['arg'])
                    elif meta['type'] == 'TAGGED':
                        if self.hasInputFromPort(pn):
                            val = self.getInputFromPort(pn)
                        elif meta['default'] != None:
                            val = meta['default']

                        if meta['file'] == True:
                            file_an = core.modules.basic_modules.File.translate_to_string(val)
                            file_bn = os.path.basename(file_an)
                            tagged.append(meta['arg'] + file_bn)
                            files.append(file_an)
                        else:
                            tagged.append(meta['arg'] + val)
                    elif meta['type'] == 'UNTAGGED':
                        if self.hasInputFromPort(pn):
                            val = self.getInputFromPort(pn)
                        elif meta['default'] != None:
                            val = meta['default']

                        if meta['file'] == True:
                            file_an = core.modules.basic_modules.File.translate_to_string(val)
                            file_bn = os.path.basename(file_an)
                            untagged.append(file_bn)
                            files.append(file_an)
                        else:
                            untagged.append(val)
                            
                    cmdline = ""

                    for i in flags:
                        cmdline += i + " "
                    for i in tagged:
                        cmdline += i + " "
                    for i in untagged:
                        cmdline += i + " "

            inputFiles = []

            for i in files:
                inputFile = ns0.InputFileType_Def('inputFile')
                inputFile._name = os.path.basename(i)                     
                inputFile._attachment = open(i, "r")
                inputFiles.append(inputFile)

            if cmdline == "":
                if self.hasInputFromPort('commandLine'):
                    cmdline = self.getInputFromPort('commandLine')
                if self.hasInputFromPort('numProcs'):
                    numProcs = self.getInputFromPort('numProcs')
                if self.hasInputFromPort("inFiles"):
                    inFilesPath = self.getInputFromPort("inFiles")
                    if inFilesPath != None:
                        for i in inFilesPath:
                            inputFile = ns0.InputFileType_Def('inputFile')
                            inputFile._name = os.path.basename(i)                     
                            inputFile._attachment = open(i, "r")
                            inputFiles.append(inputFile)
            
            print os.path.basename(url) + " from " + os.path.dirname(url) + " is going to run with arguments:\n     " + cmdline 

            appLocator = AppServiceLocator()
            appServicePort = appLocator.getAppServicePort(url)
            req = launchJobRequest()
            req._argList = cmdline
            req._inputFile = inputFiles
            if numProcs != None:
                req._numProcs = numProcs
            resp = appServicePort.launchJob(req)
            self.jobID = resp._jobID
            print "Job outputs URL: " + resp._status._baseURL # urlparse.urljoin(url, '/' + self.jobID)
            status = resp._status._code

            while (status != 4 and status != 8):
                status = appServicePort.queryStatus(queryStatusRequest(self.jobID))._code
                time.sleep(5)
             
            if (status == 8):
                resp = appServicePort.getOutputs(getOutputsRequest(self.jobID))
                outurls = [str(resp._stdOut), str(resp._stdErr)]
                if (resp._outputFile != None):
                    for i in resp._outputFile:
                        outurls.append(str(i._url))
                    print "Opal job completed successfully"
            else:
                print "ERROR: Opal job failed"
                resp = appServicePort.getOutputs(getOutputsRequest(self.jobID))
                outurls = [str(resp._stdOut), str(resp._stdErr)]

            self.setResult("outurls", tuple(outurls))