Beispiel #1
0
 def __init__(self, millarr, mprint=sys.stdout.write):
     from iotbx.gui_tools.reflections import get_array_description
     data = millarr.data()
     if (isinstance(data, flex.int)):
         data = [e for e in data if e != display.inanval]
     if millarr.is_complex_array():
         data = flex.abs(millarr.data())
     data = [e for e in data if not math.isnan(e)]
     self.maxdata = max(data)
     self.mindata = min(data)
     self.maxsigmas = self.minsigmas = None
     if millarr.sigmas() is not None:
         data = millarr.sigmas()
         data = [e for e in data if not math.isnan(e)]
         self.maxsigmas = max(data)
         self.minsigmas = min(data)
     self.minmaxdata = (roundoff(self.mindata), roundoff(self.maxdata))
     self.minmaxsigs = (roundoff(self.minsigmas), roundoff(self.maxsigmas))
     self.labels = self.desc = ""
     #import code, traceback; code.interact(local=locals(), banner="".join( traceback.format_stack(limit=10) ) )
     if millarr.info():
         self.labels = millarr.info().label_string()
         self.desc = get_array_description(millarr)
     self.span = ("?", "?")
     dmin = 0.0
     dmax = 0.0
     try:
         self.span = (millarr.index_span().min(),
                      millarr.index_span().max())
         dmin = millarr.d_max_min()[1]
         dmax = millarr.d_max_min()[0]
     except Exception, e:
         mprint(to_str(e))
Beispiel #2
0
def run(args):
    pcl = iotbx.phil.process_command_line_with_files(
        args=args,
        master_phil=master_phil,
        reflection_file_def="data",
        pdb_file_def="symmetry_file",
        usage_string="xia2.plot_multiplicity scaled_unmerged.mtz [options]",
    )
    settings = pcl.work.extract()
    file_name = settings.data

    try:
        hkl_file = any_reflection_file(file_name)
    except Exception as e:
        raise Sorry(str(e))
    arrays = hkl_file.as_miller_arrays(merge_equivalents=False)
    valid_arrays = []
    array_info = []
    for array in arrays:
        if array.is_hendrickson_lattman_array():
            continue
        if (not array.is_real_array()) and (not array.is_complex_array()):
            continue
        labels = array.info().label_string()
        desc = get_array_description(array)
        array_info.append(f"{labels} ({desc})")
        valid_arrays.append(array)
    if len(valid_arrays) == 0:
        msg = "No arrays of the supported types in this file."
        raise Sorry(msg)
    miller_array = valid_arrays[0]
    plot_multiplicity(miller_array, settings)
Beispiel #3
0
 def load_reflections_file(self, file_name, set_array=True, data_only=True):
     if (file_name != ""):
         from iotbx.reflection_file_reader import any_reflection_file
         from iotbx.gui_tools.reflections import get_array_description
         try:
             hkl_file = any_reflection_file(file_name)
         except Exception as e:
             raise Sorry(str(e))
         arrays = hkl_file.as_miller_arrays(
             merge_equivalents=False,
         )  #observation_type_callback=misc_dialogs.get_shelx_file_data_type)
         #arrays = f.file_server.miller_arrays
         valid_arrays = []
         array_info = []
         for array in arrays:
             if array.is_hendrickson_lattman_array():
                 continue
             elif (data_only):
                 if (not array.is_real_array()) and (
                         not array.is_complex_array()):
                     continue
             labels = array.info().label_string()
             desc = get_array_description(array)
             array_info.append("%s (%s)" % (labels, desc))
             valid_arrays.append(array)
         if (len(valid_arrays) == 0):
             msg = "No arrays of the supported types in this file."
             raise Sorry(msg)
         elif (len(valid_arrays) >= 1):
             if (set_array):
                 self.set_miller_array(valid_arrays[0])
             return valid_arrays[0]
     raise Abort()
Beispiel #4
0
 def __init__(self, millarr):
   from iotbx.gui_tools.reflections import get_array_description
   data = millarr.data()
   if (isinstance(data, flex.int)):
     data = [e for e in data if e!= display.inanval]
   if millarr.is_complex_array():
     data = flex.abs(millarr.data())
   self.maxdata =max( data )
   self.mindata =min( data )
   self.maxsigmas = self.minsigmas = display.nanval
   if millarr.sigmas() is not None:
     data = millarr.sigmas()
     self.maxsigmas =max( data )
     self.minsigmas =min( data )
     self.minmaxstr = "MinMaxValues:[%s; %s], MinMaxSigmaValues:[%s; %s]" \
       %(roundoff(self.mindata), roundoff(self.maxdata), \
           roundoff(self.minsigmas), roundoff(self.maxsigmas))
   else:
     self.minmaxstr = "MinMaxValues:[%s; %s]" %(roundoff(self.mindata), roundoff(self.maxdata))
   self.labels = self.desc = ""
   if millarr.info():
     self.labels = millarr.info().label_string()
     self.desc = get_array_description(millarr)
   self.span = "HKLs: %s to %s" % \
     ( millarr.index_span().min(), millarr.index_span().max())
   self.infostr = "%s (%s), %s %s, %s, d_min: %s" % \
     (self.labels, self.desc, millarr.size(), self.span, self.minmaxstr, roundoff(millarr.d_min()))
