Ejemplo n.º 1
0
    def rfree(self, override=False):
        if not override:
            for m_a in self.miller_arrays:
                if looks_like_r_free_flags_info(m_a.info()):
                    raise RuntimeError(
                        "R-free column already found in {0}. Set override to true to generate a new"
                        "R-free column.")

        for m_a in self.miller_arrays:
            if looks_like_r_free_flags_info(m_a.info()):
                self.delete(m_a.info().labels)

        rfree_m_a = self.miller_arrays[0].generate_r_free_flags(format='ccp4')
        self.miller_arrays['FreeR_flag'] = rfree_m_a
Ejemplo n.º 2
0
def get_array_description(miller_array):
    from iotbx import reflection_file_utils
    info = miller_array.info()
    labels = info.label_string()
    if labels in ["PHI", "PHIB", "PHIM", "PHIC"]:
        return "Phases"
    if labels in ["FOM", "FOMM"]:
        return "Weights"
    if ((miller_array.is_integer_array() or miller_array.is_bool_array())
            and reflection_file_utils.looks_like_r_free_flags_info(info)):
        return "R-free flag"
    methods_and_meanings = [
        ("is_complex_array", "Map coeffs"),
        ("is_xray_amplitude_array", "Amplitude"),
        ("is_xray_intensity_array", "Intensity"),
        ("is_hendrickson_lattman_array", "HL coeffs"),
        ("is_bool_array", "Boolean"),
        ("is_integer_array", "Integer"),
        ("is_real_array", "Floating-point"),
    ]
    for method, desc in methods_and_meanings:
        test = getattr(miller_array, method)
        if test():
            return desc
    return "Unknown"
Ejemplo n.º 3
0
def get_array_description(miller_array):
    from iotbx import reflection_file_utils
    info = miller_array.info()
    labels = info.label_string()
    if labels in ["PHI", "PHIB", "PHIM", "PHIC"]:
        return "Phases"
    if labels in ["FOM", "FOMM"]:
        return "Weights"
    if ((miller_array.is_integer_array() or miller_array.is_bool_array())
            and reflection_file_utils.looks_like_r_free_flags_info(info)):
        return "R-free flag"
    methods_and_meanings = [("is_complex_array", "Map coeffs"),
                            ("is_xray_amplitude_array", "Amplitude"),
                            ("is_xray_reconstructed_amplitude_array",
                             "Amplitude"),
                            ("is_xray_intensity_array", "Intensity"),
                            ("is_hendrickson_lattman_array", "HL coeffs"),
                            ("is_bool_array", "Boolean"),
                            ("is_integer_array", "Integer"),
                            ("is_real_array", "Floating-point"),
                            ("is_string_array", "String")]
    for method, desc in methods_and_meanings:
        test = getattr(miller_array, method)
        if test():
            return desc
    # resort to the name of the python data type if not matching any of the above
    return type(miller_array.data()).__name__
Ejemplo n.º 4
0
 def detect_Rfree(self, array):
   from iotbx.reflection_file_utils import looks_like_r_free_flags_info
   info = array.info()
   if (array.is_integer_array()) and (looks_like_r_free_flags_info(info)) :
     from iotbx.reflection_file_utils import get_r_free_flags_scores
     score_array = get_r_free_flags_scores([array], None)
     test_flag_value = score_array.test_flag_values[0]
     array = array.customized_copy(data=(array.data() == test_flag_value))
     array.set_info(info)
   return array
