Exemplo n.º 1
0
    def run(self):
        sqlite = (
            'select'
            ' CrystalName,'
            ' PANDDA_site_event_map,'
            ' PANDDA_site_ligand_resname,'
            ' PANDDA_site_ligand_chain,'
            ' PANDDA_site_ligand_sequence_number,'
            ' PANDDA_site_ligand_altLoc '
            'from panddaTable '
            'where PANDDA_site_event_map not like "event%"'
        )

        query=self.db.execute_statement(sqlite)

        progress_step=1
        if len(query) != 0:
            progress_step=100/float(len(query))
        else:
            progress_step=1
        progress=0
        self.emit(QtCore.SIGNAL('update_progress_bar'), progress)

        for item in query:
            xtalID=str(item[0])
            event_map=str(item[1])
            resname=str(item[2])
            chainID=str(item[3])
            resseq=str(item[4])
            altLoc=str(item[5])

            if os.path.isfile(os.path.join(self.initial_model_directory,xtalID,'refine.pdb')):
                os.chdir(os.path.join(self.initial_model_directory,xtalID))
                self.Logfile.insert('extracting ligand (%s,%s,%s,%s) from refine.pdb' %(str(resname),str(chainID),str(resseq),str(altLoc)))
                XChemUtils.pdbtools('refine.pdb').save_specific_ligands_to_pdb(resname,chainID,resseq,altLoc)
                if os.path.isfile('ligand_%s_%s_%s_%s.pdb' %(str(resname),str(chainID),str(resseq),str(altLoc))):
                    ligand_pdb='ligand_%s_%s_%s_%s.pdb' %(str(resname),str(chainID),str(resseq),str(altLoc))
                    print os.path.join(self.initial_model_directory,xtalID,ligand_pdb)
                else:
                    self.Logfile.insert('could not extract ligand; trying next...')
                    continue
            else:
                self.Logfile.insert('directory: '+os.path.join(self.initial_model_directory,xtalID)+' -> cannot find refine.pdb; trying next')
                continue

            if os.path.isfile(os.path.join(self.initial_model_directory,xtalID,'refine.mtz')):
                resolution=XChemUtils.mtztools(os.path.join(self.initial_model_directory,xtalID,'refine.mtz')).get_high_resolution_from_mtz()
            else:
                self.Logfile.insert('directory: '+os.path.join(self.initial_model_directory,xtalID)+' -> cannot find refine.mtz; trying next')
                continue

            convert_event_map_to_SF(self.initial_model_directory,xtalID,event_map,ligand_pdb,self.xce_logfile,self.datasource,resolution).run()

            progress += progress_step
            self.emit(QtCore.SIGNAL('update_progress_bar'), progress)
Exemplo n.º 2
0
 def prepare_e_density_maps(self, xtal, ligand):
     FWT, PHWT, DELFWT, PHDELWT = XChemUtils.mtztools_gemmi(
         'refine.mtz').get_map_labels()
     self.Logfile.insert(xtal + ': calculating 2fofc map...')
     XChemUtils.maptools().calculate_map('refine.mtz', FWT, PHWT)
     if os.path.isfile('refine.ccp4'):
         self.Logfile.insert(xtal + ': 2fofc map successfully calculated')
     else:
         self.Logfile.error(xtal + ': 2fofc map could not be calculated')
     self.Logfile.insert(xtal + ': cutting 2fofc map 7A around ' + ligand)
     XChemUtils.maptools().cut_map_around_ligand('refine.ccp4',
                                                 ligand + '.pdb', '7')
     if os.path.isfile('refine_mapmask.ccp4'):
         self.Logfile.insert(xtal + ': 2fofc map around ' + ligand +
                             ' successfully created')
     else:
         self.Logfile.error(xtal + ': 2fofc map around ' + ligand +
                            ' could not be created')
     os.system('/bin/mv %s %s_%s_2fofc.ccp4' %
               ('refine_mapmask.ccp4', xtal, ligand))
     FWTmap = xtal + '_' + ligand + '_2fofc.ccp4'
     self.Logfile.insert(xtal + ': current 2fofc map -> ' + xtal + '_' +
                         ligand + '_2fofc.ccp4')
     XChemUtils.maptools().calculate_map('refine.mtz', DELFWT, PHDELWT)
     XChemUtils.maptools().cut_map_around_ligand('refine.ccp4',
                                                 ligand + '.pdb', '7')
     os.system('/bin/mv %s %s_%s_fofc.ccp4' %
               ('refine_mapmask.ccp4', xtal, ligand))
     DELFWTmap = xtal + '_' + ligand + '_fofc.ccp4'
     return FWTmap, DELFWTmap
