Exemple #1
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
Exemple #2
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
Exemple #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)
Exemple #4
0
 def change_basis_in_place(self,
       cb_op,
       new_space_group_info=None,
       assert_is_compatible_unit_cell=False):
   assert len(column_type_legend) == 17 # programmer alert
     # force update if column_type_legend is changed
   for column_type in self.column_types():
     if (column_type == "P"):
       raise RuntimeError(
         "In-place transformation of phase angles not implemented.")
     if (column_type == "A"):
       raise RuntimeError(
         "In-place transformation of Hendrickson-Lattman coefficients"
         " not implemented.")
   if (new_space_group_info is None):
     new_space_group_info = self.space_group_info().change_basis(cb_op)
   if "M_ISYM" in self.column_labels():
     original_miller_indices = self.extract_original_index_miller_indices()
     indices = cb_op.apply(original_miller_indices)
     isym = flex.int(len(indices))
     self.replace_original_index_miller_indices(indices)
   else:
     self.replace_miller_indices(cb_op.apply(self.extract_miller_indices()))
   self.set_space_group_info(space_group_info=new_space_group_info)
   for crystal in self.crystals():
     crystal_symmetry = cctbx.crystal.symmetry(
       unit_cell=crystal.unit_cell().change_basis(cb_op=cb_op),
       space_group_info=new_space_group_info,
       assert_is_compatible_unit_cell=assert_is_compatible_unit_cell,
       raise_sorry_if_incompatible_unit_cell=True)
     crystal.set_unit_cell_parameters(
       crystal_symmetry.unit_cell().parameters())
   # transform & symmetrize per-batch unit cell to support Scala 6.0 (NKS)
   # re-zero the U-matrix so nobody tries to use it downstream
   for batch in self.batches():
     batch_uc = uctbx.unit_cell(list(batch.cell()))
     batch_crystal_symmetry = cctbx.crystal.symmetry(
       unit_cell=batch_uc.change_basis(cb_op=cb_op),
       space_group_info=new_space_group_info,
       assert_is_compatible_unit_cell=assert_is_compatible_unit_cell)
     batch.set_cell(flex.float(
       batch_crystal_symmetry.unit_cell().parameters()))
     batch.set_umat(flex.float(
       (0,0,0,0,0,0,0,0,0)))
Exemple #5
0
  def change_basis_in_place(self,
        cb_op,
        new_space_group_info=None,
        assert_is_compatible_unit_cell=False):
    assert len(column_type_legend) == 17 # programmer alert
      # force update if column_type_legend is changed
    for column_type in self.column_types():
      if (column_type == "P"):
        raise RuntimeError(
          "In-place transformation of phase angles not implemented.")
      if (column_type == "A"):
        raise RuntimeError(
          "In-place transformation of Hendrickson-Lattman coefficients"
          " not implemented.")
    if (new_space_group_info is None):
      new_space_group_info = self.space_group_info().change_basis(cb_op)
    if "M_ISYM" in self.column_labels():
      original_miller_indices = self.extract_original_index_miller_indices()
      indices = cb_op.apply(original_miller_indices)
      isym = flex.int(len(indices))
      self.replace_original_index_miller_indices(indices)
    else:
      self.replace_miller_indices(cb_op.apply(self.extract_miller_indices()))
    self.set_space_group_info(space_group_info=new_space_group_info)
    for crystal in self.crystals():
      crystal_symmetry = cctbx.crystal.symmetry(
        unit_cell=crystal.unit_cell().change_basis(cb_op=cb_op),
        space_group_info=new_space_group_info,
        assert_is_compatible_unit_cell=assert_is_compatible_unit_cell,
        raise_sorry_if_incompatible_unit_cell=True)
      crystal.set_unit_cell_parameters(
        crystal_symmetry.unit_cell().parameters())

    # transform & symmetrize per-batch unit cell to support Scala 6.0 (NKS)
    # MTZ stores umat corresponding to Busing & Levy convention

    def mosflm_B(unit_cell):
      from math import cos, sin, radians

      params = unit_cell.parameters()
      rparams = unit_cell.reciprocal_parameters()

      a, b, c = params[:3]
      alpha, beta, gamma = [radians(a) for a in params[3:]]
      ra, rb, rc = rparams[:3]
      ralpha, rbeta, rgamma = [radians(a) for a in rparams[3:]]

      B = (ra, rb * cos(rgamma),  rc * cos(rbeta),
           0, rb * sin(rgamma), -rc * sin(rbeta) * cos(alpha),
           0, 0, 1/c)

      return B

    from scitbx import matrix
    for batch in self.batches():
      batch_uc = uctbx.unit_cell(list(batch.cell()))
      B = matrix.sqr(mosflm_B(batch_uc))
      U = matrix.sqr(batch.umat()).transpose()
      A = U * B
      direct_matrix = A.inverse()
      M = cb_op.c_inv().r().transpose().as_rational()
      new_direct_matrix = M * direct_matrix
      new_uc = batch_uc.change_basis(cb_op=cb_op)
      new_B = matrix.sqr(mosflm_B(new_uc))
      new_U = (new_direct_matrix.inverse() * new_B.inverse()).transpose()
      batch_crystal_symmetry = cctbx.crystal.symmetry(
        unit_cell=new_uc,
        space_group_info=new_space_group_info,
        assert_is_compatible_unit_cell=assert_is_compatible_unit_cell)
      batch.set_cell(flex.float(
        batch_crystal_symmetry.unit_cell().parameters()))
      batch.set_umat(flex.float(new_U))