Ejemplo n.º 1
0
 def as_miller_arrays(self,
       crystal_symmetry=None,
       force_symmetry=False,
       merge_equivalents=True,
       base_array_info=None,
       include_unmerged_data=False,
       anomalous=None,
       reconstruct_amplitudes=True
       ):
   assert not include_unmerged_data, "Unmerged data not supported in MTZ"
   other_symmetry = crystal_symmetry
   if (base_array_info is None):
     base_array_info = miller.array_info(source_type="ccp4_mtz")
   result = []
   for crystal in self.crystals():
     try :
       unit_cell = crystal.unit_cell()
     except ValueError as e :
       raise Sorry(str(e))
     crystal_symmetry_from_file = cctbx.crystal.symmetry(
       unit_cell=unit_cell,
       space_group_info=self.space_group_info(),
       raise_sorry_if_incompatible_unit_cell=True)
     crystal_symmetry = crystal_symmetry_from_file.join_symmetry(
       other_symmetry=other_symmetry,
       force=force_symmetry)
     for dataset in crystal.datasets():
       base_dataset_info = base_array_info.customized_copy(
         wavelength=dataset.wavelength())
       column_groups = self.group_columns(
         crystal_symmetry_from_file=crystal_symmetry_from_file,
         crystal_symmetry=crystal_symmetry,
         base_array_info=base_dataset_info,
         dataset=dataset,
         anomalous=anomalous,
         reconstruct_amplitudes=reconstruct_amplitudes
       )
       for column_group in column_groups:
         if (merge_equivalents
             and isinstance(column_group.data(), flex.double)
             and isinstance(column_group.sigmas(), flex.double)
             and column_group.sigmas().size() != 0
             and flex.min(column_group.sigmas()) > 0):
           merged_column_group = column_group.merge_equivalents().array()
           if (merged_column_group.indices().size()
               != column_group.indices().size()):
             merged_column_group.set_info(
               column_group.info().customized_copy(merged=True))
             column_group = merged_column_group
         result.append(column_group)
   return result
Ejemplo n.º 2
0
 def show_summary(self, out=None, prefix=""):
   if (out is None): out = sys.stdout
   p = prefix
   print >> out, p+"Title:", self.title()
   print >> out, p+"Space group symbol from file:", self.space_group_name()
   print >> out, p+"Space group number from file:", self.space_group_number()
   self.space_group_info().show_summary(
     f=out, prefix=p+"Space group from matrices: ")
   print >> out, p+"Point group symbol from file:", self.point_group_name()
   if (self.n_batches() > 0):
     print >> out, p+"Number of batches:", self.n_batches()
   print >> out, p+"Number of crystals:", self.n_crystals()
   print >> out, p+"Number of Miller indices:", self.n_reflections()
   if (self.n_crystals() > 0 and self.n_reflections() > 0):
     print >> out, p+"Resolution range: %.6g %.6g" % self.max_min_resolution()
   print >> out, p+"History:"
   for line in self.history():
     print >> out, p+" ", line.rstrip()
   for i_crystal,crystal in enumerate(self.crystals()):
     print >> out, p+"Crystal %d:" % (i_crystal+1)
     print >> out, p+"  Name:", crystal.name()
     print >> out, p+"  Project:", crystal.project_name()
     print >> out, p+"  Id:", crystal.id()
     crystal.unit_cell().show_parameters(f=out, prefix=p+"  Unit cell: ")
     print >> out, p+"  Number of datasets:", crystal.n_datasets()
     for i_dataset,dataset in enumerate(crystal.datasets()):
       print >> out, p+"  Dataset %d:" % (i_dataset+1)
       print >> out, p+"    Name:", dataset.name()
       print >> out, p+"    Id:", dataset.id()
       print >> out, p+"    Wavelength: %.6g" % dataset.wavelength()
       print >> out, p+"    Number of columns:", dataset.n_columns()
       if (dataset.n_columns() > 0):
         fields_list = [[
           "label", "#valid", "%valid", "min", "max", "type", ""]]
         max_field_lengths = [len(field) for field in fields_list[0]]
         max_field_lengths[-2] = 0
         for i_column,column in enumerate(dataset.columns()):
           fields = column.format_fields_for_mtz_dump(
             n_refl=self.n_reflections())
           fields_list.append(fields)
           for i,field in enumerate(fields):
             max_field_lengths[i] = max(max_field_lengths[i], len(field))
         format = "    %%-%ds %%%ds %%%ds %%%ds %%%ds %%%ds %%s" % tuple(
           max_field_lengths[:6])
         for fields in fields_list:
           print >> out, p+(format % tuple(fields)).rstrip()
   return self
