示例#1
0
def test_mosflm_indexer(regression_test, ccp4, dials_data, run_in_tmpdir):
    template = dials_data("insulin").join("insulin_1_###.img").strpath

    from xia2.Modules.Indexer.MosflmIndexer import MosflmIndexer

    indexer = MosflmIndexer()
    indexer.set_working_directory(run_in_tmpdir.strpath)
    from dxtbx.model.experiment_list import ExperimentListTemplateImporter

    importer = ExperimentListTemplateImporter([template])
    experiments = importer.experiments
    imageset = experiments.imagesets()[0]
    indexer.add_indexer_imageset(imageset)

    with mock.patch.object(
            sys, "argv",
        []):  # otherwise indexing fails when running pytest with '--runslow'
        indexer.index()

    assert indexer.get_indexer_cell() == pytest.approx(
        (78.6657, 78.6657, 78.6657, 90.0, 90.0, 90.0), abs=1e-3)
    experiment = indexer.get_indexer_experiment_list()[0]
    sgi = experiment.crystal.get_space_group().info()
    assert sgi.type().number() == 197

    beam_centre = indexer.get_indexer_beam_centre()
    assert beam_centre == pytest.approx((94.34, 94.57), abs=1e-2)
    assert indexer.get_indexer_images() == [(1, 1), (22, 22), (45, 45)]
    print(indexer.get_indexer_experiment_list()[0].crystal)
    print(indexer.get_indexer_experiment_list()[0].detector)

    # test serialization of indexer
    json_str = indexer.as_json()
    print(json_str)
    indexer2 = MosflmIndexer.from_json(string=json_str)
    indexer2.index()

    assert indexer.get_indexer_cell() == pytest.approx(
        indexer2.get_indexer_cell(), abs=1e-6)
    assert indexer.get_indexer_beam_centre() == pytest.approx(
        indexer2.get_indexer_beam_centre(), abs=1e-6)
    assert indexer2.get_indexer_images() == [
        [1, 1],
        [22, 22],
        [45, 45],
    ]  # coming from json these are now lists

    indexer.eliminate()
    indexer2.eliminate()

    assert indexer.get_indexer_cell() == pytest.approx(
        indexer2.get_indexer_cell(), abs=1e-6)
    assert indexer.get_indexer_lattice() == "hR"
    assert indexer2.get_indexer_lattice() == "hR"
示例#2
0
def exercise_mosflm_indexer():
  if not have_dials_regression:
    print "Skipping exercise_mosflm_indexer(): dials_regression not configured"
    return

  xia2_demo_data = os.path.join(dials_regression, "xia2_demo_data")
  template = os.path.join(xia2_demo_data, "insulin_1_###.img")

  cwd = os.path.abspath(os.curdir)
  tmp_dir = os.path.abspath(open_tmp_directory())
  os.chdir(tmp_dir)

  from xia2.Modules.Indexer.MosflmIndexer import MosflmIndexer
  indexer = MosflmIndexer()
  indexer.set_working_directory(tmp_dir)
  from dxtbx.datablock import DataBlockTemplateImporter
  importer = DataBlockTemplateImporter([template])
  datablocks = importer.datablocks
  imageset = datablocks[0].extract_imagesets()[0]
  indexer.add_indexer_imageset(imageset)

  indexer.index()

  assert approx_equal(indexer.get_indexer_cell(),
                      (78.6657, 78.6657, 78.6657, 90.0, 90.0, 90.0), eps=1e-3)
  experiment = indexer.get_indexer_experiment_list()[0]
  sgi = experiment.crystal.get_space_group().info()
  assert sgi.type().number() == 197

  beam_centre = indexer.get_indexer_beam_centre()
  assert approx_equal(beam_centre, (94.34, 94.57), eps=1e-2)
  assert indexer.get_indexer_images() == [(1, 1), (22, 22), (45, 45)]
  print indexer.get_indexer_experiment_list()[0].crystal
  print indexer.get_indexer_experiment_list()[0].detector

  # test serialization of indexer
  json_str = indexer.as_json()
  print json_str
  indexer2 = MosflmIndexer.from_json(string=json_str)
  indexer2.index()

  assert approx_equal(indexer.get_indexer_cell(), indexer2.get_indexer_cell())
  assert approx_equal(
    indexer.get_indexer_beam_centre(), indexer2.get_indexer_beam_centre())
  assert approx_equal(
    indexer.get_indexer_images(), indexer2.get_indexer_images())

  indexer.eliminate()
  indexer2.eliminate()

  assert approx_equal(indexer.get_indexer_cell(), indexer2.get_indexer_cell())
  assert indexer.get_indexer_lattice() == 'hR'
  assert indexer2.get_indexer_lattice() == 'hR'