Ejemplo n.º 5
0
 def process_miller_array(self, array):
     if (array is None): return
     if (array.is_hendrickson_lattman_array()):
         raise Sorry("Hendrickson-Lattman coefficients are not supported.")
     info = array.info()
     if isinstance(info, str):
         labels = "TEST DATA"
     else:
         labels = info.label_string()
     if self.settings.unit_cell is not None:
         symm = crystal.symmetry(unit_cell=self.settings.unit_cell,
                                 space_group=array.space_group())
         array = array.customized_copy(crystal_symmetry=symm).set_info(info)
     if self.settings.space_group is not None:
         symm = crystal.symmetry(
             unit_cell=array.unit_cell(),
             space_group=self.settings.space_group.group())
         array = array.customized_copy(crystal_symmetry=symm).set_info(info)
     if (array.unit_cell() is None) or (array.space_group() is None):
         dlg = wxtbx.symmetry_dialog.SymmetryDialog(self, -1,
                                                    "Enter symmetry")
         dlg.SetUnitCell(array.unit_cell())
         dlg.SetSpaceGroup(array.space_group_info())
         if (dlg.ShowModal() == wx.ID_OK):
             symm = dlg.GetSymmetry()
             array = array.customized_copy(
                 crystal_symmetry=symm).set_info(info)
         wx.CallAfter(dlg.Destroy)
     details = []
     merge = True
     details.append("merged")
     self.update_settings_for_merged(True)
     if array.is_complex_array():
         array = array.amplitudes().set_info(info)
         details.append("as amplitudes")
     from iotbx.reflection_file_utils import looks_like_r_free_flags_info
     if (array.is_integer_array()) and (looks_like_r_free_flags_info(info)):
         from iotbx.reflection_file_utils import get_r_free_flags_scores
         score_array = get_r_free_flags_scores([array], None)
         test_flag_value = score_array.test_flag_values[0]
         array = array.customized_copy(
             data=(array.data() == test_flag_value))
         array.set_info(info)
     sg = "%s" % array.space_group_info()
     uc = "a=%g b=%g c=%g angles=%g,%g,%g" % array.unit_cell().parameters()
     details_str = ""
     if (len(details) > 0):
         details_str = "(%s)" % ", ".join(details)
     array_info = group_args(labels=labels,
                             details_str=details_str,
                             merge=merge,
                             sg=sg,
                             uc=uc)
     return array, array_info
Ejemplo n.º 6
0
 def detect_Rfree(self, array):
   from iotbx.reflection_file_utils import looks_like_r_free_flags_info
   info = array.info()
   if (array.is_integer_array()) and (looks_like_r_free_flags_info(info)) :
     from iotbx.reflection_file_utils import get_r_free_flags_scores
     score_array = get_r_free_flags_scores([array], None)
     test_flag_value = score_array.test_flag_values[0]
     if test_flag_value not in array.data():
       return array # for the few cases where a miller array cannot be considered as a valid Rfree array
     array = array.customized_copy(data=(array.data() == test_flag_value))
     array.set_info(info)
     array._data = array.data().as_int()
   return array
Ejemplo n.º 7
0
    def run(self, mtz_file):
        reflection_file = reflection_file_reader.any_reflection_file(
            file_name=mtz_file)
        if not reflection_file.file_type() == "ccp4_mtz":
            msg = "File is not of type ccp4_mtz: {0}".format(mtz_file)
            logging.critical(msg)
            raise RuntimeError(msg)

        miller_arrays = reflection_file.as_miller_arrays()

        for m_a in miller_arrays:
            if looks_like_r_free_flags_info(m_a.info()) and not self.free:
                self.free = m_a.info().labels[0]
            elif self.check_anomalous(m_a):
                if self.check_for_dano_labels(m_a):
                    if len(m_a.info().labels) == 5:
                        self.f, self.sigf, self.dano, self.sigdano, isym = m_a.info(
                        ).labels
                    elif len(m_a.info().labels) == 4:
                        self.f, self.sigf, self.dano, self.sigdano = m_a.info(
                        ).labels
                    elif len(m_a.info().labels) == 2:
                        self.dano, self.sigdano = m_a.info().labels
                    else:
                        msg = "Unexpected number of columns found in anomalous miller array"
                        logging.debug(msg)
                elif self.check_for_plus_minus_labels(m_a):
                    if m_a.is_xray_amplitude_array():
                        self.fplus, self.sigfplus, self.fminus, self.sigfminus = m_a.info(
                        ).labels
                    elif m_a.is_xray_intensity_array():
                        self.iplus, self.sigiplus, self.iminus, self.sigiminus = m_a.info(
                        ).labels
                    else:
                        msg = "Type of anomalous miller array unknown"
                        logging.debug(msg)
                else:
                    msg = "Type of anomalous miller array unknown"
                    logging.debug(msg)
            elif m_a.is_xray_intensity_array() and len(
                    m_a.info().labels) == 2 and not self.i:
                self.i, self.sigi = m_a.info().labels
            elif m_a.is_xray_amplitude_array() and len(
                    m_a.info().labels) == 2 and not self.f:
                self.f, self.sigf = m_a.info().labels
            else:
                pass
