Пример #1
0
    def run(self):
      from xia2.Handlers.Streams import Debug
      Debug.write('Running %s' %self.get_executable())

      self.clear_command_line()
      self.add_command_line(self._sweep_filename)
      self.add_command_line(self._spot_filename)
      nproc = Flags.get_parallel()
      self.set_cpu_threads(nproc)
      self.add_command_line('nproc=%i' % nproc)
      for scan_range in self._scan_ranges:
        self.add_command_line('scan_range=%d,%d' % scan_range)

      if self._phil_file is not None:
        self.add_command_line("%s" %self._phil_file)

      self._optimized_filename = os.path.join(
        self.get_working_directory(), '%d_optimized_datablock.json' %self.get_xpid())
      self.add_command_line("output.datablock=%s" %self._optimized_filename)

      self.start()
      self.close_wait()
      self.check_for_errors()

      records = self.get_all_output()

      assert os.path.exists(self._optimized_filename), self._optimized_filename

      return
Пример #2
0
    def __init__(self):

      # set up the object ancestors...
      DriverInstance.__class__.__init__(self)

      # now set myself up...
      self._parallel = Flags.get_parallel()
      if self._parallel <= 1:
        self.set_executable('xscale')
      else:
        self.set_executable('xscale_par')

      self._version = 'new'

      # overall information
      self._resolution_shells = ''
      self._cell = None
      self._spacegroup_number = None
      self._reindex_matrix = None

      # corrections to apply - N.B. default values come from the
      # factory function default arguments...
      self._correct_decay = correct_decay
      self._correct_absorption = correct_absorption
      self._correct_modulation = correct_modulation

      # input reflections information - including grouping information
      # in the same way as the .xinfo files - through the wavelength
      # names, which will be used for the output files.
      self._input_reflection_files = []
      self._input_reflection_wavelength_names = []
      self._input_resolution_ranges = []

      # these are generated at the run time
      self._transposed_input = { }
      self._transposed_input_keys = []

      # output
      self._output_reflection_files = { }
      self._remove = []

      # decisions about the scaling
      self._crystal = None
      self._zero_dose = False
      self._anomalous = True
      self._merge = False

      # scale factor output
      self._scale_factor = 1.0

      # Rmerge values - for the scale model analysis - N.B. get
      # one for each data set, obviously...
      self._rmerges = { }


      return
Пример #3
0
    def __init__(self, params=None):
      super(XDSIntegrateWrapper, self).__init__()

      # phil parameters

      if not params:
        from xia2.Handlers.Phil import master_phil
        params = master_phil.extract().xds.integrate
      self._params = params

      # now set myself up...

      self._parallel = Flags.get_parallel()
      self.set_cpu_threads(self._parallel)

      if self._parallel <= 1:
        self.set_executable('xds')
      else:
        self.set_executable('xds_par')

      # generic bits

      self._data_range = (0, 0)

      self._input_data_files = { }
      self._output_data_files = { }

      self._input_data_files_list = ['X-CORRECTIONS.cbf',
                                     'Y-CORRECTIONS.cbf',
                                     'BLANK.cbf',
                                     'BKGPIX.cbf',
                                     'GAIN.cbf',
                                     'XPARM.XDS']

      self._output_data_files_list = ['FRAME.cbf']

      self._refined_xparm = False

      self._updates = { }

      # note well - INTEGRATE.HKL is not included in this list
      # because it is likely to be very large - this is treated
      # separately...

      self._integrate_hkl = None

      # FIXME these will also be wanted by the full integrater
      # interface I guess?

      self._mean_mosaic = None
      self._min_mosaic = None
      self._max_mosaic = None

      return
