Exemplo n.º 1
0
def test_load_specific_sweeps_from_multi_xinfo():
  from xia2.Handlers.XInfo import XInfo
  import xia2
  xinfo_dir = os.path.join(xia2.__path__[0], 'Test', 'Handlers')

  xinfo = XInfo(os.path.join(xinfo_dir, 'multi.xinfo'),
                sweep_ids=['SWEEP1', 'swEEp4'])
  assert xinfo.get_crystals()['DEFAULT']['sweeps'] == {
  'SWEEP4': {'DIRECTORY': '/path/to/data/dir2', 'wavelength': 'NATIVE',
             'IMAGE': 'sweep_4_0001.cbf', 'start_end': [1, 900],
             'excluded_regions': []},
  'SWEEP1': {'DIRECTORY': '/path/to/data/dir1', 'wavelength': 'NATIVE',
             'IMAGE': 'sweep_1_0001.cbf', 'start_end': [1, 900],
             'excluded_regions': []}}
Exemplo n.º 2
0
def test_insulin_xinfo():
  from xia2.Handlers.XInfo import XInfo
  import xia2
  xinfo_dir = os.path.join(xia2.__path__[0], 'Test', 'Handlers')

  xinfo = XInfo(os.path.join(xinfo_dir, 'insulin.xinfo'))
  assert list(xinfo.get_crystals()) == ['DEFAULT']
  assert xinfo.get_crystals()['DEFAULT']['wavelengths'] == {
    'NATIVE': {'wavelength': 0.979}}
  assert xinfo.get_crystals()['DEFAULT']['sweeps'] == {
    'SWEEP1': {
      'excluded_regions': [], 'IMAGE': 'insulin_1_001.img',
      'beam': [94.34, 94.5], 'start_end': [1, 45],
      'DIRECTORY': '/path/to/build/xia2_regression/test_data/insulin',
      'wavelength': 'NATIVE'}}
Exemplo n.º 3
0
def run():
  from xia2.Handlers.XInfo import XInfo

  import libtbx.load_env
  xinfo_dir = os.path.join(libtbx.env.dist_path('xia2'), 'Test', 'Handlers')

  xinfo = XInfo(os.path.join(xinfo_dir, 'insulin.xinfo'))
  assert xinfo.get_crystals().keys() == ['DEFAULT']
  assert xinfo.get_crystals()['DEFAULT']['wavelengths'] == {
    'NATIVE': {'wavelength': 0.979}}
  assert xinfo.get_crystals()['DEFAULT']['sweeps'] ==  {
    'SWEEP1': {
      'excluded_regions': [], 'IMAGE': 'insulin_1_001.img',
      'beam': [94.34, 94.5], 'start_end': [1, 45],
      'DIRECTORY': '/path/to/build/xia2_regression/test_data/insulin',
      'wavelength': 'NATIVE'}}

  xinfo = XInfo(os.path.join(xinfo_dir, 'multi.xinfo'))
  assert xinfo.get_crystals().keys() == ['DEFAULT']
  assert xinfo.get_crystals()['DEFAULT']['wavelengths'] == {
    'NATIVE': {'wavelength': 1.77}}
  assert xinfo.get_crystals()['DEFAULT']['sweeps'] == {
    'SWEEP4': {'DIRECTORY': '/path/to/data/dir2', 'wavelength': 'NATIVE',
               'IMAGE': 'sweep_4_0001.cbf', 'start_end': [1, 900],
               'excluded_regions': []},
    'SWEEP2': {'DIRECTORY': '/path/to/data/dir1', 'wavelength': 'NATIVE',
               'IMAGE': 'sweep_2_0001.cbf', 'start_end': [1, 900],
               'excluded_regions': []},
    'SWEEP3': {'DIRECTORY': '/path/to/data/dir2', 'wavelength': 'NATIVE',
               'IMAGE': 'sweep_3_0001.cbf', 'start_end': [1, 900],
               'excluded_regions': []},
    'SWEEP1': {'DIRECTORY': '/path/to/data/dir1', 'wavelength': 'NATIVE',
               'IMAGE': 'sweep_1_0001.cbf', 'start_end': [1, 900],
               'excluded_regions': []}}

  xinfo = XInfo(os.path.join(xinfo_dir, 'multi.xinfo'),
                sweep_ids=['SWEEP1', 'swEEp4'])
  assert xinfo.get_crystals()['DEFAULT']['sweeps'] == {
  'SWEEP4': {'DIRECTORY': '/path/to/data/dir2', 'wavelength': 'NATIVE',
             'IMAGE': 'sweep_4_0001.cbf', 'start_end': [1, 900],
             'excluded_regions': []},
  'SWEEP1': {'DIRECTORY': '/path/to/data/dir1', 'wavelength': 'NATIVE',
             'IMAGE': 'sweep_1_0001.cbf', 'start_end': [1, 900],
             'excluded_regions': []}}
