def testAnnotMtz2PdbxGood(self):
        """  Test mtz to pdbx conversion  (good mtz)
        """
        self.__lfh.write(
            "\nStarting %s %s\n" %
            (self.__class__.__name__, sys._getframe().f_code.co_name))
        diagfn = os.path.join(self.__tmpPath, "sf-convert-diags.cif")
        ciffn = os.path.join(self.__tmpPath, "sf-convert-datafile.cif")
        dmpfn = os.path.join(self.__tmpPath, "sf-convert-mtzdmp.log")
        #
        dp = RcsbDpUtility(tmpPath=self.__tmpPath,
                           siteId=self.__siteId,
                           verbose=True)
        mtzPath = os.path.join(self.__testFilePath, self.__testFileMtzGood)
        dp.imp(mtzPath)
        dp.setTimeout(15)
        ret = dp.op("annot-sf-convert")
        dp.expLog(os.path.join(self.__tmpPath, "sf-convert.log"))
        dp.expList(dstPathList=[ciffn, diagfn, dmpfn])
        # dp.cleanup()

        self.assertTrue(ret == 0)
        self.assertTrue(ciffn)
        self.assertTrue(diagfn)
        self.assertTrue(dmpfn)
 def testAnnotMtz2PdbxBad(self):
     """Test mtz to pdbx conversion"""
     logger.info("\nStarting")
     try:
         diagfn = "sf-convert-diags-bad.cif"
         ciffn = "sf-convert-datafile-bad.cif"
         dmpfn = "sf-convert-mtzdmp-bad.log"
         #
         # self.__testFileMtzRunaway  = "bad-runaway.mtz"
         # self.__testFileXyzRunaway  = "bad-runaway.cif"
         #
         dp = RcsbDpUtility(tmpPath=self.__tmpPath,
                            siteId=self.__siteId,
                            verbose=True)
         mtzPath = os.path.join(self.__testFilePath, self.__testFileMtzBad)
         dp.imp(mtzPath)
         # xyzPath=os.path.join(self.__testFilePath,self.__testFileXyzBad)
         dp.setTimeout(15)
         # dp.addInput(name="xyz_file_path",value=xyzPath)
         dp.op("annot-sf-convert")
         dp.expLog("sf-convert-bad.log")
         dp.expList(dstPathList=[ciffn, diagfn, dmpfn])
         # dp.cleanup()
     except Exception as e:
         logger.exception("Failing with %s", str(e))
         self.fail()
    def read_mtz_sf(self, pathin):
        """Reads MTZ structure factor file 

            Return True on success, otherwise False
        """

        logger.debug("Starting mtz read %s" % pathin)

        suffix = '-dir'
        prefix = 'rcsb-'
        if self.__tmppath is not None and os.path.isdir(self.__tmppath):
            workpath = tempfile.mkdtemp(suffix, prefix, self.__tmppath)
        else:
            workpath = tempfile.mkdtemp(suffix, prefix)

        diagfn = os.path.join(workpath, "sf-convert-diags.cif")
        ciffn = os.path.join(workpath, "sf-convert-datafile.cif")
        dmpfn = os.path.join(workpath, "sf-convert-mtzdmp.log")
        logfn = os.path.join(workpath, "sf-convert.log")

        dp = RcsbDpUtility(siteId=self.__siteid, tmpPath=self.__tmppath)
        dp.imp(pathin)
        dp.op('annot-sf-convert')
        dp.expLog(logfn)
        dp.expList(dstPathList=[ciffn, diagfn, dmpfn])
        if os.path.exists(ciffn):
            ret = self.read_mmcif_sf(ciffn)
        else:
            ret = False

        if self.__cleanup:
            dp.cleanup()
            shutil.rmtree(workpath, ignore_errors=True)
        return ret
    def testAnnotValidateListXrayTest(self):
        """Test create validation report for the test list of example PDB ids (NMR examples)"""
        logger.info("\nStarting")
        try:
            for pdbId in self.__testValidateXrayIdList:
                ofpdf = pdbId + "-valrpt.pdf"
                ofxml = pdbId + "-valdata.xml"
                offullpdf = pdbId + "-valrpt_full.pdf"
                ofpng = pdbId + "-val-slider.png"
                ofsvg = pdbId + "-val-slider.svg"
                #
                testFileValidateXyz = pdbId + ".cif"
                testFileValidateSf = pdbId + "-sf.cif"
                dp = RcsbDpUtility(tmpPath=self.__tmpPath,
                                   siteId=self.__siteId,
                                   verbose=True)
                # dp.setDebugMode(True)

                xyzPath = os.path.abspath(
                    os.path.join(self.__testFilePath, testFileValidateXyz))
                sfPath = os.path.abspath(
                    os.path.join(self.__testFilePath, testFileValidateSf))
                # dp.addInput(name="request_annotation_context", value="yes")
                dp.addInput(name="request_validation_mode", value="annotate")
                # dp.addInput(name="request_validation_mode", value="server")
                dp.imp(xyzPath)
                dp.addInput(name="sf_file_path", value=sfPath)
                dp.op("annot-wwpdb-validate-all")
                dp.expLog(pdbId + "-annot-validate-test.log")
                dp.expList(dstPathList=[ofpdf, ofxml, offullpdf, ofpng, ofsvg])
                # dp.cleanup()
        except Exception as e:
            logger.exception("Failing with %s", str(e))
            self.fail()
    def testAnnotMapCalc(self):
        """Test create density maps --"""
        logger.info("\nStarting")
        try:
            for pdbId in ["1cbs", "3of4", "3oqp"]:
                of2fofc = pdbId + "_2fofc.map"
                offofc = pdbId + "_fofc.map"

                testFileXyz = pdbId + ".cif"
                testFileSf = pdbId + "-sf.cif"

                dp = RcsbDpUtility(tmpPath=self.__tmpPath,
                                   siteId=self.__siteId,
                                   verbose=True)
                xyzPath = os.path.join(self.__testFilePath, testFileXyz)
                sfPath = os.path.join(self.__testFilePath, testFileSf)
                dp.imp(xyzPath)
                dp.addInput(name="sf_file_path", value=sfPath)
                dp.op("annot-make-maps")
                dp.expLog(pdbId + "-annot-make-maps.log")
                dp.expList(dstPathList=[of2fofc, offofc])
                # dp.cleanup()
        except Exception as e:
            logger.exception("Failing with %s", str(e))
            self.fail()
 def testAnnotMtz2PdbxBadTimeout(self):
     """  Test mtz to pdbx conversion
     """
     logger.info("\nStarting %s %s\n" %
                 (self.__class__.__name__, sys._getframe().f_code.co_name))
     try:
         diagfn = "sf-convert-diags-bad-runaway.cif"
         ciffn = "sf-convert-datafile-bad-runaway.cif"
         dmpfn = "sf-convert-mtzdmp-bad-runaway.log"
         #
         dp = RcsbDpUtility(tmpPath=self.__tmpPath,
                            siteId=self.__siteId,
                            verbose=True)
         dp.setDebugMode()
         mtzPath = os.path.join(self.__testFilePath,
                                self.__testFileMtzRunaway)
         dp.imp(mtzPath)
         dp.setTimeout(15)
         dp.op("annot-sf-convert")
         dp.expLog("sf-convert-runaway.log")
         dp.expList(dstPathList=[ciffn, diagfn, dmpfn])
         # dp.cleanup()
     except Exception as e:
         logger.exception("Failing with %s" % str(e))
         self.fail()
    def testAnnotOmitMapCalc(self):
        """  Test create density maps --
        """
        logger.info("\nStarting %s %s\n" %
                    (self.__class__.__name__, sys._getframe().f_code.co_name))
        try:
            for pdbId in self.__testValidateIdList:
                of2fofc = pdbId + "_map-omit-2fofc_P1.map"
                offofc = pdbId + "_map-omit-fofc_P1.map"

                testFileXyz = pdbId + ".cif"
                testFileSf = pdbId + "-sf.cif"

                dp = RcsbDpUtility(tmpPath=self.__tmpPath,
                                   siteId=self.__siteId,
                                   verbose=True)
                dp.setDebugMode()
                xyzPath = os.path.join(self.__testFilePath, testFileXyz)
                sfPath = os.path.join(self.__testFilePath, testFileSf)
                dp.imp(xyzPath)
                dp.addInput(name="sf_file_path", value=sfPath)
                dp.op("annot-make-maps")
                dp.expLog(pdbId + "-annot-make-maps.log")
                dp.expList(dstPathList=[of2fofc, offofc])
                # dp.cleanup()
        except Exception as e:
            logger.exception("Failing with %s" % str(e))
            self.fail()
    def testAnnotValidateListNmrTest(self):
        """  Test create validation report for the test list of example PDB ids (NMR examples)
        """
        logger.info("\nStarting %s %s\n" % (self.__class__.__name__, sys._getframe().f_code.co_name))
        try:
            count = 0
            for pdbId in self.__testValidateNmrIdList:
                ofpdf = pdbId + "-valrpt.pdf"
                ofxml = pdbId + "-valdata.xml"
                offullpdf = pdbId + "-valrpt_full.pdf"
                ofpng = pdbId + "-val-slider.png"
                ofsvg = pdbId + "-val-slider.svg"
                #
                testFileValidateXyz = pdbId + ".cif"
                testFileValidateCs = pdbId + "-cs.cif"
                dp = RcsbDpUtility(tmpPath=self.__tmpPath, siteId=self.__siteId, verbose=True)

                xyzPath = os.path.abspath(os.path.join(self.__testFilePath, testFileValidateXyz))
                csPath = os.path.abspath(os.path.join(self.__testFilePath, testFileValidateCs))
                dp.addInput(name="request_annotation_context", value="yes")
                # adding explicit selection of steps --
                # Alternate
                if count % 2 == 0:
                    dp.addInput(name="step_list", value=" coreclust,chemicalshifts,writexml,writepdf ")
                count += 1
                dp.imp(xyzPath)
                dp.addInput(name="cs_file_path", value=csPath)
                dp.op("annot-wwpdb-validate-all")
                dp.expLog(pdbId + "-annot-validate-test.log")
                dp.expList(dstPathList=[ofpdf, ofxml, offullpdf, ofpng, ofsvg])
                dp.cleanup()
        except Exception as e:
            logger.exception("Failing with %s" % str(e))
            self.fail()
    def mtz2Pdbx(self,
                 mtzFilePath,
                 outSfFilePath,
                 pdbxFilePath=None,
                 logFilePath=None,
                 diagsFilePath=None,
                 dumpFilePath=None,
                 timeout=120):
        """ Convert input MTZ format to PDBx sf file.
        """
        try:
            diagfn = logFilePath if logFilePath is not None else "sf-convert-diags.cif"
            dmpfn = dumpFilePath if dumpFilePath is not None else "sf-convert-mtzdmp.log"
            #
            dp = RcsbDpUtility(tmpPath=self.__sessionPath,
                               siteId=self.__siteId,
                               verbose=self.__verbose,
                               log=self.__lfh)
            dp.imp(mtzFilePath)
            dp.setTimeout(timeout)
            if pdbxFilePath is not None:
                dp.addInput(name="xyz_file_path", value=pdbxFilePath)
            dp.op("annot-sf-convert")
            dp.expLog(logFilePath)
            dp.expList(dstPathList=[outSfFilePath, diagfn, dmpfn])

            if (not self.__debug):
                dp.cleanup()
            return True
        except:
            self.__lfh.write(
                "+DataFileAdapter.mtz2Pdbx() - failing for mtz file path %s output path %s\n"
                % (mtzFilePath, outSfFilePath))
            traceback.print_exc(file=self.__lfh)
            return False
    def testFixSpecialPosition(self):
        """  Test for fixing atoms on special position
        """
        logger.info("\nStarting %s %s\n" % (self.__class__.__name__, sys._getframe().f_code.co_name))
        try:

            dp = RcsbDpUtility(tmpPath=self.__tmpPath, siteId=self.__siteId, verbose=True)
            #
            inpPath = os.path.join(self.__testFilePath, self.__testFileValidateXyz)
            dp.imp(inpPath)
            dp.op("annot-dcc-fix-special-position")
            dp.expLog("special-position-fix.log")
            dp.exp("special-position-output-fix.log")

            # No output - none on special
            self.assertEqual(['missing'], dp.getResultPathList())

            f = open('special-position-output-fix.log', 'r')
            lines = f.read()
            f.close()
            self.assertIn('No atoms sit on special position', lines)
            dp.cleanup()
        except Exception as e:
            logger.exception("Failing with %s" % str(e))
            self.fail()

        # This case has atoms on special position that needs correction
        try:

            dp = RcsbDpUtility(tmpPath=self.__tmpPath, siteId=self.__siteId, verbose=True)
            #
            # dp.setDebugMode(True)
            #
            inpPath = os.path.join(self.__testFilePath, self.__testSpecialPosition)
            dp.imp(inpPath)
            dp.op("annot-dcc-fix-special-position")
            dp.expLog("special-position-fix2.log")
            dp.exp("special-position-output-fix2.log")

            print(dp.getResultPathList())

            # We expect output
            self.assertNotEqual(['missing'], dp.getResultPathList())

            dp.expList(dstPathList=['special-position-out-fix2.cif'])
            # Check output - for differences...

            f = open('special-position-output-fix2.log', 'r')
            lines = f.read()
            f.close()
            self.assertIn('Error: Wrong occupancy of 1.00 for atom (O : id=D_HOH_1)', lines)
            dp.cleanup()
        except Exception as e:
            logger.exception("Failing with %s" % str(e))
            self.fail()
    def testAnnotValidateListNmrTestRemote(self):
        """  Test create validation report for the test list of example PDB ids (NMR examples)
        """
        self.__lfh.write(
            "\nStarting %s %s\n" %
            (self.__class__.__name__, sys._getframe().f_code.co_name))
        for pdbId in self.__testValidateNmrIdList:
            self.__tmpPath = tempfile.mkdtemp(
                dir=self.__siteWebAppsSessionsPath)
            self.__lfh.write("\nStarting {} in {}\n".format(
                pdbId, self.__tmpPath))
            ofpdf = os.path.join(self.__tmpPath, pdbId + "-valrpt.pdf")
            ofxml = os.path.join(self.__tmpPath, pdbId + "-valdata.xml")
            offullpdf = os.path.join(self.__tmpPath,
                                     pdbId + "-valrpt_full.pdf")
            ofpng = os.path.join(self.__tmpPath, pdbId + "-val-slider.png")
            ofsvg = os.path.join(self.__tmpPath, pdbId + "-val-slider.svg")
            #
            testFileValidateXyz = pdbId + ".cif"
            testFileValidateCs = pdbId + "-cs.cif"
            dp = RcsbDpUtility(tmpPath=self.__tmpPath,
                               siteId=self.__siteId,
                               verbose=True)

            xyzPath = os.path.abspath(
                os.path.join(self.__testFilePath, testFileValidateXyz))
            csPath = os.path.abspath(
                os.path.join(self.__testFilePath, testFileValidateCs))
            dp.addInput(name="request_annotation_context", value="yes")
            dp.addInput(name='run_dir',
                        value=os.path.join(
                            self.__siteWebAppsSessionsPath,
                            "validation_%s" % random.randrange(9999999)))
            # adding explicit selection of steps --
            # Alternate
            #dp.addInput(name="step_list", value=" coreclust,chemicalshifts,writexml,writepdf ")
            dp.addInput(name='kind', value='nmr')
            dp.imp(xyzPath)
            dp.addInput(name="cs_file_path", value=csPath)
            # dp.setRunRemote()
            ret = dp.op("annot-wwpdb-validate-all")
            dp.expLog(
                os.path.join(self.__tmpPath,
                             pdbId + "-annot-validate-test.log"))
            dp.expList(dstPathList=[ofpdf, ofxml, offullpdf, ofpng, ofsvg])
            # dp.cleanup()

            self.assertTrue(ret == 0)
            self.assertTrue(os.path.exists(ofpdf))
            self.assertTrue(os.path.exists(ofxml))
            self.assertTrue(os.path.exists(offullpdf))
            self.assertTrue(os.path.exists(ofpng))
            self.assertTrue(os.path.exists(ofsvg))
    def testAnnotValidateListXrayTestRemote(self):
        """  Test create validation report for the test list of example PDB ids (x-ray examples)
        """
        self.__lfh.write(
            "\nStarting %s %s\n" %
            (self.__class__.__name__, sys._getframe().f_code.co_name))
        for pdbId in self.__testValidateXrayIdList:
            self.__tmpPath = tempfile.mkdtemp(
                dir=self.__siteWebAppsSessionsPath)
            self.__lfh.write("\nStarting {} in {}\n".format(
                pdbId, self.__tmpPath))
            ofpdf = os.path.join(self.__tmpPath, pdbId + "-valrpt.pdf")
            ofxml = os.path.join(self.__tmpPath, pdbId + "-valdata.xml")
            offullpdf = os.path.join(self.__tmpPath,
                                     pdbId + "-valrpt_full.pdf")
            ofpng = os.path.join(self.__tmpPath, pdbId + "-val-slider.png")
            ofsvg = os.path.join(self.__tmpPath, pdbId + "-val-slider.svg")
            #
            testFileValidateXyz = pdbId + ".cif"
            testFileValidateSf = pdbId + "-sf.cif"
            dp = RcsbDpUtility(tmpPath=self.__tmpPath,
                               siteId=self.__siteId,
                               verbose=True)
            # dp.setDebugMode(True)

            xyzPath = os.path.abspath(
                os.path.join(self.__testFilePath, testFileValidateXyz))
            sfPath = os.path.abspath(
                os.path.join(self.__testFilePath, testFileValidateSf))
            # dp.addInput(name="request_annotation_context", value="yes")
            dp.addInput(name="request_validation_mode", value="annotate")
            dp.addInput(name='run_dir',
                        value=os.path.join(
                            self.__siteWebAppsSessionsPath,
                            "validation_%s" % random.randrange(9999999)))
            # dp.addInput(name="request_validation_mode", value="server")
            dp.imp(xyzPath)
            dp.addInput(name="sf_file_path", value=sfPath)
            # dp.setRunRemote()
            ret = dp.op("annot-wwpdb-validate-all")
            dp.expLog(
                os.path.join(self.__tmpPath,
                             pdbId + "-annot-validate-test.log"))
            dp.expList(dstPathList=[ofpdf, ofxml, offullpdf, ofpng, ofsvg])
            # dp.cleanup()

            self.assertTrue(ret == 0)
            self.assertTrue(os.path.exists(ofpdf))
            self.assertTrue(os.path.exists(ofxml))
            self.assertTrue(os.path.exists(offullpdf))
            self.assertTrue(os.path.exists(ofpng))
            self.assertTrue(os.path.exists(ofsvg))