Ejemplo n.º 8
0
 def __init__(self, file_name=None, miller_arrays=()):
     assert (file_name is not None) or (len(miller_arrays) > 0)
     self.file_name = file_name
     self.miller_arrays = miller_arrays
     if (len(self.miller_arrays) == 0):
         from iotbx import file_reader
         f = file_reader.any_file(file_name, force_type="hkl")
         f.assert_file_type("hkl")
         self.miller_arrays = f.file_server.miller_arrays
     assert (len(self.miller_arrays) > 0)
     self.map_coeffs = []
     self.array_labels = []
     self.data_arrays = []
     self.phase_arrays = []
     self.weight_arrays = []
     self.rfree_arrays = []
     self.fcalc_arrays = []
     self._pdb_cache = {}
     from iotbx.reflection_file_utils import looks_like_r_free_flags_info
     for array in self.miller_arrays:
         labels = array.info().label_string()
         self.array_labels.append(labels)
         if (array.is_xray_amplitude_array()
                 or array.is_xray_intensity_array()):
             if (labels.startswith("FC")):
                 self.fcalc_arrays.append(array)
             else:
                 self.data_arrays.append(array)
         elif (array.is_complex_array()):
             if (labels.startswith("FC") or labels.startswith("FMODEL")
                     or labels.startswith("F-model")):
                 self.fcalc_arrays.append(array)
             else:
                 self.map_coeffs.append(array)
         elif (array.is_real_array()):
             if (labels.startswith("PH")):
                 self.phase_arrays.append(array)
             elif (labels.startswith("FOM")):
                 self.weight_arrays.append(array)
         elif (array.is_bool_array()):
             self.rfree_arrays.append(array)
         elif (array.is_integer_array()):
             if (looks_like_r_free_flags_info(array.info())):
                 self.rfree_arrays.append(array)
Ejemplo n.º 9
0
 def __init__ (self, file_name=None, miller_arrays=()) :
   assert (file_name is not None) or (len(miller_arrays) > 0)
   self.file_name = file_name
   self.miller_arrays = miller_arrays
   if (len(self.miller_arrays) == 0) :
     from iotbx import file_reader
     f = file_reader.any_file(file_name, force_type="hkl")
     f.assert_file_type("hkl")
     self.miller_arrays = f.file_server.miller_arrays
   assert (len(self.miller_arrays) > 0)
   self.map_coeffs = []
   self.array_labels = []
   self.data_arrays = []
   self.phase_arrays = []
   self.weight_arrays = []
   self.rfree_arrays = []
   self.fcalc_arrays = []
   self._pdb_cache = {}
   from iotbx.reflection_file_utils import looks_like_r_free_flags_info
   for array in self.miller_arrays :
     labels = array.info().label_string()
     self.array_labels.append(labels)
     if (array.is_xray_amplitude_array() or array.is_xray_intensity_array()) :
       if (labels.startswith("FC")) :
         self.fcalc_arrays.append(array)
       else :
         self.data_arrays.append(array)
     elif (array.is_complex_array()) :
       if (labels.startswith("FC") or labels.startswith("FMODEL") or
           labels.startswith("F-model")) :
         self.fcalc_arrays.append(array)
       else :
         self.map_coeffs.append(array)
     elif (array.is_real_array()) :
       if (labels.startswith("PH")) :
         self.phase_arrays.append(array)
       elif (labels.startswith("FOM")) :
         self.weight_arrays.append(array)
     elif (array.is_bool_array()) :
       self.rfree_arrays.append(array)
     elif (array.is_integer_array()) :
       if (looks_like_r_free_flags_info(array.info())) :
         self.rfree_arrays.append(array)
Ejemplo n.º 10
0
def get_array_description (miller_array) :
  from iotbx import reflection_file_utils
  info = miller_array.info()
  labels = info.label_string()
  if labels in ["PHI", "PHIB", "PHIM", "PHIC"] :
    return "Phases"
  if labels in ["FOM", "FOMM"] :
    return "Weights"
  if ((miller_array.is_integer_array() or miller_array.is_bool_array()) and
      reflection_file_utils.looks_like_r_free_flags_info(info)) :
    return "R-free flag"
  methods_and_meanings = [ ("is_complex_array", "Map coeffs"),
                           ("is_xray_amplitude_array", "Amplitude"),
                           ("is_xray_intensity_array", "Intensity"),
                           ("is_hendrickson_lattman_array", "HL coeffs"),
                           ("is_bool_array", "Boolean"),
                           ("is_integer_array", "Integer"),
                           ("is_real_array", "Floating-point"), ]
  for method, desc in methods_and_meanings :
    test = getattr(miller_array, method)
    if test() :
      return desc
  return "Unknown"