Exemplo n.º 4
0
def test_multi_xinfo():
    from xia2.Handlers.XInfo import XInfo
    import xia2

    xinfo_dir = os.path.join(xia2.__path__[0], "Test", "Handlers")

    xinfo = XInfo(os.path.join(xinfo_dir, "multi.xinfo"))
    assert list(xinfo.get_crystals()) == ["DEFAULT"]
    assert xinfo.get_crystals()["DEFAULT"]["wavelengths"] == {
        "NATIVE": {
            "wavelength": 1.77
        }
    }
    assert xinfo.get_crystals()["DEFAULT"]["sweeps"] == {
        "SWEEP4": {
            "DIRECTORY": "/path/to/data/dir2",
            "wavelength": "NATIVE",
            "IMAGE": "sweep_4_0001.cbf",
            "start_end": [1, 900],
            "excluded_regions": [],
        },
        "SWEEP2": {
            "DIRECTORY": "/path/to/data/dir1",
            "wavelength": "NATIVE",
            "IMAGE": "sweep_2_0001.cbf",
            "start_end": [1, 900],
            "excluded_regions": [],
        },
        "SWEEP3": {
            "DIRECTORY": "/path/to/data/dir2",
            "wavelength": "NATIVE",
            "IMAGE": "sweep_3_0001.cbf",
            "start_end": [1, 900],
            "excluded_regions": [],
        },
        "SWEEP1": {
            "DIRECTORY": "/path/to/data/dir1",
            "wavelength": "NATIVE",
            "IMAGE": "sweep_1_0001.cbf",
            "start_end": [1, 900],
            "excluded_regions": [],
        },
    }
Exemplo n.º 5
0
def test_write_xinfo_template_missing_images(insulin_with_missing_image,
                                             run_in_tmpdir):
    result = procrunner.run(
        [
            "xia2.setup",
            f"image={insulin_with_missing_image.parent.joinpath('insulin_1_001.img:1:22')}",
            "read_all_image_headers=False",
        ],
        environment_override={"CCP4": run_in_tmpdir},
    )
    assert not result.returncode
    assert not result.stderr
    xinfo = run_in_tmpdir.join("automatic.xinfo")
    assert xinfo.check(file=1)
    x = XInfo(xinfo)
    assert len(x.get_crystals()["DEFAULT"]["sweeps"]) == 1
    assert x.get_crystals()["DEFAULT"]["sweeps"]["SWEEP1"]["start_end"] == [
        1, 22
    ]
Exemplo n.º 6
0
def test_multi_xinfo():
    from xia2.Handlers.XInfo import XInfo
    import xia2
    xinfo_dir = os.path.join(xia2.__path__[0], 'Test', 'Handlers')

    xinfo = XInfo(os.path.join(xinfo_dir, 'multi.xinfo'))
    assert xinfo.get_crystals().keys() == ['DEFAULT']
    assert xinfo.get_crystals()['DEFAULT']['wavelengths'] == {
        'NATIVE': {
            'wavelength': 1.77
        }
    }
    assert xinfo.get_crystals()['DEFAULT']['sweeps'] == {
        'SWEEP4': {
            'DIRECTORY': '/path/to/data/dir2',
            'wavelength': 'NATIVE',
            'IMAGE': 'sweep_4_0001.cbf',
            'start_end': [1, 900],
            'excluded_regions': []
        },
        'SWEEP2': {
            'DIRECTORY': '/path/to/data/dir1',
            'wavelength': 'NATIVE',
            'IMAGE': 'sweep_2_0001.cbf',
            'start_end': [1, 900],
            'excluded_regions': []
        },
        'SWEEP3': {
            'DIRECTORY': '/path/to/data/dir2',
            'wavelength': 'NATIVE',
            'IMAGE': 'sweep_3_0001.cbf',
            'start_end': [1, 900],
            'excluded_regions': []
        },
        'SWEEP1': {
            'DIRECTORY': '/path/to/data/dir1',
            'wavelength': 'NATIVE',
            'IMAGE': 'sweep_1_0001.cbf',
            'start_end': [1, 900],
            'excluded_regions': []
        }
    }