Beispiel #5
0
    def load_reflections_file(self,
                              file_name,
                              set_array=True,
                              data_only=False):
        file_name = to_str(file_name)
        if (file_name != ""):
            from iotbx.reflection_file_reader import any_reflection_file
            from iotbx.gui_tools.reflections import get_array_description
            try:
                hkl_file = any_reflection_file(file_name)
            except Exception as e:
                raise Sorry(to_str(e))
            arrays = hkl_file.as_miller_arrays(
                merge_equivalents=False,
            )  #observation_type_callback=misc_dialogs.get_shelx_file_data_type)
            #arrays = f.file_server.miller_arrays
            valid_arrays = []
            array_info = []
            for array in arrays:
                if array.is_hendrickson_lattman_array():
                    continue
                elif (data_only):
                    if (not array.is_real_array()) and (
                            not array.is_complex_array()):
                        continue
                labels = array.info().label_string()
                desc = get_array_description(array)
                array_info.append("%s (%s)" % (labels, desc))
                valid_arrays.append(array)
            self.valid_arrays = valid_arrays
            if (len(valid_arrays) == 0):
                msg = "No arrays of the supported types in this file."
                raise Sorry(msg)
            elif (len(valid_arrays) == 1):
                if (set_array):
                    self.set_miller_array(valid_arrays[0])
                return valid_arrays[0]
            else:
                #dlg = SelectArrayDialog(self, -1, "Select data")
                dlg = wx.SingleChoiceDialog(
                    parent=None,
                    message="Please select the data you wish to view:",
                    caption="Select data",
                    choices=array_info)
                # print("kau labels info is", array_info) #Kau added
                # print("Kau printing array_info from calling ", array_info)

                if (dlg.ShowModal() == wx.ID_OK):
                    sel = dlg.GetSelection()
                    if (set_array):
                        self.set_miller_array(valid_arrays[sel])
                    wx.CallAfter(dlg.Destroy)
                    self.settings_panel.update_column_choices(
                        array_info, valid_arrays, sel)  # kau added
                    # self.settings_panel.update_column_choices(array_info,valid_arrays,sel) # kau added
                    return valid_arrays[sel]
                wx.CallAfter(dlg.Destroy)

        raise Abort()
Beispiel #6
0
def run(args):
    from libtbx.utils import Sorry
    pcl = iotbx.phil.process_command_line_with_files(
        args=args,
        master_phil=master_phil,
        reflection_file_def="data",
        pdb_file_def="symmetry_file",
        usage_string="%s scaled_unmerged.mtz [options]" %
        libtbx.env.dispatcher_name)
    settings = pcl.work.extract()
    file_name = settings.data

    data_only = True
    from iotbx.reflection_file_reader import any_reflection_file
    from iotbx.gui_tools.reflections import get_array_description
    try:
        hkl_file = any_reflection_file(file_name)
    except Exception as e:
        raise Sorry(str(e))
    arrays = hkl_file.as_miller_arrays(merge_equivalents=False)
    valid_arrays = []
    array_info = []
    for array in arrays:
        if array.is_hendrickson_lattman_array():
            continue
        elif (data_only):
            if (not array.is_real_array()) and (not array.is_complex_array()):
                continue
        labels = array.info().label_string()
        desc = get_array_description(array)
        array_info.append("%s (%s)" % (labels, desc))
        valid_arrays.append(array)
    if (len(valid_arrays) == 0):
        msg = "No arrays of the supported types in this file."
        raise Sorry(msg)
    miller_array = valid_arrays[0]

    settings.scale_colors_multiplicity = True
    settings.scale_radii_multiplicity = True
    settings.expand_to_p1 = True
    settings.expand_anomalous = True
    settings.slice_mode = True

    if settings.plot.filename is not None:
        view = MultiplicityViewPng(scene(miller_array, settings, merge=True),
                                   settings=settings)

    if settings.json.filename is not None:
        view = MultiplicityViewJson(scene(miller_array, settings, merge=True),
                                    settings=settings)
 def load_reflections_file (self, file_name, set_array=True,
     data_only=False) :
   if (isinstance(file_name, unicode)) :
     file_name = str(file_name)
   if (file_name != "") :
     from iotbx.reflection_file_reader import any_reflection_file
     from iotbx.gui_tools.reflections import get_array_description
     try :
       hkl_file = any_reflection_file(file_name)
     except Exception, e :
       raise Sorry(str(e))
     arrays = hkl_file.as_miller_arrays(merge_equivalents=False,
       )#observation_type_callback=misc_dialogs.get_shelx_file_data_type)
     #arrays = f.file_server.miller_arrays
     valid_arrays = []
     array_info = []
     for array in arrays :
       if array.is_hendrickson_lattman_array() :
         continue
       elif (data_only) :
         if (not array.is_real_array()) and (not array.is_complex_array()) :
           continue
       labels = array.info().label_string()
       desc = get_array_description(array)
       array_info.append("%s (%s)" % (labels, desc))
       valid_arrays.append(array)
     if (len(valid_arrays) == 0) :
       msg = "No arrays of the supported types in this file."
       raise Sorry(msg)
     elif (len(valid_arrays) == 1) :
       if (set_array) :
         self.set_miller_array(valid_arrays[0])
       return valid_arrays[0]
     else :
       #dlg = SelectArrayDialog(self, -1, "Select data")
       dlg = wx.SingleChoiceDialog(parent=None,
         message="Please select the data you wish to view:",
         caption="Select data",
         choices=array_info)
       if (dlg.ShowModal() == wx.ID_OK) :
         sel = dlg.GetSelection()
         if (set_array) :
           self.set_miller_array(valid_arrays[sel])
         wx.CallAfter(dlg.Destroy)
         return valid_arrays[sel]
       wx.CallAfter(dlg.Destroy)
