Пример #1
0
    def load_ground_state_map_thread(self):
        self.spinnerBox.add(self.refinementRunning)
        self.refinementRunning.show()
        self.refinementRunning.start()

        # first remove all ground state maps files
        if len(coot_utils_XChem.molecule_number_list()) > 0:
            for item in coot_utils_XChem.molecule_number_list():
                if 'ground-state-mean-map' in coot.molecule_name(item):
                    coot.close_molecule(item)

        # first remove all entries for self.cb_select_mean_map_by_resolution
        # clear CB first, 100 is sort of arbitrary since it's unlikely there will ever be 100 maps
        for n in range(-1, 100):
            self.cb_select_mean_map_by_resolution.remove_text(0)

        self.status_label.set_text('loading ground state maps')
        self.get_ground_state_maps_by_resolution()
        blueStart = 0.02
        for map in self.ground_state_map_List:
            self.cb_select_mean_map_by_resolution.append_text(map[0])
            imol = coot.handle_read_ccp4_map((map[1]), 0)
            coot.set_contour_level_in_sigma(imol, 1)
            coot.set_last_map_colour(0.74, 0.44, blueStart)
            blueStart += 0.05
        # show only highest resolution map to start with
        self.show_highres_ground_state_map()
        self.cb_select_mean_map_by_resolution.set_active(0)
        self.end_thread('')
Пример #2
0
    def REFINE(self,widget):

        #######################################################
        # create folder for new refinement cycle
        os.mkdir(os.path.join(self.project_directory,self.xtalID,'Refine_'+str(self.Serial)))

        #######################################################
        # write PDB file
        # now take protein pdb file and write it to newly create Refine_<serial> folder
        # note: the user has to make sure that the ligand file was merged into main file
        for item in coot_utils_XChem.molecule_number_list():
            if coot.molecule_name(item).endswith(self.pdb_style):
                coot.write_pdb_file(item,os.path.join(self.project_directory,self.xtalID,'Refine_'+str(self.Serial),'in.pdb'))
                break
            elif coot.molecule_name(item).endswith('dimple.pdb'):
                coot.write_pdb_file(item,os.path.join(self.project_directory,self.xtalID,'Refine_'+str(self.Serial),'in.pdb'))
                break


        #######################################################
        # run REFMAC
        self.Refine.RunRefmac(self.Serial,self.RefmacParams,self.external_software,self.xce_logfile)

        self.index+=1
        if self.index >= len(self.Todo):
#            self.index = len(self.Todo)
            self.index = 0
        self.cb.set_active(self.index)
Пример #3
0
 def show_highres_ground_state_map(self):
     if len(self.ground_state_map_List) >= 1:
         for imol in coot_utils_XChem.molecule_number_list():
             if coot.molecule_name(
                     imol) in self.ground_state_map_List[0][1]:
                 coot.set_map_displayed(imol, 1)
             elif 'ground-state-mean-map' in coot.molecule_name(imol):
                 coot.set_map_displayed(imol, 0)
