Beispiel #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
Beispiel #2
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()
Beispiel #3
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
Beispiel #4
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()
Beispiel #5
0
    def run(self):

        # Prepare ample job

        # fetch input data
        hkl = self.makeClass ( self.input_data.data.hkl[0] )
        seq = self.input_data.data.seq[0]

        # make command line parameters
        cmd = [ os.path.join(self.inputDir(),hkl.files[0]),
                os.path.join(self.inputDir(),seq.files[0]),
                "-rvapi_document",self.reportDocumentName() ]

        # pass rvapi document with metadata
        """
        self.storeReportDocument(
            '{ "jobId"       : "' + str(self.job_id).zfill(4) + '",' +
            '  "reportTabId" : "' + self.report_page_id() + '",'
            '  "logTabId"    : "' + self.log_page_id()    + '"'
            '}'
        )
        """
        self.storeReportDocument ( self.log_page_id() )

        #test_ample_path = os.path.join ( os.environ["CCP4"],"bin","ample_mock.py" )

        # run ample
        #self.runApp ( "ccp4-python",[test_ample_path] + cmd )
        self.runApp ( "ample",cmd )

        self.restoreReportDocument()

        f = open ( 'xxx.json','w' )
        f.write ( pyrvapi.rvapi_get_meta() )
        f.close()

        """
        {"results": [
          {"info": "SHELXE trace of MR result",
             "mtz": "../../../../../../opt/ample.git/ample_testing/from_existing_models/MRBUMP/search_c1_t100_r3_polyAla_mrbump/data/loc0_ALL_c1_t100_r3_polyAla/unmod/mr/phaser/build/shelxe/shelxe_phaser_loc0_ALL_c1_t100_r3_polyAla_UNMOD.mtz",
             "type": "SHELXE",
             "name": "c1_t100_r3_polyAla",
             "pdb": "../../../../../../opt/ample.git/ample_testing/from_existing_models/MRBUMP/search_c1_t100_r3_polyAla_mrbump/data/loc0_ALL_c1_t100_r3_polyAla/unmod/mr/phaser/build/shelxe/shelxe_phaser_loc0_ALL_c1_t100_r3_polyAla_UNMOD.pdb"
           },
           {"info": "SHELXE trace of MR result",
             "mtz": "../../../../../../opt/ample.git/ample_testing/from_existing_models/MRBUMP/search_c1_t49_r1_polyAla_mrbump/data/loc0_ALL_c1_t49_r1_polyAla/unmod/mr/phaser/build/shelxe/shelxe_phaser_loc0_ALL_c1_t49_r1_polyAla_UNMOD.mtz",
             "type": "SHELXE",
             "name": "c1_t49_r1_polyAla",
             "pdb": "../../../../../../opt/ample.git/ample_testing/from_existing_models/MRBUMP/search_c1_t49_r1_polyAla_mrbump/data/loc0_ALL_c1_t49_r1_polyAla/unmod/mr/phaser/build/shelxe/shelxe_phaser_loc0_ALL_c1_t49_r1_polyAla_UNMOD.pdb"
            },
            {"info": "SHELXE trace of MR result",
             "mtz": "../../../../../../opt/ample.git/ample_testing/from_existing_models/MRBUMP/search_c1_t49_r3_polyAla_mrbump/data/loc0_ALL_c1_t49_r3_polyAla/unmod/mr/phaser/build/shelxe/shelxe_phaser_loc0_ALL_c1_t49_r3_polyAla_UNMOD.mtz",
             "type": "SHELXE",
             "name": "c1_t49_r3_polyAla",
             "pdb": "../../../../../../opt/ample.git/ample_testing/from_existing_models/MRBUMP/search_c1_t49_r3_polyAla_mrbump/data/loc0_ALL_c1_t49_r3_polyAla/unmod/mr/phaser/build/shelxe/shelxe_phaser_loc0_ALL_c1_t49_r3_polyAla_UNMOD.pdb"
            }
          ]
        }
        """

        rvapi_meta = pyrvapi.rvapi_get_meta()
        if rvapi_meta:
            try:
                ample_meta = json.loads ( rvapi_meta )
            except:
                self.putMessage ( "<b>Program error:</b> <i>unparseable metadata from Ample</i>" +
                                  "<p>'" + rvapi_meta + "'" )
        else:
            self.putMessage ( "<b>Program error:</b> <i>no metadata from Ample</i>" )
            ample_meta = {}
            ample_meta["results"] = []

        results = ample_meta["results"]
        if len(results)<=0:
            self.putTitle ( "Solution Not Found" )
        else:

            generic_parser_summary = None
            for i in range(len(results)):
                result = results[i]
                self.putTitle ( "Solution " + result["name"] )

                mtzfile   = os.path.join ( self.reportDir(),result["mtz"] )
                final_pdb = os.path.join ( self.reportDir(),result["pdb"] )
                sol_hkl   = hkl

                meta = xyzmeta.getXYZMeta ( final_pdb,self.file_stdout,
                                            self.file_stderr )
                if "cryst" in meta:
                    sol_spg    = meta["cryst"]["spaceGroup"]
                    spg_change = self.checkSpaceGroupChanged ( sol_spg,hkl,mtzfile )
                    if spg_change:
                        mtzfile = spg_change[0]
                        sol_hkl = spg_change[1]

                # ================================================================
                # make output structure and register it

                structure = self.finaliseStructure ( final_pdb,self.outputFName,
                                                     sol_hkl,None,[seq],1,False,"" )

                if structure:
                    # update structure revision
                    revision = self.makeClass  ( self.input_data.data.revision[0] )
                    revision.setReflectionData ( sol_hkl   )
                    revision.setStructureData  ( structure )
                    self.registerRevision      ( revision,i+1,"" )
                    if not generic_parser_summary:
                        generic_parser_summary = self.generic_parser_summary.copy()

                else:
                    self.putMessage ( "Structure Data cannot be formed (probably a bug)" )

            if generic_parser_summary:
                self.generic_parser_summary = generic_parser_summary.copy()


        # close execution logs and quit
        self.success()
        return
