예제 #1
0
 def _set_res(self, event):
     if len(self._ref_files) > 0 and len(self._in_files) > 0:        
         ref = self._ref_files[self._reflections.GetCurrentSelection()]
         ins = self._in_files[self._structure.GetCurrentSelection()]
         
         
         if os.path.exists(ref) and os.path.exists(ins):
             hkl = hklf.reader(open(ref))
             try:
                 ma = hkl.as_miller_arrays(crystal_symmetry=crystal_symmetry_from_ins.extract_from(ins))
             except:
                 return
                 
             rr = ma[0].resolution_range()
             
             self._res_high.SetValue(str(round(rr[1], 2)))
             self._res_low.SetValue(str(round(rr[0], 2)))
             
             ins_obj = Shelx(ins)
             self._hydrogens.SetValue(ins_obj.has_hydrogen())
             
             self._residues.Clear()
             self._residue_list = []
             for r in sorted(ins_obj.residue_list()):
                 if r not in (ShelxData._r + ['HOH', 'DOD', 'CL', 'MG']) or (r in ['ASP', 'GLU', 'HIS', 'ARG']):
                     self._residues.Append(r)
                     self._residue_list.append(r)
예제 #2
0
    def load_refinement(self, ref, stats):
        hkl = hklf.reader(open(ref.replace('.dat', '.hkl')))
        pdbf = pdb.input(file_name=ref.replace('.dat', '.pdb'))
        pdbt = PDBTools(file_name=ref.replace('.dat', '.pdb'))
        
        cs = crystal_symmetry_from_ins.extract_from(ref.replace('.dat', '.ins'))
        ma = hkl.as_miller_arrays(crystal_symmetry=cs)
        
        mp = pdbf.xray_structure_simple().scatterers()[0].multiplicity()
        s = pdbt.get_s()
        vm = cs.unit_cell().volume() / (pdbt.get_rmm() * mp)
        
        c = ma[0].completeness(d_max=stats['res'])
        dmin = stats['res']
        r = stats['r']
        rfree = stats['rfree']

        self._mv.SetLabel('%.2f' % vm)
        self._s.SetLabel('%.2f' % s)
        self._dmin.SetLabel('%.2f' % dmin)
        self._c.SetLabel('%.1f' % (c*100))
        self._r.SetLabel('%.3f' % r)
        self._rfree.SetLabel('%.3f' % rfree)
        
        sigxr = self._sigx_r(s, vm, c, r, dmin)
        self._sigxr.SetLabel('%.4f' % sigxr)
        sigxrf = self._sigx_rfree(s, vm, c, rfree, dmin)
        self._sigxrf.SetLabel('%.4f' % sigxrf)
        
        x = np.linspace(dmin+0.5,dmin-0.5, 20)
        ys = [[],[],[],[],[],[]]
        for i in x:
            sr = self._sigx_r(s, vm, c, r, i)
            ys[0].append(sr)
            ys[1].append(sr*1.15)
            ys[2].append(sr*0.85)
            
            sr = self._sigx_rfree(s, vm, c, rfree, i)
            ys[3].append(sr)
            ys[4].append(sr*1.15)
            ys[5].append(sr*0.85)
    
        self.ax1.plot(x, ys[0], 'b-', label='R')
        self.ax1.fill_between(x, ys[1], ys[2], alpha=0.1, facecolor='blue')

        self.ax1.plot(x, ys[3], 'g-', label='Rfree')
        self.ax1.fill_between(x, ys[4], ys[5], alpha=0.1, facecolor='green')
                
        al = self.ax1.axis()
        yam = al[3]-al[2]
        xam = al[1]-al[0]

        self.ax1.axhline(y=0.0236, color='purple', label='3sig (ASP)')
                
        self.ax1.axvline(x=dmin, ymin=0, ymax=(sigxr-al[2])/yam, color='0.7', label='Actual')
        self.ax1.axhline(y=sigxr, xmin=0, xmax=(dmin-al[0])/xam, color='0.7')
        self.ax1.legend(prop={'size':8}, numpoints=1, loc='best', fancybox=True)