Exemplo n.º 7
0
def test_insulin_xinfo():
    xinfo_dir = os.path.join(xia2.__path__[0], "Test", "Handlers")

    xinfo = XInfo(os.path.join(xinfo_dir, "insulin.xinfo"))
    assert list(xinfo.get_crystals()) == ["DEFAULT"]
    assert xinfo.get_crystals()["DEFAULT"]["wavelengths"] == {
        "NATIVE": {
            "wavelength": 0.979
        }
    }
    assert xinfo.get_crystals()["DEFAULT"]["sweeps"] == {
        "SWEEP1": {
            "excluded_regions": [],
            "IMAGE": "insulin_1_001.img",
            "beam": [94.34, 94.5],
            "start_end": [1, 45],
            "DIRECTORY": "/path/to/build/regression_data/insulin",
            "wavelength": "NATIVE",
        }
    }
Exemplo n.º 8
0
def test_load_specific_sweeps_from_multi_xinfo():
    xinfo_dir = os.path.join(xia2.__path__[0], "Test", "Handlers")

    xinfo = XInfo(os.path.join(xinfo_dir, "multi.xinfo"),
                  sweep_ids=["SWEEP1", "swEEp4"])
    assert xinfo.get_crystals()["DEFAULT"]["sweeps"] == {
        "SWEEP4": {
            "DIRECTORY": "/path/to/data/dir2",
            "wavelength": "NATIVE",
            "IMAGE": "sweep_4_0001.cbf",
            "start_end": [1, 900],
            "excluded_regions": [],
        },
        "SWEEP1": {
            "DIRECTORY": "/path/to/data/dir1",
            "wavelength": "NATIVE",
            "IMAGE": "sweep_1_0001.cbf",
            "start_end": [1, 900],
            "excluded_regions": [],
        },
    }
Exemplo n.º 9
0
def test_write_xinfo_unroll(dials_data, tmpdir):
    # This test partially exercises the fix to https://github.com/xia2/xia2/issues/498 with a different syntax
    result = procrunner.run(
        [
            "xia2.setup",
            f"image={dials_data('insulin').join('insulin_1_001.img:1:45:15')}",
            "read_all_image_headers=False",
        ],
        working_directory=tmpdir,
        environment_override={"CCP4": tmpdir},
    )
    assert not result.returncode
    assert not result.stderr
    xinfo = tmpdir.join("automatic.xinfo")
    assert xinfo.check(file=1)
    x = XInfo(xinfo)
    assert len(x.get_crystals()["DEFAULT"]["sweeps"]) == 3
    assert x.get_crystals()["DEFAULT"]["sweeps"]["SWEEP1"]["start_end"] == [
        1, 15
    ]
    assert x.get_crystals()["DEFAULT"]["sweeps"]["SWEEP2"]["start_end"] == [
        16, 30
    ]
    assert x.get_crystals()["DEFAULT"]["sweeps"]["SWEEP3"]["start_end"] == [
        31, 45
    ]
Exemplo n.º 10
0
def test_write_xinfo_split_sweep(dials_data, tmpdir):
    result = procrunner.run(
        [
            "xia2.setup",
            f"image={dials_data('insulin').join('insulin_1_001.img:1:22')}",
            f"image={dials_data('insulin').join('insulin_1_001.img:23:45')}",
            "read_all_image_headers=False",
        ],
        working_directory=tmpdir,
        environment_override={"CCP4": tmpdir},
    )
    assert not result.returncode
    assert not result.stderr
    xinfo = tmpdir.join("automatic.xinfo")
    assert xinfo.check(file=1)
    x = XInfo(xinfo)
    assert len(x.get_crystals()["DEFAULT"]["sweeps"]) == 2
    assert x.get_crystals()["DEFAULT"]["sweeps"]["SWEEP1"]["start_end"] == [
        1, 22
    ]
    assert x.get_crystals()["DEFAULT"]["sweeps"]["SWEEP2"]["start_end"] == [
        23, 45
    ]