Beispiel #8
0
 def __init__(self, millarr, mprint=sys.stdout.write):
     from iotbx.gui_tools.reflections import get_array_description
     data = millarr.data()
     if (isinstance(data, flex.int)):
         data = [e for e in data if e != display.inanval]
     if millarr.is_complex_array():
         data = flex.abs(millarr.data())
     data = [e for e in data if not math.isnan(e)]
     self.maxdata = max(data)
     self.mindata = min(data)
     self.maxsigmas = self.minsigmas = None
     if millarr.sigmas() is not None:
         data = millarr.sigmas()
         data = [e for e in data if not math.isnan(e)]
         self.maxsigmas = max(data)
         self.minsigmas = min(data)
     self.minmaxdata = (roundoff(self.mindata), roundoff(self.maxdata))
     self.minmaxsigs = (roundoff(self.minsigmas), roundoff(self.maxsigmas))
     self.labels = self.desc = ""
     #import code, traceback; code.interact(local=locals(), banner="".join( traceback.format_stack(limit=10) ) )
     if millarr.info():
         self.labels = millarr.info().label_string()
         self.desc = get_array_description(millarr)
     self.span = ("?", "?")
     dmin = 0.0
     dmax = 0.0
     try:
         self.span = (millarr.index_span().min(),
                      millarr.index_span().max())
         dmin = millarr.d_max_min()[1]
         dmax = millarr.d_max_min()[0]
     except Exception as e:
         mprint(to_str(e))
     issymunique = millarr.is_unique_set_under_symmetry()
     self.infotpl = (self.labels, self.desc, millarr.indices().size(),
                     self.span, self.minmaxdata, self.minmaxsigs,
                     (roundoff(dmin), roundoff(dmax)), issymunique)
     self.infostr = "%s (%s), %s HKLs: %s, MinMax: %s, MinMaxSigs: %s, d_minmax: %s, SymUnique: %d" % self.infotpl