Example #13
0
    def testAnnotValidateXrayNeutronRemote(self):
        """Test create validation report for the test list of example PDB ids (x-ray examples)"""
        logger.debug("\nStarting")

        self.__tmpPath = tempfile.mkdtemp(dir=self.__siteWebAppsSessionsPath)
        logger.debug("\nStarting x-ray neutron in %s\n", self.__tmpPath)
        ofpdf = os.path.join(self.__tmpPath, "test-valrpt.pdf")
        ofxml = os.path.join(self.__tmpPath, "test-valdata.xml")
        offullpdf = os.path.join(self.__tmpPath, "test-valrpt_full.pdf")
        ofpng = os.path.join(self.__tmpPath, "test-val-slider.png")
        ofsvg = os.path.join(self.__tmpPath, "test-val-slider.svg")
        #
        dp = RcsbDpUtility(tmpPath=self.__tmpPath,
                           siteId=self.__siteId,
                           verbose=True)
        # dp.setDebugMode(True)

        xyzPath = os.path.abspath(
            os.path.join(self.__testFilePath,
                         self.__testValidateXrayNeutronModel))
        sfPath = os.path.abspath(
            os.path.join(self.__testFilePath,
                         self.__testValidateXrayNeutronSF))
        # dp.addInput(name="request_annotation_context", value="yes")
        dp.addInput(name="request_validation_mode", value="annotate")
        dp.addInput(name="run_dir",
                    value=os.path.join(
                        self.__siteWebAppsSessionsPath,
                        "validation_%s" % random.randrange(9999999)))
        # dp.addInput(name="request_validation_mode", value="server")
        dp.imp(xyzPath)
        dp.addInput(name="sf_file_path", value=sfPath)
        # dp.setRunRemote()
        ret = dp.op("annot-wwpdb-validate-all")
        dp.expLog(os.path.join(self.__tmpPath, "test-annot-validate-test.log"))
        dp.expList(dstPathList=[ofpdf, ofxml, offullpdf, ofpng, ofsvg])
        # dp.cleanup()

        self.assertTrue(ret == 0)
        self.assertTrue(os.path.exists(ofpdf))
        self.assertTrue(os.path.exists(ofxml))
        self.assertTrue(os.path.exists(offullpdf))
        self.assertTrue(os.path.exists(ofpng))
        self.assertTrue(os.path.exists(ofsvg))
Example #14
0
 def testAnnotMtz2PdbxGood(self):
     """Test mtz to pdbx conversion  (good mtz)"""
     logger.info("\nStarting")
     try:
         diagfn = "sf-convert-diags.cif"
         ciffn = "sf-convert-datafile.cif"
         dmpfn = "sf-convert-mtzdmp.log"
         #
         dp = RcsbDpUtility(tmpPath=self.__tmpPath, siteId=self.__siteId, verbose=True)
         dp.setDebugMode()
         mtzPath = os.path.join(self.__testFilePath, self.__testFileMtzGood)
         dp.imp(mtzPath)
         dp.setTimeout(15)
         dp.op("annot-sf-convert")
         dp.expLog("sf-convert.log")
         dp.expList(dstPathList=[ciffn, diagfn, dmpfn])
         # dp.cleanup()
     except Exception as e:
         logger.exception("Failing with %s", str(e))
         self.fail()