Example #1
0
    def runValidationCryoEMStep(self):
        version = Plugin.getPhenixVersion()
        if version == '1.13':
            print("PHENIX version: 1.13")
        else:
            print("PHENIX version: ", version)

        fileName = self.inputStructure.get().getFileName()
        atomStruct = os.path.abspath(fileName)

        # starting volume (.mrc)
        if self.vol is not None:
            tmpMapFile = self.VALIDATIONCRYOEMFILE
            volume = os.path.abspath(self._getExtraPath(tmpMapFile))
        else:
            volume = None

        # MolProbity is run to get the file molprobity.out
        # (necessary to get geometry outliers)
        numberOfThreads = self.numberOfThreads.get()

        args = self._writeArgsMolProbity(atomStruct, vol=volume)
        cwd = os.getcwd() + "/" + self._getExtraPath()
        # script with auxiliary files
        retry(Plugin.runPhenixProgram, Plugin.getProgram(MOLPROBITY),
              args, cwd=cwd, listAtomStruct=[atomStruct], log=self._log)

        args = self._writeArgsValCryoEM(atomStruct, volume, self.vol)

        if Plugin.getPhenixVersion() != PHENIXVERSION and self.vol is not None:
            retry(Plugin.runPhenixProgram, Plugin.getProgram(VALIDATION_CRYOEM),
                  args, cwd=cwd, listAtomStruct=[atomStruct], log=self._log)
 def testgetVersion(self):
     version = Plugin.getPhenixVersion()
     if version == PHENIXVERSION:
         self.assertEqual(version, PHENIXVERSION)
     else:
         print(("Your version is not " + PHENIXVERSION + " anymore"))
         print(("Your current version is " + version))
Example #3
0
    def testPhenixRSRefineFromPDB(self):
        """ This test checks that phenix real space refine protocol runs
        with an atomic structure; No Volume was provided and an error message
        is expected
        """
        print("Run phenix real space refine protocol from imported pdb file "
              "without imported or pdb-associated volume")

        # import PDB
        structure_refmac3 = self._importStructRefmac3()
        self.assertTrue(structure_refmac3.getFileName())
        self.assertFalse(structure_refmac3.getVolume())

        # real_space_refine
        args = {
            'resolution': 3.5,
            'inputStructure': structure_refmac3,
            'numberOfThreads': 4
        }
        if Plugin.getPhenixVersion() == PHENIXVERSION:
            args['doSecondary'] = False
        protRSRefine = self.newProtocol(PhenixProtRunRSRefine, **args)
        protRSRefine.setObjLabel('RSRefine without\nvolume, should NOT work')
        try:
            self.launchProtocol(protRSRefine)
        except Exception as e:
            self.assertTrue(
                True, "This test should return a error message as '"
                " Input volume cannot be EMPTY.'\n")

            return
        self.assertTrue(False)
Example #4
0
 def runMolprobityStep(self):
     version = Plugin.getPhenixVersion()
     if version == '1.13':
         print("PHENIX version: 1.13")
     else:
         print(("PHENIX version: ", version))
     # PDBx/mmCIF
     fileName = self.inputStructure.get().getFileName()
     # self.atomStruct = os.path.abspath(fileName)
     self.atomStruct = os.getcwd() + "/" + fileName
     # starting volume (.mrc)
     if (self.inputVolume.get() or self.inputStructure.get().getVolume()) \
             is not None:
         tmpMapFile = self.MOLPROBITYFILE
         # self.vol = os.path.abspath(self._getExtraPath(tmpMapFile))
         self.vol = os.getcwd() + "/" + self._getExtraPath(tmpMapFile)
         args = self._writeArgsMolProbityExpand(self.atomStruct, self.vol)
     else:
         args = self._writeArgsMolProbityExpand(self.atomStruct, vol=None)
     # script with auxiliary files
     retry(
         Plugin.runPhenixProgram,
         Plugin.getProgram(MOLPROBITY),
         # args, cwd=os.path.abspath(self._getExtraPath()),
         args,
         cwd=self._getExtraPath(),
         listAtomStruct=[self.atomStruct],
         log=self._log)
Example #5
0
 def _writeArgsMolProbityExpand(self, atomStruct, vol=None):
     args = self._writeArgsMolProbity(atomStruct, vol)
     if Plugin.getPhenixVersion() != PHENIXVERSION:
         args += " pickle=True"
     args += " pdb_interpretation.clash_guard.nonbonded_distance_threshold=None"
     args += " %s " % self.extraParams.get()
     # args += " wxplots=True" # TODO: Avoid the direct opening of plots
     return args
 def _insertAllSteps(self):
     self._insertFunctionStep('convertInputStep', self.REALSPACEFILE)
     self._insertFunctionStep('runRSrefineStep', self.REALSPACEFILE)
     self._insertFunctionStep('runMolprobityStep', self.REALSPACEFILE)
     if Plugin.getPhenixVersion() != PHENIXVERSION:
         self._insertFunctionStep('runValidationCryoEMStep',
                                  self.REALSPACEFILE)
     self._insertFunctionStep('createOutputStep')
 def _writeArgsMolProbity(self, atomStruct, vol=None):
     args = ""
     args += atomStruct
     if Plugin.getPhenixVersion() == PHENIXVERSION:
         args += " "
         args += " map_file_name=%s" % vol
         args += " pickle=True"
         args += " "
         args += " d_min=%f" % self.resolution.get()
     args += " "
     numberOfThreads = self.numberOfThreads.get()
     if numberOfThreads > 1:
         args += " nproc=%d" % numberOfThreads
     return args
 def _writeArgsRSR(self, atomStruct, vol):
     if Plugin.getPhenixVersion() == PHENIXVERSION19:
         args = " "
     else:
         args = " model_file="
     args += "%s " % atomStruct
     if Plugin.getPhenixVersion() == PHENIXVERSION19:
         args += " "
     else:
         args += " map_file="
     args += "%s " % vol
     args += " resolution=%f" % self.resolution
     args += " secondary_structure.enabled=%s" % self.doSecondary
     args += " run="
     if self.minimizationGlobal == True:
         args += "minimization_global+"
     if self.rigidBody == True:
         args += "rigid_body+"
     if self.localGridSearch == True:
         args += "local_grid_search+"
     if self.morphing == True:
         args += "morphing+"
     if self.simulatedAnnealing == True:
         args += "simulated_annealing+"
     if self.adp == True:
         args += "adp+"
     args = args[:-1]
     # args += " run=minimization_global+local_grid_search+morphing+simulated_annealing"
     args += " macro_cycles=%d" % self.macroCycles
     args += " model_format=pdb+mmcif"
     # args += " write_pkl_stats=True"
     args += " %s " % self.extraParams.get()
     numberOfThreads = self.numberOfThreads.get()
     if numberOfThreads > 1:
         args += " nproc=%d" % numberOfThreads
     return args
Example #9
0
    def testMolProbityValidationSeveralChains(self):
        """ This test checks that MolProbity validation protocol runs with a
        volume provided directly as inputVol, the input PDB was fitted to
        the volume and refined previously by coot and refmac in another project
         """
        print("Run MolProbity validation from imported volume and pdb file " \
              "already refined by Coot and Refmac in another project")

        # Import Volume
        volume3 = self._importVolume3()

        # import PDB
        structure5_PDB = self._importStructurePDBWoVol2()

        # MolProbity
        args = {
            'inputVolume': volume3,
            'resolution': 2.2,
            'inputStructure': structure5_PDB,
            'numberOfThreads': 4
        }
        protMolProbity = self.newProtocol(PhenixProtRunMolprobity, **args)
        protMolProbity.setObjLabel('MolProbity validation\n volume and pdb\n')
        self.launchProtocol(protMolProbity)

        # check MolProbity results
        if Plugin.getPhenixVersion() == PHENIXVERSION18:
            self.checkResults(ramOutliers=0.12,
                              ramFavored=95.86,
                              rotOutliers=0.52,
                              cbetaOutliers=0,
                              clashScore=9.70,
                              overallScore=1.80,
                              protMolProbity=protMolProbity)
        else:
            self.checkResults(ramOutliers=0.12,
                              ramFavored=95.86,
                              rotOutliers=0.52,
                              cbetaOutliers=0,
                              clashScore=9.74,
                              overallScore=1.80,
                              protMolProbity=protMolProbity)
    def createOutputStep(self):
        # self._getRSRefineOutput()
        pdb = AtomStruct()
        pdb.setFileName(self.outAtomStructName)

        if self.inputVolume.get() is not None:
            pdb.setVolume(self.inputVolume.get())
        else:
            pdb.setVolume(self.inputStructure.get().getVolume())
        self._defineOutputs(outputPdb=pdb)
        self._defineSourceRelation(self.inputStructure.get(), pdb)
        if self.inputVolume.get() is not None:
            self._defineSourceRelation(self.inputVolume.get(), pdb)

        if Plugin.getPhenixVersion() == PHENIXVERSION:
            MOLPROBITYOUTFILENAME = self._getExtraPath(
                self.MOLPROBITYOUTFILENAME)
            self._parseFile(MOLPROBITYOUTFILENAME)
        else:
            VALIDATIONCRYOEMPKLFILENAME = self._getExtraPath(
                self.VALIDATIONCRYOEMPKLFILE)
            self._readValidationPklFile(VALIDATIONCRYOEMPKLFILENAME)
        self._store()