Exemplo n.º 3
0
    def __init__(self,panddas_directory,datasource,initial_model_directory,xce_logfile,update_datasource_only,which_models):
        QtCore.QThread.__init__(self)
        self.panddas_directory=panddas_directory
        self.datasource=datasource
        self.initial_model_directory=initial_model_directory
        self.db=XChemDB.data_source(self.datasource)
        self.db.create_missing_columns()
        self.db_list=self.db.get_empty_db_dict()
        self.external_software=XChemUtils.external_software(xce_logfile).check()
        self.xce_logfile=xce_logfile
        self.Logfile=XChemLog.updateLog(xce_logfile)
        self.update_datasource_only=update_datasource_only
        self.which_models=which_models
        self.already_exported_models=[]

        self.RefmacParams={ 'HKLIN':            '',                 'HKLOUT': '',
                            'XYZIN':            '',                 'XYZOUT': '',
                            'LIBIN':            '',                 'LIBOUT': '',
                            'TLSIN':            '',                 'TLSOUT': '',
                            'TLSADD':           '',
                            'NCYCLES':          '10',
                            'MATRIX_WEIGHT':    'AUTO',
                            'BREF':             '    bref ISOT\n',
                            'TLS':              '',
                            'NCS':              '',
                            'TWIN':             ''    }
Exemplo n.º 4
0
 def get_datasets_which_fit_to_reference_file(self,ref,reference_directory,cluster_dict,allowed_unitcell_difference_percent):
     refStructure=XChemUtils.pdbtools(os.path.join(reference_directory,ref+'.pdb'))
     symmRef=refStructure.get_spg_number_from_pdb()
     ucVolRef=refStructure.calc_unitcell_volume_from_pdb()
     cluster_dict[ref]=[]
     cluster_dict[ref].append(os.path.join(reference_directory,ref+'.pdb'))
     for dataset in glob.glob(os.path.join(self.data_directory,self.pdb_style)):
         datasetStructure=XChemUtils.pdbtools(dataset)
         symmDataset=datasetStructure.get_spg_number_from_pdb()
         ucVolDataset=datasetStructure.calc_unitcell_volume_from_pdb()
         if symmDataset == symmRef:
             try:
                 difference=math.fabs(1-(float(ucVolRef)/float(ucVolDataset)))*100
                 if difference < allowed_unitcell_difference_percent:
                     sampleID=dataset.replace('/'+self.pdb_style,'')[dataset.replace('/'+self.pdb_style,'').rfind('/')+1:]
                     cluster_dict[ref].append(sampleID)
             except ZeroDivisionError:
                 continue
     return cluster_dict
Exemplo n.º 5
0
 def compare_number_of_atoms_in_reference_vs_all_datasets(self,refData,dataset_list):
     mismatched_datasets=[]
     pdbtools=XChemUtils.pdbtools(refData)
     refPDB=refData[refData.rfind('/')+1:]
     refPDBlist=pdbtools.get_init_pdb_as_list()
     n_atom_ref=len(refPDBlist)
     for n_datasets,dataset in enumerate(dataset_list):
         if os.path.isfile(os.path.join(self.data_directory.replace('*',''),dataset,self.pdb_style)):
             n_atom=len(pdbtools.get_pdb_as_list(os.path.join(self.data_directory.replace('*',''),dataset,self.pdb_style)))
             if n_atom_ref == n_atom:
                 self.Logfile.insert('%s: atoms in PDB file (%s): %s; atoms in Reference file: %s ===> OK' %(dataset,self.pdb_style,str(n_atom),str(n_atom_ref)))
             if n_atom_ref != n_atom:
                 self.Logfile.insert('%s: atoms in PDB file (%s): %s; atoms in Reference file: %s ===> ERROR' %(dataset,self.pdb_style,str(n_atom),str(n_atom_ref)))
                 mismatched_datasets.append(dataset)
     return n_datasets,mismatched_datasets