Ejemplo n.º 11
0
    def __init__(self,
                 mtz_object,
                 custom_cif_labels_dict=None,
                 log=None,
                 test_flag_value=None):

        self.cif_blocks = {'xray': None, 'neutron': None}

        if log is None: log = sys.stdout

        miller_arrays = mtz_object.as_miller_arrays()

        miller_arrays_as_cif_block = None

        input_observations_xray = None
        input_observations_neutron = None
        r_free_xray = None
        r_free_neutron = None
        f_obs_filtered_xray = None
        f_obs_filtered_neutron = None

        mtz_to_cif_labels_dict = {}
        mtz_to_cif_labels_dict.update(phenix_to_cif_labels_dict)
        mtz_to_cif_labels_dict.update(ccp4_to_cif_labels_dict)
        if custom_cif_labels_dict is not None:
            mtz_to_cif_labels_dict.update(custom_cif_labels_dict)

        unknown_mtz_labels = []

        for array in miller_arrays:
            labels = array.info().labels
            label = labels[0]
            if reflection_file_utils.looks_like_r_free_flags_info(
                    array.info()):
                if "(+)" in label:
                    array = array.average_bijvoet_mates()
                    labels = [label.replace("(+)", "")]
                if label.endswith(("neutron", "_N")):
                    r_free_neutron = array
                else:
                    r_free_xray = array
                continue  # deal with these later
            elif label.startswith("F-obs-filtered"):
                if label.endswith(("neutron", "_N")):
                    f_obs_filtered_neutron = array
                else:
                    f_obs_filtered_xray = array
            elif label.startswith("F-obs") or label.startswith("I-obs"):
                if label.strip("(+)").endswith(("neutron", "_N")):
                    input_observations_neutron = array
                else:
                    input_observations_xray = array
            #elif label.startswith("R-free-flags"):
            column_names = []
            for mtz_label in labels:
                cif_label = mtz_to_cif_label(mtz_to_cif_labels_dict, mtz_label)
                column_names.append(cif_label)
            if column_names.count(None) > 0:
                # I don't know what to do with this array
                for i, mtz_label in enumerate(labels):
                    if column_names[i] is None:
                        unknown_mtz_labels.append(mtz_label)
                continue
            assert column_names.count(None) == 0
            if labels[0].strip("(+)").endswith(("neutron", "_N")):
                data_type = "neutron"
            else:
                data_type = "xray"
            if column_names[0].startswith(
                ("_refln.F_meas", "_refln.F_squared_meas", "_refln.pdbx_F_",
                 "_refln.pdbx_I_")):
                if data_type == "neutron":
                    input_observations_neutron = array
                else:
                    input_observations_xray = array

            if self.cif_blocks.get(data_type) is None:
                self.cif_blocks[
                    data_type] = iotbx.cif.miller_arrays_as_cif_block(
                        array=array, column_names=column_names, format="mmcif")
            else:
                self.cif_blocks[data_type].add_miller_array(
                    array, column_names=column_names)

        if len(unknown_mtz_labels):
            print >> log, "Warning: Unknown mtz label%s: %s" % (plural_s(
                len(unknown_mtz_labels))[1], ", ".join(unknown_mtz_labels))
            print >> log, "  Use mtz_labels and cif_labels keywords to provide translation for custom labels."

        data_types = set(["xray"])
        if self.cif_blocks['neutron'] is not None:
            data_types.add("neutron")

        if input_observations_xray is None and f_obs_filtered_xray is not None:
            self.cif_blocks["xray"].add_miller_array(
                array=f_obs_filtered_xray,
                column_names=('_refln.F_meas_au', '_refln.F_meas_sigma_au'))
        if input_observations_neutron is None and f_obs_filtered_neutron is not None:
            self.cif_blocks["neutron"].add_miller_array(
                array=f_obs_filtered_neutron,
                column_names=('_refln.F_meas_au', '_refln.F_meas_sigma_au'))

        for data_type in data_types:
            if data_type == "xray":
                r_free = r_free_xray
                input_obs = input_observations_xray
                f_obs_filtered = f_obs_filtered_xray
                if (self.cif_blocks["xray"] is None and r_free_xray is not None
                        and self.cif_blocks["neutron"] is not None
                        and r_free_neutron is None):
                    r_free_neutron = r_free_xray
            elif data_type == "neutron":
                r_free = r_free_neutron
                input_obs = input_observations_neutron
                f_obs_filtered = f_obs_filtered_neutron
            if self.cif_blocks[data_type] is not None and r_free is not None:
                self.cif_blocks[data_type].add_miller_array(
                    array=r_free, column_name='_refln.pdbx_r_free_flag')

            if input_obs is None or r_free is None: continue
            if (test_flag_value is None):
                test_flag_value = reflection_file_utils.guess_r_free_flag_value(
                    miller_array=r_free)
            assert (test_flag_value is not None)
            refln_status = r_free.array(
                data=flex.std_string(r_free.size(), "."))
            input_obs_non_anom = input_obs.average_bijvoet_mates()
            match = r_free.match_indices(input_obs_non_anom)
            refln_status.data().set_selected(match.pair_selection(0), "o")
            refln_status.data().set_selected(r_free.data() == test_flag_value,
                                             "f")
            if f_obs_filtered is not None:
                f_obs_filtered_non_anom = f_obs_filtered.average_bijvoet_mates(
                )
                match = r_free.match_indices(f_obs_filtered_non_anom)
                refln_status.data().set_selected(match.single_selection(0),
                                                 "<")  # XXX
            self.cif_blocks[data_type].add_miller_array(
                array=refln_status, column_name="_refln.status")