Пример #4
0
    def run(self):
      from xia2.Handlers.Streams import Debug
      Debug.write('Running dials.find_spots')

      self.clear_command_line()
      self.add_command_line('input.datablock="%s"' % self._input_sweep_filename)
      if self._output_sweep_filename is not None:
        self.add_command_line(
          'output.datablock="%s"' % self._output_sweep_filename)
      self.add_command_line('output.reflections="%s"' % self._input_spot_filename)
      nproc = Flags.get_parallel()
      self.set_cpu_threads(nproc)
      self.add_command_line('nproc=%i' % nproc)
      for scan_range in self._scan_ranges:
        self.add_command_line('spotfinder.scan_range=%d,%d' % scan_range)
      if self._min_spot_size is not None:
        self.add_command_line('min_spot_size=%i' % self._min_spot_size)
      if self._min_local is not None:
        self.add_command_line('min_local=%i' % self._min_local)
      if self._kernel_size is not None:
        self.add_command_line('kernel_size=%i %i' % \
                              (self._kernel_size, self._kernel_size))
      if self._global_threshold is not None:
        self.add_command_line('global_threshold=%s' % self._global_threshold)
      if self._sigma_strong is not None:
        self.add_command_line('sigma_strong=%i' % self._sigma_strong)
      if self._filter_ice_rings:
        self.add_command_line('ice_rings.filter=%s' % self._filter_ice_rings)
      if self._phil_file is not None:
        self.add_command_line("%s" % self._phil_file)
      if self._write_hot_mask:
        self.add_command_line("write_hot_mask=true")
      if self._gain:
        self.add_command_line("gain=%f" % self._gain)
      self.start()
      self.close_wait()
      self.check_for_errors()

      for record in self.get_all_output():
        if record.startswith('Saved') and 'reflections to' in record:
          self._nspots = int(record.split()[1])

      return
Пример #5
0
    def __init__(self, params=None):
      super(XDSColspotWrapper, self).__init__()

      # phil parameters

      if not params:
        from xia2.Handlers.Phil import master_phil
        params = master_phil.extract().xds.colspot
      self._params = params

      # now set myself up...

      self._parallel = Flags.get_parallel()
      self.set_cpu_threads(self._parallel)

      if self._parallel <= 1:
        self.set_executable('xds')
      else:
        self.set_executable('xds_par')

      # generic bits

      self._data_range = (0, 0)
      self._spot_range = []
      self._background_range = (0, 0)
      self._resolution_range = (0, 0)

      self._input_data_files = { }
      self._output_data_files = { }

      self._input_data_files_list = ['X-CORRECTIONS.cbf',
                                     'Y-CORRECTIONS.cbf',
                                     'BLANK.cbf',
                                     'BKGINIT.cbf',
                                     'GAIN.cbf']

      self._output_data_files_list = ['SPOT.XDS']

      return
Пример #6
0
    def __init__(self, params=None):
      super(XDSIdxrefWrapper, self).__init__()

      # phil parameters

      if not params:
        from xia2.Handlers.Phil import master_phil
        params = master_phil.extract().xds.index
      self._params = params

      # now set myself up...

      self._parallel = Flags.get_parallel()
      self.set_cpu_threads(self._parallel)

      if self._parallel <= 1:
        self.set_executable('xds')
      else:
        self.set_executable('xds_par')

      # generic bits

      self._data_range = (0, 0)
      self._spot_range = []
      self._background_range = (0, 0)
      self._resolution_range = (0, 0)

      self._org = [0.0, 0.0]

      self._refined_origin = None
      self._refined_beam_vector = None
      self._refined_rotation_axis = None

      self._starting_angle = 0.0
      self._starting_frame = 0

      self._cell = None
      self._symm = 0

      self._a_axis = None
      self._b_axis = None
      self._c_axis = None

      # results

      self._refined_beam = (0, 0)
      self._refined_distance = 0

      self._indexing_solutions = { }

      self._indxr_input_lattice = None
      self._indxr_input_cell = None
      self._indxr_user_input_lattice = False

      self._indxr_lattice = None
      self._indxr_cell = None
      self._indxr_mosaic = None

      self._input_data_files = { }
      self._output_data_files = { }

      self._input_data_files_list = ['SPOT.XDS']

      self._output_data_files_list = ['SPOT.XDS',
                                      'XPARM.XDS']

      self._index_tree_problem = False

      self._fraction_rmsd_rmsphi = None

      return