Example #11
0
    def testValCryoEMFFromVolumeAndPDB4(self):
        """ This test checks that phenix real_space_refine protocol runs
        with a volume provided directly as inputVol (with half1 and half2)
        and the input PDB from data banks; default refine strategy;
        (MolProbity has been run to
        compare values before and after refinement). MolProbity and
        ValCryoEM after RSRefine should show identical values.
        """
        print("Run phenix real_space_refine from imported volume and pdb file "
              "from data banks (vol origin 0.0, 0.0, 0.0); default refine "
              "strategy; (MolProbity has been run to compare values before "
              "and after refinement). MolProbity and ValCryoEM after RSRefine "
              "should show identical values.")

        # Import Volume
        volume_hemo_half1_hal2 = self._importHemoHalf1Half2()

        # import PDB
        structure_hemo_pdb = self._importStructHemoPDB()

        # MolProbity
        args = {
            'inputVolume': volume_hemo_half1_hal2,
            'resolution': 3.2,
            'inputStructure': structure_hemo_pdb,
            'numberOfThreads': 4
        }
        protMolProbity = self.newProtocol(PhenixProtRunMolprobity, **args)
        protMolProbity.setObjLabel(
            'MolProbity validation\n'
            'full and half volumes\nand pdb\nhemoglobin')
        self.launchProtocol(protMolProbity)

        # check MolProbity results
        self.checkMPResults(ramOutliers=0.00,
                            ramFavored=95.23,
                            rotOutliers=0.43,
                            cbetaOutliers=0,
                            clashScore=3.53,
                            overallScore=1.48,
                            protMolProbity=protMolProbity)

        # real_space_refine
        args = {
            'inputVolume': volume_hemo_half1_hal2,
            'resolution': 3.2,
            'inputStructure': structure_hemo_pdb,
            'numberOfThreads': 4
        }
        if Plugin.getPhenixVersion() == PHENIXVERSION:
            args['doSecondary'] = False
        protRSRefine = self.newProtocol(PhenixProtRunRSRefine, **args)
        protRSRefine.setObjLabel(
            'RSRefine hemo\n emd_3488.map (full, half1, half2)\nand '
            '5ni1.pdb\n')
        self.launchProtocol(protRSRefine)

        # check real_space_refine results
        if Plugin.getPhenixVersion() == PHENIXVERSION:
            self.checkRSRefineResults(ramOutliers=0.00,
                                      ramFavored=97.53,
                                      rotOutliers=0.00,
                                      cbetaOutliers=0,
                                      clashScore=2.43,
                                      overallScore=1.12,
                                      protRSRefine=protRSRefine)

        else:
            self.checkRSRefineResults(ramOutliers=0.00,
                                      ramFavored=96.11,
                                      rotOutliers=3.04,
                                      cbetaOutliers=0,
                                      clashScore=5.30,
                                      overallScore=1.92,
                                      protRSRefine=protRSRefine)

        # MolProbity2
        args = {
            'inputVolume': volume_hemo_half1_hal2,
            'resolution': 3.2,
            'inputStructure': protRSRefine.outputPdb,
            'numberOfThreads': 4
        }
        protMolProbity2 = self.newProtocol(PhenixProtRunMolprobity, **args)
        protMolProbity2.setObjLabel(
            'MolProbity validation\n'
            'full and half volumes\nand pdb\nhemoglobin')
        self.launchProtocol(protMolProbity2)

        # check MolProbity results
        if Plugin.getPhenixVersion() == PHENIXVERSION:
            self.checkMPResults(ramOutliers=0.00,
                                ramFavored=97.53,
                                rotOutliers=0.00,
                                cbetaOutliers=0,
                                clashScore=2.43,
                                overallScore=1.12,
                                protMolProbity=protMolProbity2)
        elif Plugin.getPhenixVersion() == PHENIXVERSION18:
            self.checkMPResults(ramOutliers=0.00,
                                ramFavored=96.64,
                                rotOutliers=4.77,
                                cbetaOutliers=0,
                                clashScore=6.07,
                                overallScore=2.06,
                                protMolProbity=protMolProbity2)
        elif Plugin.getPhenixVersion() == PHENIXVERSION19:
            self.checkMPResults(ramOutliers=0.00,
                                ramFavored=97.35,
                                rotOutliers=2.39,
                                cbetaOutliers=0,
                                clashScore=3.87,
                                overallScore=1.59,
                                protMolProbity=protMolProbity2)
        else:
            self.checkMPResults(ramOutliers=0.00,
                                ramFavored=96.11,
                                rotOutliers=3.04,
                                cbetaOutliers=0,
                                clashScore=5.30,
                                overallScore=1.92,
                                protMolProbity=protMolProbity2)

        # validation_cryoEM
        args = {
            'inputVolume': volume_hemo_half1_hal2,
            'resolution': 3.2,
            'inputStructure': protRSRefine.outputPdb
        }
        protValCryoEM = self.newProtocol(PhenixProtRunValidationCryoEM, **args)
        protValCryoEM.setObjLabel(
            'ValCryoEM\nafter RSRefine\nvolume_hemo_org and '
            'protRSRefine.outputPdb\n')
        try:
            self.launchProtocol(protValCryoEM)
        except Exception as e:
            self.assertTrue(
                True, "This test should return a error message as '"
                " Protocol has validation errors:\n"
                "Binary '/usr/local/phenix-1.13-2998/modules/phenix/phenix/"
                "command_line/validation_cryoem.py' does not exists.\n"
                "Check if you need to upgrade your PHENIX version to run "
                "VALIDATION_CRYOEM.\nYour current PHENIX version is 1.13.\n"
                "Check configuration file: " + Config.SCIPION_LOCAL_CONFIG +
                "\n"
                "and set VALIDATION_CRYOEM and PHENIX_HOME variables properly.\n"
                "Current values:\nPHENIX_HOME = /usr/local/phenix-1.13-2998\n")

            return
        # self.assertTrue(False)

        # check validation cryoem results
        self.checkValCryoEMResults(ramOutliers=0.00,
                                   ramFavored=96.11,
                                   rotOutliers=3.04,
                                   cbetaOutliers=0,
                                   clashScore=5.30,
                                   overallScore=1.92,
                                   protValCryoEM=protValCryoEM)
Example #12
0
    def testValCryoEMFromVolumeAndPDB1(self):
        """ This test checks that phenix real_space_refine protocol runs
        with a volume provided directly as inputVol, the input PDB was fitted
        to the volume and refined previously by coot and refmac withouth mask
        in another project; (MolProbity has been run to compare values before
        and after refinement); default refine strategy;
        MolProbity and ValCryoEM after RSRefine should show identical values
        """
        print("Run phenix real_space_refine from imported volume and pdb file "
              "previously fitted and refined by Coot and Refmac without mask "
              "(MolProbity has been run to compare values before and after "
              "refinement); default refine strategy; MolProbity and ValCryoEM "
              "after RSRefine should show identical values")

        # Import Volume
        volume_refmac3 = self._importVolRefmac3()

        # import PDB
        structure_refmac3 = self._importStructRefmac3()

        #MolProbity
        args = {
            'inputVolume': volume_refmac3,
            'resolution': 3.5,
            'inputStructure': structure_refmac3,
            'numberOfThreads': 4
        }

        protMolProbity = self.newProtocol(PhenixProtRunMolprobity, **args)
        protMolProbity.setObjLabel('MolProbity validation\n'
                                   'volume and pdb\n')
        self.launchProtocol(protMolProbity)

        # check MolProbity results
        self.checkMPResults(ramOutliers=0.47,
                            ramFavored=83.96,
                            rotOutliers=5.68,
                            cbetaOutliers=1,
                            clashScore=4.77,
                            overallScore=2.50,
                            protMolProbity=protMolProbity)

        # real_space_refine
        args = {
            'inputVolume': volume_refmac3,
            'resolution': 3.5,
            'inputStructure': structure_refmac3
            # default parameters in Optimization strategy options
        }
        if Plugin.getPhenixVersion() == PHENIXVERSION:
            args['doSecondary'] = False
        protRSRefine = self.newProtocol(PhenixProtRunRSRefine, **args)
        protRSRefine.setObjLabel('RSRefine\n refmac3.mrc and ' 'refmac3.pdb\n')
        self.launchProtocol(protRSRefine)

        # check real_space_refine results
        if Plugin.getPhenixVersion() == PHENIXVERSION:
            self.checkRSRefineResults(ramOutliers=0.00,
                                      ramFavored=95.75,
                                      rotOutliers=0.00,
                                      cbetaOutliers=0,
                                      clashScore=2.09,
                                      overallScore=1.27,
                                      protRSRefine=protRSRefine)
        else:
            self.checkRSRefineResults(ramOutliers=0.00,
                                      ramFavored=96.23,
                                      rotOutliers=3.41,
                                      cbetaOutliers=0,
                                      clashScore=4.17,
                                      overallScore=1.86,
                                      protRSRefine=protRSRefine)
        # MolProbity2
        args = {
            'inputVolume': volume_refmac3,
            'resolution': 3.5,
            'inputStructure': protRSRefine.outputPdb,
            'numberOfThreads': 4
        }
        protMolProbity2 = self.newProtocol(PhenixProtRunMolprobity, **args)
        protMolProbity2.setObjLabel('MolProbity\n' 'after RSRefine\n')
        self.launchProtocol(protMolProbity2)

        # check MolProbity results
        if Plugin.getPhenixVersion() == PHENIXVERSION:
            self.checkMPResults(ramOutliers=0.00,
                                ramFavored=95.75,
                                rotOutliers=0.00,
                                cbetaOutliers=0,
                                clashScore=2.09,
                                overallScore=1.27,
                                protMolProbity=protMolProbity2)
        elif Plugin.getPhenixVersion() == PHENIXVERSION19:
            self.checkMPResults(ramOutliers=0.00,
                                ramFavored=98.58,
                                rotOutliers=1.70,
                                cbetaOutliers=0,
                                clashScore=2.09,
                                overallScore=1.16,
                                protMolProbity=protMolProbity2)
        else:
            self.checkMPResults(ramOutliers=0.00,
                                ramFavored=96.23,
                                rotOutliers=3.41,
                                cbetaOutliers=0,
                                clashScore=4.17,
                                overallScore=1.86,
                                protMolProbity=protMolProbity2)

        # validation_cryoEM
        args = {
            'inputVolume': volume_refmac3,
            'resolution': 3.5,
            'inputStructure': protRSRefine.outputPdb
        }
        protValCryoEM = self.newProtocol(PhenixProtRunValidationCryoEM, **args)
        protValCryoEM.setObjLabel('ValCryoEM\nafter RSRefine\nrefmac3.mrc and '
                                  'protRSRefine.outputPdb\n')
        try:
            self.launchProtocol(protValCryoEM)
        except Exception as e:
            self.assertTrue(
                True, "This test should return a error message as '"
                " Protocol has validation errors:\n"
                "Binary '/usr/local/phenix-1.13-2998/modules/phenix/phenix/"
                "command_line/validation_cryoem.py' does not exists.\n"
                "Check if you need to upgrade your PHENIX version to run "
                "VALIDATION_CRYOEM.\nYour current PHENIX version is 1.13.\n"
                "Check configuration file: " + Config.SCIPION_LOCAL_CONFIG +
                "\n"
                "and set VALIDATION_CRYOEM and PHENIX_HOME variables properly.\n"
                "Current values:\nPHENIX_HOME = /usr/local/phenix-1.13-2998\n")

            return
        # self.assertTrue(False)

        # check validation cryoem results
        self.checkValCryoEMResults(ramOutliers=0.00,
                                   ramFavored=96.70,
                                   rotOutliers=3.98,
                                   cbetaOutliers=0,
                                   clashScore=4.47,
                                   overallScore=1.89,
                                   protValCryoEM=protValCryoEM)