Пример #4
0
    def REFINE(self, widget):

        if self.job_running:
            coot.info_dialog('*** refinement in progress ***')
            return None

        #######################################################
        # create folder for new refinement cycle and check if free.mtz exists
        if not os.path.isdir(
                os.path.join(self.reference_directory, self.refinementDir)):
            os.mkdir(os.path.join(self.reference_directory,
                                  self.refinementDir))
        if not os.path.isdir(
                os.path.join(self.reference_directory, self.refinementDir,
                             'Refine_' + str(self.Serial))):
            os.mkdir(
                os.path.join(self.reference_directory, self.refinementDir,
                             'Refine_' + str(self.Serial)))
        if not os.path.isfile(
                os.path.join(self.reference_directory, self.refinementDir,
                             self.refinementDir + '.free.mtz')):
            os.chdir(os.path.join(self.reference_directory,
                                  self.refinementDir))
            os.symlink(self.mtzFree, self.refinementDir + '.free.mtz')

        #######################################################
        # write PDB file
        # now take protein pdb file and write it to newly create Refine_<serial> folder
        # note: the user has to make sure that the ligand file was merged into main file
        for item in coot_utils_XChem.molecule_number_list():
            if coot.molecule_name(item) in self.pdbFile:
                coot.write_pdb_file(
                    item,
                    os.path.join(self.reference_directory, self.refinementDir,
                                 'Refine_' + str(self.Serial), 'in.pdb'))
                break

        self.Refine.RunRefmac(self.Serial, self.RefmacParams,
                              self.external_software, self.xce_logfile)
        #        self.spinnerBox.add(self.refinementRunning)
        #        self.refinementRunning.start()
        self.status_label.set_text('Refinement running...')

        time.sleep(
            1
        )  # waiting 1s to make sure that REFINEMENT_IN_PROGRESS is written
        snooze = 0
        while os.path.exists(
                os.path.join(self.reference_directory, self.refinementDir,
                             'REFINEMENT_IN_PROGRESS')):
            time.sleep(10)
            print '==> XCE: waiting for refinement to finish; elapsed time = ' + str(
                snooze) + 's'
            snooze += 10
        self.update_pdb_mtz_files('')
Пример #5
0
 def show_selected_mean_map(self, widget):
     reso = str(self.cb_select_mean_map_by_resolution.get_active_text())
     mapToshow = ''
     for maps in self.ground_state_map_List:
         if maps[0] == reso:
             mapToshow = maps[1]
     for imol in coot_utils_XChem.molecule_number_list():
         if coot.molecule_name(imol) in mapToshow:
             coot.set_map_displayed(imol, 1)
         elif 'ground-state-mean-map' in coot.molecule_name(imol):
             coot.set_map_displayed(imol, 0)
Пример #6
0
    def RefreshData(self):
        # initialize Refinement library
        self.Refine=XChemRefine.Refine(self.project_directory,self.xtalID,self.compoundID,self.data_source)
        self.Serial=self.Refine.GetSerial()
        if self.Serial==1:
            # i.e. no refinement has been done; data is probably straight out of dimple
            if os.path.isfile(os.path.join(self.project_directory,self.xtalID,self.pdb_style)):
                print '==> XCE: updating quality indicators in data source for '+self.xtalID
                XChemUtils.parse().update_datasource_with_PDBheader(self.xtalID,self.data_source,os.path.join(self.project_directory,self.xtalID,self.pdb_style))
                XChemUtils.parse().update_datasource_with_phenix_validation_summary(self.xtalID,self.data_source,'')   # '' because file does not exist
            elif os.path.isfile(os.path.join(self.project_directory,self.xtalID,'dimple.pdb')):
                print '==> XCE: updating quality indicators in data source for '+self.xtalID
                XChemUtils.parse().update_datasource_with_PDBheader(self.xtalID,self.data_source,os.path.join(self.project_directory,self.xtalID,'dimple.pdb'))
                XChemUtils.parse().update_datasource_with_phenix_validation_summary(self.xtalID,self.data_source,'')   # '' because file does not exist

        # all this information is now updated in the datasource after each refinement cycle
        self.QualityIndicators=self.db.get_db_dict_for_sample(self.xtalID)
        if int(self.selected_site[0]) > 0:
            self.spider_plot_data=self.db.get_db_pandda_dict_for_sample_and_site(self.xtalID,self.selected_site[0])
            self.ligandIDValue.set_label(self.spider_plot_data['PANDDA_site_ligand_id'])
            try:
                self.ligand_occupancyValue.set_label(           str(round(float(self.spider_plot_data['PANDDA_site_occupancy']),2)) )
                self.ligand_BaverageValue.set_label(            str(round(float(self.spider_plot_data['PANDDA_site_B_average']),2)) )
                self.ligand_BratioSurroundingsValue.set_label(  str(round(float(self.spider_plot_data['PANDDA_site_B_ratio_residue_surroundings']),2)) )
                self.ligand_RSCCValue.set_label(                str(round(float(self.spider_plot_data['PANDDA_site_RSCC']),2)) )
                self.ligand_rmsdValue.set_label(                str(round(float(self.spider_plot_data['PANDDA_site_rmsd']),2)) )
                self.ligand_RSRValue.set_label(                 str(round(float(self.spider_plot_data['PANDDA_site_RSR']),2)) )
                self.ligand_RSZDValue.set_label(                str(round(float(self.spider_plot_data['PANDDA_site_RSZD']),2)) )
            except ValueError:
                self.ligand_occupancyValue.set_label('-')
                self.ligand_BaverageValue.set_label('-')
                self.ligand_BratioSurroundingsValue.set_label('-')
                self.ligand_RSCCValue.set_label('-')
                self.ligand_rmsdValue.set_label('-')
                self.ligand_RSRValue.set_label('-')
                self.ligand_RSZDValue.set_label('-')


        #########################################################################################
        # history
        # if the structure was previously refined, try to read the parameters
