Пример #1
0
 def setup(self, work_dir=None, ccp4i2_xml=None, rvapi_document=None, show_gui=False):
     if not pyrvapi or not self.generate_output:
         return
     title = "AMPLE Results"
     logger.debug("Using Andre's Pyrvapi" if API else "COULD NOT FIND Andre's API!")
     if rvapi_document:
         logger.debug("Restoring document: %s", rvapi_document)
         pyrvapi.rvapi_restore_document2(rvapi_document)
         self.jsrview_dir = os.path.dirname(rvapi_document)
     else:
         # Quick hack to init with Andre's stuff - can switch out for Felix's API when done
         logger.debug("Starting with xml %s", ccp4i2_xml)
         self.jsrview_dir = os.path.join(work_dir, "jsrview")
         if not os.path.isdir(self.jsrview_dir):
             os.mkdir(self.jsrview_dir)
         kwargs = dict(wintitle=title,
                       reportdir=self.jsrview_dir,
                       xml=ccp4i2_xml,
                       abspaths=False,
                       # bug in jsrview:
                       # layout = 4 if i1 else 7,
                      )
         API.document.newdoc(**kwargs)
     if not self.own_log_tab:
         self.log_tab_id = pyrvapi.rvapi_get_meta()
     if show_gui:
         # We start our own browser
         jsrview = os.path.join(os.environ["CCP4"], "libexec", "jsrview")
         subprocess.Popen([jsrview, os.path.join(self.jsrview_dir, "index.html")])
     return
Пример #2
0
    def setup(self,
              work_dir=None,
              ccp4i2_xml=None,
              rvapi_document=None,
              no_gui=None,
              own_gui=False):
        if not pyrvapi or no_gui: return
        report_dir = os.path.join(work_dir, "jsrview")
        if not os.path.isdir(report_dir): os.mkdir(report_dir)
        docid = "AMPLE_results"
        title = "AMPLE Results"
        logger.debug(
            "Using Andre's Pyrvapi" if API else "COULD NOT FIND Andre's API!")
        if API is None:
            share_jsrview = os.path.join(os.environ["CCP4"], "share",
                                         "jsrview")
            pyrvapi.rvapi_init_document(docid, report_dir, title, 1, 7,
                                        share_jsrview, None, None, None, None)
        else:
            if rvapi_document:
                logger.debug("Restoring document: {0}".format(rvapi_document))
                pyrvapi.rvapi_restore_document2(rvapi_document)
            else:
                # Quick hack to init with Andre's stuff - can switch out for Felix's API when done
                logger.debug("Starting with xml {0}".format(ccp4i2_xml))
                kwargs = dict(
                    wintitle=title,
                    reportdir=report_dir,
                    xml=ccp4i2_xml,
                    abspaths=False,
                    # bug in jsrview:
                    # layout = 4 if i1 else 7,
                )
                API.document.newdoc(**kwargs)

        if own_gui:
            # We start our own browser
            jsrview = os.path.join(os.environ["CCP4"], "libexec", "jsrview")
            subprocess.Popen([jsrview, os.path.join(report_dir, "index.html")])
        return
Пример #3
0
 def restoreReportDocument(self):
     #if not os.path.isfile(self.rvapi_doc_path):
     #    print " *** NO PATH TO RVAPI DOCUMENT"
     pyrvapi.rvapi_restore_document2(self.rvapi_doc_path)
     return pyrvapi.rvapi_get_meta()