예제 #3
0
def shelxd_substructure_ecalc(pdb_sub, ea, fa_ins, d_min, n_bins):
    '''Calculate E-values for heavy atom substructure'''

    pdb_obj =  iotbx.pdb.hierarchy.input(file_name=pdb_sub)
    c = crystal_symmetry_from_ins.extract_from(file_name=fa_ins)
    structure = pdb_obj.xray_structure_simple(crystal_symmetry=c)
    fcalc = ea.structure_factors_from_scatterers(xray_structure=structure, algorithm="direct").f_calc().amplitudes()
    fcalc.setup_binner(n_bins=n_bins)

    ecalc = fcalc.quasi_normalize_structure_factors()
    ecalc.setup_binner(n_bins=n_bins)
    return ecalc
예제 #4
0
def shelxd_read_hklf(fa_file, fa_ins, d_min, n_bins):
    '''Normalise Fa values output by SHELX'''

    fa_data = hklf.reader(file_name=fa_file)
    c = crystal_symmetry_from_ins.extract_from(file_name=fa_ins)

    fsigf_all = fa_data.as_miller_arrays(crystal_symmetry=c)[0]
    fsigf = fsigf_all.select(fsigf_all.d_spacings().data()>d_min)
    fsigf.setup_binner(n_bins=n_bins)

    ea = fsigf.quasi_normalize_structure_factors()
    ea.setup_binner(n_bins=n_bins)
    ea_weak = ea.select((abs(ea.data())<1.5))
    ea_weak.setup_binner(n_bins=n_bins)
    return ea, ea_weak
  def as_miller_arrays(self,
                       crystal_symmetry=None,
                       force_symmetry=False,
                       merge_equivalents=True,
                       base_array_info=None,
                       assume_shelx_observation_type_is=None,
                       enforce_positive_sigmas=False,
     ):
    """
    Convert the contents of the reflection file into a list of
    :py:class:`cctbx.miller.array` objects, each of which may contain multiple
    columns of data from the underlying file.  By default this will
    automatically merge redundant observations to obtain a unique set under
    symmetry.

    :param crystal_symmetry: :py:class:`cctbx.crystal.symmetry` object
      (defaults to using internally specified symmetry, if any)
    :param force_symmetry: TODO
    :param merge_equivalents: merge redundant obervations (default=True)
    :param base_array_info: :py:class:`cctbx.miller.array_info` object
      containing basic information to be propagated to the arrays
    :param assume_shelx_observation_type_is: if specified, instead of raising
      an exception if the SHELX file type is not known from the file name plus
      data type tag, the function will force the specified data type.
    """
    assert (assume_shelx_observation_type_is in
            [None, "amplitudes", "intensities"])
    if (self._file_type is None):
      return []
    info_source = self._file_name
    if (info_source.startswith("./") or info_source.startswith(".\\")):
      info_source = info_source[2:]
    if (base_array_info is None):
      base_array_info = miller.array_info(
        source=info_source,
        source_type=self._file_type)
    if (self._file_type == "cctbx.miller.array"):
      result = []
      for miller_array in self._file_content:
        info = miller_array.info()
        if (info is None or not isinstance(info, miller.array_info)):
          info = base_array_info
        info.source = info_source
        info.crystal_symmetry_from_file = crystal.symmetry(
          unit_cell=miller_array.unit_cell(),
          space_group_info=miller_array.space_group_info(),
          raise_sorry_if_incompatible_unit_cell=True)
        result.append(miller_array.customized_copy(
          crystal_symmetry=miller_array.join_symmetry(
            other_symmetry=crystal_symmetry,
            force=force_symmetry,
            raise_sorry_if_incompatible_unit_cell=True))
              .set_info(info)
              .set_observation_type(miller_array.observation_type()))
      return result
    if ((   crystal_symmetry is None
         or crystal_symmetry.unit_cell() is None)
        and self._observation_type == 'hklf+ins/res'
        ):
        name, ext = os.path.splitext(self._file_name)
        if ext != '.hkl': # it may be compressed: name.hkl.gz
          name, ext = os.path.splitext(name)
        for shelx_file_name in ('%s.ins' % name, '%s.res' % name):
          try:
            shelx_file = open(shelx_file_name)
            break
          except IOError:
            continue
        else:
          raise Sorry("Can't open files %s.ins or %s.res"
                      "required by the option hklf+ins/res" % ((name,)*2))
        crystal_symmetry = crystal_symmetry_from_ins.extract_from(
          file=shelx_file)
        shelx_file.seek(0)
        remaining = shelx_file.read()
        shelx_file.close()
        m = re.search("^HKLF\s*(\d)", remaining, re.X|re.M|re.S)
        if m is None:
          raise Sorry("%s does not contain the mandatory HKLF instruction"
                      % shelx_file.name)
        if m.group(1) == "4":
          self._observation_type = "intensities"
        elif m.group(1) == "3":
          self._observation_type = "amplitudes"
        else:
          raise Sorry("HKLF %s not supported" % m.group(1))
    result = self._file_content.as_miller_arrays(
      crystal_symmetry=crystal_symmetry,
      force_symmetry=force_symmetry,
      merge_equivalents=merge_equivalents,
      base_array_info=base_array_info,
      )
    if (self.file_type() == "shelx_hklf"):
      if ((self._observation_type == "intensities") or
          (assume_shelx_observation_type_is == "intensities")) :
        result[0].set_info(result[0].info().customized_copy(
          labels=["Iobs", "SigIobs"]))
        result[0].set_observation_type_xray_intensity()
      elif ((self._observation_type == "amplitudes") or
            (assume_shelx_observation_type_is == "amplitudes")) :
        result[0].set_info(result[0].info().customized_copy(
          labels=["Fobs", "SigFobs"]))
        result[0].set_observation_type_xray_amplitude()
      else:
        raise Sorry("Unresolved amplitude/intensity ambiguity: %s\n"
          "  SHELX reflection files may contain amplitudes or intensities.\n"
          "  Please append   =amplitudes\n"
          "             or   =hklf3\n"
          "             or   =intensities\n"
          "             or   =hklf4\n"
          "  to the file name argument or parameter to resolve the"
          " ambiguity.\n"
          "  If a corresponding .ins file is available, look for the"
          " HKLF codeword.\n"
          "  Alternatively, run the phenix.reflection_statistics"
          " command twice,\n"
          "  once with =amplitudes and once with =intensities. Inspect"
          " the <I^2>/(<I>)^2\n"
          "  statistics. For acentric structures the values should"
          " fluctuate around\n"
          "  2.0, for centric structures around 3.0. If the statistics"
          " are not conclusive\n"
          "  it will be best to recover the original reflection data, such"
          " as SCALEPACK,\n"
          "  SCALA MTZ, XDS, or d*TREK files." % self._file_name)
    # discard reflections where sigma <= 0
    # XXX note that this will happen after data merging, so for unmerged data
    # it is better to specify merge_equivalents=False!
    if (enforce_positive_sigmas) :
      result_ = []
      for array in result :
        result_.append(array.enforce_positive_sigmas())
      result = result_
    return result