Exemplo n.º 6
0
    def calculate_electron_density_map(self,mtzin):
        missing_columns=False
        column_dict=XChemUtils.mtztools(mtzin).get_all_columns_as_dict()
        if 'FWT' in column_dict['F'] and 'PHWT' in column_dict['PHS']:
            labin=' labin F1=FWT PHI=PHWT\n'
        elif '2FOFCWT' in column_dict['F'] and 'PH2FOFCWT' in column_dict['PHS']:
            labin=' labin F1=2FOFCWT PHI=PH2FOFCWT\n'
        else:
            missing_columns=True

        if not missing_columns:
            os.chdir(os.path.join(self.project_directory,self.xtalID))
            cmd = (
                'fft hklin '+mtzin+' mapout 2fofc.map << EOF\n'
                +labin+
                'EOF\n'
                    )
            self.Logfile.insert('calculating 2fofc map from '+mtzin)
            os.system(cmd)
        else:
            self.Logfile.insert('cannot calculate 2fofc.map; missing map coefficients')
Exemplo n.º 7
0
    def settings(self, xce_object):
        # set XCE version
        xce_object.xce_version = 'v1.4.0'

        # general settings
        xce_object.allowed_unitcell_difference_percent = 12
        xce_object.acceptable_low_resolution_limit_for_data = 3.5
        xce_object.filename_root = '${samplename}'
        xce_object.data_source_set = False
        xce_object.max_queue_jobs = 100

        ## directory settings

        # set current directory and direct log to it
        xce_object.current_directory = os.getcwd()
        xce_object.xce_logfile = os.path.join(xce_object.current_directory,
                                              'xce.log')

        # if in the correct place, set the various directories
        if 'labxchem' in xce_object.current_directory:
            if len(xce_object.current_directory.split('/')
                   ) >= 9 and xce_object.current_directory.split(
                       '/'
                   )[6] == 'processing' and xce_object.current_directory.split(
                       '/')[8] == 'processing':
                xce_object.labxchem_directory = '/' + os.path.join(
                    *xce_object.current_directory.split('/')
                    [1:8])  # need splat operator: *
                xce_object.labxchem_directory_current = '/' + os.path.join(
                    *xce_object.current_directory.split('/')[1:9]
                )  # labxchem_directory_current is where they actually have write permission
            else:
                xce_object.labxchem_directory = '/' + os.path.join(
                    *xce_object.current_directory.split('/')
                    [1:6])  # need splat operator: *
                xce_object.labxchem_directory_current = '/' + os.path.join(
                    *xce_object.current_directory.split('/')
                    [1:7])  # need splat operator: *