Example #13
0
    def testValCryoEMFFromVolumeAssociatedToPDB3(self):
        """ This test checks that phenix real_space_refine protocol runs
        with a volume provided directly as inputVol and the input PDB from
        data banks; default refine strategy; (MolProbity has been run to
        compare values before and after refinement). MolProbity and
        ValCryoEM after RSRefine should show identical values.
        """
        print("Run phenix real_space_refine from imported volume and pdb file "
              "from data banks (vol origin 0.0, 0.0, 0.0); default refine "
              "strategy; (MolProbity has been run to compare values before "
              "and after refinement). MolProbity and ValCryoEM after RSRefine "
              "should show identical values.")

        # import PDB
        structure_nucleosome_pdb = self._importStructNucleosomePDB()

        # MolProbity
        args = {
            'inputStructure': structure_nucleosome_pdb,
            'numberOfThreads': 4
        }
        protMolProbity = self.newProtocol(PhenixProtRunMolprobity, **args)
        protMolProbity.setObjLabel('MolProbity validation\n'
                                   'volume and pdb\nnucleosome')
        self.launchProtocol(protMolProbity)

        # check MolProbity results
        self.checkMPResults(ramOutliers=1.77,
                            ramFavored=87.62,
                            rotOutliers=10.40,
                            cbetaOutliers=2,
                            clashScore=12.17,
                            overallScore=2.98,
                            protMolProbity=protMolProbity)

        # real_space_refine
        args = {
            'resolution': 4.0,
            'inputStructure': structure_nucleosome_pdb,
            'numberOfThreads': 4
        }
        if Plugin.getPhenixVersion() == PHENIXVERSION:
            args['doSecondary'] = False
        protRSRefine = self.newProtocol(PhenixProtRunRSRefine, **args)
        protRSRefine.setObjLabel('RSRefine nucleosome\nvolume and ' 'pdb\n')

        # TODO, this protocol fails because
        # Opening quote in middle of word: ATOM 5963 O5' . DA I -72 ? 73.27900 73.22500 141.39500 1.000 212.95366 O ? L ? . 1
        # so 05' is not valid for the cif reader, I think is fair and should
        # not be counted as a problem
        self.launchProtocol(
            protRSRefine)  #Keep this line commented in pull requests
        # return; self.launchProtocol(protRSRefine)

        # check real_space_refine results
        if Plugin.getPhenixVersion() == PHENIXVERSION:
            self.checkRSRefineResults(ramOutliers=0.00,
                                      ramFavored=95.92,
                                      rotOutliers=0.16,
                                      cbetaOutliers=0,
                                      clashScore=7.46,
                                      overallScore=1.69,
                                      protRSRefine=protRSRefine)
        elif Plugin.getPhenixVersion() == PHENIXVERSION18:
            self.checkRSRefineResults(ramOutliers=0.00,
                                      ramFavored=96.19,
                                      rotOutliers=12.32,
                                      cbetaOutliers=0,
                                      clashScore=12.40,
                                      overallScore=2.69,
                                      protRSRefine=protRSRefine)
        elif Plugin.getPhenixVersion() == PHENIXVERSION19:
            self.checkRSRefineResults(ramOutliers=0.00,
                                      ramFavored=98.23,
                                      rotOutliers=2.72,
                                      cbetaOutliers=0,
                                      clashScore=7.65,
                                      overallScore=1.75,
                                      protRSRefine=protRSRefine)
        else:
            self.checkRSRefineResults(ramOutliers=0.00,
                                      ramFavored=94.42,
                                      rotOutliers=11.04,
                                      cbetaOutliers=0,
                                      clashScore=12.92,
                                      overallScore=2.79,
                                      protRSRefine=protRSRefine)

        # MolProbity2
        args = {'inputStructure': protRSRefine.outputPdb, 'numberOfThreads': 4}
        protMolProbity2 = self.newProtocol(PhenixProtRunMolprobity, **args)
        protMolProbity2.setObjLabel('MolProbity validation\n'
                                    'volume and pdb\nnucleosome')
        self.launchProtocol(protMolProbity2)

        # check MolProbity results
        if Plugin.getPhenixVersion() == PHENIXVERSION:
            self.checkMPResults(ramOutliers=0.00,
                                ramFavored=95.92,
                                rotOutliers=0.16,
                                cbetaOutliers=0,
                                clashScore=7.46,
                                overallScore=1.69,
                                protMolProbity=protMolProbity2)
        elif Plugin.getPhenixVersion() == PHENIXVERSION18:
            self.checkMPResults(ramOutliers=0.00,
                                ramFavored=96.19,
                                rotOutliers=12.32,
                                cbetaOutliers=0,
                                clashScore=12.45,
                                overallScore=2.69,
                                protMolProbity=protMolProbity2)
        elif Plugin.getPhenixVersion() == PHENIXVERSION19:
            self.checkMPResults(ramOutliers=0.00,
                                ramFavored=98.23,
                                rotOutliers=2.72,
                                cbetaOutliers=0,
                                clashScore=7.65,
                                overallScore=1.75,
                                protMolProbity=protMolProbity2)
        else:
            self.checkMPResults(ramOutliers=0.00,
                                ramFavored=94.42,
                                rotOutliers=12.96,
                                cbetaOutliers=0,
                                clashScore=12.96,
                                overallScore=2.80,
                                protMolProbity=protMolProbity2)
        # TODO: Talk to Roberto if we have to continue testing these values (rotOutliers)

        # validation_cryoEM
        args = {'resolution': 4.0, 'inputStructure': protRSRefine.outputPdb}
        protValCryoEM = self.newProtocol(PhenixProtRunValidationCryoEM, **args)
        protValCryoEM.setObjLabel('ValCryoEM\nafter RSRefine\nnucleosome and '
                                  'protRSRefine.outputPdb\n')
        try:
            self.launchProtocol(protValCryoEM)
        except Exception as e:
            self.assertTrue(
                True, "This test should return a error message as '"
                " Protocol has validation errors:\n"
                "Binary '/usr/local/phenix-1.13-2998/modules/phenix/phenix/"
                "command_line/validation_cryoem.py' does not exists.\n"
                "Check if you need to upgrade your PHENIX version to run "
                "VALIDATION_CRYOEM.\nYour current PHENIX version is 1.13.\n"
                "Check configuration file: " + Config.SCIPION_LOCAL_CONFIG +
                "\n"
                "and set VALIDATION_CRYOEM and PHENIX_HOME variables properly.\n"
                "Current values:\nPHENIX_HOME = /usr/local/phenix-1.13-2998\n")

            return
        # self.assertTrue(False)

        # check validation cryoem results
        if Plugin.getPhenixVersion() == PHENIXVERSION18:
            self.checkValCryoEMResults(ramOutliers=0.00,
                                       ramFavored=96.19,
                                       rotOutliers=12.32,
                                       cbetaOutliers=0,
                                       clashScore=12.40,
                                       overallScore=2.69,
                                       protValCryoEM=protValCryoEM)
        elif Plugin.getPhenixVersion() == PHENIXVERSION19:
            self.checkValCryoEMResults(ramOutliers=0.00,
                                       ramFavored=98.23,
                                       rotOutliers=2.72,
                                       cbetaOutliers=0,
                                       clashScore=7.65,
                                       overallScore=1.75,
                                       protValCryoEM=protValCryoEM)
        else:
            self.checkValCryoEMResults(ramOutliers=0.00,
                                       ramFavored=98.58,
                                       rotOutliers=1.70,
                                       cbetaOutliers=0,
                                       clashScore=2.09,
                                       overallScore=1.16,
                                       protValCryoEM=protValCryoEM)
