Example #1
0
def exercise_mosflm_integrater(dials_regression, tmp_dir, nproc):
  from xia2.Handlers.Phil import PhilIndex
  PhilIndex.params.xia2.settings.multiprocessing.nproc = nproc

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

  # otherwise if this test is running multiple times simultaneously two mosflm
  # processes try to write to the same genfile
  os.environ['CCP4_SCR'] = tmp_dir

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

  from xia2.Schema.XCrystal import XCrystal
  from xia2.Schema.XWavelength import XWavelength
  from xia2.Schema.XSweep import XSweep
  from xia2.Schema.XSample import XSample
  cryst = XCrystal("CRYST1", None)
  wav = XWavelength("WAVE1", cryst, indexer.get_wavelength())
  samp = XSample("X1", cryst)
  directory, image = os.path.split(imageset.get_path(1))
  sweep = XSweep('SWEEP1', wav, samp, directory=directory, image=image)
  indexer.set_indexer_sweep(sweep)

  from xia2.Modules.Refiner.MosflmRefiner import MosflmRefiner
  refiner = MosflmRefiner()
  refiner.set_working_directory(tmp_dir)
  refiner.add_refiner_indexer(sweep.get_epoch(1), indexer)

  nref_error = 500

  integrater = MosflmIntegrater()
  integrater.set_working_directory(tmp_dir)
  integrater.setup_from_image(imageset.get_path(1))
  integrater.set_integrater_refiner(refiner)
  #integrater.set_integrater_indexer(indexer)
  integrater.set_integrater_sweep(sweep)
  integrater.integrate()

  integrater_intensities = integrater.get_integrater_intensities()
  assert os.path.exists(integrater_intensities)
  from iotbx.reflection_file_reader import any_reflection_file
  reader = any_reflection_file(integrater_intensities)
  assert reader.file_type() == "ccp4_mtz"
  mtz_object = reader.file_content()
  assert abs(mtz_object.n_reflections() - 81116) < nref_error, \
      mtz_object.n_reflections()
  assert mtz_object.column_labels() == [
    'H', 'K', 'L', 'M_ISYM', 'BATCH', 'I', 'SIGI', 'IPR', 'SIGIPR',
    'FRACTIONCALC', 'XDET', 'YDET', 'ROT', 'WIDTH', 'LP', 'MPART', 'FLAG',
    'BGPKRATIOS']

  assert integrater.get_integrater_wedge() == (1, 45)
  assert approx_equal(integrater.get_integrater_cell(),
                      (78.014, 78.014, 78.014, 90.0, 90.0, 90.0), eps=1e-2)

  # test serialization of integrater
  json_str = integrater.as_json()
  #print json_str
  integrater2 = MosflmIntegrater.from_json(string=json_str)
  integrater2.set_integrater_sweep(sweep, reset=False)
  integrater2_intensities = integrater.get_integrater_intensities()
  assert integrater2_intensities == integrater_intensities

  integrater2.set_integrater_finish_done(False)
  integrater2_intensities = integrater2.get_integrater_intensities()
  assert os.path.exists(integrater2_intensities)
  reader = any_reflection_file(integrater2_intensities)
  assert reader.file_type() == "ccp4_mtz"
  mtz_object = reader.file_content()
  assert abs(mtz_object.n_reflections() - 81116) < nref_error, \
      mtz_object.n_reflections()

  integrater2.set_integrater_done(False)
  integrater2_intensities = integrater2.get_integrater_intensities()
  assert os.path.exists(integrater2_intensities)
  reader = any_reflection_file(integrater2_intensities)
  assert reader.file_type() == "ccp4_mtz"
  mtz_object = reader.file_content()
  assert abs(mtz_object.n_reflections() - 81116) < nref_error, \
      mtz_object.n_reflections()

  integrater2.set_integrater_prepare_done(False)
  integrater2_intensities = integrater2.get_integrater_intensities()
  assert os.path.exists(integrater2_intensities)
  reader = any_reflection_file(integrater2_intensities)
  assert reader.file_type() == "ccp4_mtz"
  mtz_object = reader.file_content()
  assert abs(mtz_object.n_reflections() - 81116) < nref_error, \
         mtz_object.n_reflections()