#            xce_object.labxchem_directory = '/' + os.path.join(
#                *xce_object.current_directory.split('/')[1:6])  # need splat operator: *
            xce_object.beamline_directory = os.path.join(
                xce_object.labxchem_directory, 'processing', 'beamline')
            if os.path.isdir(
                    os.path.join(xce_object.labxchem_directory, 'processing',
                                 'analysis', 'model_building')):
                xce_object.initial_model_directory = os.path.join(
                    xce_object.labxchem_directory, 'processing', 'analysis',
                    'model_building')
            else:
                xce_object.initial_model_directory = os.path.join(
                    xce_object.labxchem_directory, 'processing', 'analysis',
                    'initial_model')
            xce_object.reference_directory = os.path.join(
                xce_object.labxchem_directory, 'processing', 'reference')
            xce_object.database_directory = os.path.join(
                xce_object.labxchem_directory, 'processing', 'database')
            xce_object.panddas_directory = os.path.join(
                xce_object.labxchem_directory, 'processing', 'analysis',
                'panddas')
            xce_object.datasets_summary_file = os.path.join(
                xce_object.database_directory,
                str(os.getcwd().split('/')[5]) + '_summary.pkl')
            xce_object.data_source_file = ''
            xce_object.html_export_directory = os.path.join(
                xce_object.labxchem_directory, 'processing', 'html')
            xce_object.group_deposit_directory = os.path.join(
                xce_object.labxchem_directory, 'processing',
                'group_deposition')
            if os.path.isfile(
                    os.path.join(xce_object.labxchem_directory, 'processing',
                                 'database', 'soakDBDataFile.sqlite')):
                xce_object.data_source_file = 'soakDBDataFile.sqlite'
                xce_object.database_directory = os.path.join(
                    xce_object.labxchem_directory, 'processing', 'database')
                xce_object.data_source_set = True
                xce_object.db = XChemDB.data_source(
                    os.path.join(xce_object.database_directory,
                                 xce_object.data_source_file))
                xce_object.db.create_missing_columns()

            xce_object.ccp4_scratch_directory = os.path.join(
                xce_object.labxchem_directory, 'processing', 'tmp')

            directory_list = [
                xce_object.beamline_directory,
                os.path.join(xce_object.labxchem_directory, 'processing',
                             'analysis'), xce_object.initial_model_directory,
                xce_object.panddas_directory, xce_object.reference_directory,
                xce_object.database_directory,
                xce_object.ccp4_scratch_directory,
                xce_object.html_export_directory,
                xce_object.group_deposit_directory
            ]

            for directory in directory_list:
                if not os.path.isdir(directory):
                    os.mkdir(directory)

        # otherwise, use the current working directory
        else:
            xce_object.labxchem_directory_current = xce_object.current_directory
            xce_object.beamline_directory = xce_object.current_directory
            xce_object.initial_model_directory = xce_object.current_directory
            xce_object.reference_directory = xce_object.current_directory
            xce_object.database_directory = xce_object.current_directory
            xce_object.data_source_file = ''
            xce_object.ccp4_scratch_directory = os.getenv('CCP4_SCR')
            xce_object.panddas_directory = xce_object.current_directory
            xce_object.datasets_summary_file = ''
            xce_object.group_deposit_directory = xce_object.current_directory

        ## deposition

        xce_object.deposit_dict = {}

        ## internal lists and dictionaries

        xce_object.data_collection_list = []
        xce_object.visit_list = []
        xce_object.target = ''
        xce_object.dataset_outcome_combobox_dict = {}
        xce_object.data_collection_dict = {}
        xce_object.xtal_db_dict = {}
        xce_object.pandda_analyse_input_table_dict = {}
        xce_object.dewar_configuration_dict = {}
        xce_object.data_collection_statistics_dict = {}
        xce_object.initial_model_dimple_dict = {
        }  # contains toggle button if dimple should be run
        xce_object.reference_file_list = []
        xce_object.all_columns_in_data_source = XChemDB.data_source(os.path.join
                                                                    (xce_object.database_directory,
                                                                     xce_object.data_source_file)) \
            .return_column_list()
        xce_object.albula_button_dict = {
        }  # using dials.image_viewer instead of albula, but keep name for dictionary
        xce_object.xtalform_dict = {}

        xce_object.dataset_outcome_dict = {
        }  # contains the dataset outcome buttons
        xce_object.data_collection_table_dict = {
        }  # contains the dataset table
        xce_object.data_collection_image_dict = {}
        xce_object.data_collection_column_three_dict = {}
        xce_object.datasets_summary_dict = {}
        xce_object.diffraction_data_table_dict = {}
        xce_object.refinement_table_dict = {}
        xce_object.main_data_collection_table_exists = False
        xce_object.timer_to_check_for_new_data_collection = QtCore.QTimer()

        xce_object.agamemnon = False
        xce_object.target_list, xce_object.visit_list = XChemMain.get_target_and_visit_list(
            xce_object.beamline_directory, False)

        xce_object.diffraction_data_dict = {}

        ## internal switches and flags

        xce_object.explorer_active = 0
        xce_object.coot_running = 0
        xce_object.progress_bar_start = 0
        xce_object.progress_bar_step = 0
        xce_object.albula = None
        xce_object.albula_subframes = []
        xce_object.show_diffraction_image = None
        xce_object.gdaLogInstructions = [0, False]
        # can be any widget to be displayed in data collection summary tab
        xce_object.data_collection_details_currently_on_display = None

        xce_object.dataset_outcome = [
            "success", "Failed - centring failed", "Failed - no diffraction",
            "Failed - processing", "Failed - loop empty",
            "Failed - loop broken", "Failed - low resolution",
            "Failed - no X-rays", "Failed - unknown"
        ]

        xce_object.refinement_stage = [
            '0 - All Datasets', '1 - Analysis Pending', '2 - PANDDA model',
            '3 - In Refinement', '4 - CompChem ready', '5 - Deposition ready',
            '6 - Deposited'
        ]

        self.set_xce_logfile(xce_object)

        ## external software packages
        xce_object.using_remote_qsub_submission = False
        xce_object.remote_qsub_submission = "/usr/bin/ssh <dls fed ID>@nx.diamond.ac.uk 'module load global/cluster; qsub'"

        xce_object.update_log = XChemLog.updateLog(xce_object.xce_logfile)
        xce_object.update_log.insert('new session started')
        xce_object.diffraction_data_directory = xce_object.current_directory
        xce_object.diffraction_data_search_info = 'n/a'
        xce_object.diffraction_data_reference_mtz = 'ignore'
        xce_object.html_export_directory = os.getcwd()
        xce_object.external_software = XChemUtils.external_software(
            xce_object.xce_logfile).check()

        xce_object.second_cif_file = None

        software_list = ['acedrg', 'phenix.elbow', 'grade']

        for software in software_list:
            if xce_object.external_software[software]:
                xce_object.restraints_program = str(software)
                xce_object.update_log.insert(
                    'will use ' + str(software) +
                    ' for generation of ligand coordinates and'
                    ' restraints')
            else:
                xce_object.restraints_program = ''
                xce_object.update_log.insert(
                    'No program for generation of ligand coordinates and restraints available!'
                )