Example #14
0
class PhenixProtSearchFit(PhenixProtRunRefinementBase):
    """given a chain of n alanines, a 3D map and
    a sequence search for the subsequence of n aminoacids
    that better fits in the density. Only works if the
    atomic structure has a single chain
    """
    _label = 'search fit'
    _program = ""
    FITTEDFILE = 'fitted.mrc'
    version = Plugin.getPhenixVersion()

    def __init__(self, **kwargs):
        super(PhenixProtSearchFit, self).__init__(**kwargs)
        self.stepsExecutionMode = STEPS_PARALLEL

    # --------------------------- DEFINE param functions -------------------
    def _defineParams(self, form):
        super(PhenixProtSearchFit, self)._defineParams(form)
        param = form.getParam('numberOfThreads')
        param.default.set(1)
        param = form.getParam('inputStructure')
        param.help.set('Alanine chain used as template')
        form.addParam('inputSequence',
                      PointerParam,
                      pointerClass="Sequence",
                      label='Test sequence',
                      important=True,
                      help="Input the aminoacid sequence to fit with the "
                      "ALA chain.")
        form.addParam('firstaa',
                      StringParam,
                      important=True,
                      label='First residue',
                      help='Select the first residue of the sequence fragment '
                      'that you would like to consider.\n The sequence '
                      'should overlap total or partially the ALA chain.')
        form.addParam('lastaa',
                      StringParam,
                      important=True,
                      label='Last residue',
                      help='Select the last residue of the sequence fragment '
                      'that you would like to consider.\nThe sequence '
                      'should overlap total or partially the ALA chain.')
        form.addParam('extraCommands',
                      StringParam,
                      label="Extra Params ",
                      default="",
                      expertLevel=LEVEL_ADVANCED,
                      help="This string will be added to the Coot\n"
                      " script")
        # real space refine
        form.addParam(
            "doSecondary",
            BooleanParam,
            label="Secondary structure",
            default=True,
            expertLevel=LEVEL_ADVANCED,
            help="Set to TRUE to use secondary structure "
            "restraints.\nOnly for PHENIX versions higher than 1.13.")
        form.addParam("macroCycles",
                      IntParam,
                      label="Macro cycles",
                      default=5,
                      expertLevel=LEVEL_ADVANCED,
                      help="Number of iterations of refinement.\nAlthough 5 "
                      "macro-cycles is usually sufficient, in cases in "
                      "which model geometry or/and model-to-map fit is "
                      "poor the use of more macro-cycles could be "
                      "helpful.\n")
        group = form.addGroup('Optimization strategy options')
        group.addParam('minimizationGlobal',
                       BooleanParam,
                       label="Global minimization: ",
                       default=True,
                       expertLevel=LEVEL_ADVANCED,
                       help="Phenix default parameter to look for the global "
                       "minimum of the model.\nGenerally, refinement "
                       "with all defaults is "
                       "sufficient.\nOther options "
                       "of use: run=minimization_global+local_grid_search"
                       "+morphing+simulated_annealing\n")
        group.addParam('rigidBody',
                       BooleanParam,
                       label="Rigid body: ",
                       default=False,
                       expertLevel=LEVEL_ADVANCED,
                       help="Refinement strategy that considers groups of "
                       "atoms that move (rotate and translate) as a "
                       "single body.\n")
        group.addParam('localGridSearch',
                       BooleanParam,
                       label="Local grid search: ",
                       default=False,
                       expertLevel=LEVEL_ADVANCED,
                       help="Refinement strategy that considers "
                       "local rotamer fitting.\n\n Generally, refinement "
                       "with all defaults is sufficient.\n Including "
                       "local fitting, morphing, "
                       "or simulated annealing "
                       "( local_grid_search+morphing+simulated_annealing) "
                       "into refinement may significantly increase "
                       "runtime.\nOther options "
                       "of use: run=minimization_global+local_grid_search"
                       "+morphing+simulated_annealing\n")
        group.addParam('morphing',
                       BooleanParam,
                       label="Morphing ",
                       default=False,
                       expertLevel=LEVEL_ADVANCED,
                       help="Morphing procedure distorts a model to match an "
                       "electron density map.\n\nGenerally, refinement "
                       "with all defaults is "
                       "sufficient.\n Including local fitting, morphing, "
                       "or simulated annealing "
                       "( local_grid_search+morphing+simulated_annealing) "
                       "into refinement may significantly increase "
                       "runtime.\nOther options "
                       "of use: run=minimization_global+local_grid_search"
                       "+morphing+simulated_annealing\n")
        group.addParam('simulatedAnnealing',
                       BooleanParam,
                       label="Simulated annealing ",
                       default=False,
                       expertLevel=LEVEL_ADVANCED,
                       help="Optimization technique known as molecular "
                       "dynamics refinement; it minimizes the energy of "
                       "the model.\n"
                       "Generally, refinement with all defaults is "
                       "sufficient.\n Including local fitting, morphing, "
                       "or simulated annealing "
                       "( local_grid_search+morphing+simulated_annealing) "
                       "into refinement may significantly increase "
                       "runtime.\nOther options "
                       "of use: run=minimization_global+local_grid_search"
                       "+morphing+simulated_annealing\n")
        group.addParam('adp',
                       BooleanParam,
                       label="Atomic Displacement Parameters (ADPs) ",
                       default=True,
                       expertLevel=LEVEL_ADVANCED,
                       help="Phenix default parameter.\nGenerally, refinement "
                       "with all defaults is sufficient.\n\nADP ("
                       "B-factors) refinement against the map is "
                       "performed at the last macro-cycle only. ")
        form.addParallelSection(threads=0, mpi=1)

    # --------------------------- INSERT steps functions ---------------
    def _insertAllSteps(self):
        # compute alanine atom struct len
        inputPdb = self.inputStructure.get().getFileName()
        atomStruct = AtomicStructHandler(inputPdb)
        # we assume that there is a single model and a single chain
        atomStructSize = sum(1
                             for _ in atomStruct.getStructure().get_residues())
        chainName = next(atomStruct.getStructure().get_chains()).get_id()
        firstAAinChain = next(atomStruct.getStructure().get_residues()).id[1]

        # starting and ending residue
        firstaa = int(self.firstaa.get().split(":")[1].split(",")[0].strip())
        lastaa = int(self.lastaa.get().split(":")[1].split(",")[0].strip())

        # compute number of steps according to the sequence size
        numberOfSteps = lastaa - firstaa + 1

        # steps
        prepareId = self._insertFunctionStep('convertInputStep',
                                             self.FITTEDFILE)
        # mutateChain
        mutateId = self._insertFunctionStep(
            'mutateStep',
            firstaa,  # in seq
            firstAAinChain,  # in struct
            atomStructSize,
            chainName,
            numberOfSteps,
            prerequisites=[prepareId])
        refineIdList = []
        numberOfThreads = self.numberOfMpi.get()
        for start in range(numberOfThreads):
            refineId = self._insertFunctionStep('refineStep2',
                                                prerequisites=[mutateId])
            refineIdList.append(refineId)

        self._insertFunctionStep('createOutputStep',
                                 prerequisites=refineIdList)

    # --------------------------- STEPS functions --------------------------

    def createTable(self):
        """ Create table and clean it if needed"""
        conn = sqlite3.connect(os.path.abspath(self._getExtraPath(DATAFILE)))
        c = conn.cursor()
        create_table_sql = """CREATE TABLE IF NOT EXISTS %s (   id INTEGER PRIMARY KEY AUTOINCREMENT,
                                                                  filename TEXT,
                                                                  done int DEFAULT 0,
                                                                  model_to_map_fit float DEFAULT -1,
                                                                  phenix_id TEXT default ''
                                                                  )""" % TABLE
        print("create_table_sql", create_table_sql)
        c.execute(create_table_sql)
        c.close()
        conn.close()

    def mutateStep(self, firstaa, firstAAinChain, atomStructSize, chainName,
                   numberOfSteps):
        """ mutate atom struct inputStructure using
           aa in sequence  inputSequence starting at firstaa"""
        scriptFile = self._getExtraPath(COOTSCRIPTFILENAME)
        f = open(scriptFile, "w")
        fnAtomStruct = self.inputStructure.get().getFileName()
        f.write("# read atom structure (pdb) file\n")
        f.write("read_pdb('%s')\n" % os.path.abspath(fnAtomStruct))
        f.write("# mutation loop\n")
        database = os.path.abspath(self._getExtraPath(DATAFILE))
        f.write("import sqlite3\n")
        f.write("conn = sqlite3.connect('%s')\n" % database)
        f.write("cur = conn.cursor()\n")
        iMol = 0  # pdb id is  0 or 1 for inverse
        startMut = firstAAinChain  # 1
        endMut = firstAAinChain + atomStructSize - 1
        self.createTable()

        for start in range(numberOfSteps):
            seq = self.inputSequence.get().getSequence()[firstaa +
                                                         start:firstaa +
                                                         start +
                                                         atomStructSize]
            f.write("mutate_residue_range(%d, '%s', %d, %d, '%s')\n" %
                    (iMol, chainName, startMut, endMut, seq))
            outFileName = self._getExtraPath(COOTPDBTEMPLATEFILENAME %
                                             (0, 0, start))
            f.write("save_coordinates(0, '%s')\n" % outFileName)
            command = "INSERT INTO %s(filename) VALUES('%s')" % (
                TABLE, os.path.abspath(outFileName))
            f.write('cur.execute("%s")\n' % command)
        # invert sequence
        ##iMol = 1 # pdb id is  0 or 1 for inverse
        ##f.write('reverse_direction_of_fragment(0, "%s", 1)\n'% chainName)
        ##f.write('db_mainchain(0, "%s", %d, %d,"forwards")\n' % (chainName, startMut, endMut))
        ##for start in range(numberOfSteps):
        ##    seq = self.inputSequence.get().getSequence()[firstaa + start : firstaa + start + atomStructSize]
        ##    f.write("mutate_residue_range(%d, '%s', %d, %d, '%s')\n" % (iMol,
        ##                                                              chainName,
        ##                                                              startMut,
        ##                                                              endMut,
        ##                                                              seq))
        ##    outFileName = self._getExtraPath(COOTPDBTEMPLATEFILENAMEINV% (0,0,start))
        ##    f.write("save_coordinates(1, '%s')\n" % outFileName)
        ##    command = "INSERT INTO %s(filename) VALUES('%s')" % (TABLE,
        ##                                                         os.path.abspath(outFileName)
        ##                                                         )
        ##    f.write('cur.execute("%s")\n' % command)
        if len(self.extraCommands.get()) > 0:
            f.write("\n#Extra Commands\n")
            f.write("%s\n" % self.extraCommands.get())
        f.write("conn.commit()\n")
        f.write("cur.close()\n")
        f.write("conn.close()\n")
        f.write("exit(0)\n")
        f.close()

        args = ""
        args += " --no-graphics "
        args += " -s %s" % scriptFile
        # run
        self._log.info('Launching: ' + PluginCCP4.getProgram(COOT) + ' ' +
                       args)
        runCCP4Program(PluginCCP4.getProgram(COOT), args)

    def extractNumber(self, filename):
        myfile = open(filename, "rt")
        contents = myfile.read()
        myfile.close()
        m = re.findall(
            r"verall(.+)\n(\*+)\nmodel-to-map fit, CC_mask: (\d+.\d+)",
            contents)[-1]
        # [-1] --> find last ocurrence
        return m[2]

    def refineStep2(self):
        # atomStruct = os.path.abspath(self.inputStructure.get().getFileName())
        ## vol = os.path.abspath(self._getInputVolume().getFileName())
        vol = os.path.abspath(self._getExtraPath(self.FITTEDFILE))
        cwd = os.getcwd() + "/" + self._getExtraPath()
        conn = sqlite3.connect(os.path.abspath(self._getExtraPath(DATAFILE)))
        c = conn.cursor()
        while 1:
            command = """SELECT filename from %s
                         WHERE done=0
                         LIMIT 1""" % TABLE
            c.execute(command)
            myrow = c.fetchone()
            if not myrow:
                print("refineStep: no more available works")
                break  # break while if no job is available

            atomStructFn, = myrow
            c.execute("""UPDATE %s
                            SET done=1
                          WHERE filename='%s' AND done=0""" %
                      (TABLE, atomStructFn))
            # ^^^^^^ This will return the number of rows updated (c.rowcount).
            # Note that we only update if done is still '0', so if we get 1 updated
            # row, we're sure no one else took our job. This works because UPDATE is atomic.

            if not c.rowcount:
                # Whoops this job was taken! Try again and get another one
                continue
            conn.commit()

            args = self._writeArgsRSR(atomStructFn, vol)
            retry(
                Plugin.runPhenixProgram,
                Plugin.getProgram(REALSPACEREFINE),
                args,
                # cwd=os.path.abspath(self._getExtraPath()),
                cwd=cwd,
                listAtomStruct=[atomStructFn],
                log=self._log)
            if Plugin.getPhenixVersion() >= PHENIXVERSION19:
                # update data base with phenix version
                logFileFn = atomStructFn[:-4] + "_real_space_refined_???.log"
                # last file
                lastLogFile = sorted(glob.glob(logFileFn))[-1]
                phenix_id = lastLogFile[-8:-4]  # _000
                c.execute("""UPDATE %s
                                SET phenix_id='%s'
                              WHERE filename='%s'""" %
                          (TABLE, phenix_id, atomStructFn))
            else:
                phenix_id = ''
            conn.commit()
            #            refinedFile = False
            #            for item in os.listdir(self._getExtraPath()):
            #                p = re.compile('\d+')
            #                if p.search(item) is not None and item.endswith(".cif"):
            #                    self.refinedFile = True
            #                    break
            #
            #            if self.refinedFile == False:
            #                print("WARNING!!!\nPHENIX error:\n pdb_interpretation.clash_guard" \
            #                      " failure: High number of nonbonded interaction distances " \
            #                      "< 0.5. This error has been disable by running the same " \
            #                      "command with the same following additional " \
            #                      "argument:\npdb_interpretation.clash_guard." \
            #                      "nonbonded_distance_threshold=None ")
            #                args += " "
            #                args += "pdb_interpretation.clash_guard." \
            #                        "nonbonded_distance_threshold=None"
            #                retry(Plugin.runPhenixProgram,
            #                      Plugin.getProgram(REALSPACEREFINE), args,
            #                      # cwd=os.path.abspath(self._getExtraPath()),
            #                      cwd=cwd,
            #                      listAtomStruct=[atomStructFn], log=self._log)
            # coot_000000_Imol_0000_version_0004_real_space_refined_001.eff
            # coot_000000_Imol_0000_version_0030.pdb
            # glob
            logFileFn = atomStructFn[:-4] + "_real_space_refined%s.log" % phenix_id
            model_to_map_fit = self.extractNumber(logFileFn)
            accepted = c.execute(
                """UPDATE %s
                                    SET model_to_map_fit=%f
                                    WHERE filename='%s'""" %
                (TABLE, float(model_to_map_fit), atomStructFn))
            conn.commit()
        c.close()
        conn.close()

    def createOutputStep(self):
        # viewer: extract cc from database and plot it
        # make 5 pdbs with higher score available to scipion
        conn = sqlite3.connect(os.path.abspath(self._getExtraPath(DATAFILE)))
        c = conn.cursor()
        sqlCommand = """SELECT filename, model_to_map_fit, phenix_id
                                    FROM   %s
                                    ORDER BY model_to_map_fit DESC
                                    LIMIT 5""" % TABLE
        c.execute(sqlCommand)
        rows = c.fetchall()

        argsOutput = {}
        for counter, row in enumerate(rows):
            atomStructFn = row[0][:-4] + "_real_space_refined%s.log" % row[2]
            atomStruct = AtomStruct()
            atomStruct.setFileName(atomStructFn)
            argsOutput["outputAtomStruct_%d" % counter] = atomStruct
        c.close()
        conn.close()
        self._defineOutputs(**argsOutput)

    # --------------------------- INFO functions ---------------------------

    def _validate(self):
        errors = []
        # Check that the input volume exist
        if self._getInputVolume() is None:
            errors.append("Error: You should provide a volume.\n")
        return errors