示例#3
0
def test_mosflm_indexer(ccp4, xia2_regression_build, tmpdir):
    template = os.path.join(xia2_regression_build, "test_data", "insulin",
                            "insulin_1_###.img")
    tmpdir.chdir()

    from xia2.Modules.Indexer.MosflmIndexer import MosflmIndexer
    indexer = MosflmIndexer()
    indexer.set_working_directory(tmpdir.strpath)
    from dxtbx.datablock import DataBlockTemplateImporter
    importer = DataBlockTemplateImporter([template])
    datablocks = importer.datablocks
    imageset = datablocks[0].extract_imagesets()[0]
    indexer.add_indexer_imageset(imageset)

    with mock.patch.object(
            sys, 'argv',
        []):  # otherwise indexing fails when running pytest with '--runslow'
        indexer.index()

    assert indexer.get_indexer_cell() == pytest.approx(
        (78.6657, 78.6657, 78.6657, 90.0, 90.0, 90.0), abs=1e-3)
    experiment = indexer.get_indexer_experiment_list()[0]
    sgi = experiment.crystal.get_space_group().info()
    assert sgi.type().number() == 197

    beam_centre = indexer.get_indexer_beam_centre()
    assert beam_centre == pytest.approx((94.34, 94.57), abs=1e-2)
    assert indexer.get_indexer_images() == [(1, 1), (22, 22), (45, 45)]
    print(indexer.get_indexer_experiment_list()[0].crystal)
    print(indexer.get_indexer_experiment_list()[0].detector)

    # test serialization of indexer
    json_str = indexer.as_json()
    print(json_str)
    indexer2 = MosflmIndexer.from_json(string=json_str)
    indexer2.index()

    assert indexer.get_indexer_cell() == pytest.approx(
        indexer2.get_indexer_cell(), abs=1e-6)
    assert indexer.get_indexer_beam_centre() == pytest.approx(
        indexer2.get_indexer_beam_centre(), abs=1e-6)
    assert indexer2.get_indexer_images() == [[1, 1], [22, 22], [
        45, 45
    ]]  # coming from json these are now lists

    indexer.eliminate()
    indexer2.eliminate()

    assert indexer.get_indexer_cell() == pytest.approx(
        indexer2.get_indexer_cell(), abs=1e-6)
    assert indexer.get_indexer_lattice() == 'hR'
    assert indexer2.get_indexer_lattice() == 'hR'
示例#4
0
def exercise_mosflm_index():
  if not have_dials_regression:
    print 'SKIP: dials_regression not configured'
    exit(0)

  xia2_demo_data = os.path.join(dials_regression, "xia2_demo_data")
  template = os.path.join(xia2_demo_data, "insulin_1_%03i.img")

  cwd = os.path.abspath(os.curdir)
  tmp_dir1 = os.path.abspath(open_tmp_directory())
  os.chdir(tmp_dir1)

  from xia2.Modules.Indexer.MosflmIndexer import MosflmIndexer
  m1 = MosflmIndexer()
  m1.set_working_directory(tmp_dir1)
  m1.setup_from_image(template % 1)
  m1.index()

  os.chdir(cwd)
  tmp_dir2 = os.path.abspath(open_tmp_directory())
  os.chdir(tmp_dir2)

  from Original import Mosflm
  m2 = Mosflm()
  m2.set_working_directory(tmp_dir2)
  m2.setup_from_image(template % 1)
  m2.index()

  assert m1.get_indexer_beam_centre() == m2.get_indexer_beam_centre()
  assert m1.get_indexer_distance() == m2.get_indexer_distance()
  assert m1.get_indexer_cell() == m2.get_indexer_cell()
  assert m1.get_indexer_lattice() == m2.get_indexer_lattice()
  assert m1.get_indexer_mosaic() == m2.get_indexer_mosaic()

  os.chdir(cwd)

  return