Пример #7
0
    def __init__(self, params=None):
      super(XDSCorrectWrapper, self).__init__()

      # phil parameters

      if not params:
        from xia2.Handlers.Phil import master_phil
        params = master_phil.extract().xds.correct
      self._params = params

      # now set myself up...

      self._parallel = Flags.get_parallel()
      self.set_cpu_threads(self._parallel)

      if self._parallel <= 1:
        self.set_executable('xds')
      else:
        self.set_executable('xds_par')

      # generic bits

      self._data_range = (0, 0)
      self._spot_range = []
      self._background_range = (0, 0)
      self._resolution_range = (0, 0)
      self._resolution_high = 0.0
      self._resolution_low = 40.0

      # specific information

      self._cell = None
      self._spacegroup_number = None
      self._anomalous = False

      self._polarization = 0.0

      self._reindex_matrix = None
      self._reindex_used = None

      self._input_data_files = { }
      self._output_data_files = { }

      self._input_data_files_list = []

      self._output_data_files_list = ['GXPARM.XDS']

      self._ice = 0
      self._excluded_regions = []

      # the following input files are also required:
      #
      # INTEGRATE.HKL
      # REMOVE.HKL
      #
      # and XDS_ASCII.HKL is produced.

      # in
      self._integrate_hkl = None
      self._remove_hkl = None

      # out
      self._xds_ascii_hkl = None
      self._results = None
      self._remove = []

      return
Пример #8
0
    def run(self, method):
      from xia2.Handlers.Streams import Debug
      Debug.write('Running dials.index')

      self.clear_command_line()
      for f in self._sweep_filenames:
        self.add_command_line(f)
      for f in self._spot_filenames:
        self.add_command_line(f)
      self.add_command_line('indexing.method=%s' % method)
      nproc = Flags.get_parallel()
      self.set_cpu_threads(nproc)
      self.add_command_line('indexing.nproc=%i' % nproc)
      if Flags.get_small_molecule():
        self.add_command_line('filter_ice=false')
      if self._reflections_per_degree is not None:
        self.add_command_line(
          'reflections_per_degree=%i' %self._reflections_per_degree)
      if self._fft3d_n_points is not None:
        self.add_command_line(
          'fft3d.reciprocal_space_grid.n_points=%i' %self._fft3d_n_points)
      if self._close_to_spindle_cutoff is not None:
        self.add_command_line(
          'close_to_spindle_cutoff=%f' %self._close_to_spindle_cutoff)
      if self._outlier_algorithm:
        self.add_command_line('outlier.algorithm=%s' % self._outlier_algorithm)
      if self._max_cell:
        self.add_command_line('max_cell=%d' % self._max_cell)
      if self._min_cell:
        self.add_command_line('min_cell=%d' % self._min_cell)
      if self._d_min_start:
        self.add_command_line('d_min_start=%f' % self._d_min_start)
      if self._indxr_input_lattice is not None:
        from xia2.Experts.SymmetryExpert import lattice_to_spacegroup_number
        self._symm = lattice_to_spacegroup_number(
            self._indxr_input_lattice)
        self.add_command_line('known_symmetry.space_group=%s' % self._symm)
      if self._indxr_input_cell is not None:
        self.add_command_line(
          'known_symmetry.unit_cell="%s,%s,%s,%s,%s,%s"' %self._indxr_input_cell)
      if self._maximum_spot_error:
        self.add_command_line('maximum_spot_error=%.f' %
                              self._maximum_spot_error)
      if self._detector_fix:
        self.add_command_line('detector.fix=%s' % self._detector_fix)
      if self._beam_fix:
        self.add_command_line('beam.fix=%s' % self._beam_fix)
      if self._phil_file is not None:
        self.add_command_line("%s" %self._phil_file)

      self._experiment_filename = os.path.join(
        self.get_working_directory(), '%d_experiments.json' %self.get_xpid())
      self._indexed_filename = os.path.join(
        self.get_working_directory(), '%d_indexed.pickle' %self.get_xpid())
      self.add_command_line("output.experiments=%s" %self._experiment_filename)
      self.add_command_line("output.reflections=%s" %self._indexed_filename)

      self.start()
      self.close_wait()
      self.check_for_errors()

      records = self.get_all_output()

      for i, record in enumerate(records):
        if 'Unit cell:' in record:
          self._p1_cell = map(float, record.replace('(', '').replace(
            ')', '').replace(',', '').split()[-6:])

        if 'Final RMSDs by experiment' in record:
          values = records[i+6].strip().strip('|').split('|')
          if len(values):
            values = [float(v) for v in values]
            if values[0] == 0:
              self._nref = int(values[1])
              self._rmsd_x = values[2]
              self._rmsd_y = values[3]
              self._rmsd_z = values[4]

      return