Example #2
0
def exercise_mosflm_integrater(nproc=None):
  if not have_dials_regression:
    print "Skipping exercise_mosflm_integrater(): dials_regression not configured"
    return

  if nproc is not None:
    from xia2.Handlers.Phil import PhilIndex
    PhilIndex.params.xia2.settings.multiprocessing.nproc = nproc

  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)
  # otherwise if this test is running multiple times simultaneously two mosflm
  # processes try to write to the same genfile
  os.environ['CCP4_SCR'] = tmp_dir

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

  from xia2.Schema.XCrystal import XCrystal
  from xia2.Schema.XWavelength import XWavelength
  from xia2.Schema.XSweep import XSweep
  from xia2.Schema.XSample import XSample
  cryst = XCrystal("CRYST1", None)
  wav = XWavelength("WAVE1", cryst, indexer.get_wavelength())
  samp = XSample("X1", cryst)
  directory, image = os.path.split(imageset.get_path(1))
  sweep = XSweep('SWEEP1', wav, samp, directory=directory, image=image)
  indexer.set_indexer_sweep(sweep)

  from xia2.Modules.Refiner.MosflmRefiner import MosflmRefiner
  refiner = MosflmRefiner()
  refiner.set_working_directory(tmp_dir)
  refiner.add_refiner_indexer(sweep.get_epoch(1), indexer)

  nref_error = 500

  integrater = MosflmIntegrater()
  integrater.set_working_directory(tmp_dir)
  integrater.setup_from_image(imageset.get_path(1))
  integrater.set_integrater_refiner(refiner)
  #integrater.set_integrater_indexer(indexer)
  integrater.set_integrater_sweep(sweep)
  integrater.integrate()

  integrater_intensities = integrater.get_integrater_intensities()
  assert os.path.exists(integrater_intensities)
  from iotbx.reflection_file_reader import any_reflection_file
  reader = any_reflection_file(integrater_intensities)
  assert reader.file_type() == "ccp4_mtz"
  mtz_object = reader.file_content()
  assert abs(mtz_object.n_reflections() - 81116) < nref_error, \
      mtz_object.n_reflections()
  assert mtz_object.column_labels() == [
    'H', 'K', 'L', 'M_ISYM', 'BATCH', 'I', 'SIGI', 'IPR', 'SIGIPR',
    'FRACTIONCALC', 'XDET', 'YDET', 'ROT', 'WIDTH', 'LP', 'MPART', 'FLAG',
    'BGPKRATIOS']

  assert integrater.get_integrater_wedge() == (1, 45)
  assert approx_equal(integrater.get_integrater_cell(),
                      (78.014, 78.014, 78.014, 90.0, 90.0, 90.0), eps=1e-2)

  # test serialization of integrater
  json_str = integrater.as_json()
  #print json_str
  integrater2 = MosflmIntegrater.from_json(string=json_str)
  integrater2.set_integrater_sweep(sweep, reset=False)
  integrater2_intensities = integrater.get_integrater_intensities()
  assert integrater2_intensities == integrater_intensities

  integrater2.set_integrater_finish_done(False)
  integrater2_intensities = integrater2.get_integrater_intensities()
  assert os.path.exists(integrater2_intensities)
  reader = any_reflection_file(integrater2_intensities)
  assert reader.file_type() == "ccp4_mtz"
  mtz_object = reader.file_content()
  assert abs(mtz_object.n_reflections() - 81116) < nref_error, \
      mtz_object.n_reflections()

  integrater2.set_integrater_done(False)
  integrater2_intensities = integrater2.get_integrater_intensities()
  assert os.path.exists(integrater2_intensities)
  reader = any_reflection_file(integrater2_intensities)
  assert reader.file_type() == "ccp4_mtz"
  mtz_object = reader.file_content()
  assert abs(mtz_object.n_reflections() - 81116) < nref_error, \
      mtz_object.n_reflections()

  integrater2.set_integrater_prepare_done(False)
  integrater2_intensities = integrater2.get_integrater_intensities()
  assert os.path.exists(integrater2_intensities)
  reader = any_reflection_file(integrater2_intensities)
  assert reader.file_type() == "ccp4_mtz"
  mtz_object = reader.file_content()
  assert abs(mtz_object.n_reflections() - 81116) < nref_error, \
         mtz_object.n_reflections()
