Beispiel #1
0
  def processPhaser(self,chain):
    """
    Run Phaser on input pdb file.
    """
    if self.verbose:
      self.logger.debug('AutoMolRep::processPhaser')
    
    def launchJob(inp2,k):
      """
      Launch Phaser job on cluster and pass back the process job and pid.
      """
      Utils.folders(self,k)
      #Remove leftover file if rerunning.
      if os.path.exists('adf.com'):
        os.system('rm -rf adf.com')
      queue = Queue()
      j = Process(target=RunPhaser,args=(inp2,queue,self.logger))
      j.start()
      queue.get()#For the log I am not using
      if self.output['jobs'] == None:
        self.output['jobs'] = {j:k}
        self.output['pids'] = {k:queue.get()}
      else:
        self.output['jobs'].update({j:k})
        self.output['pids'].update({k:queue.get()})
      #Setup initial results for all running jobs.
      self.phaser_results[k] = { 'AutoMR results' : Parse.setPhaserFailed('Still running')}
        
    try:
      sg_name = []
      #set lays in self.output if not there.
      self.output.setdefault('jobs',None)
      self.output.setdefault('pids',None)
      
      d = {'data':self.datafile,'pdb':self.pdb_info[chain]['file'],'verbose':self.verbose,
           'copy':self.pdb_info[chain]['NMol'],'test':self.test,'cluster':self.cluster_use,
           'res':Utils.setPhaserRes(self,self.pdb_info[chain]['res']),'large':self.large_cell,
           #'mwaa':self.pdb_info[chain]['MWaa'],'mwna':self.pdb_info[chain]['MWna'],
           }
      run_sg = Utils.subGroups(self,Utils.convertSG(self,self.input_sg),'phaser')
      #Run Phaser in all the space groups.
      for sg in run_sg:
        sg2 = Utils.convertSG(self,sg,True)
        sg_name.append(sg2)
        d['sg'] = sg2
        if self.run_before == False:
          key = '%s_%s_%s'%(sg2,chain,'0')
          d['run_before'] = False
          launchJob(d,key)
        #Run both fast and full Phaser at same time if in cluster mode
        if self.run_before or self.cluster_use:
          key = '%s_%s_%s'%(sg2,chain,'1')
          d['run_before'] = True
          launchJob(d,key)

    except:
      self.logger.exception('**ERROR in AutoMolRep.processPhaser**')
Beispiel #2
0
    def labelitSort(self):
        """
    Sort out which iteration of Labelit has the highest symmetry and choose that solution. If
    Labelit does not find a solution, finish up the pipeline.
    """
        if self.verbose:
            self.logger.debug('LabelitPP::labelitSort')
        import numpy
        rms_list1 = []
        metric_list1 = []
        sol_dict = {}
        sg_list1 = []
        sg_dict = {}
        sym = '0'
        try:
            for run in self.labelit_results.keys():
                if type(self.labelit_results[run].get(
                        "labelit_results")) == dict:
                    #Check for pseudotranslation
                    if self.labelit_results[run].get("labelit_results").get(
                            'pseudotrans') == True:
                        self.pseudotrans = True
                    Utils.getLabelitStats(self, inp=run, simple=False)
                    rms_list1.append(
                        float(self.labelit_results[run].get(
                            'labelit_stats').get('best').get('mos_rms')))
                    metric_list1.append(
                        float(self.labelit_results[run].get(
                            'labelit_stats').get('best').get('metric')))
                    sg = Utils.convertSG(
                        self, self.labelit_results[run].get(
                            'labelit_stats').get('best').get('SG'))
                    sg_dict[run] = sg
                    sg_list1.append(float(sg))
                else:
                    #If Labelit failed, set dummy params
                    sg_dict[run] = '0'
                    sg_list1.append(0)
                    rms_list1.append(100)
                    metric_list1.append(100)
            for x in range(len(sg_list1)):
                if sg_list1[x] == numpy.amax(sg_list1):
                    #If its P1 look at the Mosflm RMS, else look at the Labelit metric.
                    if str(sg_list1[x]) == '1.0':
                        sol_dict[rms_list1[x]] = self.labelit_results.keys()[x]
                    else:
                        sol_dict[
                            metric_list1[x]] = self.labelit_results.keys()[x]
            l = sol_dict.keys()
            l.sort()
            #Best Labelit_results key
            highest = sol_dict[l[0]]
            #symmetry of best solution
            sym = sg_dict[highest]

            #If there is a solution...
            if sym != '0':
                self.labelit_results = self.labelit_results[highest]
                os.chdir(os.path.join(self.labelit_dir, highest))
                self.logger.debug('The sorted labelit solution was #%s' %
                                  highest)
            else:
                failed = False
                #If pairs failed, then retry autoindexing on single frames.
                if len(self.images) == 6:
                    if self.cycle in (0, 1):
                        junk = list(self.images)
                        del junk[3 - self.cycle]
                        self.cycle += 1
                        self.processLabelit(junk)
                        self.labelitSort()
                    else:
                        failed = True
                else:
                    failed = True
                #If there is no solution from Labelit...
                if failed:
                    self.logger.debug(
                        'No solution was found when sorting Labelit results.')
                    self.labelit_failed = True
                    self.labelit_results = {"labelit_results": 'FAILED'}

        except:
            self.logger.exception('**ERROR in LabelitPP.labelitSort**')