Пример #9
0
    def scale(self):
      '''Actually perform the scaling.'''

      self.check_hklin()
      self.check_hklout()

      if self._chef_unmerged and self._scalepack:
        raise RuntimeError, 'CHEF and scalepack incompatible'

      if self._onlymerge:
        raise RuntimeError, 'use merge() method'

      if not self._scalepack:
        self.set_task('Scaling reflections from %s => %s' % \
                     (os.path.split(self.get_hklin())[-1],
                      os.path.split(self.get_hklout())[-1]))
      else:
        self.set_task('Scaling reflections from %s => scalepack %s' % \
                     (os.path.split(self.get_hklin())[-1],
                      os.path.split(self.get_hklout())[-1]))

      self._xmlout = os.path.join(self.get_working_directory(),
                                  '%d_aimless.xml' % self.get_xpid())

      self.start()

      nproc = Flags.get_parallel()
      if nproc > 1:
        self.set_working_environment('OMP_NUM_THREADS', '%d' %nproc)
        self.input('refine parallel')
      self.input('xmlout %d_aimless.xml' % self.get_xpid())
      if not Flags.get_small_molecule():
        self.input('bins 20')
      self.input('intensities %s' %self._intensities)

      if self._new_scales_file:
        self.input('dump %s' % self._new_scales_file)

      run_number = 0
      for run in self._runs:
        run_number += 1

        if not run[5]:
          self.input('run %d batch %d to %d' % (run_number,
                                                run[0], run[1]))

        if run[6] != 0.0 and not run[5]:
          self.input('resolution run %d high %f' % \
                     (run_number, run[6]))

      run_number = 0
      for run in self._runs:
        run_number += 1

        if run[7]:
          Debug.write('Run %d corresponds to sweep %s' % \
                      (run_number, run[7]))

        if run[5]:
          continue

      self.input('sdcorrection same')

      # FIXME this is a bit of a hack - should be better determined
      # than this...
      if Flags.get_small_molecule():
        #self.input('sdcorrection tie sdfac 0.707 0.3 tie sdadd 0.01 0.05')
        #self.input('reject all 30')
        self.input('sdcorrection fixsdb')

      if self._secondary and self._surface_tie:
        self.input('tie surface %.4f' % self._surface_tie)
        if not self._surface_link:
          self.input('unlink all')

      # assemble the scales command
      if self._mode == 'rotation':
        scale_command = 'scales rotation spacing %f' % self._spacing

        if self._secondary:
          nterm = int(self._secondary)
          if self._fixed_secondary_lmax:
            scale_command += ' secondary %d %d absorption %d %d' % \
              (nterm, nterm - 1, nterm, nterm - 1)
          else:
            scale_command += ' secondary %d absorption %d' % \
              (nterm, nterm)

        if self._bfactor:
          scale_command += ' bfactor on'

          if self._brotation:
            scale_command += ' brotation %f' % \
                             self._brotation

        else:
          scale_command += ' bfactor off'

        if self._tails:
          scale_command += ' tails'

        self.input(scale_command)

      else:

        scale_command = 'scales batch'

        if self._bfactor:
          scale_command += ' bfactor on'

          if self._brotation:
            scale_command += ' brotation %f' % \
                             self._brotation
          else:
            scale_command += ' brotation %f' % \
                             self._spacing

        else:
          scale_command += ' bfactor off'

        if self._tails:
          scale_command += ' tails'

        self.input(scale_command)

      # Debug.write('Scaling command: "%s"' % scale_command)

      # next any 'generic' parameters

      if self._resolution:
        self.input('resolution %f' % self._resolution)

      if self._resolution_by_run != { }:
        # FIXME 20/NOV/06 this needs implementing somehow...
        pass

      self.input('cycles %d' % self._cycles)

      if self._anomalous:
        self.input('anomalous on')
      else:
        self.input('anomalous off')

      if self._scalepack:
        self.input('output polish unmerged')
      elif self._chef_unmerged:
        self.input('output unmerged together')
      else:
        self.input('output unmerged')

      # run using previously determined scales

      if self._scales_file:
        self.input('onlymerge')
        self.input('restore %s' % self._scales_file)

      self.close_wait()

      # check for errors

      if True:
        # try:
        try:
          self.check_for_errors()
          self.check_ccp4_errors()
          self.check_aimless_error_negative_scale_run()
          self.check_aimless_errors()
        except Exception, e:
          Chatter.write(
            "Aimless failed, see log file for more details:\n  %s" %self.get_log_file())
          raise

        status = 'OK'

        Debug.write('Aimless status: %s' % status)

        if 'Error' in status:
          raise RuntimeError, '[AIMLESS] %s' % status