Example #3
0
  if not integrater and \
         (not preselection or preselection == 'dials'):
    try:
      integrater = DialsIntegrater()
      Debug.write('Using Dials Integrater')
    except NotAvailableError, e:
      if preselection == 'dials':
        raise RuntimeError, \
              'preselected integrater dials not available: ' + \
              'dials not installed?'
      pass

  if not integrater and (not preselection or preselection == 'mosflmr'):
    try:
      integrater = MosflmIntegrater()
      Debug.write('Using MosflmR Integrater')
      if not get_preferences().get('scaler'):
        add_preference('scaler', 'ccp4a')
    except NotAvailableError, e:
      if preselection == 'mosflmr':
        raise RuntimeError, \
              'preselected integrater mosflmr not available'
      pass

  if not integrater and \
         (not preselection or preselection == 'xdsr'):
    try:
      integrater = XDSIntegrater()
      Debug.write('Using XDS Integrater in new resolution mode')
    except NotAvailableError, e:
Example #4
0
def Integrater():
  '''Return an  Integrater implementation.'''

  # FIXME this should take an indexer as an argument...

  integrater = None
  preselection = get_preferences().get('integrater')

  if not integrater and \
         (not preselection or preselection == 'dials'):
    try:
      integrater = DialsIntegrater()
      Debug.write('Using Dials Integrater')
    except NotAvailableError:
      if preselection == 'dials':
        raise RuntimeError( \
              'preselected integrater dials not available: ' + \
              'dials not installed?')

  if not integrater and (not preselection or preselection == 'mosflmr'):
    try:
      integrater = MosflmIntegrater()
      Debug.write('Using MosflmR Integrater')
      if not get_preferences().get('scaler'):
        add_preference('scaler', 'ccp4a')
    except NotAvailableError:
      if preselection == 'mosflmr':
        raise RuntimeError('preselected integrater mosflmr not available')

  if not integrater and \
         (not preselection or preselection == 'xdsr'):
    try:
      integrater = XDSIntegrater()
      Debug.write('Using XDS Integrater in new resolution mode')
    except NotAvailableError:
      if preselection == 'xdsr':
        raise RuntimeError( \
              'preselected integrater xdsr not available: ' + \
              'xds not installed?')

  if not integrater:
    raise RuntimeError('no integrater implementations found')

  # check to see if resolution limits were passed in through the
  # command line...

  dmin = PhilIndex.params.xia2.settings.resolution.d_min
  dmax = PhilIndex.params.xia2.settings.resolution.d_max

  if dmin:
    Debug.write('Adding user-assigned resolution limits:')

    if dmax:

      Debug.write('dmin: %.3f dmax: %.2f' % (dmin, dmax))
      integrater.set_integrater_resolution(dmin, dmax, user=True)

    else:

      Debug.write('dmin: %.3f' % dmin)
      integrater.set_integrater_high_resolution(dmin, user=True)

  return integrater
Example #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
def Integrater():
    """Return an  Integrater implementation."""

    # FIXME this should take an indexer as an argument...

    integrater = None
    preselection = get_preferences().get("integrater")

    if not integrater and (not preselection or preselection == "dials"):
        try:
            integrater = DialsIntegrater()
            Debug.write("Using Dials Integrater")
        except NotAvailableError:
            if preselection == "dials":
                raise RuntimeError(
                    "preselected integrater dials not available: " +
                    "dials not installed?")

    if not integrater and (not preselection or preselection == "mosflmr"):
        try:
            integrater = MosflmIntegrater()
            Debug.write("Using MosflmR Integrater")
            if not get_preferences().get("scaler"):
                add_preference("scaler", "ccp4a")
        except NotAvailableError:
            if preselection == "mosflmr":
                raise RuntimeError(
                    "preselected integrater mosflmr not available")

    if not integrater and (not preselection or preselection == "xdsr"):
        try:
            integrater = XDSIntegrater()
            Debug.write("Using XDS Integrater in new resolution mode")
        except NotAvailableError:
            if preselection == "xdsr":
                raise RuntimeError(
                    "preselected integrater xdsr not available: " +
                    "xds not installed?")

    if not integrater:
        raise RuntimeError("no integrater implementations found")

    # check to see if resolution limits were passed in through the
    # command line...

    dmin = PhilIndex.params.xia2.settings.resolution.d_min
    dmax = PhilIndex.params.xia2.settings.resolution.d_max

    if dmin:
        Debug.write("Adding user-assigned resolution limits:")

        if dmax:

            Debug.write("dmin: %.3f dmax: %.2f" % (dmin, dmax))
            integrater.set_integrater_resolution(dmin, dmax, user=True)

        else:

            Debug.write("dmin: %.3f" % dmin)
            integrater.set_integrater_high_resolution(dmin, user=True)

    return integrater