#   def _citations(self):
#        return ['Barad_2015']

    def _summary(self):
        summary = ""
        #        summary = PhenixProtRunRefinementBase._summary(self)
        #        summary.append(
        #            "https://www.phenix-online.org/documentation/reference/"
        #            "real_space_refine.html")
        return summary

    def _writeArgsRSR(self, atomStruct, vol):
        if Plugin.getPhenixVersion() >= PHENIXVERSION19:
            args = " "
        else:
            args = " model_file="
        args += "%s " % atomStruct
        if Plugin.getPhenixVersion() >= PHENIXVERSION19:
            args += " "
        else:
            args += " map_file="
        args += "%s " % vol
        args += " resolution=%f" % self.resolution
        args += " secondary_structure.enabled=%s" % self.doSecondary
        args += " run="
        if self.minimizationGlobal == True:
            args += "minimization_global+"
        if self.rigidBody == True:
            args += "rigid_body+"
        if self.localGridSearch == True:
            args += "local_grid_search+"
        if self.morphing == True:
            args += "morphing+"
        if self.simulatedAnnealing == True:
            args += "simulated_annealing+"
        if self.adp == True:
            args += "adp+"
        args = args[:-1]
        # args += " run=minimization_global+local_grid_search+morphing+simulated_annealing"
        args += " macro_cycles=%d" % self.macroCycles
        args += " model_format=pdb+mmcif"
        # args += " write_pkl_stats=True"
        args += " %s " % self.extraParams.get()
        numberOfThreads = self.numberOfThreads.get()
        if numberOfThreads > 1:
            args += " nproc=%d" % numberOfThreads
        return args
Example #15
0
    def testValCryoEMFFromVolumeAndCIFFromPDB(self):
        """ This test checks that phenix real_space_refine protocol runs
        with a volume provided directly as inputVol (with half1 and half2)
        and the input CIF from data banks; default refine strategy;
        (MolProbity has been run to
        compare values before and after refinement). MolProbity and
        ValCryoEM after RSRefine should show identical values.
        """
        print("Run phenix real_space_refine from imported volume and pdb file "
              "from data banks (vol origin 0.0, 0.0, 0.0); default refine "
              "strategy; (MolProbity has been run to compare values before "
              "and after refinement). MolProbity and ValCryoEM after RSRefine "
              "should show identical values.")

        # Import Volume
        volume_hemo_org = self._importVolHemoOrg()

        # import cif
        structure_hemo_cif_PDB = self._importStructHemoFromDB()

        # chimera operate to repair cif file
        extraCommands = ""
        extraCommands += "scipionwrite #2 " \
                         "prefix repaired_CIF_ChimeraX_\n"
        extraCommands += "exit\n"

        args = {
            'extraCommands': extraCommands,
            'pdbFileToBeRefined': structure_hemo_cif_PDB
        }
        protChimera = self.newProtocol(ChimeraProtOperate, **args)
        protChimera.setObjLabel('chimera operate\n repairing CIF\n')
        self.launchProtocol(protChimera)
        result = eval("protChimera.repaired_CIF_ChimeraX_Atom_struct__2_%06d" % \
                 protChimera.getObjId())

        # MolProbity
        args = {
            'inputVolume': volume_hemo_org,
            'resolution': 3.2,
            'inputStructure': result,
            'numberOfThreads': 4
        }
        protMolProbity = self.newProtocol(PhenixProtRunMolprobity, **args)
        protMolProbity.setObjLabel('MolProbity validation\n'
                                   'volume\nand cif from PDB\nhemoglobin')
        self.launchProtocol(protMolProbity)

        # check MolProbity results
        self.checkMPResults(ramOutliers=0.00,
                            ramFavored=95.23,
                            rotOutliers=0.43,
                            cbetaOutliers=0,
                            clashScore=3.53,
                            overallScore=1.48,
                            protMolProbity=protMolProbity)

        # real_space_refine
        args = {
            'inputVolume': volume_hemo_org,
            'resolution': 3.2,
            'inputStructure': structure_hemo_cif_PDB,
            'numberOfThreads': 4
        }
        if Plugin.getPhenixVersion() == PHENIXVERSION:
            args['doSecondary'] = False
        protRSRefine = self.newProtocol(PhenixProtRunRSRefine, **args)
        protRSRefine.setObjLabel('RSRefine hemo\n emd_3488.map\nand '
                                 '5ni1.cif from PDB\n')
        self.launchProtocol(protRSRefine)

        # check real_space_refine results
        if Plugin.getPhenixVersion() == PHENIXVERSION:
            self.checkRSRefineResults(ramOutliers=0.00,
                                      ramFavored=97.53,
                                      rotOutliers=0.00,
                                      cbetaOutliers=0,
                                      clashScore=2.43,
                                      overallScore=1.12,
                                      protRSRefine=protRSRefine)

        elif Plugin.getPhenixVersion() == PHENIXVERSION18:
            self.checkRSRefineResults(ramOutliers=0.00,
                                      ramFavored=96.64,
                                      rotOutliers=4.77,
                                      cbetaOutliers=0,
                                      clashScore=6.07,
                                      overallScore=2.06,
                                      protRSRefine=protRSRefine)
        elif Plugin.getPhenixVersion() == PHENIXVERSION19:
            self.checkRSRefineResults(ramOutliers=0.00,
                                      ramFavored=97.35,
                                      rotOutliers=2.39,
                                      cbetaOutliers=0,
                                      clashScore=3.87,
                                      overallScore=1.59,
                                      protRSRefine=protRSRefine)
        else:
            # values obtained from phenix GUI v. 1.16
            # (minimization_global + adp)
            self.checkRSRefineResults(ramOutliers=0.00,
                                      ramFavored=96.11,
                                      rotOutliers=3.04,
                                      cbetaOutliers=0,
                                      clashScore=5.30,
                                      overallScore=1.92,
                                      protRSRefine=protRSRefine)

        # MolProbity2
        args = {
            'inputVolume': volume_hemo_org,
            'resolution': 3.2,
            'inputStructure': protRSRefine.outputPdb,
            'numberOfThreads': 4
        }
        protMolProbity2 = self.newProtocol(PhenixProtRunMolprobity, **args)
        protMolProbity2.setObjLabel('MolProbity validation\n'
                                    'volume\nand cif\nhemoglobin')
        self.launchProtocol(protMolProbity2)

        # check MolProbity results
        if Plugin.getPhenixVersion() == PHENIXVERSION:
            self.checkMPResults(ramOutliers=0.00,
                                ramFavored=97.53,
                                rotOutliers=0.00,
                                cbetaOutliers=0,
                                clashScore=2.43,
                                overallScore=1.12,
                                protMolProbity=protMolProbity2)
        elif Plugin.getPhenixVersion() == PHENIXVERSION18:
            self.checkMPResults(ramOutliers=0.00,
                                ramFavored=96.64,
                                rotOutliers=4.77,
                                cbetaOutliers=0,
                                clashScore=6.07,
                                overallScore=2.06,
                                protMolProbity=protMolProbity2)
        elif Plugin.getPhenixVersion() == PHENIXVERSION19:
            self.checkMPResults(ramOutliers=0.00,
                                ramFavored=97.35,
                                rotOutliers=2.39,
                                cbetaOutliers=0,
                                clashScore=3.87,
                                overallScore=1.59,
                                protMolProbity=protMolProbity2)
        else:
            self.checkMPResults(ramOutliers=0.00,
                                ramFavored=96.11,
                                rotOutliers=3.04,
                                cbetaOutliers=0,
                                clashScore=5.30,
                                overallScore=1.92,
                                protMolProbity=protMolProbity2)

        # validation_cryoEM
        args = {
            'inputVolume': volume_hemo_org,
            'resolution': 3.2,
            'inputStructure': protRSRefine.outputPdb
        }
        protValCryoEM = self.newProtocol(PhenixProtRunValidationCryoEM, **args)
        protValCryoEM.setObjLabel(
            'ValCryoEM\nafter RSRefine\nvolume_hemo_org and '
            'protRSRefine.outputPdb\n')
        try:
            self.launchProtocol(protValCryoEM)
        except Exception as e:
            self.assertTrue(
                True, "This test should return a error message as '"
                " Protocol has validation errors:\n"
                "Binary '/usr/local/phenix-1.13-2998/modules/phenix/phenix/"
                "command_line/validation_cryoem.py' does not exists.\n"
                "Check if you need to upgrade your PHENIX version to run "
                "VALIDATION_CRYOEM.\nYour current PHENIX version is 1.13.\n"
                "Check configuration file: " + Config.SCIPION_LOCAL_CONFIG +
                "\n"
                "and set VALIDATION_CRYOEM and PHENIX_HOME variables properly.\n"
                "Current values:\nPHENIX_HOME = /usr/local/phenix-1.13-2998\n")

            return
        # self.assertTrue(False)

        # check validation cryoem results
        if Plugin.getPhenixVersion() == PHENIXVERSION19:
            self.checkValCryoEMResults(ramOutliers=0.00,
                                       ramFavored=97.35,
                                       rotOutliers=2.39,
                                       cbetaOutliers=0,
                                       clashScore=3.87,
                                       overallScore=1.59,
                                       protValCryoEM=protValCryoEM)
        else:
            self.checkValCryoEMResults(ramOutliers=0.00,
                                       ramFavored=96.11,
                                       rotOutliers=3.04,
                                       cbetaOutliers=0,
                                       clashScore=5.30,
                                       overallScore=1.92,
                                       protValCryoEM=protValCryoEM)