Beispiel #9
0
def exercise_reflections():
    hkl_handler = reflections.reflections_handler(
        allowed_param_names=phil_names)
    from cctbx import miller
    from cctbx import crystal
    from cctbx.array_family import flex
    symm = crystal.symmetry(unit_cell=(30, 30, 40, 90, 90, 120),
                            space_group_symbol="P 61 2 2")
    miller_set = miller.build_set(crystal_symmetry=symm,
                                  anomalous_flag=True,
                                  d_min=1.5)
    n_refl = miller_set.indices().size()
    data = flex.random_double(n_refl)
    sigmas = flex.random_double(n_refl)
    f_obs = miller_set.array(data=data, sigmas=sigmas)
    f_obs_merged = f_obs.average_bijvoet_mates()
    flags = f_obs_merged.generate_r_free_flags()
    # single dataset
    mtz_dataset = f_obs_merged.as_mtz_dataset(column_root_label="F-obs",
                                              wavelength=1.54)
    mtz_dataset.add_miller_array(flags, column_root_label="R-free-flags")
    file_name = "tst_iotbs_gui_tools.mtz"
    mtz_dataset.mtz_object().write(file_name)
    assert (hkl_handler.set_param_file(
        file_name=file_name,
        file_param_name="refinement.input.xray_data.file_name") == True)
    assert (hkl_handler.set_param_file(
        file_name=file_name,
        file_param_name="refinement.input.xray_data.r_free_flags.file_name") ==
            False)
    assert (hkl_handler.get_rfree_labels(
        file_param_name="refinement.input.xray_data.r_free_flags.file_name") ==
            hkl_handler.get_rfree_labels(file_name=file_name) ==
            ['R-free-flags'])
    assert (hkl_handler.get_rfree_labels(file_name=file_name, neutron=False) ==
            hkl_handler.get_rfree_labels(file_name=file_name,
                                         neutron=True) == ['R-free-flags'])
    assert approx_equal(
        1.54,
        hkl_handler.get_wavelength(file_name=file_name,
                                   labels="F-obs,SIGF-obs"))
    # join X/N datasets
    hkl_handler = reflections.reflections_handler(
        allowed_param_names=phil_names)
    data_neutron = flex.random_double(n_refl)
    sigmas_neutron = flex.random_double(n_refl)
    f_obs_neutron = miller_set.array(data=data_neutron, sigmas=sigmas_neutron)
    mtz_dataset = f_obs_merged.as_mtz_dataset(column_root_label="F-obs-xray")
    mtz_dataset.add_miller_array(f_obs_neutron,
                                 column_root_label="F-obs-neutron")
    mtz_dataset.add_miller_array(flags, column_root_label="R-free-flags-xray")
    mtz_dataset.add_miller_array(flags.deep_copy(),
                                 column_root_label="R-free-flags-neutron")
    file_name = "tst_iotbs_gui_tools.mtz"
    mtz_dataset.mtz_object().write(file_name)
    assert (hkl_handler.set_param_file(
        file_name=file_name,
        file_param_name="refinement.input.xray_data.file_name") == True)
    for i, phil_name in enumerate(phil_names[1:4]):
        assert (hkl_handler.set_param_file(file_name=file_name,
                                           file_param_name=phil_name) == False)
    assert (hkl_handler.get_rfree_labels(
        file_param_name="refinement.input.xray_data.r_free_flags.file_name") ==
            hkl_handler.get_rfree_labels(file_name=file_name) ==
            ['R-free-flags-xray', 'R-free-flags-neutron'])
    assert (hkl_handler.get_rfree_labels(
        file_name=file_name, neutron=False) == ['R-free-flags-xray'])
    assert (hkl_handler.get_rfree_labels(
        file_name=file_name, neutron=True) == ['R-free-flags-neutron'])
    hkl_handler.check_symmetry(file_name=file_name)
    assert (hkl_handler.get_data_labels(
        file_param_name="refinement.input.xray_data.file_name") ==
            hkl_handler.get_data_labels(file_name=file_name) ==
            hkl_handler.get_amplitude_labels(file_name=file_name) == [
                "F-obs-xray,SIGF-obs-xray",
                "F-obs-neutron(+),SIGF-obs-neutron(+)," +
                "F-obs-neutron(-),SIGF-obs-neutron(-)"
            ])
    assert (hkl_handler.get_anomalous_data_labels(
        file_param_name="refinement.input.xray_data.file_name") == [
            "F-obs-neutron(+),SIGF-obs-neutron(+)," +
            "F-obs-neutron(-),SIGF-obs-neutron(-)"
        ])
    assert (hkl_handler.has_anomalous_data(
        file_param_name="refinement.input.xray_data.file_name"))
    assert (hkl_handler.get_rfree_flag_value(
        array_name="F-obs-xray,SIGF-obs-xray",
        file_param_name="refinement.input.xray_data.file_name") is None)
    assert (hkl_handler.get_rfree_flag_value(
        array_name='R-free-flags-xray',
        file_param_name="refinement.input.xray_data.r_free_flags.file_name") ==
            1)
    (d_max, d_min) = hkl_handler.d_max_min()
    assert approx_equal(d_max, 25.98, eps=0.01)
    assert approx_equal(d_min, 1.5, eps=0.01)
    assert hkl_handler.space_group_as_str() == "P 61 2 2"
    assert (hkl_handler.unit_cell_as_str() == "30 30 40 90 90 120")
    assert (hkl_handler.unit_cell_as_str(
        separator=",") == "30,30,40,90,90,120")

    n_refl_merged = len(f_obs_merged.indices())
    phi_array = f_obs_merged.random_phases_compatible_with_phase_restrictions(
        deg=True)
    fom_array = phi_array.array(data=flex.random_double(n_refl_merged))
    hl_data = flex.hendrickson_lattman(n_refl_merged, (0, 0, 0, 0))
    hl_coeffs = phi_array.array(data=hl_data)
    assert (hl_coeffs.is_hendrickson_lattman_array())
    from iotbx.mtz import label_decorator
    import iotbx.mtz

    class resolve_label_decorator(label_decorator):
        def phases(self, *args, **kwds):
            return label_decorator.phases(self, *args, **kwds) + "M"

        def hendrickson_lattman(self, *args, **kwds):
            return label_decorator.hendrickson_lattman(self, *args, **
                                                       kwds) + "M"

    mtz_dataset = f_obs_merged.as_mtz_dataset(column_root_label="FP")
    mtz_dataset.add_miller_array(phi_array,
                                 column_root_label="PHIM",
                                 label_decorator=resolve_label_decorator(),
                                 column_types="P")
    mtz_dataset.add_miller_array(fom_array,
                                 column_root_label="FOMM",
                                 column_types="W")
    mtz_dataset.add_miller_array(hl_coeffs,
                                 column_root_label="HL",
                                 label_decorator=resolve_label_decorator())
    fwt_map = f_obs_merged.customized_copy(
        sigmas=None).phase_transfer(phi_array)
    mtz_dataset.add_miller_array(
        fwt_map,
        column_root_label="FWT",
        label_decorator=iotbx.mtz.ccp4_label_decorator())
    mtz_dataset.add_miller_array(flags, column_root_label="FreeR_flag")
    resolve_file = "tst_iotbx_gui_tools_resolve.mtz"
    mtz_dataset.mtz_object().write(resolve_file)
    hkl_handler = reflections.reflections_handler(
        allowed_param_names=["map_coeffs"])
    hkl_handler.set_param_file(file_name=resolve_file,
                               file_param_name="map_coeffs")
    assert hkl_handler.has_data(file_name=resolve_file)
    l1 = hkl_handler.get_map_coeff_labels(file_name=resolve_file)
    assert (l1 == ['FWT,PHWT', 'FP,PHIM,FOMM'])
    l2 = hkl_handler.get_phase_deg_labels(file_name=resolve_file)
    assert (l2 == [
        'HLAM,HLBM,HLCM,HLDM',
        'FWT,PHWT',
        'PHIM',
    ]), l2
    l3 = hkl_handler.get_experimental_phase_labels(file_name=resolve_file)
    #print l3
    l4 = hkl_handler.get_data_labels_for_wizard(file_name=resolve_file)
    assert (l4 == ['FP SIGFP'])
    l5 = hkl_handler.get_map_coeff_labels_for_build(file_name=resolve_file)
    assert (l5 == ['FWT,PHWT', 'FP,PHIM,FOMM']), l5
    hkl_in = hkl_handler.get_file(file_name=resolve_file)
    assert (reflections.get_mtz_label_prefix(hkl_in) == "/crystal/dataset")
    map_coeffs = reflections.map_coeffs_from_mtz_file(resolve_file,
                                                      f_label="FP,SIGFP")
    assert map_coeffs.is_complex_array()
    try:
        map_coeffs = reflections.map_coeffs_from_mtz_file(resolve_file)
    except Sorry:
        pass
    else:
        raise Exception_expected
    assert (hkl_handler.get_map_coeff_labels_for_fft(
        file_name=resolve_file) == ['FWT,PHWT', 'FP,SIGFP PHIM FOMM'])

    # miscellaneous utilities
    file_name = resolve_file
    hkl_in = file_reader.any_file(file_name)
    hkl_server = hkl_in.file_server
    assert approx_equal(reflections.get_high_resolution(hkl_server),
                        1.5,
                        eps=0.0001)
    descriptions = []
    for miller_array in hkl_server.miller_arrays:
        (sg, uc) = reflections.get_miller_array_symmetry(miller_array)
        assert (uc == "30 30 40 90 90 120")
        assert (str(sg) == "P 61 2 2")
        descriptions.append(reflections.get_array_description(miller_array))
    assert (descriptions == [
        'Amplitude', 'Phases', 'Weights', 'HL coeffs', 'Map coeffs',
        'R-free flag'
    ]), descriptions
    handler = reflections.reflections_handler()
    handler.save_file(input_file=hkl_in)
    assert (not handler.has_anomalous_data())
    assert (handler.get_resolution_range(
        file_name=file_name) == "(25.981 - 1.500)")
    assert (handler.get_resolution_limits(file_name=file_name) == ('(25.981)',
                                                                   '(1.500)'))
    fmodel = phi_array.array(
        data=flex.complex_double(n_refl_merged, complex(0.5, 0.8)))
    m1 = phi_array.array(
        data=flex.complex_double(n_refl_merged, complex(1, 0)))
    m2 = phi_array.array(
        data=flex.complex_double(n_refl_merged, complex(0.5, 0)))
    m3 = phi_array.array(flex.complex_double(n_refl_merged, complex(1, 1)))
    dec = label_decorator(phases_prefix="PH")
    mtz_dataset = fmodel.as_mtz_dataset(column_root_label="F-model",
                                        label_decorator=dec)
    mtz_dataset.add_miller_array(m1,
                                 column_root_label="2FOFCWT",
                                 label_decorator=dec)
    mtz_dataset.add_miller_array(m2,
                                 column_root_label="FOFCWT",
                                 label_decorator=dec)
    mtz_dataset.add_miller_array(m3,
                                 column_root_label="2FOFCWT_no_fill",
                                 label_decorator=dec)
    file_name = "tst_iotbx_gui_tools_map_coeffs.mtz"
    mtz_dataset.mtz_object().write(file_name)
    hkl_handler = reflections.reflections_handler(
        allowed_param_names=["fmodel", "map_coeffs"])
    hkl_handler.set_param_file(file_name=file_name, file_param_name="fmodel")
    assert (hkl_handler.get_fmodel_labels(file_name=file_name) == [
        'F-model,PHF-model'
    ])
    assert (hkl_handler.get_amplitude_labels(file_name=file_name) == [])
    phi_labels = hkl_handler.get_phase_deg_labels(file_name=file_name)
    assert (len(phi_labels) == 4)
    phi_cols = hkl_handler.get_phase_column_labels(file_name=file_name)
    assert (phi_cols == [
        'PHF-model', 'PH2FOFCWT', 'PHFOFCWT', 'PH2FOFCWT_no_fill'
    ])
    assert (len(
        hkl_handler.get_amplitude_column_labels(file_name=file_name,
                                                allow_conversion=True)) == 0)
    fc_cols = hkl_handler.get_fmodel_labels(file_name=file_name,
                                            first_column_only=True)
    assert (fc_cols == ['F-model'])
    hkl_server = file_reader.any_file(file_name).file_server
    map_labels = reflections.get_map_coeff_labels(hkl_server)
    assert (map_labels == [
        '2FOFCWT,PH2FOFCWT',
        'FOFCWT,PHFOFCWT',
        '2FOFCWT_no_fill,PH2FOFCWT_no_fill',
    ])
    map_labels = reflections.get_map_coeffs_for_build(hkl_server)
    assert map_labels == [
        '2FOFCWT,PH2FOFCWT', '2FOFCWT_no_fill,PH2FOFCWT_no_fill'
    ]
    map_coeffs = reflections.extract_phenix_refine_map_coeffs(file_name)
    assert (len(map_coeffs) == 3)
    hkl_file = file_reader.any_file(file_name)
    assert reflections.get_mtz_label_prefix(hkl_file) == "/crystal/dataset"
    # other stuff
    (fp, fpp) = reflections.get_fp_fpp_from_sasaki("Se", 0.979)
    assert fp is not None and fpp is not None