Ejemplo n.º 12
0
 def process_miller_array(self, array):
     if (array is None): return
     if (array.is_hendrickson_lattman_array()):
         raise Sorry("Hendrickson-Lattman coefficients are not supported.")
     info = array.info()
     if isinstance(info, str):
         labels = "TEST DATA"
     else:
         labels = info.label_string()
     if (array.unit_cell() is None) or (array.space_group() is None):
         dlg = wxtbx.symmetry_dialog.SymmetryDialog(self, -1,
                                                    "Enter symmetry")
         dlg.SetUnitCell(array.unit_cell())
         dlg.SetSpaceGroup(array.space_group_info())
         if (dlg.ShowModal() == wx.ID_OK):
             symm = dlg.GetSymmetry()
             array = array.customized_copy(
                 crystal_symmetry=symm).set_info(info)
         wx.CallAfter(dlg.Destroy)
     details = []
     merge = None
     if (not array.is_unique_set_under_symmetry()):
         merge = wx.MessageBox(
             "The data in the selected array are not symmetry-" +
             "unique, which usually means they are unmerged (but could also be due "
             +
             "to different indexing conventions).  Do you want to merge equivalent "
             +
             "observations (preserving anomalous data if present), or view the "
             +
             "array unmodified?  (Note that if you do not merge the array, the "
             +
             "options to expand to P1 or generate Friedel pairs will be be disabled"
             +
             ", and the 2D view will only show indices present in the file, rather "
             + "than a full pseudo-precession view.)",
             style=wx.YES_NO)
         if (merge == wx.YES):
             merge = True
             #array = array.merge_equivalents().array().set_info(info)
             details.append("merged")
             self.update_settings_for_merged(True)
         else:
             merge = False
             details.append("unmerged data")
             self.update_settings_for_unmerged()
     else:
         self.update_settings_for_merged()
     if array.is_complex_array():
         array = array.amplitudes().set_info(info)
         details.append("as amplitudes")
     from iotbx.reflection_file_utils import looks_like_r_free_flags_info
     if (array.is_integer_array()) and (looks_like_r_free_flags_info(info)):
         from iotbx.reflection_file_utils import get_r_free_flags_scores
         score_array = get_r_free_flags_scores([array], None)
         test_flag_value = score_array.test_flag_values[0]
         array = array.customized_copy(
             data=(array.data() == test_flag_value))
         array.set_info(info)
     sg = "%s" % array.space_group_info()
     uc = "a=%g b=%g c=%g angles=%g,%g,%g" % array.unit_cell().parameters()
     details_str = ""
     if (len(details) > 0):
         details_str = "(%s)" % ", ".join(details)
     array_info = group_args(labels=labels,
                             details_str=details_str,
                             merge=merge,
                             sg=sg,
                             uc=uc)
     return array, array_info