#        self.hbox_for_info_graphics.remove(self.canvas)
        if self.Serial > 1:
            self.RefmacParams=self.Refine.ParamsFromPreviousCycle(self.Serial-1)
#            refinement_cycle,Rfree,Rcryst=self.Refine.GetRefinementHistory()
#            self.canvas = FigureCanvas(self.update_plot(refinement_cycle,Rfree,Rcryst))
#        else:
#            self.canvas = FigureCanvas(self.update_plot([0],[0],[0]))  # a gtk.DrawingArea
#        self.canvas.set_size_request(190, 190)
#        self.hbox_for_info_graphics.add(self.canvas)
#        self.canvas.show()

        #########################################################################################
        # Spider plot
        # Note: refinement history was shown instead previously
        if os.path.isfile(self.spider_plot):
            spider_plot_pic = gtk.gdk.pixbuf_new_from_file(self.spider_plot)
        else:
            spider_plot_pic = gtk.gdk.pixbuf_new_from_file(os.path.join(os.getenv('XChemExplorer_DIR'),'image','NO_SPIDER_PLOT_AVAILABLE.png'))
        self.spider_plot_pic = spider_plot_pic.scale_simple(190, 190, gtk.gdk.INTERP_BILINEAR)
        self.spider_plot_image.set_from_pixbuf(self.spider_plot_pic)

        #########################################################################################
        # update pdb & maps

        #########################################################################################
        # delete old PDB and MAP files
        # - get a list of all molecules which are currently opened in COOT
        # - remove all molecules/ maps before loading a new set
        if len(coot_utils_XChem.molecule_number_list()) > 0:
            for item in coot_utils_XChem.molecule_number_list():
                coot.close_molecule(item)

        #########################################################################################
        # read new PDB files
        # read protein molecule after ligand so that this one is the active molecule
        coot.set_nomenclature_errors_on_read("ignore")
        if os.path.isfile(os.path.join(self.project_directory,self.xtalID,self.compoundID+'.pdb')):
            imol=coot.handle_read_draw_molecule_with_recentre(os.path.join(self.project_directory,self.xtalID,self.compoundID+'.pdb'),0)
            self.mol_dict['ligand']=imol
            coot.read_cif_dictionary(os.path.join(self.project_directory,self.xtalID,self.compoundID+'.cif'))
        if not os.path.isfile(os.path.join(self.project_directory,self.xtalID,self.pdb_style)):
            os.chdir(os.path.join(self.project_directory,self.xtalID))
            # we want to be able to check dimple results immediately, but don't want to interfere with refinement