Exemplo n.º 8
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)
Exemplo n.º 9
0
    def __init__(self):

        ###########################################################################################
        # read in settings file from XChemExplorer to set the relevant paths
        print 'current dir',os.getcwd()
        self.settings = pickle.load(open(".xce_settings.pkl","rb"))
        print 'setting',self.settings
#        self.refine_model_directory=self.settings['refine_model_directory']
        self.database_directory=self.settings['database_directory']
        self.xce_logfile=self.settings['xce_logfile']
        self.data_source=self.settings['data_source']
        self.db=XChemDB.data_source(self.data_source)

        # checking for external software packages
        self.external_software=XChemUtils.external_software(self.xce_logfile).check()

        self.selection_criteria = [     '0 - All Datasets',
                                        '1 - Analysis Pending',
                                        '2 - PANDDA model',
                                        '3 - In Refinement',
                                        '4 - CompChem ready',
                                        '5 - Deposition ready',
                                        '6 - Deposited'         ]

        self.experiment_stage =     [   ['Review PANDDA export',    '2 - PANDDA model',     65000,  0,  0],
                                        ['In Refinement',           '3 - In Refinement',    65000,  0,  0],
                                        ['Comp Chem Ready!',        '4 - CompChem ready',   65000,  0,  0],
                                        ['Ready for Deposition!',   '5 - Deposition ready', 65000,  0,  0]   ]

        self.ligand_confidence_category = [     '0 - no ligand present',
                                                '1 - Low Confidence',
                                                '2 - Correct ligand, weak density',
                                                '3 - Clear density, unexpected ligand',
                                                '4 - High Confidence'   ]

        self.ligand_site_information =  self.db.get_list_of_pandda_sites_for_coot()
    

        # this decides which samples will be looked at
        self.selection_mode = ''
        self.selected_site=''

        # the Folder is kind of a legacy thing because my inital idea was to have separate folders
        # for Data Processing and Refinement
        self.project_directory = self.settings['initial_model_directory']
        self.Serial=0
        self.Refine=None
        self.index = -1
        self.Todo=[]

        self.xtalID=''
        self.compoundID=''
        self.spider_plot=''
        self.ligand_confidence=''
        self.refinement_folder=''