Ejemplo n.º 13
0
 def process_miller_array (self, array) :
   if (array is None) : return
   if (array.is_hendrickson_lattman_array()) :
     raise Sorry("Hendrickson-Lattman coefficients are not supported.")
   info = array.info()
   if isinstance(info, str) :
     labels = "TEST DATA"
   else :
     labels = info.label_string()
   if (array.unit_cell() is None) or (array.space_group() is None) :
     dlg = wxtbx.symmetry_dialog.SymmetryDialog(self, -1, "Enter symmetry")
     dlg.SetUnitCell(array.unit_cell())
     dlg.SetSpaceGroup(array.space_group_info())
     if (dlg.ShowModal() == wx.ID_OK) :
       symm = dlg.GetSymmetry()
       array = array.customized_copy(crystal_symmetry=symm).set_info(info)
     wx.CallAfter(dlg.Destroy)
   details = []
   merge = None
   if (not array.is_unique_set_under_symmetry()) :
     merge = wx.MessageBox("The data in the selected array are not symmetry-"+
       "unique, which usually means they are unmerged (but could also be due "+
       "to different indexing conventions).  Do you want to merge equivalent "+
       "observations (preserving anomalous data if present), or view the "+
       "array unmodified?  (Note that if you do not merge the array, the "+
       "options to expand to P1 or generate Friedel pairs will be be disabled"+
       ", and the 2D view will only show indices present in the file, rather "+
       "than a full pseudo-precession view.)",
       style=wx.YES_NO)
     if (merge == wx.YES) :
       merge = True
       #array = array.merge_equivalents().array().set_info(info)
       details.append("merged")
       self.update_settings_for_merged(True)
     else :
       merge = False
       details.append("unmerged data")
       self.update_settings_for_unmerged()
   else :
     self.update_settings_for_merged()
   if array.is_complex_array() :
     array = array.amplitudes().set_info(info)
     details.append("as amplitudes")
   from iotbx.reflection_file_utils import looks_like_r_free_flags_info
   if (array.is_integer_array()) and (looks_like_r_free_flags_info(info)) :
     from iotbx.reflection_file_utils import get_r_free_flags_scores
     score_array = get_r_free_flags_scores([array], None)
     test_flag_value = score_array.test_flag_values[0]
     array = array.customized_copy(data=(array.data() == test_flag_value))
     array.set_info(info)
   sg = "%s" % array.space_group_info()
   uc = "a=%g b=%g c=%g angles=%g,%g,%g" % array.unit_cell().parameters()
   details_str = ""
   if (len(details) > 0) :
     details_str = "(%s)" % ", ".join(details)
   array_info = group_args(
     labels=labels,
     details_str=details_str,
     merge=merge,
     sg=sg,
     uc=uc)
   return array, array_info