#            if not os.path.isfile('REFINEMENT_IN_PROGRESS'):
#                if os.path.isfile(os.path.join(self.project_directory,self.xtalID,self.xtalID+'-ensemble-model.pdb')):
#                    os.symlink(self.xtalID+'-ensemble-model.pdb',self.pdb_style)
#                elif os.path.isfile(os.path.join(self.project_directory,self.xtalID,'dimple.pdb')):
#                    os.symlink('dimple.pdb',self.pdb_style)
#                else:
#                    self.go_to_next_xtal()
        if os.path.isfile(os.path.join(self.project_directory,self.xtalID,self.pdb_style)):
            os.chdir(os.path.join(self.project_directory,self.xtalID))
            imol=coot.handle_read_draw_molecule_with_recentre(os.path.join(self.project_directory,self.xtalID,self.pdb_style),0)
        elif os.path.isfile(os.path.join(self.project_directory,self.xtalID,'dimple.pdb')):
            os.chdir(os.path.join(self.project_directory,self.xtalID))
            imol=coot.handle_read_draw_molecule_with_recentre(os.path.join(self.project_directory,self.xtalID,'dimple.pdb'),0)
        else:
            self.go_to_next_xtal()
        self.mol_dict['protein']=imol
        for item in coot_utils_XChem.molecule_number_list():
            if coot.molecule_name(item).endswith(self.pdb_style):
                coot.set_show_symmetry_master(1)    # master switch to show symmetry molecules
                coot.set_show_symmetry_molecule(item,1) # show symm for model

        #########################################################################################
        # read fofo maps
        # - read ccp4 map: 0 - 2fofc map, 1 - fofc.map
        # read 2fofc map last so that one can change its contour level
        if os.path.isfile(os.path.join(self.project_directory,self.xtalID,'2fofc.map')):
            coot.set_default_initial_contour_level_for_difference_map(3)
            coot.handle_read_ccp4_map(os.path.join(self.project_directory,self.xtalID,'fofc.map'),1)
            coot.set_default_initial_contour_level_for_map(1)
            coot.handle_read_ccp4_map(os.path.join(self.project_directory,self.xtalID,'2fofc.map'),0)
            coot.set_last_map_colour(0,0,1)
        else:
            # try to open mtz file with same name as pdb file
            coot.set_default_initial_contour_level_for_map(1)
#            if not os.path.isfile(os.path.join(self.project_directory,self.xtalID,self.mtz_style)):
#                os.chdir(os.path.join(self.project_directory,self.xtalID))
#                if not os.path.isfile('REFINEMENT_IN_PROGRESS'):
#                    if os.path.isfile(os.path.join(self.project_directory,self.xtalID,self.xtalID+'-pandda-input.mtz')):
#                        os.symlink(self.xtalID+'-pandda-input.mtz',self.mtz_style)
#                    elif os.path.isfile(os.path.join(self.project_directory,self.xtalID,'dimple.mtz')):
#                        os.symlink('dimple.mtz',self.mtz_style)
            if os.path.isfile(os.path.join(self.project_directory,self.xtalID,self.mtz_style)):
                coot.auto_read_make_and_draw_maps(os.path.join(self.project_directory,self.xtalID,self.mtz_style))
            elif os.path.isfile(os.path.join(self.project_directory,self.xtalID,'dimple.mtz')):
                coot.auto_read_make_and_draw_maps(os.path.join(self.project_directory,self.xtalID,'dimple.mtz'))

        #########################################################################################
        # check for PANDDAs EVENT maps
        if os.path.isfile(self.event_map):
            coot.handle_read_ccp4_map((self.event_map),0)
            for imol in coot_utils_XChem.molecule_number_list():
                if self.event_map in coot.molecule_name(imol):
                    coot.set_contour_level_in_sigma(imol,2)
#                    coot.set_contour_level_absolute(imol,0.5)
                    coot.set_last_map_colour(0.4,0,0.4)