Beispiel #10
0
  from iotbx.gui_tools.reflections import get_array_description
  try :
    hkl_file = any_reflection_file(file_name)
  except Exception, e :
    raise Sorry(str(e))
  arrays = hkl_file.as_miller_arrays(merge_equivalents=False)
  valid_arrays = []
  array_info = []
  for array in arrays :
    if array.is_hendrickson_lattman_array() :
      continue
    elif (data_only) :
      if (not array.is_real_array()) and (not array.is_complex_array()) :
        continue
    labels = array.info().label_string()
    desc = get_array_description(array)
    array_info.append("%s (%s)" % (labels, desc))
    valid_arrays.append(array)
  if (len(valid_arrays) == 0) :
    msg = "No arrays of the supported types in this file."
    raise Sorry(msg)
  miller_array = valid_arrays[0]

  settings.scale_colors_multiplicity = True
  settings.scale_radii_multiplicity = True
  settings.expand_to_p1 = True
  settings.expand_anomalous = True
  settings.slice_mode = True

  view = MultiplicityViewPng(
    scene(miller_array, settings, merge=True), settings=settings)
Beispiel #11
0
def exercise_reflections () :
  hkl_handler = reflections.reflections_handler(allowed_param_names=phil_names)
  from cctbx import miller
  from cctbx import crystal
  from cctbx.array_family import flex
  symm = crystal.symmetry(
    unit_cell=(30,30,40,90,90,120),
    space_group_symbol="P 61 2 2")
  miller_set = miller.build_set(
    crystal_symmetry=symm,
    anomalous_flag=True,
    d_min=1.5)
  n_refl = miller_set.indices().size()
  data = flex.random_double(n_refl)
  sigmas = flex.random_double(n_refl)
  f_obs = miller_set.array(data=data, sigmas=sigmas)
  f_obs_merged = f_obs.average_bijvoet_mates()
  flags = f_obs_merged.generate_r_free_flags()
  # single dataset
  mtz_dataset = f_obs_merged.as_mtz_dataset(
    column_root_label="F-obs",
    wavelength=1.54)
  mtz_dataset.add_miller_array(flags,
    column_root_label="R-free-flags")
  file_name = "tst_iotbs_gui_tools.mtz"
  mtz_dataset.mtz_object().write(file_name)
  assert (hkl_handler.set_param_file(file_name=file_name,
          file_param_name="refinement.input.xray_data.file_name") == True)
  assert (hkl_handler.set_param_file(file_name=file_name,
          file_param_name="refinement.input.xray_data.r_free_flags.file_name")
          == False)
  assert (hkl_handler.get_rfree_labels(
    file_param_name="refinement.input.xray_data.r_free_flags.file_name") ==
    hkl_handler.get_rfree_labels(file_name=file_name) == ['R-free-flags'])
  assert (hkl_handler.get_rfree_labels(file_name=file_name, neutron=False) ==
          hkl_handler.get_rfree_labels(file_name=file_name, neutron=True) ==
          ['R-free-flags'])
  assert approx_equal(1.54, hkl_handler.get_wavelength(file_name=file_name,
                              labels="F-obs,SIGF-obs"))
  # join X/N datasets
  hkl_handler = reflections.reflections_handler(allowed_param_names=phil_names)
  data_neutron = flex.random_double(n_refl)
  sigmas_neutron = flex.random_double(n_refl)
  f_obs_neutron = miller_set.array(data=data_neutron, sigmas=sigmas_neutron)
  mtz_dataset = f_obs_merged.as_mtz_dataset(
    column_root_label="F-obs-xray")
  mtz_dataset.add_miller_array(f_obs_neutron,
    column_root_label="F-obs-neutron")
  mtz_dataset.add_miller_array(flags,
    column_root_label="R-free-flags-xray")
  mtz_dataset.add_miller_array(flags.deep_copy(),
    column_root_label="R-free-flags-neutron")
  file_name = "tst_iotbs_gui_tools.mtz"
  mtz_dataset.mtz_object().write(file_name)
  assert (hkl_handler.set_param_file(file_name=file_name,
          file_param_name="refinement.input.xray_data.file_name") == True)
  for i, phil_name in enumerate(phil_names[1:4]) :
    assert (hkl_handler.set_param_file(file_name=file_name,
            file_param_name=phil_name) == False)
  assert (hkl_handler.get_rfree_labels(
    file_param_name="refinement.input.xray_data.r_free_flags.file_name") ==
    hkl_handler.get_rfree_labels(file_name=file_name) ==
    ['R-free-flags-xray', 'R-free-flags-neutron'])
  assert (hkl_handler.get_rfree_labels(file_name=file_name, neutron=False) ==
          ['R-free-flags-xray'])
  assert (hkl_handler.get_rfree_labels(file_name=file_name, neutron=True) ==
          ['R-free-flags-neutron'])
  hkl_handler.check_symmetry(file_name=file_name)
  assert (hkl_handler.get_data_labels(
          file_param_name="refinement.input.xray_data.file_name") ==
          hkl_handler.get_data_labels(file_name=file_name) ==
          hkl_handler.get_amplitude_labels(file_name=file_name) ==
          ["F-obs-xray,SIGF-obs-xray", "F-obs-neutron(+),SIGF-obs-neutron(+),"+
                             "F-obs-neutron(-),SIGF-obs-neutron(-)"])
  assert (hkl_handler.get_anomalous_data_labels(
          file_param_name="refinement.input.xray_data.file_name") ==
          ["F-obs-neutron(+),SIGF-obs-neutron(+)," +
           "F-obs-neutron(-),SIGF-obs-neutron(-)"])
  assert (hkl_handler.has_anomalous_data(
          file_param_name="refinement.input.xray_data.file_name"))
  assert (hkl_handler.get_rfree_flag_value(
    array_name="F-obs-xray,SIGF-obs-xray",
    file_param_name="refinement.input.xray_data.file_name") is None)
  assert (hkl_handler.get_rfree_flag_value(array_name='R-free-flags-xray',
    file_param_name="refinement.input.xray_data.r_free_flags.file_name") == 1)
  (d_max, d_min) = hkl_handler.d_max_min()
  assert approx_equal(d_max, 25.98, eps=0.01)
  assert approx_equal(d_min, 1.5, eps=0.01)
  assert hkl_handler.space_group_as_str() == "P 61 2 2"
  assert (hkl_handler.unit_cell_as_str() ==
          "30 30 40 90 90 120")
  assert (hkl_handler.unit_cell_as_str(separator=",") ==
          "30,30,40,90,90,120")

  n_refl_merged = len(f_obs_merged.indices())
  phi_array = f_obs_merged.random_phases_compatible_with_phase_restrictions(
    deg=True)
  fom_array = phi_array.array(data=flex.random_double(n_refl_merged))
  hl_data = flex.hendrickson_lattman(n_refl_merged, (0,0,0,0))
  hl_coeffs = phi_array.array(data=hl_data)
  assert (hl_coeffs.is_hendrickson_lattman_array())
  from iotbx.mtz import label_decorator
  import iotbx.mtz
  class resolve_label_decorator (label_decorator) :
    def phases (self, *args, **kwds) :
      return label_decorator.phases(self, *args, **kwds) + "M"
    def hendrickson_lattman (self, *args, **kwds) :
      return label_decorator.hendrickson_lattman(self, *args, **kwds) + "M"
  mtz_dataset = f_obs_merged.as_mtz_dataset(
    column_root_label="FP")
  mtz_dataset.add_miller_array(phi_array,
    column_root_label="PHIM",
    label_decorator=resolve_label_decorator(),
    column_types="P")
  mtz_dataset.add_miller_array(fom_array,
    column_root_label="FOMM",
    column_types="W")
  mtz_dataset.add_miller_array(hl_coeffs,
    column_root_label="HL",
    label_decorator=resolve_label_decorator())
  fwt_map = f_obs_merged.customized_copy(sigmas=None).phase_transfer(phi_array)
  mtz_dataset.add_miller_array(fwt_map,
    column_root_label="FWT",
    label_decorator=iotbx.mtz.ccp4_label_decorator())
  mtz_dataset.add_miller_array(flags,
    column_root_label="FreeR_flag")
  resolve_file = "tst_iotbx_gui_tools_resolve.mtz"
  mtz_dataset.mtz_object().write(resolve_file)
  hkl_handler = reflections.reflections_handler(
    allowed_param_names=["map_coeffs"])
  hkl_handler.set_param_file(
    file_name=resolve_file,
    file_param_name="map_coeffs")
  assert hkl_handler.has_data(file_name=resolve_file)
  l1 = hkl_handler.get_map_coeff_labels(file_name=resolve_file)
  assert (l1 == ['FWT,PHWT', 'FP,PHIM,FOMM'])
  l2 = hkl_handler.get_phase_deg_labels(file_name=resolve_file)
  assert (l2 == ['HLAM,HLBM,HLCM,HLDM', 'FWT,PHWT', 'PHIM',]), l2
  l3 = hkl_handler.get_experimental_phase_labels(file_name=resolve_file)
  #print l3
  l4 = hkl_handler.get_data_labels_for_wizard(file_name=resolve_file)
  assert (l4 == ['FP SIGFP'])
  l5 = hkl_handler.get_map_coeff_labels_for_build(file_name=resolve_file)
  assert (l5 == ['FWT,PHWT', 'FP,PHIM,FOMM']), l5
  hkl_in = hkl_handler.get_file(file_name=resolve_file)
  assert (reflections.get_mtz_label_prefix(hkl_in) == "/crystal/dataset")
  map_coeffs = reflections.map_coeffs_from_mtz_file(resolve_file,
    f_label="FP,SIGFP")
  assert map_coeffs.is_complex_array()
  try :
    map_coeffs = reflections.map_coeffs_from_mtz_file(resolve_file)
  except Sorry :
    pass
  else :
    raise Exception_expected
  assert (hkl_handler.get_map_coeff_labels_for_fft(file_name=resolve_file) ==
    ['FWT,PHWT', 'FP,SIGFP PHIM FOMM'])

  # miscellaneous utilities
  file_name = resolve_file
  hkl_in = file_reader.any_file(file_name)
  hkl_server = hkl_in.file_server
  assert approx_equal(reflections.get_high_resolution(hkl_server), 1.5,
    eps=0.0001)
  descriptions = []
  for miller_array in hkl_server.miller_arrays :
    (sg, uc) = reflections.get_miller_array_symmetry(miller_array)
    assert (uc == "30 30 40 90 90 120")
    assert (str(sg) == "P 61 2 2")
    descriptions.append(reflections.get_array_description(miller_array))
  assert (descriptions == [
    'Amplitude', 'Phases', 'Weights', 'HL coeffs', 'Map coeffs',
    'R-free flag']), descriptions
  handler = reflections.reflections_handler()
  handler.save_file(input_file=hkl_in)
  assert (not handler.has_anomalous_data())
  assert (handler.get_resolution_range(file_name=file_name)=="(25.981 - 1.500)")
  assert (handler.get_resolution_limits(file_name=file_name) ==
          ('(25.981)', '(1.500)'))
  fmodel = phi_array.array(data=flex.complex_double(n_refl_merged,
    complex(0.5,0.8)))
  m1 = phi_array.array(data=flex.complex_double(n_refl_merged, complex(1,0)))
  m2 = phi_array.array(data=flex.complex_double(n_refl_merged, complex(0.5,0)))
  m3 = phi_array.array(flex.complex_double(n_refl_merged, complex(1,1)))
  dec = label_decorator(phases_prefix="PH")
  mtz_dataset = fmodel.as_mtz_dataset(
    column_root_label="F-model",
    label_decorator=dec)
  mtz_dataset.add_miller_array(m1,
    column_root_label="2FOFCWT",
    label_decorator=dec)
  mtz_dataset.add_miller_array(m2,
    column_root_label="FOFCWT",
    label_decorator=dec)
  mtz_dataset.add_miller_array(m3,
    column_root_label="2FOFCWT_no_fill",
    label_decorator=dec)
  file_name = "tst_iotbx_gui_tools_map_coeffs.mtz"
  mtz_dataset.mtz_object().write(file_name)
  hkl_handler = reflections.reflections_handler(
    allowed_param_names=["fmodel", "map_coeffs"])
  hkl_handler.set_param_file(
    file_name=file_name,
    file_param_name="fmodel")
  assert (hkl_handler.get_fmodel_labels(file_name=file_name) ==
    ['F-model,PHF-model'])
  assert (hkl_handler.get_amplitude_labels(file_name=file_name) == [])
  phi_labels = hkl_handler.get_phase_deg_labels(file_name=file_name)
  assert (len(phi_labels)  == 4)
  phi_cols = hkl_handler.get_phase_column_labels(file_name=file_name)
  assert (phi_cols == ['PHF-model','PH2FOFCWT','PHFOFCWT','PH2FOFCWT_no_fill'])
  assert (len(hkl_handler.get_amplitude_column_labels(file_name=file_name,
              allow_conversion=True)) == 0)
  fc_cols = hkl_handler.get_fmodel_labels(file_name=file_name,
    first_column_only=True)
  assert (fc_cols == ['F-model'])
  hkl_server = file_reader.any_file(file_name).file_server
  map_labels = reflections.get_map_coeff_labels(hkl_server)
  assert (map_labels == ['2FOFCWT,PH2FOFCWT', 'FOFCWT,PHFOFCWT',
    '2FOFCWT_no_fill,PH2FOFCWT_no_fill',])
  map_labels = reflections.get_map_coeffs_for_build(hkl_server)
  assert map_labels == ['2FOFCWT,PH2FOFCWT','2FOFCWT_no_fill,PH2FOFCWT_no_fill']
  map_coeffs = reflections.extract_phenix_refine_map_coeffs(file_name)
  assert (len(map_coeffs) == 3)
  hkl_file = file_reader.any_file(file_name)
  assert reflections.get_mtz_label_prefix(hkl_file) == "/crystal/dataset"
  # other stuff
  (fp, fpp) = reflections.get_fp_fpp_from_sasaki("Se", 0.979)
  assert fp is not None and fpp is not None