Ejemplo n.º 14
0
  def __init__(self, mtz_object, custom_cif_labels_dict=None, log=None,
      test_flag_value=None):

    self.cif_blocks = {
      'xray': None,
      'neutron': None
    }

    if log is None: log = sys.stdout

    miller_arrays = mtz_object.as_miller_arrays()

    miller_arrays_as_cif_block = None

    input_observations_xray = None
    input_observations_neutron = None
    r_free_xray = None
    r_free_neutron = None
    f_obs_filtered_xray = None
    f_obs_filtered_neutron = None

    mtz_to_cif_labels_dict = {}
    mtz_to_cif_labels_dict.update(phenix_to_cif_labels_dict)
    mtz_to_cif_labels_dict.update(ccp4_to_cif_labels_dict)
    if custom_cif_labels_dict is not None:
      mtz_to_cif_labels_dict.update(custom_cif_labels_dict)

    unknown_mtz_labels = []

    for array in miller_arrays:
      labels = array.info().labels
      label = labels[0]
      if reflection_file_utils.looks_like_r_free_flags_info(array.info()):
        if "(+)" in label:
          array = array.average_bijvoet_mates()
          labels = [label.replace("(+)", "")]
        if label.endswith(("neutron", "_N")):
          r_free_neutron = array
        else:
          r_free_xray = array
        continue # deal with these later
      elif label.startswith("F-obs-filtered"):
        if label.endswith(("neutron", "_N")):
          f_obs_filtered_neutron = array
        else:
          f_obs_filtered_xray = array
      elif label.startswith("F-obs") or label.startswith("I-obs"):
        if label.strip("(+)").endswith(("neutron", "_N")):
          input_observations_neutron = array
        else:
          input_observations_xray = array
      #elif label.startswith("R-free-flags"):
      column_names = []
      for mtz_label in labels:
        cif_label = mtz_to_cif_label(mtz_to_cif_labels_dict, mtz_label)
        column_names.append(cif_label)
      if column_names.count(None) > 0:
        # I don't know what to do with this array
        for i, mtz_label in enumerate(labels):
          if column_names[i] is None:
            unknown_mtz_labels.append(mtz_label)
        continue
      assert column_names.count(None) == 0
      if labels[0].strip("(+)").endswith(("neutron", "_N")):
        data_type = "neutron"
      else:
        data_type = "xray"
      if column_names[0].startswith(("_refln.F_meas",
                                     "_refln.F_squared_meas",
                                     "_refln.pdbx_F_",
                                     "_refln.pdbx_I_")):
        if data_type == "neutron":
          input_observations_neutron = array
        else:
          input_observations_xray = array

      if self.cif_blocks.get(data_type) is None:
        self.cif_blocks[data_type] = iotbx.cif.miller_arrays_as_cif_block(
          array=array, column_names=column_names, format="mmcif")
      else:
        self.cif_blocks[data_type].add_miller_array(array, column_names=column_names)

    if len(unknown_mtz_labels):
      print >> log, "Warning: Unknown mtz label%s: %s" %(
        plural_s(len(unknown_mtz_labels))[1], ", ".join(unknown_mtz_labels))
      print >> log, "  Use mtz_labels and cif_labels keywords to provide translation for custom labels."

    data_types = set(["xray"])
    if self.cif_blocks['neutron'] is not None:
      data_types.add("neutron")

    if input_observations_xray is None and f_obs_filtered_xray is not None:
      self.cif_blocks["xray"].add_miller_array(
        array=f_obs_filtered_xray,
        column_names=('_refln.F_meas_au','_refln.F_meas_sigma_au'))
    if input_observations_neutron is None and f_obs_filtered_neutron is not None:
      self.cif_blocks["neutron"].add_miller_array(
        array=f_obs_filtered_neutron,
        column_names=('_refln.F_meas_au','_refln.F_meas_sigma_au'))

    for data_type in data_types:
      if data_type == "xray":
        r_free = r_free_xray
        input_obs = input_observations_xray
        f_obs_filtered = f_obs_filtered_xray
        if (self.cif_blocks["xray"] is None and r_free_xray is not None and
            self.cif_blocks["neutron"] is not None and r_free_neutron is None):
          r_free_neutron = r_free_xray
      elif data_type == "neutron":
        r_free = r_free_neutron
        input_obs = input_observations_neutron
        f_obs_filtered = f_obs_filtered_neutron
      if self.cif_blocks[data_type] is not None and r_free is not None:
        self.cif_blocks[data_type].add_miller_array(
          array=r_free, column_name='_refln.pdbx_r_free_flag')

      if input_obs is None or r_free is None: continue
      if (test_flag_value is None) :
        test_flag_value = reflection_file_utils.guess_r_free_flag_value(
          miller_array=r_free)
      assert (test_flag_value is not None)
      refln_status = r_free.array(data=flex.std_string(r_free.size(), "."))
      input_obs_non_anom = input_obs.average_bijvoet_mates()
      match = r_free.match_indices(input_obs_non_anom)
      refln_status.data().set_selected(match.pair_selection(0), "o")
      refln_status.data().set_selected(r_free.data() == test_flag_value, "f")
      if f_obs_filtered is not None:
        f_obs_filtered_non_anom = f_obs_filtered.average_bijvoet_mates()
        match = r_free.match_indices(f_obs_filtered_non_anom)
        refln_status.data().set_selected(match.single_selection(0), "<") # XXX
      self.cif_blocks[data_type].add_miller_array(
        array=refln_status, column_name="_refln.status")
Ejemplo n.º 15
0
 def reindex(self, sg):
     for m_a in self.miller_arrays:
         if not looks_like_r_free_flags_info(m_a.info()):
             m_a.change_symmetry(sg)