Example #16
0
    def testPhenixRSRefineFromVolumeAndPDB4(self):
        """ This test checks that phenix real_space_refine protocol runs
        with a volume provided directly as inputVol and the input PDB from
        data banks; default refine strategy; (MolProbity has been run to
        compare values before and after refinement).
        """
        print("Run phenix real_space_refine from imported volume and pdb file "
              "from data banks (vol origin 0.0, 0.0, 0.0); default refine "
              "strategy; (MolProbity has been run to compare values before "
              "and after refinement).")

        # Import Volume
        volume_hemo_org = self._importVolHemoOrg()

        # import PDB
        structure_hemo_pdb = self._importStructHemoPDB()

        # MolProbity
        args = {
            'inputVolume': volume_hemo_org,
            'resolution': 3.2,
            'inputStructure': structure_hemo_pdb,
            'numberOfThreads': 4
        }
        protMolProbity = self.newProtocol(PhenixProtRunMolprobity, **args)
        protMolProbity.setObjLabel('MolProbity validation\n'
                                   'volume and pdb\n')
        self.launchProtocol(protMolProbity)

        # check MolProbity results
        self.checkMPResults(ramOutliers=0.00,
                            ramFavored=95.23,
                            rotOutliers=0.43,
                            cbetaOutliers=0,
                            clashScore=3.53,
                            overallScore=1.48,
                            protMolProbity=protMolProbity)

        # real_space_refine
        args = {
            'inputVolume': volume_hemo_org,
            'resolution': 3.2,
            'inputStructure': structure_hemo_pdb,
            'numberOfThreads': 4
        }
        if Plugin.getPhenixVersion() == PHENIXVERSION:
            args['doSecondary'] = False
        protRSRefine = self.newProtocol(PhenixProtRunRSRefine, **args)
        protRSRefine.setObjLabel('RSRefine hemo\n emd_3488.map and '
                                 '5ni1.pdb\n')
        self.launchProtocol(protRSRefine)

        # check real_space_refine results
        if Plugin.getPhenixVersion() == PHENIXVERSION:
            self.checkRSRefineResults(ramOutliers=0.00,
                                      ramFavored=97.53,
                                      rotOutliers=0.00,
                                      cbetaOutliers=0,
                                      clashScore=2.43,
                                      overallScore=1.12,
                                      protRSRefine=protRSRefine)
        elif Plugin.getPhenixVersion() == PHENIXVERSION18:
            self.checkRSRefineResults(ramOutliers=0.00,
                                      ramFavored=96.64,
                                      rotOutliers=4.77,
                                      cbetaOutliers=0,
                                      clashScore=6.07,
                                      overallScore=2.06,
                                      protRSRefine=protRSRefine)
        elif Plugin.getPhenixVersion() == PHENIXVERSION19:
            self.checkRSRefineResults(ramOutliers=0.00,
                                      ramFavored=97.35,
                                      rotOutliers=2.39,
                                      cbetaOutliers=0,
                                      clashScore=3.87,
                                      overallScore=1.59,
                                      protRSRefine=protRSRefine)
        else:
            self.checkRSRefineResults(ramOutliers=0.00,
                                      ramFavored=96.11,
                                      rotOutliers=3.04,
                                      cbetaOutliers=0,
                                      clashScore=5.30,
                                      overallScore=1.92,
                                      protRSRefine=protRSRefine)
Example #17
0
    def testPhenixRSRefineFromVolumeAndPDB1(self):
        """ This test checks that phenix real_space_refine protocol runs
        with a volume provided directly as inputVol, the input PDB was fitted
        to the volume and refined previously by coot and refmac withouth mask
        in another project; (MolProbity has been run to compare values before
        and after refinement); default refine strategy
        """
        print("Run phenix real_space_refine from imported volume and pdb file "
              "previously fitted and refined by Coot and Refmac without mask "
              "(MolProbity has been run to compare values before and after "
              "refinement); default refine strategy")

        # Import Volume
        volume_refmac3 = self._importVolRefmac3()

        # import PDB
        structure_refmac3 = self._importStructRefmac3()

        #MolProbity
        args = {
            'inputVolume': volume_refmac3,
            'resolution': 3.5,
            'inputStructure': structure_refmac3,
            'numberOfThreads': 4
        }
        protMolProbity = self.newProtocol(PhenixProtRunMolprobity, **args)
        protMolProbity.setObjLabel('MolProbity validation\n'
                                   'volume and pdb\n')
        self.launchProtocol(protMolProbity)

        # check MolProbity results
        self.checkMPResults(ramOutliers=0.47,
                            ramFavored=83.96,
                            rotOutliers=5.68,
                            cbetaOutliers=1,
                            clashScore=4.77,
                            overallScore=2.50,
                            protMolProbity=protMolProbity)

        # real_space_refine
        args = {
            'inputVolume': volume_refmac3,
            'resolution': 3.5,
            'inputStructure': structure_refmac3,
            'numberOfThreads': 4
            # default parameters in Optimization strategy options
        }
        if Plugin.getPhenixVersion() == PHENIXVERSION:
            args['doSecondary'] = False
        protRSRefine = self.newProtocol(PhenixProtRunRSRefine, **args)
        protRSRefine.setObjLabel('RSRefine\n refmac3.mrc and ' 'refmac3.pdb\n')
        self.launchProtocol(protRSRefine)

        # check real_space_refine results
        if Plugin.getPhenixVersion() == PHENIXVERSION:
            self.checkRSRefineResults(ramOutliers=0.00,
                                      ramFavored=95.75,
                                      rotOutliers=0.00,
                                      cbetaOutliers=0,
                                      clashScore=2.09,
                                      overallScore=1.27,
                                      protRSRefine=protRSRefine)
        elif Plugin.getPhenixVersion() == PHENIXVERSION19:
            self.checkRSRefineResults(ramOutliers=0.00,
                                      ramFavored=98.56,
                                      rotOutliers=1.70,
                                      cbetaOutliers=0,
                                      clashScore=2.09,
                                      overallScore=1.16,
                                      protRSRefine=protRSRefine)
        else:
            self.checkRSRefineResults(ramOutliers=0.00,
                                      ramFavored=96.70,
                                      rotOutliers=3.98,
                                      cbetaOutliers=0,
                                      clashScore=4.47,
                                      overallScore=1.89,
                                      protRSRefine=protRSRefine)