Exemplo n.º 11
0
  def setup_from_xinfo_file(self, xinfo_file):
    '''Set up this object & all subobjects based on the .xinfo
    file contents.'''

    settings = PhilIndex.params.xia2.settings

    sweep_ids = [sweep.id for sweep in settings.sweep]
    sweep_ranges = [sweep.range for sweep in settings.sweep]

    if not sweep_ids:
      sweep_ids = None
      sweep_ranges = None

    xinfo = XInfo(xinfo_file, sweep_ids=sweep_ids, sweep_ranges=sweep_ranges)

    self._name = xinfo.get_project()
    crystals = xinfo.get_crystals()

    for crystal in crystals.keys():
      xc = XCrystal(crystal, self)
      if 'sequence' in crystals[crystal]:
        xc.set_aa_sequence(crystals[crystal]['sequence'])
      if 'ha_info' in crystals[crystal]:
        if crystals[crystal]['ha_info'] != { }:
          xc.set_ha_info(crystals[crystal]['ha_info'])

      if 'scaled_merged_reflection_file' in crystals[crystal]:
        xc.set_scaled_merged_reflections(
          crystals[crystal]['scaled_merged_reflections'])

      if 'reference_reflection_file' in crystals[crystal]:
        xc.set_reference_reflection_file(
          crystals[crystal]['reference_reflection_file'])
      if 'freer_file' in crystals[crystal]:
        xc.set_freer_file(crystals[crystal]['freer_file'])

      # user assigned spacegroup
      if 'user_spacegroup' in crystals[crystal]:
        xc.set_user_spacegroup(crystals[crystal]['user_spacegroup'])
      elif settings.space_group is not None:
        # XXX do we ever actually get here?
        xc.set_user_spacegroup(settings.space_group.type().lookup_symbol())

      # add a default sample if none present in xinfo file
      if not crystals[crystal]['samples']:
        crystals[crystal]['samples']['X1'] = {}

      for sample in crystals[crystal]['samples'].keys():
        sample_info = crystals[crystal]['samples'][sample]

        xsample = XSample(sample, xc)
        xc.add_sample(xsample)

      if not crystals[crystal]['wavelengths']:
        raise RuntimeError('No wavelengths specified in xinfo file')

      for wavelength in crystals[crystal]['wavelengths'].keys():
        # FIXME 29/NOV/06 in here need to be able to cope with
        # no wavelength information - this should default to the
        # information in the image header (John Cowan pointed
        # out that this was untidy - requiring that it agrees
        # with the value in the header makes this almost
        # useless.)

        wave_info = crystals[crystal]['wavelengths'][wavelength]

        if 'wavelength' not in wave_info:
          Debug.write(
            'No wavelength value given for wavelength %s' % wavelength)
        else:
          Debug.write(
            'Overriding value for wavelength %s to %8.6f' % \
              (wavelength, float(wave_info['wavelength'])))

        # handle case where user writes f" in place of f''

        if 'f"' in wave_info and not \
              'f\'\'' in wave_info:
          wave_info['f\'\''] = wave_info['f"']

        xw = XWavelength(wavelength, xc,
                         wavelength = wave_info.get('wavelength', 0.0),
                         f_pr = wave_info.get('f\'', 0.0),
                         f_prpr = wave_info.get('f\'\'', 0.0),
                         dmin = wave_info.get('dmin', 0.0),
                         dmax = wave_info.get('dmax', 0.0))

        # in here I also need to look and see if we have
        # been given any scaled reflection files...

        # check to see if we have a user supplied lattice...
        if 'user_spacegroup' in crystals[crystal]:
          lattice = Syminfo.get_lattice(
            crystals[crystal]['user_spacegroup'])
        elif settings.space_group is not None:
          # XXX do we ever actually get here?
          lattice = Syminfo.get_lattice(
            settings.space_group.type().lookup_symbol())
        else:
          lattice = None

        # and also user supplied cell constants - from either
        # the xinfo file (the first port of call) or the
        # command-line.

        if 'user_cell' in crystals[crystal]:
          cell = crystals[crystal]['user_cell']
        elif settings.unit_cell is not None:
          # XXX do we ever actually get here?
          cell = settings.unit_cell.parameters()
        else:
          cell = None

        dmin = wave_info.get('dmin', 0.0)
        dmax = wave_info.get('dmax', 0.0)

        if dmin == 0.0 and dmax == 0.0:
          dmin = PhilIndex.params.xia2.settings.resolution.d_min
          dmax = PhilIndex.params.xia2.settings.resolution.d_max

        # want to be able to locally override the resolution limits
        # for this sweep while leaving the rest for the data set
        # intact...

        for sweep_name in crystals[crystal]['sweeps'].keys():
          sweep_info = crystals[crystal]['sweeps'][sweep_name]

          sample_name = sweep_info.get('sample')
          if sample_name is None:
            if len(crystals[crystal]['samples']) == 1:
              sample_name = crystals[crystal]['samples'].keys()[0]
            else:
              raise RuntimeError('No sample given for sweep %s' %sweep_name)

          xsample = xc.get_xsample(sample_name)
          assert xsample is not None

          dmin_old = dmin
          dmax_old = dmax
          replace = False

          if 'RESOLUTION' in sweep_info:

            values = map(float, sweep_info['RESOLUTION'].split())
            if len(values) == 1:
              dmin = values[0]
            elif len(values) == 2:
              dmin = min(values)
              dmax = max(values)
            else:
              raise RuntimeError, \
                  'bad resolution for sweep %s' % sweep_name

            replace = True

          # FIXME: AJP to implement
          # FIXME ticket number here please
          if 'ice' in sweep_info:
            pass
          if 'excluded_regions' in sweep_info:
            pass

          if sweep_info['wavelength'] == wavelength:

            frames_to_process = sweep_info.get('start_end')

            xsweep = xw.add_sweep(
              sweep_name,
              sample=xsample,
              directory = sweep_info.get('DIRECTORY'),
              image = sweep_info.get('IMAGE'),
              beam = sweep_info.get('beam'),
              reversephi = sweep_info.get('reversephi', False),
              distance = sweep_info.get('distance'),
              gain = float(sweep_info.get('GAIN', 0.0)),
              dmin = dmin, dmax = dmax,
              polarization = float(sweep_info.get(
                  'POLARIZATION', 0.0)),
              frames_to_process = frames_to_process,
              user_lattice = lattice,
              user_cell = cell,
              epoch = sweep_info.get('epoch', 0),
              ice = sweep_info.get('ice', False),
              excluded_regions = sweep_info.get(
                'excluded_regions', []),
              )

            xsample.add_sweep(xsweep)

          dmin = dmin_old
          dmax = dmax_old

        xc.add_wavelength(xw)

      self.add_crystal(xc)

    return