#        #########################################################################################
#        # update Ligand Confidence combobox
#        if str(self.ligand_confidence_of_sample)=='None':
#            self.ligand_confidence_of_sample='Analysis Pending'
#            db_dict={'RefinementLigandConfidence': self.ligand_confidence_of_sample}
##            self.db.update_data_source(self.xtalID,db_dict)
#        for n,criteria in enumerate(self.ligand_confidence):
#            if criteria.replace('Ligand Confidence: ','')==self.ligand_confidence_of_sample:
#                self.cb_ligand_confidence.set_active(n)

        #########################################################################################
        # update Quality Indicator table
        try:
            self.RRfreeValue.set_label(  str(round(float(self.QualityIndicators['RefinementRcryst']),3)) +' / '+str(round(float(self.QualityIndicators['RefinementRfree']),3)))
        except ValueError:
            self.RRfreeValue.set_label('-')

        try:
            self.RRfreeBox.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(self.QualityIndicators['RefinementRfreeTraficLight']))
        except ValueError:
            pass
        self.ResolutionValue.set_label(self.QualityIndicators['RefinementResolution'])
        try:
            self.ResolutionBox.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(self.QualityIndicators['RefinementResolutionTL']))
        except ValueError:
            pass
        self.MolprobityScoreValue.set_label(self.QualityIndicators['RefinementMolProbityScore'])
        try:
            self.MolprobityScoreBox.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(self.QualityIndicators['RefinementMolProbityScoreTL']))
        except ValueError:
            pass
        self.RamachandranOutliersValue.set_label(self.QualityIndicators['RefinementRamachandranOutliers'])
        try:
            self.RamachandranOutliersBox.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(self.QualityIndicators['RefinementRamachandranOutliersTL']))
        except ValueError:
            pass
        self.RamachandranFavoredValue.set_label(self.QualityIndicators['RefinementRamachandranFavored'])
        try:
            self.RamachandranFavoredBox.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(self.QualityIndicators['RefinementRamachandranFavoredTL']))
        except ValueError:
            pass
        self.rmsdBondsValue.set_label(self.QualityIndicators['RefinementRmsdBonds'])
        try:
            self.rmsdBondsBox.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(self.QualityIndicators['RefinementRmsdBondsTL']))
        except ValueError:
            pass
        self.rmsdAnglesValue.set_label(self.QualityIndicators['RefinementRmsdAngles'])
        try:
            self.rmsdAnglesBox.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(self.QualityIndicators['RefinementRmsdAnglesTL']))
        except ValueError:
            pass
        self.MatrixWeightValue.set_label(self.QualityIndicators['RefinementMatrixWeight'])

        try:
            pic = gtk.gdk.pixbuf_new_from_file(os.path.join(self.project_directory,self.xtalID,self.compoundID+'.png'))
        except gobject.GError:
            pic = gtk.gdk.pixbuf_new_from_file(os.path.join(os.getenv('XChemExplorer_DIR'),'image','NO_COMPOUND_IMAGE_AVAILABLE.png'))
        self.pic = pic.scale_simple(190, 190, gtk.gdk.INTERP_BILINEAR)
        self.image.set_from_pixbuf(self.pic)