Ejemplo n.º 3
0
 def as_miller_arrays(self,
       crystal_symmetry=None,
       force_symmetry=False,
       merge_equivalents=True,
       base_array_info=None,
       include_unmerged_data=False,
       ):
   assert not include_unmerged_data, "Unmerged data not supported in MTZ"
   other_symmetry = crystal_symmetry
   if (base_array_info is None):
     base_array_info = miller.array_info(source_type="ccp4_mtz")
   result = []
   for crystal in self.crystals():
     try :
       unit_cell = crystal.unit_cell()
     except ValueError, e :
       raise Sorry(str(e))
     crystal_symmetry_from_file = cctbx.crystal.symmetry(
       unit_cell=unit_cell,
       space_group_info=self.space_group_info(),
       raise_sorry_if_incompatible_unit_cell=True)
     crystal_symmetry = crystal_symmetry_from_file.join_symmetry(
       other_symmetry=other_symmetry,
       force=force_symmetry)
     for dataset in crystal.datasets():
       base_dataset_info = base_array_info.customized_copy(
         wavelength=dataset.wavelength())
       column_groups = self.group_columns(
         crystal_symmetry_from_file=crystal_symmetry_from_file,
         crystal_symmetry=crystal_symmetry,
         base_array_info=base_dataset_info,
         dataset=dataset)
       for column_group in column_groups:
         if (merge_equivalents
             and isinstance(column_group.data(), flex.double)
             and isinstance(column_group.sigmas(), flex.double)
             and column_group.sigmas().size() != 0
             and flex.min(column_group.sigmas()) > 0):
           merged_column_group = column_group.merge_equivalents().array()
           if (merged_column_group.indices().size()
               != column_group.indices().size()):
             merged_column_group.set_info(
               column_group.info().customized_copy(merged=True))
             column_group = merged_column_group
         result.append(column_group)
Ejemplo n.º 4
0
def measure(hklin, spacegroup):
  '''Look at HKLIN, see how strong the absences (according to the given
  spacegroup) are... looking for IPR / SIGIPR.'''

  mtz_obj = mtz.object(hklin)

  sg = sgtbx.space_group(sgtbx.space_group_symbols(spacegroup).hall())
  mi = mtz_obj.extract_miller_indices()
  sg_m = mtz_obj.space_group()

  ipr_column = None
  sigipr_column = None

  for crystal in mtz_obj.crystals():
    for dataset in crystal.datasets():
      for column in dataset.columns():

        if column.label() == 'IPR':
          ipr_column = column
        elif column.label() == 'SIGIPR':
          sigipr_column = column

  assert(ipr_column != None)
  assert(sigipr_column != None)

  ipr_values = ipr_column.extract_values(not_a_number_substitute = 0.0)
  sigipr_values = sigipr_column.extract_values(not_a_number_substitute = 0.0)

  present = []
  absent = []

  for j in range(mi.size()):
    hkl = mi[j]

    if sg.is_sys_absent(hkl):
      absent.append(ipr_values[j] / sigipr_values[j])
    else:
      present.append(ipr_values[j] / sigipr_values[j])

  print 'A: %f' % (sum(absent) / len(absent))
  print 'P: %f' % (sum(present) / len(present))