示例#5
0
def exercise_mosflm_integrate(nproc):
  if not have_dials_regression:
    raise RuntimeError, 'dials_regression not available'

  xia2_demo_data = os.path.join(dials_regression, "xia2_demo_data")
  template = os.path.join(xia2_demo_data, "insulin_1_%03i.img")

  from xia2.Schema.XCrystal import XCrystal
  from xia2.Schema.XWavelength import XWavelength
  from xia2.Schema.XSweep import XSweep
  from xia2.Schema.XSample import XSample

  from xia2.Handlers.Flags import Flags
  Flags.set_parallel(nproc)

  cwd = os.path.abspath(os.curdir)
  tmp_dir1 = os.path.abspath(open_tmp_directory())
  os.chdir(tmp_dir1)

  from xia2.Modules.Integrater.MosflmIntegrater import MosflmIntegrater
  from xia2.Modules.Refiner.MosflmRefiner import MosflmRefiner
  from xia2.Modules.Indexer.MosflmIndexer import MosflmIndexer
  indexer = MosflmIndexer()
  indexer.set_working_directory(tmp_dir1)
  indexer.setup_from_image(template % 1)
  refiner = MosflmRefiner()
  refiner.add_refiner_indexer(1, indexer)
  m1 = MosflmIntegrater()
  m1.set_working_directory(tmp_dir1)
  m1.setup_from_image(template % 1)
  cryst = XCrystal("CRYST1", None)
  wav = XWavelength("WAVE1", cryst, m1.get_wavelength())
  samp = XSample("X1", cryst)
  directory, image = os.path.split(template %1)
  sweep = XSweep('SWEEP1', wav, samp, directory=directory, image=image)
  indexer.set_indexer_sweep(sweep)
  m1.set_integrater_sweep(sweep)
  m1.set_integrater_refiner(refiner)
  m1.set_frame_wedge(1, 45)
  m1.set_integrater_wedge(1, 45)
  m1.integrate()

  os.chdir(cwd)
  tmp_dir2 = os.path.abspath(open_tmp_directory())
  os.chdir(tmp_dir2)

  from Original import Mosflm
  m2 = Mosflm()
  m2.set_working_directory(tmp_dir2)
  m2.setup_from_image(template % 1)
  m2.set_integrater_indexer(m2)
  m2.set_integrater_sweep(sweep)
  m2.set_frame_wedge(1, 45)
  m2.set_integrater_wedge(1, 45)
  m2.integrate()

  from libtbx.test_utils import approx_equal
  assert approx_equal(m1.get_integrater_cell(), m2.get_integrater_cell(),
                      eps=0.02)

  assert approx_equal(indexer.get_indexer_distance(), m2.get_indexer_distance(),
                      eps=0.2)

  assert approx_equal(m1.get_integrater_cell(),
                      m2.get_integrater_cell(), eps=0.02)
  assert indexer.get_indexer_lattice() == m2.get_indexer_lattice()
  assert approx_equal(indexer.get_indexer_mosaic(), m2.get_indexer_mosaic(),
                      eps=0.01)

  m1_mtz = m1.get_integrater_intensities()
  m2_mtz = m2.get_integrater_intensities()

  from iotbx.reflection_file_reader import any_reflection_file
  mas_1 = any_reflection_file(m1_mtz).as_miller_arrays()
  mas_2 = any_reflection_file(m2_mtz).as_miller_arrays()

  assert len(mas_1) == len(mas_2)
  for ma1, ma2 in zip(mas_1, mas_2):
    assert ma1.size() == ma2.size()
    assert ma1.space_group() == ma2.space_group()
    assert ma1.unit_cell().parameters() == ma2.unit_cell().parameters()
    assert ma1.indices() == ma2.indices()
    assert ma1.data() == ma2.data()
    assert ma1.sigmas() == ma2.sigmas()

  return