Пример #4
0
    def __init__(self, args=None):
        #   args = optional replacement for sys.argv to allow this class to be
        #     called from within other Python programs (such as tests)

        rvapi_v = "...................."
        pyrvapi.rvapi_version(rvapi_v)
        rvapi_v = rvapi_v.split(".")
        self.rvapi_version[0] = int(rvapi_v[0])
        self.rvapi_version[1] = int(rvapi_v[1])
        self.rvapi_version[2] = int(rvapi_v[2].replace("\x00", ""))

        self.workdir = os.getcwd()
        self.output_meta["retcode"] = ""
        self.output_meta["report_row"] = 0
        self.output_meta["results"] = {}
        self.output_meta["resorder"] = []

        self.file_stdout = sys.stdout
        self.file_stderr = sys.stderr

        # first parse command-line parameters

        if args is None:
            args = sys.argv[1:]

        narg = 0
        while narg < len(args):
            key = args[narg]
            narg += 1
            if key == "--sge" or key == "--mp": self.exeType = key
            elif key == "--no-simbad12": self.trySimbad12 = False
            elif key == "--no-morda": self.tryMoRDa = False
            elif key == "--no-crank2": self.tryCrank2 = False
            elif key == "--no-fitligands": self.tryFitLigands = False
            elif narg < len(args):
                value = args[narg]
                if key == "--wkdir": self.workdir = value
                elif key == "--rdir": self.reportdir = value
                elif key == "--outdir": self.outputdir = value
                elif key == "--rvapi-prefix": self.rvapi_prefix = value
                elif key == "--rvapi-document": self.rvapi_doc_path = value
                elif key == "--jobid": self.jobId = value
                elif key == "--qname": self.queueName = value
                elif key == "--njobs": self.nSubJobs = int(value)
                else:
                    self.output_meta[
                        "retcode"] = "[01-001] unknown command line parameter"
                    self.stderr(" *** unrecognised command line parameter " +
                                key)
                narg += 1

        # read data from standard input

        self.stdout("\n INPUT DATA:" +
                    "\n -----------------------------------------------")
        ilist = sys.stdin.read().splitlines()
        for i in range(len(ilist)):
            s = ilist[i].strip()
            if s.startswith("HKLIN"):
                self.hklpath = s.replace("HKLIN", "", 1).strip()
                self.stdout("\n HKLIN " + self.hklpath)
            elif s.startswith("SEQIN"):
                self.seqpath = s.replace("SEQIN", "", 1).strip()
                self.stdout("\n SEQIN " + self.seqpath)
            elif s.startswith("XYZIN"):
                self.xyzpath = s.replace("XYZIN", "", 1).strip()
                self.stdout("\n XYZIN " + self.xyzpath)
            elif s.startswith("HATOMS"):
                self.ha_type = s.replace("HATOMS", "", 1).strip()
                self.stdout("\n HATOMS " + self.ha_type)
            elif s.startswith("LIGAND"):
                lst = filter(None, s.replace("LIGAND", "", 1).split(" "))
                self.ligands.append(lst)
                self.stdout("\n LIGAND " + lst[0])
                if len(lst) > 1:
                    self.stdout(" " + lst[1])
            elif s:
                self.output_meta[
                    "retcode"] = "[01-002] unrecognised input line"
                self.stderr(" *** unrecognised input line " + s + "\n")
        self.stdout("\n -----------------------------------------------\n")

        # initialise work directory structure

        self.scriptsdir = os.path.join(self.workdir, "scripts")
        if not os.path.isdir(self.scriptsdir):
            os.mkdir(self.scriptsdir)

        outdir = os.path.join(self.workdir, self.outputdir)
        if not os.path.isdir(outdir):
            os.mkdir(outdir)

        # initialise RVAPI report

        self.layout = 4
        if self.compare_rvapi_version([1, 0, 15]) <= 0:
            self.layout = 0

        self.page_cursor = [self.summaryTabId, 0]
        if not self.rvapi_doc_path:  # initialise rvapi report document

            report_type = 1  # report with tabs
            if not self.rvapi_prefix or not self.reportdir:
                report_type = 0x00100000  # report will not be created

            rdir = self.reportdir
            if not rdir:
                rdir = "report"
            rdir = os.path.join(self.workdir,
                                rdir)  # has to be full path because of Crank-2

            if not os.path.isdir(rdir):
                os.mkdir(rdir)

            # initialise HTML report document; note that we use absolute path for
            # the report directory, which is necessary for passing RVAPI document
            # to applications via creation of the rvapi_document file with
            # pyrvapi.rvapi_store_document2(..)

            pyrvapi.rvapi_init_document(
                "jscofe_report",  # document Id
                rdir,  # report directory
                "Title",  # title (immaterial)
                report_type,  # HTML report to be produced
                self.layout,  # Report will start with plain page
                self.rvapi_prefix,  # where to look for js support
                None,
                None,
                "task.tsk",
                "i2.xml")

            if self.layout == 0:
                # Add tree widget
                pyrvapi.rvapi_add_tree_widget(
                    self.navTreeId,  # tree widget reference (Id)
                    "Workflow",  # tree widget title
                    "body",  # reference to widget holder (grid)
                    0,  # holder row
                    0,  # holder column
                    1,  # row span
                    1  # column span
                )
                pyrvapi.rvapi_set_tab_proxy(self.navTreeId, "")

            self.page_cursor = self.addTab(self.summaryTabId, "Summary", True)
            self.putMessage(
                "<h2>CCP4go (Combined Automated Structure Solution)</h2>")

        else:  # continue rvapi document given
            pyrvapi.rvapi_restore_document2(self.rvapi_doc_path)
            meta = pyrvapi.rvapi_get_meta()
            #self.stdout ( "\n META = " + meta )
            if meta:
                d = json.loads(meta)
                if "jobId" in d: self.jobId = d["jobId"]
                if "stageNo" in d: self.stage_no = d["stageNo"]
                if "sge_q" in d: self.SGE = True
                if "sge_tc" in d: self.nSubJobs = d["sge_tc"]
                if "summaryTabId" in d:
                    self.summaryTabId = d["summaryTabId"]
                    self.page_cursor[0] = self.summaryTabId
                if "summaryTabRow" in d:
                    self.summaryTabRow = d["summaryTabRow"]
                    self.page_cursor[1] = self.summaryTabRow
                if "navTreeId" in d:
                    self.navTreeId = d["navTreeId"]
                    pyrvapi.rvapi_set_tab_proxy(self.navTreeId, "")
                if "outputDir" in d: self.outputdir = d["outputDir"]
                if "outputName" in d: self.outputname = d["outputName"]
            #self.stdout ( "\n summaryTabId = " + self.summaryTabId )
            #self.stdout ( "\n summaryTabRow = " + str(self.summaryTabRow) )
            #self.stdout ( "\n layout = " + str(self.layout) )
            #self.stdout ( "\n navTreeId = " + self.navTreeId + "\n" )
            #self.putMessage ( "<h2>YYYYYYYYYYYYYYY</h2>" )
            #self.page_cursor = self.addTab ( "new","New",True )
            #self.putMessage ( "<h2>ZZZZZZZZZZZZZZZZ</h2>" )
            #self.file_stdout.write ( "nSubJobs=" + str(self.nSubJobs) + "\n" )

        return