Exemplo n.º 12
0
    def _setup_from_xinfo_file(self, xinfo_file):
        """Set up this object & all subobjects based on the .xinfo
        file contents."""

        settings = PhilIndex.params.xia2.settings

        sweep_ids = [sweep.id for sweep in settings.sweep]
        sweep_ranges = [sweep.range for sweep in settings.sweep]

        if not sweep_ids:
            sweep_ids = None
            sweep_ranges = None

        xinfo = XInfo(xinfo_file,
                      sweep_ids=sweep_ids,
                      sweep_ranges=sweep_ranges)

        self._name = xinfo.get_project()
        crystals = xinfo.get_crystals()

        for crystal in crystals:
            xc = XCrystal(crystal, self)
            if "sequence" in crystals[crystal]:
                xc.set_aa_sequence(crystals[crystal]["sequence"])
            if "ha_info" in crystals[crystal]:
                if crystals[crystal]["ha_info"] != {}:
                    xc.set_ha_info(crystals[crystal]["ha_info"])

            if "scaled_merged_reflection_file" in crystals[crystal]:
                xc.set_scaled_merged_reflections(
                    crystals[crystal]["scaled_merged_reflections"])

            if "reference_reflection_file" in crystals[crystal]:
                xc.set_reference_reflection_file(
                    crystals[crystal]["reference_reflection_file"])
            if "freer_file" in crystals[crystal]:
                xc.set_freer_file(crystals[crystal]["freer_file"])

            # user assigned spacegroup
            if "user_spacegroup" in crystals[crystal]:
                xc.set_user_spacegroup(crystals[crystal]["user_spacegroup"])
            elif settings.space_group is not None:
                # XXX do we ever actually get here?
                xc.set_user_spacegroup(
                    settings.space_group.type().lookup_symbol())

            # add a default sample if none present in xinfo file
            if not crystals[crystal]["samples"]:
                crystals[crystal]["samples"]["X1"] = {}

            for sample in crystals[crystal]["samples"]:
                xsample = XSample(sample, xc)
                xc.add_sample(xsample)

            if not crystals[crystal]["wavelengths"]:
                raise RuntimeError("No wavelengths specified in xinfo file")

            for wavelength, wave_info in crystals[crystal][
                    "wavelengths"].items():
                # FIXME 29/NOV/06 in here need to be able to cope with
                # no wavelength information - this should default to the
                # information in the image header (John Cowan pointed
                # out that this was untidy - requiring that it agrees
                # with the value in the header makes this almost
                # useless.)

                if "wavelength" not in wave_info:
                    logger.debug("No wavelength value given for wavelength %s",
                                 wavelength)
                else:
                    logger.debug(
                        "Overriding value for wavelength %s to %8.6f",
                        wavelength,
                        float(wave_info["wavelength"]),
                    )

                # handle case where user writes f" in place of f''

                if 'f"' in wave_info and "f''" not in wave_info:
                    wave_info["f''"] = wave_info['f"']

                xw = XWavelength(
                    wavelength,
                    xc,
                    wavelength=wave_info.get("wavelength", 0.0),
                    f_pr=wave_info.get("f'", 0.0),
                    f_prpr=wave_info.get("f''", 0.0),
                    dmin=wave_info.get("dmin", 0.0),
                    dmax=wave_info.get("dmax", 0.0),
                )

                # in here I also need to look and see if we have
                # been given any scaled reflection files...

                # check to see if we have a user supplied lattice...
                if "user_spacegroup" in crystals[crystal]:
                    lattice = Syminfo.get_lattice(
                        crystals[crystal]["user_spacegroup"])
                elif settings.space_group is not None:
                    # XXX do we ever actually get here?
                    lattice = Syminfo.get_lattice(
                        settings.space_group.type().lookup_symbol())
                else:
                    lattice = None

                # and also user supplied cell constants - from either
                # the xinfo file (the first port of call) or the
                # command-line.

                if "user_cell" in crystals[crystal]:
                    cell = crystals[crystal]["user_cell"]
                elif settings.unit_cell is not None:
                    # XXX do we ever actually get here?
                    cell = settings.unit_cell.parameters()
                else:
                    cell = None

                dmin = wave_info.get("dmin", 0.0)
                dmax = wave_info.get("dmax", 0.0)

                if dmin == 0.0 and dmax == 0.0:
                    dmin = PhilIndex.params.xia2.settings.resolution.d_min
                    dmax = PhilIndex.params.xia2.settings.resolution.d_max

                # want to be able to locally override the resolution limits
                # for this sweep while leaving the rest for the data set
                # intact...

                for sweep_name, sweep_info in crystals[crystal][
                        "sweeps"].items():
                    sample_name = sweep_info.get("sample")
                    if sample_name is None:
                        if len(crystals[crystal]["samples"]) == 1:
                            sample_name = list(crystals[crystal]["samples"])[0]
                        else:
                            raise RuntimeError("No sample given for sweep %s" %
                                               sweep_name)

                    xsample = xc.get_xsample(sample_name)
                    assert xsample is not None

                    dmin_old = dmin
                    dmax_old = dmax

                    if "RESOLUTION" in sweep_info:
                        values = [
                            float(x) for x in sweep_info["RESOLUTION"].split()
                        ]
                        if len(values) == 1:
                            dmin = values[0]
                        elif len(values) == 2:
                            dmin = min(values)
                            dmax = max(values)
                        else:
                            raise RuntimeError("bad resolution for sweep %s" %
                                               sweep_name)

                    if sweep_info["wavelength"] == wavelength:
                        frames_to_process = sweep_info.get("start_end")

                        xsweep = xw.add_sweep(
                            sweep_name,
                            sample=xsample,
                            directory=sweep_info.get("DIRECTORY"),
                            image=sweep_info.get("IMAGE"),
                            beam=sweep_info.get("beam"),
                            reversephi=sweep_info.get("reversephi", False),
                            distance=sweep_info.get("distance"),
                            gain=float(sweep_info.get("GAIN", 0.0)),
                            dmin=dmin,
                            dmax=dmax,
                            polarization=float(
                                sweep_info.get("POLARIZATION", 0.0)),
                            frames_to_process=frames_to_process,
                            user_lattice=lattice,
                            user_cell=cell,
                            epoch=sweep_info.get("epoch", 0),
                            ice=sweep_info.get("ice", False),
                            excluded_regions=sweep_info.get(
                                "excluded_regions", []),
                        )

                        xsample.add_sweep(xsweep)

                    dmin = dmin_old
                    dmax = dmax_old

                xc.add_wavelength(xw)

            self.add_crystal(xc)