def exercise_mosflm_integrater(dials_data, tmp_dir, nproc):
    from xia2.Handlers.Phil import PhilIndex

    PhilIndex.params.xia2.settings.multiprocessing.nproc = nproc

    template = dials_data("insulin").join("insulin_1_###.img").strpath

    # otherwise if this test is running multiple times simultaneously two mosflm
    # processes try to write to the same genfile
    os.environ["CCP4_SCR"] = tmp_dir

    from xia2.Modules.Indexer.MosflmIndexer import MosflmIndexer
    from xia2.Modules.Integrater.MosflmIntegrater import MosflmIntegrater
    from dxtbx.model.experiment_list import ExperimentListTemplateImporter

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

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

    cryst = XCrystal("CRYST1", None)
    wav = XWavelength("WAVE1", cryst, indexer.get_wavelength())
    samp = XSample("X1", cryst)
    directory, image = os.path.split(imageset.get_path(1))
    sweep = XSweep("SWEEP1", wav, samp, directory=directory, image=image)
    indexer.set_indexer_sweep(sweep)

    from xia2.Modules.Refiner.MosflmRefiner import MosflmRefiner

    refiner = MosflmRefiner()
    refiner.set_working_directory(tmp_dir)
    refiner.add_refiner_indexer(sweep.get_epoch(1), indexer)

    nref_error = 500

    integrater = MosflmIntegrater()
    integrater.set_working_directory(tmp_dir)
    integrater.setup_from_image(imageset.get_path(1))
    integrater.set_integrater_refiner(refiner)
    # integrater.set_integrater_indexer(indexer)
    integrater.set_integrater_sweep(sweep)
    integrater.integrate()

    integrater_intensities = integrater.get_integrater_intensities()
    assert os.path.exists(integrater_intensities)
    from iotbx.reflection_file_reader import any_reflection_file

    reader = any_reflection_file(integrater_intensities)
    assert reader.file_type() == "ccp4_mtz"
    mtz_object = reader.file_content()
    assert (abs(mtz_object.n_reflections() - 81116) <
            nref_error), mtz_object.n_reflections()
    assert mtz_object.column_labels() == [
        "H",
        "K",
        "L",
        "M_ISYM",
        "BATCH",
        "I",
        "SIGI",
        "IPR",
        "SIGIPR",
        "FRACTIONCALC",
        "XDET",
        "YDET",
        "ROT",
        "WIDTH",
        "LP",
        "MPART",
        "FLAG",
        "BGPKRATIOS",
    ]

    assert integrater.get_integrater_wedge() == (1, 45)
    assert approx_equal(
        integrater.get_integrater_cell(),
        (78.014, 78.014, 78.014, 90.0, 90.0, 90.0),
        eps=1e-2,
    )

    # test serialization of integrater
    json_str = integrater.as_json()
    # print json_str
    integrater2 = MosflmIntegrater.from_json(string=json_str)
    integrater2.set_integrater_sweep(sweep, reset=False)
    integrater2_intensities = integrater.get_integrater_intensities()
    assert integrater2_intensities == integrater_intensities

    integrater2.set_integrater_finish_done(False)
    integrater2_intensities = integrater2.get_integrater_intensities()
    assert os.path.exists(integrater2_intensities)
    reader = any_reflection_file(integrater2_intensities)
    assert reader.file_type() == "ccp4_mtz"
    mtz_object = reader.file_content()
    assert (abs(mtz_object.n_reflections() - 81116) <
            nref_error), mtz_object.n_reflections()

    integrater2.set_integrater_done(False)
    integrater2_intensities = integrater2.get_integrater_intensities()
    assert os.path.exists(integrater2_intensities)
    reader = any_reflection_file(integrater2_intensities)
    assert reader.file_type() == "ccp4_mtz"
    mtz_object = reader.file_content()
    assert (abs(mtz_object.n_reflections() - 81116) <
            nref_error), mtz_object.n_reflections()

    integrater2.set_integrater_prepare_done(False)
    integrater2_intensities = integrater2.get_integrater_intensities()
    assert os.path.exists(integrater2_intensities)
    reader = any_reflection_file(integrater2_intensities)
    assert reader.file_type() == "ccp4_mtz"
    mtz_object = reader.file_content()
    assert (abs(mtz_object.n_reflections() - 81116) <
            nref_error), mtz_object.n_reflections()