Пример #1
0
Файл: Cad.py Проект: hainm/xia2
    def copyfree(self):
      '''Copy the free column from freein into hklin -> hklout.'''

      if not self._hklin_files:
        raise RuntimeError, 'no hklin files defined'

      if len(self._hklin_files) > 1:
        raise RuntimeError, 'can have only one hklin to update'

      hklin = self._hklin_files[0]

      # get the resolution limit to give as a limit for the FreeR
      # column

      md = Mtzdump()
      md.set_working_directory(self.get_working_directory())
      md.set_hklin(hklin)
      md.dump()
      resolution_range = md.get_resolution_range()

      self.check_hklout()
      if self._freein is None:
        raise RuntimeError, 'freein not defined'
      if self._freein_column is None:
        raise RuntimeError, 'freein column not defined'

      self.add_command_line('hklin1')
      self.add_command_line(self._freein)
      self.add_command_line('hklin2')
      self.add_command_line(hklin)
      self.start()

      self.input('labin file_number 1 E1=%s' % self._freein_column)
      self.input('resolution file_number 1 %f %f' % resolution_range)
      self.input('labin file_number 2 all')

      self.close_wait()

      try:
        self.check_for_errors()
        self.check_ccp4_errors()

      except RuntimeError, e:
        # something went wrong; remove the output file
        try:
          os.remove(self.get_hklout())
        except:
          pass
        raise e
Пример #2
0
Файл: Cad.py Проект: hainm/xia2
    def merge(self):
      '''Merge multiple reflection files into one file.'''

      if not self._hklin_files:
        raise RuntimeError, 'no hklin files defined'

      self.check_hklout()

      hklin_counter = 0

      # for each reflection file, need to gather the column names
      # and so on, to put in the cad input here - also check to see
      # if the column names clash... check also that the spacegroups
      # match up...

      spacegroup = None
      column_names = []
      column_names_by_file = { }

      for hklin in self._hklin_files:
        md = Mtzdump()
        md.set_working_directory(self.get_working_directory())
        md.set_hklin(hklin)
        md.dump()
        columns = md.get_columns()
        spag = md.get_spacegroup()

        if spacegroup is None:
          spacegroup = spag

        if spag != spacegroup:
          raise RuntimeError, 'spacegroups do not match'

        column_names_by_file[hklin] = []

        for c in columns:
          name = c[0]
          if name in ['H', 'K', 'L']:
            continue
          if name in column_names:
            raise RuntimeError, 'duplicate column names'
          column_names.append(name)
          column_names_by_file[hklin].append(name)

      # if we get to here then this is a good set up...

      # create the command line

      hklin_counter = 0
      for hklin in self._hklin_files:
        hklin_counter += 1
        self.add_command_line('hklin%d' % hklin_counter)
        self.add_command_line(hklin)

      self.start()

      hklin_counter = 0

      for hklin in self._hklin_files:
        column_counter = 0
        hklin_counter += 1
        labin_command = 'labin file_number %d' % hklin_counter
        for column in column_names_by_file[hklin]:
          column_counter += 1
          labin_command += ' E%d=%s' % (column_counter, column)

        self.input(labin_command)

      self.close_wait()

      try:
        self.check_for_errors()
        self.check_ccp4_errors()

      except RuntimeError, e:
        # something went wrong; remove the output file
        try:
          os.remove(self.get_hklout())
        except:
          pass
        raise e