Beispiel #3
0
  def labelitSort(self):
    """
    Sort out which iteration of Labelit has the highest symmetry and choose that solution. If
    Labelit does not find a solution, finish up the pipeline.
    """
    if self.verbose:
      self.logger.debug('LabelitPP::labelitSort')
    import numpy
    rms_list1 = []
    metric_list1 = []
    sol_dict = {}
    sg_list1 = []
    sg_dict  = {}
    sym = '0'
    try:
      for run in self.labelit_results.keys():
        if type(self.labelit_results[run].get('Labelit results')) == dict:
          #Check for pseudotranslation
          if self.labelit_results[run].get('Labelit results').get('pseudotrans') == True:
            self.pseudotrans = True
          Utils.getLabelitStats(self,inp=run,simple=False)
          rms_list1.append(float(self.labelit_results[run].get('labelit_stats').get('best').get('mos_rms')))
          metric_list1.append(float(self.labelit_results[run].get('labelit_stats').get('best').get('metric')))
          sg = Utils.convertSG(self,self.labelit_results[run].get('labelit_stats').get('best').get('SG'))
          sg_dict[run] = sg
          sg_list1.append(float(sg))
        else:
          #If Labelit failed, set dummy params
          sg_dict[run] = '0'
          sg_list1.append(0)
          rms_list1.append(100)
          metric_list1.append(100)
      for x in range(len(sg_list1)):
        if sg_list1[x] == numpy.amax(sg_list1):
          #If its P1 look at the Mosflm RMS, else look at the Labelit metric.
          if str(sg_list1[x]) == '1.0':
            sol_dict[rms_list1[x]]    = self.labelit_results.keys()[x]
          else:
            sol_dict[metric_list1[x]] = self.labelit_results.keys()[x]
      l = sol_dict.keys()
      l.sort()
      #Best Labelit_results key
      highest = sol_dict[l[0]]
      #symmetry of best solution
      sym = sg_dict[highest]
      
      #If there is a solution...
      if sym != '0':
        self.labelit_results = self.labelit_results[highest]
        os.chdir(os.path.join(self.labelit_dir,highest))
        self.logger.debug('The sorted labelit solution was #%s'%highest)
      else:
        failed = False
        #If pairs failed, then retry autoindexing on single frames.
        if len(self.images) == 6:
          if self.cycle in (0,1):
            junk = list(self.images)
            del junk[3-self.cycle]
            self.cycle += 1
            self.processLabelit(junk)
            self.labelitSort()
          else:
            failed = True
        else:
          failed = True
        #If there is no solution from Labelit...
        if failed:
          self.logger.debug('No solution was found when sorting Labelit results.')
          self.labelit_failed = True
          self.labelit_results = { 'Labelit results'  : 'FAILED'}

    except:
      self.logger.exception('**ERROR in LabelitPP.labelitSort**')