class PhenixProtRunRSRefine(PhenixProtRunRefinementBase):
    """Tool for extensive real-space refinement of an atomic structure
    against the map provided. The map can be derived from X-ray or neutron
    crystallography, or cryoEM. The program obtains a model that fits the map
    as well as possible having appropriate geometry. The model should not show
    validation outliers, such as Ramachandran plot or rotamer outliers.
    """
    _label = 'real space refine'
    _program = ""
    # _version = VERSION_1_2
    REALSPACEFILE = 'real_space.mrc'
    if Plugin.getPhenixVersion() != PHENIXVERSION:
        VALIDATIONCRYOEMPKLFILE = 'validation_cryoem.pkl'

    # --------------------------- DEFINE param functions -------------------
    def _defineParams(self, form):
        super(PhenixProtRunRSRefine, self)._defineParams(form)
        param = form.getParam('inputVolume')
        param.help.set(
            "\nSet the starting volume.\nPhenix will refine the "
            "atomic structure according to the volume density.\n"
            "Volume and atomic structure have to be correctly fitted. "
            "Otherwise, values of real-space correlation will indicate "
            "not correlation at all.\n")
        form.addParam(
            "doSecondary",
            BooleanParam,
            label="Secondary structure",
            default=True,
            expertLevel=LEVEL_ADVANCED,
            help="Set to TRUE to use secondary structure "
            "restraints.\nOnly for PHENIX versions higher than 1.13.")
        form.addParam("macroCycles",
                      IntParam,
                      label="Macro cycles",
                      default=5,
                      expertLevel=LEVEL_ADVANCED,
                      help="Number of iterations of refinement.\nAlthough 5 "
                      "macro-cycles is usually sufficient, in cases in "
                      "which model geometry or/and model-to-map fit is "
                      "poor the use of more macro-cycles could be "
                      "helpful.\n")
        group = form.addGroup('Optimization strategy options')
        group.addParam('minimizationGlobal',
                       BooleanParam,
                       label="Global minimization: ",
                       default=True,
                       expertLevel=LEVEL_ADVANCED,
                       help="Phenix default parameter to look for the global "
                       "minimum of the model.\nGenerally, refinement "
                       "with all defaults is "
                       "sufficient.\nOther options "
                       "of use: run=minimization_global+local_grid_search"
                       "+morphing+simulated_annealing\n")
        group.addParam('rigidBody',
                       BooleanParam,
                       label="Rigid body: ",
                       default=False,
                       expertLevel=LEVEL_ADVANCED,
                       help="Refinement strategy that considers groups of "
                       "atoms that move (rotate and translate) as a "
                       "single body.\n")
        group.addParam('localGridSearch',
                       BooleanParam,
                       label="Local grid search: ",
                       default=False,
                       expertLevel=LEVEL_ADVANCED,
                       help="Refinement strategy that considers "
                       "local rotamer fitting.\n\n Generally, refinement "
                       "with all defaults is sufficient.\n Including "
                       "local fitting, morphing, "
                       "or simulated annealing "
                       "( local_grid_search+morphing+simulated_annealing) "
                       "into refinement may significantly increase "
                       "runtime.\nOther options "
                       "of use: run=minimization_global+local_grid_search"
                       "+morphing+simulated_annealing\n")
        group.addParam('morphing',
                       BooleanParam,
                       label="Morphing ",
                       default=False,
                       expertLevel=LEVEL_ADVANCED,
                       help="Morphing procedure distorts a model to match an "
                       "electron density map.\n\nGenerally, refinement "
                       "with all defaults is "
                       "sufficient.\n Including local fitting, morphing, "
                       "or simulated annealing "
                       "( local_grid_search+morphing+simulated_annealing) "
                       "into refinement may significantly increase "
                       "runtime.\nOther options "
                       "of use: run=minimization_global+local_grid_search"
                       "+morphing+simulated_annealing\n")
        group.addParam('simulatedAnnealing',
                       BooleanParam,
                       label="Simulated annealing ",
                       default=False,
                       expertLevel=LEVEL_ADVANCED,
                       help="Optimization technique known as molecular "
                       "dynamics refinement; it minimizes the energy of "
                       "the model.\n"
                       "Generally, refinement with all defaults is "
                       "sufficient.\n Including local fitting, morphing, "
                       "or simulated annealing "
                       "( local_grid_search+morphing+simulated_annealing) "
                       "into refinement may significantly increase "
                       "runtime.\nOther options "
                       "of use: run=minimization_global+local_grid_search"
                       "+morphing+simulated_annealing\n")
        group.addParam('adp',
                       BooleanParam,
                       label="Atomic Displacement Parameters (ADPs) ",
                       default=True,
                       expertLevel=LEVEL_ADVANCED,
                       help="Phenix default parameter.\nGenerally, refinement "
                       "with all defaults is sufficient.\n\nADP ("
                       "B-factors) refinement against the map is "
                       "performed at the last macro-cycle only. ")

        # form.addParallelSection(threads=1, mpi=0)

    # --------------------------- INSERT steps functions ---------------
    def _insertAllSteps(self):
        self._insertFunctionStep('convertInputStep', self.REALSPACEFILE)
        self._insertFunctionStep('runRSrefineStep', self.REALSPACEFILE)
        self._insertFunctionStep('runMolprobityStep', self.REALSPACEFILE)
        if Plugin.getPhenixVersion() != PHENIXVERSION:
            self._insertFunctionStep('runValidationCryoEMStep',
                                     self.REALSPACEFILE)
        self._insertFunctionStep('createOutputStep')

    # --------------------------- STEPS functions --------------------------
    def runRSrefineStep(self, tmpMapFile):
        atomStruct = os.path.abspath(self.inputStructure.get().getFileName())
        vol = os.path.abspath(self._getExtraPath(tmpMapFile))
        args = self._writeArgsRSR(atomStruct, vol)
        cwd = os.getcwd() + "/" + self._getExtraPath()

        retry(
            Plugin.runPhenixProgram,
            Plugin.getProgram(REALSPACEREFINE),
            args,
            # cwd=os.path.abspath(self._getExtraPath()),
            cwd=cwd,
            listAtomStruct=[atomStruct],
            log=self._log)
        self.refinedFile = False
        for item in os.listdir(self._getExtraPath()):
            p = re.compile('\d+')
            if p.search(item) is not None and item.endswith(".cif"):
                self.refinedFile = True
                break

        if self.refinedFile == False:
            print("WARNING!!!\nPHENIX error:\n pdb_interpretation.clash_guard" \
                  " failure: High number of nonbonded interaction distances " \
                  "< 0.5. This error has been disable by running the same " \
                  "command with the same following additional " \
                  "argument:\npdb_interpretation.clash_guard." \
                  "nonbonded_distance_threshold=None ")
            args += " pdb_interpretation.clash_guard." \
                    "nonbonded_distance_threshold=None"
            retry(
                Plugin.runPhenixProgram,
                Plugin.getProgram(REALSPACEREFINE),
                args,
                # cwd=os.path.abspath(self._getExtraPath()),
                cwd=cwd,
                listAtomStruct=[atomStruct],
                log=self._log)

    def runMolprobityStep(self, tmpMapFile):
        # PDBx/mmCIF
        self._getRSRefineOutput()
        atomStruct = os.path.abspath(self.outAtomStructName)
        # starting volume (.mrc)
        vol = os.path.abspath(self._getExtraPath(tmpMapFile))
        args = self._writeArgsMolProbity(atomStruct, vol)
        cwd = os.getcwd() + "/" + self._getExtraPath()
        retry(
            Plugin.runPhenixProgram,
            Plugin.getProgram(MOLPROBITY2),
            # args, cwd=os.path.abspath(self._getExtraPath()),
            args,
            cwd=cwd,
            listAtomStruct=[atomStruct],
            log=self._log)

    def runValidationCryoEMStep(self, tmpMapFile):
        # PDBx/mmCIF
        atomStruct = os.path.abspath(self.outAtomStructName)
        # starting volume (.mrc)
        volume = os.path.abspath(self._getExtraPath(tmpMapFile))
        if self.inputVolume.get() is not None:
            vol = self.inputVolume.get()
        else:
            vol = self.inputStructure.get().getVolume()

        args = self._writeArgsValCryoEM(atomStruct, volume, vol)
        cwd = os.getcwd() + "/" + self._getExtraPath()
        retry(
            Plugin.runPhenixProgram,
            Plugin.getProgram(VALIDATION_CRYOEM),
            # args, cwd=os.path.abspath(self._getExtraPath()),
            args,
            cwd=cwd,
            listAtomStruct=[atomStruct],
            log=self._log)

    def createOutputStep(self):
        # self._getRSRefineOutput()
        pdb = AtomStruct()
        pdb.setFileName(self.outAtomStructName)

        if self.inputVolume.get() is not None:
            pdb.setVolume(self.inputVolume.get())
        else:
            pdb.setVolume(self.inputStructure.get().getVolume())
        self._defineOutputs(outputPdb=pdb)
        self._defineSourceRelation(self.inputStructure.get(), pdb)
        if self.inputVolume.get() is not None:
            self._defineSourceRelation(self.inputVolume.get(), pdb)

        if Plugin.getPhenixVersion() == PHENIXVERSION:
            MOLPROBITYOUTFILENAME = self._getExtraPath(
                self.MOLPROBITYOUTFILENAME)
            self._parseFile(MOLPROBITYOUTFILENAME)
        else:
            VALIDATIONCRYOEMPKLFILENAME = self._getExtraPath(
                self.VALIDATIONCRYOEMPKLFILE)
            self._readValidationPklFile(VALIDATIONCRYOEMPKLFILENAME)
        self._store()

    # --------------------------- INFO functions ---------------------------

    def _validate(self):
        errors = self.validateBase(REALSPACEREFINE, 'REALSPACEREFINE')

        # Check that the input volume exist
        if self._getInputVolume() is None:
            errors.append("Error: You should provide a volume.\n")
        return errors

    def _citations(self):
        return ['Barad_2015']

    def _summary(self):
        summary = PhenixProtRunRefinementBase._summary(self)
        summary.append("https://www.phenix-online.org/documentation/reference/"
                       "real_space_refine.html")
        return summary

    # --------------------------- UTILS functions --------------------------

    def _getRSRefineOutput(self):
        inPdbName = os.path.basename(self.inputStructure.get().getFileName())
        list_cif = []
        for item in os.listdir(self._getExtraPath()):
            p = re.compile('\d+')
            if p.search(item) is not None and item.endswith(".cif"):
                list_cif.append(item)
        name = sorted(list_cif)[-1]
        outAtomStructName = self._getExtraPath(name)
        # convert cif to mmcif by using maxit program
        # to get the right number and name of chains
        log = self._log
        self.outAtomStructName = outAtomStructName
        fromCIFTommCIF(outAtomStructName, self.outAtomStructName, log)

    def _writeArgsRSR(self, atomStruct, vol):
        if Plugin.getPhenixVersion() == PHENIXVERSION19:
            args = " "
        else:
            args = " model_file="
        args += "%s " % atomStruct
        if Plugin.getPhenixVersion() == PHENIXVERSION19:
            args += " "
        else:
            args += " map_file="
        args += "%s " % vol
        args += " resolution=%f" % self.resolution
        args += " secondary_structure.enabled=%s" % self.doSecondary
        args += " run="
        if self.minimizationGlobal == True:
            args += "minimization_global+"
        if self.rigidBody == True:
            args += "rigid_body+"
        if self.localGridSearch == True:
            args += "local_grid_search+"
        if self.morphing == True:
            args += "morphing+"
        if self.simulatedAnnealing == True:
            args += "simulated_annealing+"
        if self.adp == True:
            args += "adp+"
        args = args[:-1]
        # args += " run=minimization_global+local_grid_search+morphing+simulated_annealing"
        args += " macro_cycles=%d" % self.macroCycles
        args += " model_format=pdb+mmcif"
        # args += " write_pkl_stats=True"
        args += " %s " % self.extraParams.get()
        numberOfThreads = self.numberOfThreads.get()
        if numberOfThreads > 1:
            args += " nproc=%d" % numberOfThreads
        return args
Example #19
0
    def testPhenixRSRefineFromVolumeAndPDB6(self):
        """ This test checks that phenix real_space_refine protocol runs
        with a volume provided directly as inputVol and the input PDB from
        data banks; alternative refine strategy; (MolProbity has been run to
        compare values before and after refinement).
        """
        print("Run phenix real_space_refine from imported volume and pdb "
              "file from data banks (vol origin 0.0, 0.0, 0.0); alternative "
              "refine strategy; (MolProbity has been run to compare values "
              "before and after refinement).")

        # Import Volume
        volume_hemo_org = self._importVolHemoOrg()

        # import PDB
        structure_hemo_pdb = self._importStructHemoPDB()

        # MolProbity
        args = {
            'inputVolume': volume_hemo_org,
            'resolution': 3.2,
            'inputStructure': structure_hemo_pdb,
            'numberOfThreads': 4
        }
        protMolProbity = self.newProtocol(PhenixProtRunMolprobity, **args)
        protMolProbity.setObjLabel('MolProbity validation\n'
                                   'volume and pdb\n')
        self.launchProtocol(protMolProbity)

        # check MolProbity results
        self.checkMPResults(ramOutliers=0.00,
                            ramFavored=95.23,
                            rotOutliers=0.43,
                            cbetaOutliers=0,
                            clashScore=3.53,
                            overallScore=1.48,
                            protMolProbity=protMolProbity)

        # real_space_refine
        args = {
            'inputVolume': volume_hemo_org,
            'resolution': 3.2,
            'inputStructure': structure_hemo_pdb,
            'localGridSearch': True,
            'morphing': True,
            'simulatedAnnealing': True,
            'adp': False,
            'numberOfThreads': 4
        }
        if Plugin.getPhenixVersion() == PHENIXVERSION:
            args['doSecondary'] = False
        protRSRefine = self.newProtocol(PhenixProtRunRSRefine, **args)
        protRSRefine.setObjLabel('RSRefine hemo\n emd_3488.map and '
                                 '5ni1.pdb\nalternative refine strategy')
        self.launchProtocol(protRSRefine)

        # check real_space_refine results
        if Plugin.getPhenixVersion() == PHENIXVERSION:
            self.checkRSRefineResults(ramOutliers=0.00,
                                      ramFavored=97.35,
                                      rotOutliers=0.00,
                                      cbetaOutliers=0,
                                      clashScore=2.10,
                                      overallScore=1.11,
                                      protRSRefine=protRSRefine)
        elif Plugin.getPhenixVersion() == PHENIXVERSION18:
            self.checkRSRefineResults(ramOutliers=0.00,
                                      ramFavored=97.89,
                                      rotOutliers=0.00,
                                      cbetaOutliers=0,
                                      clashScore=3.76,
                                      overallScore=1.19,
                                      protRSRefine=protRSRefine)
        else:
            self.checkRSRefineResults(ramOutliers=0.00,
                                      ramFavored=96.29,
                                      rotOutliers=3.47,
                                      cbetaOutliers=0,
                                      clashScore=4.86,
                                      overallScore=1.50,
                                      protRSRefine=protRSRefine)