Beispiel #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.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()
Beispiel #7
0
    def run(self):

        if self.exeType == "SGE":
            nSubJobs = "0"
            if len(sys.argv) > 5:
                nSubJobs = sys.argv[5]
        else:
            nSubJobs = "4"

        # fetch input data
        hkl = self.makeClass(self.input_data.data.hkl[0])

        sec1 = self.task.parameters.sec1.contains
        level = self.getParameter(sec1.SEARCH_SEL)
        maxnlatt = self.getParameter(sec1.MAXNLATTICES)
        maxpenalty = self.getParameter(sec1.MAXPENALTY)
        if not maxpenalty:
            maxpenalty = "12"

        app = ""
        if level == 'L':
            app = "simbad-lattice"
        elif level == 'C':
            app = "simbad-contaminant"
        elif level == 'S':
            app = "simbad-morda"
        elif level == 'LC':
            app = "simbad"
        elif level == 'LCS':
            app = "simbad-full"

        # Prepare simbad input -- script file
        cmd = [
            "-nproc", nSubJobs, "-max_lattice_results", maxnlatt,
            "-max_penalty_score", maxpenalty, "-F", hkl.dataset.Fmean.value,
            "-SIGF", hkl.dataset.Fmean.sigma, "-FREE", hkl.dataset.FREE,
            "-pdb_db", os.environ["PDB_DIR"], "--display_gui",
            "-webserver_uri", "jsrview", "-work_dir", "./", "-rvapi_document",
            self.reportDocumentName(),
            os.path.join(self.inputDir(), hkl.files[0])
        ]

        self.flush()
        self.storeReportDocument(self.log_page_id())

        # run simbad
        self.runApp(app, cmd)
        self.restoreReportDocument()

        #f = open ( 'xxx.json','w' )
        #f.write ( pyrvapi.rvapi_get_meta() )
        #f.close()
        """
        { "nResults": 1,
          "results": [
            { "mtz": "../latt/mr_lattice/1DTX/mr/molrep/refine/1DTX_refinement_output.mtz",
              "source": "latt",
              "dmap": "../latt/mr_lattice/1DTX/mr/molrep/refine/1DTX_refmac_fofcwt.map",
              "best": true,
              "map": "../latt/mr_lattice/1DTX/mr/molrep/refine/1DTX_refmac_2fofcwt.map",
              "pdb": "../latt/mr_lattice/1DTX/mr/molrep/refine/1DTX_refinement_output.pdb",
              "rank": 1,
              "name": "1DTX"
             }
          ]
        }
        """

        rvapi_meta = pyrvapi.rvapi_get_meta()
        if rvapi_meta:
            try:
                simbad_meta = json.loads(rvapi_meta)
            except:
                self.putMessage(
                    "<b>Program error:</b> <i>unparseable metadata from Simbad</i>"
                    + "<p>'" + rvapi_meta + "'")
        else:
            self.putMessage(
                "<b>Program error:</b> <i>no metadata from Simbad</i>")
            simbad_meta = {}
            simbad_meta["nResults"] = 0

        if simbad_meta["nResults"] > 0:

            result0 = simbad_meta["results"][0]

            self.putMessage("<h3>Best model found: " + result0["name"] +
                            "</h3>")

            # register structure data
            structure = self.registerStructure(
                os.path.join(self.reportDir(), result0["pdb"]),
                os.path.join(self.reportDir(), result0["mtz"]),
                os.path.join(self.reportDir(), result0["map"]),
                os.path.join(self.reportDir(), result0["dmap"]), None, True)

            if structure:

                structure.addDataAssociation(hkl.dataId)
                structure.setRefmacLabels(hkl)
                structure.addMRSubtype()
                structure.addXYZSubtype()

                self.putStructureWidget(
                    "structure_btn_",
                    result0["name"] + " structure and electron density",
                    structure)

                asudef.revisionFromStructure(self, hkl, structure,
                                             result0["name"])

            else:
                self.putMessage(
                    "Structure Data cannot be formed (probably a bug)")

        else:
            self.putTitle("No Suitable Models Found")

        # close execution logs and quit
        self.success()
        return