#        self.datasetOutcome=''

        self.pdb_style='refine.pdb'
        self.mtz_style='refine.mtz'

        # stores imol of currently loaded molecules and maps
        self.mol_dict = {   'protein':  -1,
                            'ligand':   -1,
                            '2fofc':    -1,
                            'fofc':     -1,
                            'event':    -1  }

        # two dictionaries which are flushed when a new crystal is loaded
        # and which contain information to update the data source if necessary
        self.db_dict_mainTable={}
        self.db_dict_panddaTable={}

        ###########################################################################################
        # some COOT settings
        coot.set_map_radius(15)
        coot.set_colour_map_rotation_for_map(0)
        coot.set_colour_map_rotation_on_read_pdb_flag(0)

        self.QualityIndicators = {  'RefinementRcryst':                         '-',
                                    'RefinementRfree':                          '-',
                                    'RefinementRfreeTraficLight':               'gray',
                                    'RefinementResolution':                     '-',
                                    'RefinementResolutionTL':                   'gray',
                                    'RefinementMolProbityScore':                '-',
                                    'RefinementMolProbityScoreTL':              'gray',
                                    'RefinementRamachandranOutliers':           '-',
                                    'RefinementRamachandranOutliersTL':         'gray',
                                    'RefinementRamachandranFavored':            '-',
                                    'RefinementRamachandranFavoredTL':          'gray',
                                    'RefinementRmsdBonds':                      '-',
                                    'RefinementRmsdBondsTL':                    'gray',
                                    'RefinementRmsdAngles':                     '-',
                                    'RefinementRmsdAnglesTL':                   'gray',
                                    'RefinementMatrixWeight':                   '-'   }

        self.spider_plot_data = {   'PANDDA_site_ligand_id':                    '-',
                                    'PANDDA_site_occupancy':                    '-',
                                    'PANDDA_site_B_average':                    '-',
                                    'PANDDA_site_B_ratio_residue_surroundings': '-',
                                    'PANDDA_site_RSCC':                         '-',
                                    'PANDDA_site_rmsd':                         '-',
                                    'PANDDA_site_RSR':                          '-',
                                    'PANDDA_site_RSZD':                         '-'     }


        # default refmac parameters
        self.RefmacParams={ 'HKLIN':            '',                 'HKLOUT': '',
                            'XYZIN':            '',                 'XYZOUT': '',
                            'LIBIN':            '',                 'LIBOUT': '',
                            'TLSIN':            '',                 'TLSOUT': '',
                            'TLSADD':           '',
                            'NCYCLES':          '10',
                            'MATRIX_WEIGHT':    'AUTO',
                            'BREF':             '    bref ISOT\n',
                            'TLS':              '',
                            'NCS':              '',
                            'TWIN':             ''    }