Пример #7
0
    def update_pdb_mtz_files(self, pdbRoot):
        # first remove all pdb and mtz files from memory
        self.Logfile.insert('removing all PDB and MTZ files from memory')
        if len(coot_utils_XChem.molecule_number_list()) > 0:
            for item in coot_utils_XChem.molecule_number_list():
                if coot.molecule_name(item).endswith(
                        '.pdb') or '.mtz' in coot.molecule_name(item):
                    self.Logfile.insert('removing %s' %
                                        coot.molecule_name(item))
                    coot.close_molecule(item)

        coot.set_nomenclature_errors_on_read("ignore")
        # first we check if there is a refinement folder and the respective refine.pdb
        # from previous refinement cycles
        Root = self.cb_select_pdb.get_active_text()
        print 'ROOT', Root
        print 'REFI_DIR', os.path.join(self.reference_directory,
                                       self.refinementDir, 'refine.pdb')
        if os.path.isfile(
                os.path.join(self.reference_directory, self.refinementDir,
                             'refine.pdb')):
            os.chdir(self.reference_directory)
            print 'CURRENT DIR', os.getcwd()
            os.system('/bin/rm %s 2> /dev/null' % Root)
            os.symlink(
                os.path.realpath(os.path.join(self.refinementDir,
                                              'refine.pdb')), '%s' % Root)
            self.pdbFile = os.path.join(self.reference_directory,
                                        self.refinementDir, 'refine.pdb')
        elif os.path.isfile(os.path.join(self.reference_directory, Root)):
            self.pdbFile = os.path.join(self.reference_directory, Root)
        else:
            self.Logfile.error('cannot find PDB file')

        if self.pdbFile != '':
            #            os.chdir(os.path.join(self.reference_directory,self.refinementDir))
            coot.set_colour_map_rotation_on_read_pdb(0)
            imol = coot.handle_read_draw_molecule_with_recentre(
                self.pdbFile, 0)
            self.QualityIndicators = XChemUtils.parse().PDBheader(
                os.path.join(self.pdbFile))
            self.QualityIndicators.update(
                XChemUtils.logtools(
                    os.path.join(self.reference_directory, self.refinementDir,
                                 'refine_molprobity.log')).phenix_molprobity())
            self.QualityIndicators.update(
                XChemUtils.logtools(
                    os.path.join(self.reference_directory, self.refinementDir,
                                 'Refine_' + str(self.Serial),
                                 'refmac.log')).refmac_log())
            self.mol_dict['protein'] = imol

        if self.mtzFree == '':
            print 'FREE', os.path.join(
                self.reference_directory,
                pdbRoot.replace('.pdb', '') + '.free.mtz')
            if os.path.isfile(
                    os.path.join(self.reference_directory,
                                 pdbRoot.replace('.pdb', '') + '.free.mtz')):
                self.mtzFree = os.path.join(
                    self.reference_directory,
                    pdbRoot.replace('.pdb', '') + '.free.mtz')
                self.mtzFree_label.set_text(
                    pdbRoot.replace('.pdb', '') + '.free.mtz')
                self.REFINEbutton.set_sensitive(True)
            else:
                self.mtzFree_label.set_text('missing file')
                self.Logfile.error(
                    'cannot find file with F,SIGF and FreeR_flag; cannot start refinement'
                )
                self.REFINEbutton.set_sensitive(False)

        self.mtzRefine = ''
        if os.path.isfile(
                os.path.join(self.reference_directory, self.refinementDir,
                             'refine.mtz')):
            self.mtzRefine = os.path.join(self.reference_directory,
                                          self.refinementDir, 'refine.mtz')
            mtzRefineReal = os.path.realpath(
                os.path.join(self.reference_directory, self.refinementDir,
                             'refine.mtz'))
            mtzRefineCurrent = mtzRefineReal.replace(
                os.path.join(self.reference_directory,
                             self.refinementDir + '/'), '')
            self.mtzRefine_label.set_text(mtzRefineCurrent)
            coot.set_default_initial_contour_level_for_map(1)
            if os.path.isfile(
                    os.path.join(self.reference_directory, self.refinementDir,
                                 self.mtz_style)):
                coot.auto_read_make_and_draw_maps(
                    os.path.join(self.reference_directory, self.refinementDir,
                                 self.mtz_style))
        else:
            self.mtzRefine_label.set_text('missing file')
            self.Logfile.warning(
                'cannot find file with F,SIGF and FreeR_flag; cannot start refinement'
            )

        groundStateMap = os.path.join(self.reference_directory,
                                      Root + '-mean-map.native.ccp4').replace(
                                          '.pdb', '')
        print '===>', groundStateMap
        if os.path.isfile(groundStateMap):
            imol = coot.handle_read_ccp4_map(groundStateMap, 0)
            coot.set_contour_level_in_sigma(imol, 1)
            coot.set_last_map_colour(0.6, 0.6, 0)
        else:
            print '==> XCE: ERROR - cannot find ground state mean map!'

        self.RefreshData()