Пример #5
0
 def __init__(self, identifier, html_fname=None, *args, **kwargs):
     self._identifier = identifier
     self._html_fname = html_fname
     pyrvapi.rvapi_restore_document2(self._html_fname)
Пример #6
0
    def __init__(self, rvapi_document, webserver_uri, display_gui, logfile, work_dir, ccp4i2_xml=None, tab_prefix=""):
        self.rvapi_document = rvapi_document
        self.webserver_uri = webserver_uri
        self.display_gui = display_gui
        self.logfile = logfile
        self.work_dir = work_dir
        self.ccp4i2 = bool(ccp4i2_xml)
        self.tab_prefix = tab_prefix

        self.jsrview_dir = None
        self._webserver_start = None
        self.log_tab_id = None
        self.lattice_results_tab_id = None
        self.lattice_df = None
        self.contaminant_results_tab_id = None
        self.contaminant_df = None
        self.morda_db_results_tab_id = None
        self.morda_db_df = None
        self.summary_tab_id = None
        self.summary_tab_results_sec_id = None
        self.citation_tab_id = None

        self.lattice_search_results_displayed = False
        self.contaminant_results_displayed = False
        self.morda_results_displayed = False

        self.jscofe_mode = False
        self.ccp4online_mode = False
        self.rhs_tab_id = None
        self.rvapi_meta = RvapiMetadata()

        if self.display_gui or self.ccp4i2:
            ccp4 = os.environ["CCP4"]
            share_jsrview = os.path.join(ccp4, "share", "jsrview")

            if self.rvapi_document:
                pyrvapi.rvapi_restore_document2(rvapi_document)
                self.rhs_tab_id = pyrvapi.rvapi_get_meta()
                self.jscofe_mode = True
                self.jsrview_dir = os.path.dirname(rvapi_document)
            else:
                self.jsrview_dir = os.path.join(work_dir, SIMBAD_PYRVAPI_SHAREDIR)
                os.mkdir(self.jsrview_dir)
                wintitle = "SIMBAD Results"

                if ccp4i2_xml:
                    self.init_from_ccp4i2_xml(ccp4i2_xml, self.jsrview_dir, share_jsrview, wintitle)
                else:
                    pyrvapi.rvapi_init_document("SIMBAD_results", self.jsrview_dir, wintitle, 1, 7, share_jsrview, None,
                                                None, None, None)
                    self.rvapi_document = os.path.join(self.jsrview_dir, "index.html")

            if webserver_uri:
                self._webserver_start = len(self.jsrview_dir) - 7
                self.ccp4online_mode = True
            elif not ccp4i2_xml:
                # We start our own browser
                jsrview = os.path.join(ccp4, "libexec", "jsrview")
                subprocess.Popen([jsrview, os.path.join(self.jsrview_dir, "index.html")])

            pyrvapi.rvapi_add_header("SIMBAD Results")

            if os.path.isfile(logfile) and not self.ccp4i2:
                self.create_log_tab(logfile)

        pyrvapi.rvapi_flush()