Exemplo n.º 10
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()
Exemplo n.º 11
0
    def __init__(self):

        ###########################################################################################
        # read in settings file from XChemExplorer to set the relevant paths
        self.settings = pickle.load(open(".xce_settings.pkl", "rb"))
        remote_qsub_submission = self.settings['remote_qsub']
        self.database_directory = self.settings['database_directory']
        self.xce_logfile = self.settings['xce_logfile']
        self.Logfile = XChemLog.updateLog(self.xce_logfile)
        self.Logfile.insert('starting COOT gui for reference model refinement')
        self.data_source = self.settings['data_source']

        # checking for external software packages
        self.external_software = XChemUtils.external_software(
            self.xce_logfile).check()
        self.external_software['qsub_remote'] = remote_qsub_submission

        # the Folder is kind of a legacy thing because my inital idea was to have separate folders
        # for Data Processing and Refinement
        self.reference_directory = self.settings['reference_directory']
        self.refinementDir = ''
        self.Serial = 0
        self.Refine = None

        self.xtalID = ''
        self.compoundID = ''
        self.spider_plot = ''
        self.refinement_folder = ''
        self.pdbFile = ''
        self.mtzFree = ''

        self.pdb_style = 'refine.pdb'
        self.mtz_style = 'refine.mtz'

        # stores imol of currently loaded molecules and maps
        self.mol_dict = {
            'protein': -1,
            'ligand': -1,
            '2fofc': -1,
            'fofc': -1,
            'event': -1
        }

        self.ground_state_map_List = []
        self.job_running = False

        ###########################################################################################
        # some COOT settings
        coot.set_map_radius(17)
        coot.set_colour_map_rotation_for_map(0)
        #        coot.set_colour_map_rotation_on_read_pdb_flag(21)

        self.QualityIndicators = {
            'Rcryst': '-',
            'Rfree': '-',
            'RfreeTL': 'gray',
            'ResolutionHigh': '-',
            'ResolutionColor': 'gray',
            'MolprobityScore': '-',
            'MolprobityScoreColor': 'gray',
            'RamachandranOutliers': '-',
            'RamachandranOutliersColor': 'gray',
            'RamachandranFavored': '-',
            'RamachandranFavoredColor': 'gray',
            'rmsdBonds': '-',
            'rmsdBondsTL': 'gray',
            'rmsdAngles': '-',
            'rmsdAnglesTL': 'gray',
            'MatrixWeight': '-'
        }

        # default refmac parameters
        self.RefmacParams = {
            'HKLIN': '',
            'HKLOUT': '',
            'XYZIN': '',
            'XYZOUT': '',
            'LIBIN': '',
            'LIBOUT': '',
            'TLSIN': '',
            'TLSOUT': '',
            'TLSADD': '',
            'NCYCLES': '10',
            'MATRIX_WEIGHT': 'AUTO',
            'BREF': '    bref ISOT\n',
            'TLS': '',
            'NCS': '',
            'TWIN': ''
        }
Exemplo n.º 12
0
    def prepare(self, whichSamples):
        self.Logfile.insert('======== preparing HTML summary ========')
        self.makeFolders()
        self.copy_jscss()
        html = XChemMain.html_header()
        firstFile = True
        for xtal in self.db.samples_for_html_summary(whichSamples):
            self.db_dict = self.db.get_db_dict_for_sample(xtal)
            if firstFile:
                if self.db_dict['ProteinName'] == 'None':
                    self.Logfile.warning('could not determine protein name')
                    try:
                        self.protein_name = xtal.split('-')[0]
                        self.Logfile.warning(
                            'xtal name = %s => setting protein name to %s' %
                            (xtal, self.protein_name))
                    except IndexError:
                        self.Logfile.warning(
                            'could not determine protein name from cystal name; setting to None'
                        )
                        self.protein_name = ''
                else:
                    self.protein_name = self.db_dict['ProteinName']
                    self.Logfile.insert('protein name is: ' +
                                        self.protein_name)
            self.copy_pdb(xtal)
            self.copy_mtz(xtal)
            #            self.copy_electron_density(xtal)
            self.copy_ligand_files(xtal)
            os.chdir(os.path.join(self.projectDir, xtal))
            ligandDict = XChemUtils.pdbtools_gemmi(
                'refine.pdb').center_of_mass_ligand_dict('LIG')
            self.Logfile.insert(
                xtal +
                ': saving ligand(s) of type LIG in refine.pdb as PDB files...')
            XChemUtils.pdbtools_gemmi('refine.pdb').save_ligands_to_pdb('LIG')
            for ligand in ligandDict:
                self.Logfile.insert(xtal + ': current ligand -> ' + ligand)
                os.chdir(os.path.join(self.projectDir, xtal))
                #            for ligand in self.ligands_in_pdbFile(xtal):
                ligName = ligand.split('-')[0]
                ligChain = ligand.split('-')[1]
                ligNumber = ligand.split('-')[2]
                #                eventMap = self.find_matching_event_map_from_database(xtal, ligand)
                #                if eventMap:
                #                    self.Logfile.insert('%s: using the following event map -> %s' %(xtal,eventMap))
                #                    self.cut_and_copy_map(xtal, ligand+'.pdb', eventMap, xtal + '_' + ligand + '_event.ccp4','F','PHIF')
                #                    eventMap = xtal + '_' + ligand + '_event.ccp4'
                #                else:
                #                    self.Logfile.error('%s: value of event map -> %s' %(xtal,eventMap))
                eventMap = ''
                #                self.Logfile.insert(xtal + ': looking for' + xtal + '_' + ligand + '_event.ccp4')
                if os.path.isfile(xtal + '_' + ligand + '_event.ccp4'):
                    eventMap = xtal + '_' + ligand + '_event.ccp4'