Beispiel #4
0
 def labelitSort(self):
   """
   Figure out which round has the best index fit.
   """
   if self.verbose:
     self.logger.debug('FindBeamCenter::labelitSort')
   
   try:
     li = []
     stats = {}
     passed = True
     orig_sg = 1
     #if self.sg == None:
     if SPACEGROUP == 'None':
       find_sg = True
     else:
       find_sg = False
     #Label the SG and grab the solutions with the highest SG.
     for i in range(0,2):
       for run in self.labelit_results.keys():
         if run.startswith('bc_'):
           if type(self.labelit_results[run].get('Labelit results')) == dict:
             if i == 0:
               #Check for pseudotranslation, meaning bad snap!!!
               if self.labelit_results[run].get('Labelit results').get('pseudotrans'):
                 #passed = False
                 pass
               #Get Labelit stats and SG#
               Utils.getLabelitStats(self,run)
               sg = self.labelit_results[run].get('labelit_stats').get('best').get('SG')
               new_sg = float(Utils.convertSG(self,sg))
               self.labelit_results[run].update({'labelit_best_sg#': new_sg})
               if find_sg:
                 if new_sg > orig_sg:
                   SPACEGROUP = sg
                   orig_sg = new_sg
             else:
               #Make sure I compare same SG.
               if self.labelit_results[run].get('labelit_stats').get('best').get('SG') == SPACEGROUP:
                 li.append(run)
               else:
                 del self.labelit_results[run]
     #Calculate the number of solutions for 10% of correct SG and check if enough are present.
     l = len(li)
     if l > 0:
       top = int(round(l*0.1))
       if top < 5:
         if l < top:
           top = l
         else:
           top = 5
       """
       #Does not seem to matter.
       test = decimal.Decimal(l)/decimal.Decimal(len(runs))
       if test < decimal.Decimal('0.1'):
           passed = False
       """
       #Print results for testing.
       if self.verbose:
         #print 'Iteration=',str(self.iteration)
         print 'Total number of Labelit runs: %s'%len(self.labelit_results.keys())
         print 'Total number of solutions in %s: %s'%(SPACEGROUP, l)
         print 'Number of solutions in the top 10%% = %s'%top
         self.logger.debug('Total number of Labelit runs: %s'%len(self.labelit_results.keys()))
         self.logger.debug('Total number of solutions in %s: %s'%(SPACEGROUP, l))
         self.logger.debug('Number of solutions in the top 10%% = %s'%top)
       #Sort solutions in correct SG by each param
       ls = [("self.labelit_results[run].get('labelit_stats').get('P1').get('rmsd')","Labelit P1 RMSD"),
             ("self.labelit_results[run].get('labelit_stats').get('P1').get('mos_rms')","Mosflm P1 RMS"),
             ("self.labelit_results[run].get('labelit_stats').get('best').get('metric')","Labelit Metric"),
             ("self.labelit_results[run].get('labelit_stats').get('best').get('rmsd')","Labelit RMSD"),
             ("self.labelit_results[run].get('labelit_stats').get('best').get('mos_rms')","Mosflm RMS")]
       for z in range(5):
         dict1 = {}
         for run in li:
           dict1[run] = float(eval(ls[z][0]))
         li1 = dict1.values()
         li1.sort()
         #Grab the top 10%.
         li1_top = li1[:top]
         li2 = []
         for run in li:
           for line in li1_top:
             if dict1[run] == line:
               li2.append(run)
               li1_top.remove(line)
               if line == li1[0]:
                 top1 = run
         #Grab the Labelit beam centers and calculate the stats.
         x = []
         y = []
         for run in li2:
           x.append(float(self.labelit_results[run].get('Labelit results').get('labelit_bc').get('labelit_x_beam')))
           y.append(float(self.labelit_results[run].get('Labelit results').get('labelit_bc').get('labelit_y_beam')))
         #stats[li[z][1]] = {'avg_x': numpy.average(x), 'std_x': numpy.std(x), 'avg_y': numpy.average(y), 'std_y': numpy.std(y),
         #                      'sum_std': numpy.std(x)+numpy.std(y), 'j1': li[z][0], 'top': top1}
         stats[ls[z][1]] = {'avg_x': numpy.average(x), 'std_x': numpy.std(x), 'avg_y': numpy.average(y), 'std_y': numpy.std(y),
                            'sum_std': numpy.std(x)+numpy.std(y), 'j1': ls[z][0], 'top': top1}
       #Sort all results by lowest sum of std dev (x+y) and save the best.
       temp = []
       for i in range(2):
         for key in stats.keys():
           if i == 0:
             #First, save the lowest sum_std.
             temp.append(stats[key].get('sum_std'))
           else:
             if stats[key].get('sum_std') == temp[0]:
               #Check the std dev. 
               if decimal.Decimal(str(stats[key].get('std_x'))) > decimal.Decimal(str(self.std_dev)):
                 passed = False
               if decimal.Decimal(str(stats[key].get('std_y'))) > decimal.Decimal(str(self.std_dev)):
                 passed = False
               #Save best results for each distance for further calculations.
               self.results['orig_X'] = self.x_beam
               self.results['orig_Y'] = self.y_beam
               self.results['X'] = stats[key].get('avg_x')
               self.results['Y'] = stats[key].get('avg_y')
               self.results['passed'] = passed
               #best = stats[key].get('top')
               if self.verbose:
                 print '****************************************'
                 print 'At %s mm:'%self.distance
                 print 'Best stats from %s'%key
                 print 'X =%s std=%s'%(stats[key].get('avg_x'),stats[key].get('std_x'))
                 print 'Y =%s std=%s'%(stats[key].get('avg_y'),stats[key].get('std_y'))
                 print 'Good results=%s'%passed
                 print '****************************************'
                 self.logger.debug('****************************************')
                 self.logger.debug('At %s mm:'%self.distance)
                 self.logger.debug('Best stats from %s'%key)
                 self.logger.debug('X =%s std=%s'%(stats[key].get('avg_x'),stats[key].get('std_x')))
                 self.logger.debug('Y =%s std=%s'%(stats[key].get('avg_y'),stats[key].get('std_y')))
                 self.logger.debug('Good results=%s'%passed)
                 self.logger.debug('****************************************')
         if i == 0:
           temp.sort()
     else:
       self.results = {'passed':False}
           
   except:
     self.logger.exception('**ERROR in FindBeamCenter.labelitSort**')
     self.results = {'passed':False}