Exemplo n.º 13
0
    def setup_from_xinfo_file(self, xinfo_file):
        '''Set up this object & all subobjects based on the .xinfo
    file contents.'''

        settings = PhilIndex.params.xia2.settings

        sweep_ids = [sweep.id for sweep in settings.sweep]
        sweep_ranges = [sweep.range for sweep in settings.sweep]

        if not sweep_ids:
            sweep_ids = None
            sweep_ranges = None

        xinfo = XInfo(xinfo_file,
                      sweep_ids=sweep_ids,
                      sweep_ranges=sweep_ranges)

        self._name = xinfo.get_project()
        crystals = xinfo.get_crystals()

        for crystal in crystals.keys():
            xc = XCrystal(crystal, self)
            if 'sequence' in crystals[crystal]:
                xc.set_aa_sequence(crystals[crystal]['sequence'])
            if 'ha_info' in crystals[crystal]:
                if crystals[crystal]['ha_info'] != {}:
                    xc.set_ha_info(crystals[crystal]['ha_info'])

            if 'scaled_merged_reflection_file' in crystals[crystal]:
                xc.set_scaled_merged_reflections(
                    crystals[crystal]['scaled_merged_reflections'])

            if 'reference_reflection_file' in crystals[crystal]:
                xc.set_reference_reflection_file(
                    crystals[crystal]['reference_reflection_file'])
            if 'freer_file' in crystals[crystal]:
                xc.set_freer_file(crystals[crystal]['freer_file'])

            # user assigned spacegroup
            if 'user_spacegroup' in crystals[crystal]:
                xc.set_user_spacegroup(crystals[crystal]['user_spacegroup'])
            elif settings.space_group is not None:
                # XXX do we ever actually get here?
                xc.set_user_spacegroup(
                    settings.space_group.type().lookup_symbol())

            # add a default sample if none present in xinfo file
            if not crystals[crystal]['samples']:
                crystals[crystal]['samples']['X1'] = {}

            for sample in crystals[crystal]['samples'].keys():
                sample_info = crystals[crystal]['samples'][sample]

                xsample = XSample(sample, xc)
                xc.add_sample(xsample)

            if not crystals[crystal]['wavelengths']:
                raise RuntimeError('No wavelengths specified in xinfo file')

            for wavelength in crystals[crystal]['wavelengths'].keys():
                # FIXME 29/NOV/06 in here need to be able to cope with
                # no wavelength information - this should default to the
                # information in the image header (John Cowan pointed
                # out that this was untidy - requiring that it agrees
                # with the value in the header makes this almost
                # useless.)

                wave_info = crystals[crystal]['wavelengths'][wavelength]

                if 'wavelength' not in wave_info:
                    Debug.write('No wavelength value given for wavelength %s' %
                                wavelength)
                else:
                    Debug.write(
                      'Overriding value for wavelength %s to %8.6f' % \
                        (wavelength, float(wave_info['wavelength'])))

                # handle case where user writes f" in place of f''

                if 'f"' in wave_info and not \
                      'f\'\'' in wave_info:
                    wave_info['f\'\''] = wave_info['f"']

                xw = XWavelength(wavelength,
                                 xc,
                                 wavelength=wave_info.get('wavelength', 0.0),
                                 f_pr=wave_info.get('f\'', 0.0),
                                 f_prpr=wave_info.get('f\'\'', 0.0),
                                 dmin=wave_info.get('dmin', 0.0),
                                 dmax=wave_info.get('dmax', 0.0))

                # in here I also need to look and see if we have
                # been given any scaled reflection files...

                # check to see if we have a user supplied lattice...
                if 'user_spacegroup' in crystals[crystal]:
                    lattice = Syminfo.get_lattice(
                        crystals[crystal]['user_spacegroup'])
                elif settings.space_group is not None:
                    # XXX do we ever actually get here?
                    lattice = Syminfo.get_lattice(
                        settings.space_group.type().lookup_symbol())
                else:
                    lattice = None

                # and also user supplied cell constants - from either
                # the xinfo file (the first port of call) or the
                # command-line.

                if 'user_cell' in crystals[crystal]:
                    cell = crystals[crystal]['user_cell']
                elif settings.unit_cell is not None:
                    # XXX do we ever actually get here?
                    cell = settings.unit_cell.parameters()
                else:
                    cell = None

                dmin = wave_info.get('dmin', 0.0)
                dmax = wave_info.get('dmax', 0.0)

                if dmin == 0.0 and dmax == 0.0:
                    dmin = PhilIndex.params.xia2.settings.resolution.d_min
                    dmax = PhilIndex.params.xia2.settings.resolution.d_max

                # want to be able to locally override the resolution limits
                # for this sweep while leaving the rest for the data set
                # intact...

                for sweep_name in crystals[crystal]['sweeps'].keys():
                    sweep_info = crystals[crystal]['sweeps'][sweep_name]

                    sample_name = sweep_info.get('sample')
                    if sample_name is None:
                        if len(crystals[crystal]['samples']) == 1:
                            sample_name = crystals[crystal]['samples'].keys(
                            )[0]
                        else:
                            raise RuntimeError('No sample given for sweep %s' %
                                               sweep_name)

                    xsample = xc.get_xsample(sample_name)
                    assert xsample is not None

                    dmin_old = dmin
                    dmax_old = dmax
                    replace = False

                    if 'RESOLUTION' in sweep_info:

                        values = map(float, sweep_info['RESOLUTION'].split())
                        if len(values) == 1:
                            dmin = values[0]
                        elif len(values) == 2:
                            dmin = min(values)
                            dmax = max(values)
                        else:
                            raise RuntimeError('bad resolution for sweep %s' %
                                               sweep_name)

                        replace = True

                    if sweep_info['wavelength'] == wavelength:

                        frames_to_process = sweep_info.get('start_end')

                        xsweep = xw.add_sweep(
                            sweep_name,
                            sample=xsample,
                            directory=sweep_info.get('DIRECTORY'),
                            image=sweep_info.get('IMAGE'),
                            beam=sweep_info.get('beam'),
                            reversephi=sweep_info.get('reversephi', False),
                            distance=sweep_info.get('distance'),
                            gain=float(sweep_info.get('GAIN', 0.0)),
                            dmin=dmin,
                            dmax=dmax,
                            polarization=float(
                                sweep_info.get('POLARIZATION', 0.0)),
                            frames_to_process=frames_to_process,
                            user_lattice=lattice,
                            user_cell=cell,
                            epoch=sweep_info.get('epoch', 0),
                            ice=sweep_info.get('ice', False),
                            excluded_regions=sweep_info.get(
                                'excluded_regions', []),
                        )

                        xsample.add_sweep(xsweep)

                    dmin = dmin_old
                    dmax = dmax_old

                xc.add_wavelength(xw)

            self.add_crystal(xc)