#                    self.Logfile.insert(xtal + ': found ' + eventMap)
#                else:
#                    self.Logfile.error(xtal + ': cannot find' + xtal + '_' + ligand + '_event.ccp4')
#                x,y,z = self.pdb.get_centre_of_gravity_of_residue(ligand)
                x = ligandDict[ligand][0]
                y = ligandDict[ligand][1]
                z = ligandDict[ligand][2]
                self.copy_spider_plot(xtal, ligand)
                pdbID = self.db_dict['Deposition_PDB_ID']
                compoundImage = xtal + '_' + self.db_dict[
                    'CompoundCode'] + '.png'
                compoundCIF = xtal + '_' + self.db_dict['CompoundCode'] + '.cif'
                residuePlot = xtal + '_' + ligand + '.png'
                pdb = xtal + '.pdb'
                event = xtal + '_' + ligand + '_event.ccp4'
                thumbNail = xtal + '_' + ligand + '_thumb.png'
                resoHigh = self.db_dict['DataProcessingResolutionHigh']
                spg = self.db_dict['RefinementSpaceGroup']
                unitCell = self.db_dict['DataProcessingUnitCell']
                t = ''
                for ax in unitCell.split():
                    t += str(round(float(ax), 1)) + ' '
                unitCell = t[:-1]
                os.chdir(os.path.join(self.projectDir, xtal))
                #                FWT = xtal + '-' + ligand + '_2fofc.ccp4'
                #                self.cut_and_copy_map(xtal, ligand + '.pdb', '2fofc.map', FWT,'FWT','PHWT')
                #                DELFWT = xtal + '-' + ligand + '_fofc.ccp4'
                #                self.cut_and_copy_map(xtal, ligand + '.pdb', 'fofc.map', DELFWT,'DELFWT','PHDELWT')
                if os.path.isfile('refine.mtz'):
                    self.Logfile.insert('%s: found refine.mtz' % xtal)
                    FWTmap, DELFWTmap = self.prepare_e_density_maps(
                        xtal, ligand)
                    self.copy_electron_density(xtal, ligand, eventMap)
                ligConfidence = self.db.get_ligand_confidence_for_ligand(
                    xtal, ligChain, ligNumber, ligName)
                if ligConfidence.startswith('0'):
                    self.Logfile.warning(
                        '%s: ligand confidence of %s-%s-%s is %s; ignoring...'
                        % (xtal, ligChain, ligNumber, ligName, ligConfidence))
                    self.Logfile.warning(
                        '%s: this seems unlikely because this structure is apparently ready for deposition'
                        % xtal)
                    self.Logfile.warning(
                        '%s: will set it to "not assigned" for now, but please update in soakDB'
                        % xtal)
                    ligConfidence = 'not assigned'
                modelStatus = self.db_dict['RefinementOutcome']
                if firstFile:
                    html += XChemMain.html_ngl(
                        pdb, eventMap.replace(self.projectDir, ''), FWTmap,
                        DELFWTmap, ligand)
                    html += XChemMain.html_download(self.protein_name)
                    html += XChemMain.html_guide()
                    html += XChemMain.html_table_header()
                    firstFile = False

                html += XChemMain.html_table_row(xtal, pdbID, ligand,
                                                 compoundImage, residuePlot,
                                                 pdb, event, thumbNail,
                                                 resoHigh, spg, unitCell,
                                                 FWTmap, DELFWTmap,
                                                 ligConfidence, modelStatus)
                self.make_thumbnail(xtal, x, y, z, ligand, eventMap)
                self.prepare_for_download(xtal, pdb, event, compoundCIF,
                                          ligand)
        self.prepare_zip_archives()
        #        html = XChemMain.html_download_all_section(html,self.protein_name)
        self.write_html_file(html)
        self.Logfile.insert(
            '======== finished preparing HTML summary ========')