Пример #7
0
    def __init__(self, rvapi_document, webserver_uri, display_gui, logfile, work_dir, ccp4i2_xml=None, tab_prefix=""):
        self.rvapi_document = rvapi_document
        self.webserver_uri = webserver_uri
        self.display_gui = display_gui
        self.logfile = logfile
        self.work_dir = work_dir
        self.ccp4i2 = bool(ccp4i2_xml)
        self.tab_prefix = tab_prefix

        self.jsrview_dir = None
        self._webserver_start = None
        self.log_tab_id = None
        self.lattice_results_tab_id = None
        self.lattice_df = None
        self.contaminant_results_tab_id = None
        self.contaminant_df = None
        self.morda_db_results_tab_id = None
        self.morda_db_df = None
        self.summary_tab_id = None
        self.summary_tab_results_sec_id = None

        self.lattice_search_results_displayed = False
        self.contaminant_results_displayed = False
        self.morda_results_displayed = False

        self.jscofe_mode = False
        self.rhs_tab_id = None
        self.rvapi_meta = RvapiMetadata()

        if self.display_gui or self.ccp4i2:
            ccp4 = os.environ["CCP4"]
            share_jsrview = os.path.join(ccp4, "share", "jsrview")

            if self.rvapi_document:
                pyrvapi.rvapi_restore_document2(rvapi_document)
                self.rhs_tab_id = pyrvapi.rvapi_get_meta()
                self.jscofe_mode = True
                self.jsrview_dir = os.path.dirname(rvapi_document)
            else:
                self.jsrview_dir = os.path.join(work_dir, SIMBAD_PYRVAPI_SHAREDIR)
                os.mkdir(self.jsrview_dir)
                wintitle = "SIMBAD Results"

                if ccp4i2_xml:
                    self.init_from_ccp4i2_xml(ccp4i2_xml, self.jsrview_dir, share_jsrview, wintitle)
                else:
                    pyrvapi.rvapi_init_document("SIMBAD_results", self.jsrview_dir, wintitle, 1, 7, share_jsrview, None,
                                                None, None, None)
                    self.rvapi_document = os.path.join(self.jsrview_dir, "index.html")

            if webserver_uri:
                self._webserver_start = len(self.jsrview_dir) + 1
            elif not ccp4i2_xml:
                # We start our own browser
                jsrview = os.path.join(ccp4, "libexec", "jsrview")
                subprocess.Popen([jsrview, os.path.join(self.jsrview_dir, "index.html")])

            pyrvapi.rvapi_add_header("SIMBAD Results")

            if os.path.isfile(logfile) and not self.ccp4i2:
                self.create_log_tab(logfile)

        pyrvapi.rvapi_flush()