예제 #6
0
    def as_miller_arrays(
        self,
        crystal_symmetry=None,
        force_symmetry=False,
        merge_equivalents=True,
        base_array_info=None,
        assume_shelx_observation_type_is=None,
        enforce_positive_sigmas=False,
    ):
        """
    Convert the contents of the reflection file into a list of
    :py:class:`cctbx.miller.array` objects, each of which may contain multiple
    columns of data from the underlying file.  By default this will
    automatically merge redundant observations to obtain a unique set under
    symmetry.

    :param crystal_symmetry: :py:class:`cctbx.crystal.symmetry` object
      (defaults to using internally specified symmetry, if any)
    :param force_symmetry: TODO
    :param merge_equivalents: merge redundant obervations (default=True)
    :param base_array_info: :py:class:`cctbx.miller.array_info` object
      containing basic information to be propagated to the arrays
    :param assume_shelx_observation_type_is: if specified, instead of raising
      an exception if the SHELX file type is not known from the file name plus
      data type tag, the function will force the specified data type.
    """
        assert (assume_shelx_observation_type_is
                in [None, "amplitudes", "intensities"])
        if (self._file_type is None):
            return []
        info_source = self._file_name
        if (info_source.startswith("./") or info_source.startswith(".\\")):
            info_source = info_source[2:]
        if (base_array_info is None):
            base_array_info = miller.array_info(source=info_source,
                                                source_type=self._file_type)
        if (self._file_type == "cctbx.miller.array"):
            result = []
            for miller_array in self._file_content:
                info = miller_array.info()
                if (info is None or not isinstance(info, miller.array_info)):
                    info = base_array_info
                info.source = info_source
                info.crystal_symmetry_from_file = crystal.symmetry(
                    unit_cell=miller_array.unit_cell(),
                    space_group_info=miller_array.space_group_info(),
                    raise_sorry_if_incompatible_unit_cell=True)
                result.append(
                    miller_array.customized_copy(
                        crystal_symmetry=miller_array.join_symmetry(
                            other_symmetry=crystal_symmetry,
                            force=force_symmetry,
                            raise_sorry_if_incompatible_unit_cell=True)).
                    set_info(info).set_observation_type(
                        miller_array.observation_type()))
            return result
        if ((crystal_symmetry is None or crystal_symmetry.unit_cell() is None)
                and self._observation_type == 'hklf+ins/res'):
            name, ext = os.path.splitext(self._file_name)
            if ext != '.hkl':  # it may be compressed: name.hkl.gz
                name, ext = os.path.splitext(name)
            for shelx_file_name in ('%s.ins' % name, '%s.res' % name):
                try:
                    shelx_file = open(shelx_file_name)
                    break
                except IOError:
                    continue
            else:
                raise Sorry("Can't open files %s.ins or %s.res"
                            "required by the option hklf+ins/res" %
                            ((name, ) * 2))
            crystal_symmetry = crystal_symmetry_from_ins.extract_from(
                file=shelx_file)
            shelx_file.seek(0)
            remaining = shelx_file.read()
            shelx_file.close()
            m = re.search("^HKLF\s*(\d)", remaining, re.X | re.M | re.S)
            if m is None:
                raise Sorry(
                    "%s does not contain the mandatory HKLF instruction" %
                    shelx_file.name)
            if m.group(1) == "4":
                self._observation_type = "intensities"
            elif m.group(1) == "3":
                self._observation_type = "amplitudes"
            else:
                raise Sorry("HKLF %s not supported" % m.group(1))
        result = self._file_content.as_miller_arrays(
            crystal_symmetry=crystal_symmetry,
            force_symmetry=force_symmetry,
            merge_equivalents=merge_equivalents,
            base_array_info=base_array_info,
        )
        if (self.file_type() == "shelx_hklf"):
            if ((self._observation_type == "intensities")
                    or (assume_shelx_observation_type_is == "intensities")):
                result[0].set_info(result[0].info().customized_copy(
                    labels=["Iobs", "SigIobs"]))
                result[0].set_observation_type_xray_intensity()
            elif ((self._observation_type == "amplitudes")
                  or (assume_shelx_observation_type_is == "amplitudes")):
                result[0].set_info(result[0].info().customized_copy(
                    labels=["Fobs", "SigFobs"]))
                result[0].set_observation_type_xray_amplitude()
            else:
                raise Sorry(
                    "Unresolved amplitude/intensity ambiguity: %s\n"
                    "  SHELX reflection files may contain amplitudes or intensities.\n"
                    "  Please append   =amplitudes\n"
                    "             or   =hklf3\n"
                    "             or   =intensities\n"
                    "             or   =hklf4\n"
                    "  to the file name argument or parameter to resolve the"
                    " ambiguity.\n"
                    "  If a corresponding .ins file is available, look for the"
                    " HKLF codeword.\n"
                    "  Alternatively, run the phenix.reflection_statistics"
                    " command twice,\n"
                    "  once with =amplitudes and once with =intensities. Inspect"
                    " the <I^2>/(<I>)^2\n"
                    "  statistics. For acentric structures the values should"
                    " fluctuate around\n"
                    "  2.0, for centric structures around 3.0. If the statistics"
                    " are not conclusive\n"
                    "  it will be best to recover the original reflection data, such"
                    " as SCALEPACK,\n"
                    "  SCALA MTZ, XDS, or d*TREK files." % self._file_name)
        # discard reflections where sigma <= 0
        # XXX note that this will happen after data merging, so for unmerged data
        # it is better to specify merge_equivalents=False!
        if (enforce_positive_sigmas):
            result_ = []
            for array in result:
                result_.append(array.enforce_positive_sigmas())
            result = result_
        return result