Example #20
0
    def refineStep2(self):
        # atomStruct = os.path.abspath(self.inputStructure.get().getFileName())
        ## vol = os.path.abspath(self._getInputVolume().getFileName())
        vol = os.path.abspath(self._getExtraPath(self.FITTEDFILE))
        cwd = os.getcwd() + "/" + self._getExtraPath()
        conn = sqlite3.connect(os.path.abspath(self._getExtraPath(DATAFILE)))
        c = conn.cursor()
        while 1:
            command = """SELECT filename from %s
                         WHERE done=0
                         LIMIT 1""" % TABLE
            c.execute(command)
            myrow = c.fetchone()
            if not myrow:
                print("refineStep: no more available works")
                break  # break while if no job is available

            atomStructFn, = myrow
            c.execute("""UPDATE %s
                            SET done=1
                          WHERE filename='%s' AND done=0""" %
                      (TABLE, atomStructFn))
            # ^^^^^^ This will return the number of rows updated (c.rowcount).
            # Note that we only update if done is still '0', so if we get 1 updated
            # row, we're sure no one else took our job. This works because UPDATE is atomic.

            if not c.rowcount:
                # Whoops this job was taken! Try again and get another one
                continue
            conn.commit()

            args = self._writeArgsRSR(atomStructFn, vol)
            retry(
                Plugin.runPhenixProgram,
                Plugin.getProgram(REALSPACEREFINE),
                args,
                # cwd=os.path.abspath(self._getExtraPath()),
                cwd=cwd,
                listAtomStruct=[atomStructFn],
                log=self._log)
            if Plugin.getPhenixVersion() >= PHENIXVERSION19:
                # update data base with phenix version
                logFileFn = atomStructFn[:-4] + "_real_space_refined_???.log"
                # last file
                lastLogFile = sorted(glob.glob(logFileFn))[-1]
                phenix_id = lastLogFile[-8:-4]  # _000
                c.execute("""UPDATE %s
                                SET phenix_id='%s'
                              WHERE filename='%s'""" %
                          (TABLE, phenix_id, atomStructFn))
            else:
                phenix_id = ''
            conn.commit()
            #            refinedFile = False
            #            for item in os.listdir(self._getExtraPath()):
            #                p = re.compile('\d+')
            #                if p.search(item) is not None and item.endswith(".cif"):
            #                    self.refinedFile = True
            #                    break
            #
            #            if self.refinedFile == False:
            #                print("WARNING!!!\nPHENIX error:\n pdb_interpretation.clash_guard" \
            #                      " failure: High number of nonbonded interaction distances " \
            #                      "< 0.5. This error has been disable by running the same " \
            #                      "command with the same following additional " \
            #                      "argument:\npdb_interpretation.clash_guard." \
            #                      "nonbonded_distance_threshold=None ")
            #                args += " "
            #                args += "pdb_interpretation.clash_guard." \
            #                        "nonbonded_distance_threshold=None"
            #                retry(Plugin.runPhenixProgram,
            #                      Plugin.getProgram(REALSPACEREFINE), args,
            #                      # cwd=os.path.abspath(self._getExtraPath()),
            #                      cwd=cwd,
            #                      listAtomStruct=[atomStructFn], log=self._log)
            # coot_000000_Imol_0000_version_0004_real_space_refined_001.eff
            # coot_000000_Imol_0000_version_0030.pdb
            # glob
            logFileFn = atomStructFn[:-4] + "_real_space_refined%s.log" % phenix_id
            model_to_map_fit = self.extractNumber(logFileFn)
            accepted = c.execute(
                """UPDATE %s
                                    SET model_to_map_fit=%f
                                    WHERE filename='%s'""" %
                (TABLE, float(model_to_map_fit), atomStructFn))
            conn.commit()
        c.close()
        conn.close()
Example #21
0
    def testPhenixRSRefineFromVolumeAndCIF8(self):
        """ This test checks that phenix real_space_refine protocol runs
        with a volume provided directly as inputVol and the input PDB from
        data banks; default refine strategy; (MolProbity has been run to
        compare values before and after refinement); outputFormat = mmCIF.
        """
        print("Run phenix real_space_refine from imported volume and cif file "
              "from data banks (vol origin 0.0, 0.0, 0.0); default refine "
              "strategy; (MolProbity has been run to compare values before "
              "and after refinement); outputFormat = mmCIF.")

        # Import Volume
        volume_hemo_org = self._importVolHemoOrg()

        # import PDB
        structure_hemo_cif = self._importStructHemoCIF()

        # chimera operate to repair cif file
        extraCommands = ""
        extraCommands += "scipionwrite #2 " \
                         "prefix repaired_CIF_ChimeraX_\n"
        extraCommands += "exit\n"

        args = {
            'extraCommands': extraCommands,
            'pdbFileToBeRefined': structure_hemo_cif
        }
        protChimera = self.newProtocol(ChimeraProtOperate, **args)
        protChimera.setObjLabel('chimera operate\n repairing CIF\n')
        self.launchProtocol(protChimera)
        result = eval("protChimera.repaired_CIF_ChimeraX_Atom_struct__2_%06d" % \
                      protChimera.getObjId())

        # MolProbity
        args = {
            'inputVolume': volume_hemo_org,
            'resolution': 3.2,
            'inputStructure': result,
        }
        protMolProbity = self.newProtocol(PhenixProtRunMolprobity, **args)
        protMolProbity.setObjLabel('MolProbity validation\n'
                                   'volume and cif\n')
        self.launchProtocol(protMolProbity)

        # check MolProbity results
        self.checkMPResults(ramOutliers=0.00,
                            ramFavored=95.23,
                            rotOutliers=0.43,
                            cbetaOutliers=0,
                            clashScore=3.53,
                            overallScore=1.48,
                            protMolProbity=protMolProbity)

        # real_space_refine
        args = {
            'inputVolume': volume_hemo_org,
            'resolution': 3.2,
            'inputStructure': structure_hemo_cif,
            'outputFormat': mmCIF
        }
        if Plugin.getPhenixVersion() == PHENIXVERSION:
            args['doSecondary'] = False
        protRSRefine = self.newProtocol(PhenixProtRunRSRefine, **args)
        protRSRefine.setObjLabel('RSRefine hemo\n emd_3488.map and '
                                 '5ni1.cif\ndefault refine strategy')
        self.launchProtocol(protRSRefine)

        # check real_space_refine results
        if Plugin.getPhenixVersion() == PHENIXVERSION:
            self.checkRSRefineResults(ramOutliers=0.00,
                                      ramFavored=97.53,
                                      rotOutliers=0.00,
                                      cbetaOutliers=0,
                                      clashScore=2.43,
                                      overallScore=1.12,
                                      protRSRefine=protRSRefine)
        elif Plugin.getPhenixVersion() == PHENIXVERSION18:
            self.checkRSRefineResults(ramOutliers=0.00,
                                      ramFavored=96.64,
                                      rotOutliers=4.77,
                                      cbetaOutliers=0,
                                      clashScore=6.07,
                                      overallScore=2.06,
                                      protRSRefine=protRSRefine)
        elif Plugin.getPhenixVersion() == PHENIXVERSION19:
            self.checkRSRefineResults(ramOutliers=0.00,
                                      ramFavored=97.35,
                                      rotOutliers=2.39,
                                      cbetaOutliers=0,
                                      clashScore=3.87,
                                      overallScore=1.59,
                                      protRSRefine=protRSRefine)
        else:
            self.checkRSRefineResults(ramOutliers=0.00,
                                      ramFavored=96.11,
                                      rotOutliers=3.04,
                                      cbetaOutliers=0,
                                      clashScore=5.30,
                                      overallScore=1.92,
                                      protRSRefine=protRSRefine)
Example #22
0
    def testPhenixRSRefineFromVolumeAndCIF9(self):
        """ This test checks that phenix real_space_refine protocol runs
            with a volume associated to the input mmCIF from the
            data bank; alternative refine strategy; (MolProbity has been run
            to compare values before and after refinement); outputFormat =
            mmCIF.
        """
        print("Run phenix real_space_refine from imported cif "
              "file from data banks (vol origin 0.0, 0.0, 0.0) and "
              "associated volume; "
              "alternative refine strategy; (MolProbity has been run to "
              "compare values before and after refinement); outputFormat = "
              "mmCIF.")

        # import PDB
        structure_hemo_cif2 = self._importStructHemoCIF2()

        # chimera operate to repair cif file
        extraCommands = ""
        extraCommands += "scipionwrite #3 " \
                         "prefix repaired_CIF_ChimeraX_\n"
        extraCommands += "exit\n"

        args = {
            'extraCommands': extraCommands,
            'pdbFileToBeRefined': structure_hemo_cif2
        }
        protChimera = self.newProtocol(ChimeraProtOperate, **args)
        protChimera.setObjLabel('chimera operate\n repairing CIF\n')
        self.launchProtocol(protChimera)
        result = eval("protChimera.repaired_CIF_ChimeraX_Atom_struct__3_%06d" % \
                      protChimera.getObjId())

        # MolProbity
        args = {
            'resolution': 3.2,
            'inputStructure': result,
        }
        protMolProbity = self.newProtocol(PhenixProtRunMolprobity, **args)
        protMolProbity.setObjLabel('MolProbity validation\n'
                                   'cif and associated map\n')
        self.launchProtocol(protMolProbity)

        # check MolProbity results
        self.checkMPResults(ramOutliers=0.00,
                            ramFavored=95.23,
                            rotOutliers=0.43,
                            cbetaOutliers=0,
                            clashScore=3.53,
                            overallScore=1.48,
                            protMolProbity=protMolProbity)

        # real_space_refine
        args = {
            'resolution': 3.2,
            'inputStructure': structure_hemo_cif2,
            'outputFormat': mmCIF,
            'localGridSearch': True,
            'morphing': True,
            'simulatedAnnealing': True,
            'adp': False
        }
        if Plugin.getPhenixVersion() == PHENIXVERSION:
            args['doSecondary'] = False
        protRSRefine = self.newProtocol(PhenixProtRunRSRefine, **args)
        protRSRefine.setObjLabel('RSRefine hemo\n'
                                 '5ni1.cif and associated map\n'
                                 'emd_3488.map\nalternative '
                                 'refine strategy')
        self.launchProtocol(protRSRefine)

        # check real_space_refine results
        if Plugin.getPhenixVersion() == PHENIXVERSION:
            self.checkRSRefineResults(ramOutliers=0.00,
                                      ramFavored=97.35,
                                      rotOutliers=0.00,
                                      cbetaOutliers=0,
                                      clashScore=2.10,
                                      overallScore=1.11,
                                      protRSRefine=protRSRefine)
        elif Plugin.getPhenixVersion() == PHENIXVERSION18:
            self.checkRSRefineResults(ramOutliers=0.00,
                                      ramFavored=97.52,
                                      rotOutliers=0.00,
                                      cbetaOutliers=0,
                                      clashScore=3.64,
                                      overallScore=1.25,
                                      protRSRefine=protRSRefine)
        else:
            self.checkRSRefineResults(ramOutliers=0.00,
                                      ramFavored=96.29,
                                      rotOutliers=3.47,
                                      cbetaOutliers=0,
                                      clashScore=4.86,
                                      overallScore=1.50,
                                      protRSRefine=protRSRefine)