Ejemplo n.º 5
0
  def as_miller_arrays_dict(self,
                            crystal_symmetry=None,
                            force_symmetry=False,
                            merge_equivalents=True,
                            base_array_info=None,
                            anomalous=None):
    """
    Returns a python dictionary with keys of tuples containing
    (crystal name, dataset name, column label) and values of
    the Miller arrays from :func:`as_miller_arrays`.

    The arguments to :func:`as_miller_arrays_dict` are the same
    as :func:`as_miller_arrays`.

    >>> miller_dict = mtz_file.as_miller_arrays_dict()
    >>> miller_dict[('NATIVE', 'NATIVE', 'FTOXD3')]
    <cctbx.miller.array at 0x108a87b90>
    >>> miller_dict[('NATIVE', 'NATIVE', 'SIGFTOXD3')]
    <cctbx.miller.array at 0x108a87b90>
    """
    miller_arrays = self.as_miller_arrays(
      crystal_symmetry,
      force_symmetry,
      merge_equivalents,
      base_array_info,
      anomalous=anomalous
    )
    keys = []
    for crystal in self.crystals():
      for dataset in crystal.datasets():
        for label in dataset.column_labels():
          keys.append((crystal.name(), dataset.name(), label))
    miller_dict = {}
    ikeys = iter(keys)
    for miller_array in miller_arrays:
      for label in miller_array.info().labels:
        for key in ikeys:
           if label == key[2]:
             miller_dict[key] = miller_array
             break
    return miller_dict
Ejemplo n.º 6
0
def measure(hklin, spacegroup):
    '''Look at HKLIN, see how strong the absences (according to the given
  spacegroup) are... looking for IPR / SIGIPR.'''

    mtz_obj = mtz.object(hklin)

    sg = sgtbx.space_group(sgtbx.space_group_symbols(spacegroup).hall())
    mi = mtz_obj.extract_miller_indices()
    sg_m = mtz_obj.space_group()

    ipr_column = None
    sigipr_column = None

    for crystal in mtz_obj.crystals():
        for dataset in crystal.datasets():
            for column in dataset.columns():

                if column.label() == 'IPR':
                    ipr_column = column
                elif column.label() == 'SIGIPR':
                    sigipr_column = column

    assert (ipr_column is not None)
    assert (sigipr_column is not None)

    ipr_values = ipr_column.extract_values(not_a_number_substitute=0.0)
    sigipr_values = sigipr_column.extract_values(not_a_number_substitute=0.0)

    present = []
    absent = []

    for j in range(mi.size()):
        hkl = mi[j]

        if sg.is_sys_absent(hkl):
            absent.append(ipr_values[j] / sigipr_values[j])
        else:
            present.append(ipr_values[j] / sigipr_values[j])

    print 'A: %f' % (sum(absent) / len(absent))
    print 'P: %f' % (sum(present) / len(present))
Ejemplo n.º 7
0
  def as_miller_arrays_dict(self,
                            crystal_symmetry=None,
                            force_symmetry=False,
                            merge_equivalents=True,
                            base_array_info=None):
    """
    Returns a python dictionary with keys of tuples containing
    (crystal name, dataset name, column label) and values of
    the Miller arrays from :func:`as_miller_arrays`.

    The arguments to :func:`as_miller_arrays_dict` are the same
    as :func:`as_miller_arrays`.

    >>> miller_dict = mtz_file.as_miller_arrays_dict()
    >>> miller_dict[('NATIVE', 'NATIVE', 'FTOXD3')]
    <cctbx.miller.array at 0x108a87b90>
    >>> miller_dict[('NATIVE', 'NATIVE', 'SIGFTOXD3')]
    <cctbx.miller.array at 0x108a87b90>
    """
    miller_arrays = self.as_miller_arrays(crystal_symmetry,
                                          force_symmetry,
                                          merge_equivalents,
                                          base_array_info)
    keys = []
    for crystal in self.crystals():
      for dataset in crystal.datasets():
        for label in dataset.column_labels():
          keys.append((crystal.name(), dataset.name(), label))
    miller_dict = {}
    ikeys = iter(keys)
    for miller_array in miller_arrays:
      for label in miller_array.info().labels:
        for key in ikeys:
           if label == key[2]:
             miller_dict[key] = miller_array
             break
    return miller_dict
Ejemplo n.º 8
0
 def columns(self):
   for crystal in self.crystals():
     for dataset in crystal.datasets():
       for column in dataset.columns():
         yield column
Ejemplo n.º 9
0
 def n_columns(self):
   result = 0
   for crystal in self.crystals():
     for dataset in crystal.datasets():
       result += dataset.n_columns()
   return result