Пример #10
0
    def run(self):
      from xia2.Handlers.Streams import Debug
      Debug.write('Running dials.integrate')

      self.clear_command_line()
      self.add_command_line('input.experiments=%s' % self._experiments_filename)
      nproc = Flags.get_parallel()
      self.set_cpu_threads(nproc)

      if self._use_threading:
        self.add_command_line('nthreads=%i' %nproc)
        nproc = 1

      self.add_command_line('nproc=%i' % nproc)
      self.add_command_line(('input.reflections=%s' % self._reflections_filename))
      self._integrated_reflections = os.path.join(
        self.get_working_directory(), '%d_integrated.pickle' %self.get_xpid())
      self._integrated_experiments = os.path.join(
        self.get_working_directory(), '%d_integrated_experiments.json' %self.get_xpid())
      self._integration_report_filename = os.path.join(
        self.get_working_directory(), '%d_integration_report.json' %self.get_xpid())
      self.add_command_line('output.experiments=%s' % self._integrated_experiments)
      self.add_command_line('output.reflections=%s' % self._integrated_reflections)
      self.add_command_line('output.report=%s' % self._integration_report_filename)
      self.add_command_line('output.include_bad_reference=True')
      self.add_command_line(
        'profile.fitting=%s' % self._profile_fitting)
      if self._outlier_algorithm is not None:
        self.add_command_line(
          'outlier.algorithm=%s' % self._outlier_algorithm)
      if self._background_algorithm is not None:
        self.add_command_line(
          'background.algorithm=%s' % self._background_algorithm)
      if self._phil_file is not None:
        self.add_command_line('%s' % self._phil_file)
      if self._d_max is not None:
        self.add_command_line('prediction.d_max=%f' % self._d_max)
      if self._d_min is not None and self._d_min > 0.0:
        self.add_command_line('prediction.d_min=%f' % self._d_min)
      for scan_range in self._scan_range:
        self.add_command_line('scan_range=%d,%d' %scan_range)
      if self._reflections_per_degree is not None:
        self.add_command_line('reflections_per_degree=%d' %self._reflections_per_degree)
        self.add_command_line('integrate_all_reflections=False')

      self.start()
      self.close_wait()

      for record in self.get_all_output():
        if 'There was a problem allocating memory for shoeboxes' in record:
          raise RuntimeError(
'''dials.integrate requires more memory than is available.
Try using a machine with more memory or using fewer processor.''')

      self.check_for_errors()

      # save some of the output for future reference - the per-image
      # results

      import json
      self._integration_report = json.load(
        open(self._integration_report_filename, 'rb'))

      import math

      self._per_image_statistics = {}
      table = self._integration_report['tables']['integration.image.summary']
      rows = table['rows']
      for row in table['rows']:
        n_ref = float(row['n_prf'])
        if n_ref > 0:
          ios = float(row['ios_prf'])
        else:
          ios = float(row['ios_sum'])
          n_ref = float(row['n_sum'])
        # XXX this +1 might need changing if James changes what is output in report.json
        self._per_image_statistics[int(row['image'])+1] = {
          'isigi': ios,
          'isig_tot': ios * math.sqrt(n_ref),
          'rmsd_pixel': float(row['rmsd_xy']),
          'strong': n_ref,
        }

      return