def ml_normalisation(self, aniso=False):
    # estimate number of residues per unit cell
    mr = matthews.matthews_rupp(self.intensities.crystal_symmetry())
    n_residues = mr.n_residues

    # estimate B-factor and scale factors for normalisation
    if aniso:
      normalisation = absolute_scaling.ml_aniso_absolute_scaling(
        self.intensities, n_residues=n_residues)
      u_star = normalisation.u_star
    else:
      normalisation = absolute_scaling.ml_iso_absolute_scaling(
        self.intensities, n_residues=n_residues)
      u_star = adptbx.b_as_u(
        adptbx.u_iso_as_u_star(
          self.intensities.unit_cell(), normalisation.b_wilson))

    # apply scales
    self.intensities = self.intensities.customized_copy(
      data=scaling.ml_normalise_aniso(
        self.intensities.indices(), self.intensities.data(),
        normalisation.p_scale, self.intensities.unit_cell(),
        u_star),
      sigmas=scaling.ml_normalise_aniso(
        self.intensities.indices(), self.intensities.sigmas(),
        normalisation.p_scale, self.intensities.unit_cell(),
        u_star)).set_info(self.intensities.info())

    # record output in log file
    s = StringIO()
    mr.show(out=s)
    normalisation.show(out=s)
    logger.info(s.getvalue())
def get_b_aniso_mean(i_obs):
    from mmtbx.scaling import absolute_scaling

    aniso_scale_and_b = absolute_scaling.ml_aniso_absolute_scaling(miller_array=i_obs, n_residues=200, n_bases=0)
    try:
        b_cart = aniso_scale_and_b.b_cart
    except AttributeError, e:
        raise Sorry("\nCannot correct the column %s for anisotropy\n" % (best_label))
def wilson_scaling(F, n_residues, n_bases):
    from mmtbx.scaling import absolute_scaling
    iso_scale = absolute_scaling.ml_iso_absolute_scaling(miller_array=F,
                                                         n_residues=n_residues,
                                                         n_bases=n_bases)
    aniso_scale = absolute_scaling.ml_aniso_absolute_scaling(
        miller_array=F, n_residues=n_residues, n_bases=n_bases)
    return iso_scale, aniso_scale
Exemple #4
0
    def _ml_normalisation(intensities, aniso):
        # estimate number of residues per unit cell
        mr = matthews.matthews_rupp(intensities.crystal_symmetry())
        n_residues = mr.n_residues

        # estimate B-factor and scale factors for normalisation
        if aniso:
            normalisation = absolute_scaling.ml_aniso_absolute_scaling(
                intensities, n_residues=n_residues
            )
            u_star = normalisation.u_star
        else:
            normalisation = absolute_scaling.ml_iso_absolute_scaling(
                intensities, n_residues=n_residues
            )
            u_star = adptbx.b_as_u(
                adptbx.u_iso_as_u_star(intensities.unit_cell(), normalisation.b_wilson)
            )

        # record output in log file
        if aniso:
            b_cart = normalisation.b_cart
            logger.info("ML estimate of overall B_cart value:")
            logger.info(
                """\
  %5.2f, %5.2f, %5.2f
  %12.2f, %5.2f
  %19.2f"""
                % (b_cart[0], b_cart[3], b_cart[4], b_cart[1], b_cart[5], b_cart[2])
            )
        else:
            logger.info("ML estimate of overall B value:")
            logger.info("   %5.2f A**2" % normalisation.b_wilson)
        logger.info("ML estimate of  -log of scale factor:")
        logger.info("  %5.2f" % (normalisation.p_scale))

        s = StringIO()
        mr.show(out=s)
        normalisation.show(out=s)
        logger.debug(s.getvalue())

        # apply scales
        return intensities.customized_copy(
            data=scaling.ml_normalise_aniso(
                intensities.indices(),
                intensities.data(),
                normalisation.p_scale,
                intensities.unit_cell(),
                u_star,
            ),
            sigmas=scaling.ml_normalise_aniso(
                intensities.indices(),
                intensities.sigmas(),
                normalisation.p_scale,
                intensities.unit_cell(),
                u_star,
            ),
        )
def wilson_scaling (F, n_residues, n_bases) :
  from mmtbx.scaling import absolute_scaling
  iso_scale = absolute_scaling.ml_iso_absolute_scaling(
    miller_array=F,
    n_residues=n_residues,
    n_bases=n_bases)
  aniso_scale = absolute_scaling.ml_aniso_absolute_scaling(
    miller_array=F,
    n_residues=n_residues,
    n_bases=n_bases)
  return iso_scale, aniso_scale
Exemple #6
0
def calc_principal_vectors(miller_array, log_out):
    """
    Reference: Aimless program
    Triclinic & Monoclinic: from B_cart
    Orthorhombic: along a*, b*, c*
    Trigonal, Hexagonal, Tetragonal: c* and a*b*-plane
    Cubic: no anisotropy

    return type: list of (vector, label, in-plane or not)
    """

    n_residues = p_vm_calculator(miller_array, 1, 0).best_guess

    aniso_scale_and_b = absolute_scaling.ml_aniso_absolute_scaling(miller_array=miller_array,
                                                                   n_residues=n_residues,
                                                                   n_bases=0)

    if aniso_scale_and_b.eigen_values[0] == 0:
        print >>log_out, "Error! Cannot determine B_cart"
        return

    b_cart = aniso_scale_and_b.b_cart
    print >>log_out, """ML estimate of overall B_cart:
 /  %5.2f %5.2f %5.2f \\
 |  %11.2f %5.2f |
 \\  %17.2f /
""" % (b_cart[0], b_cart[3], b_cart[4],
       b_cart[1], b_cart[5], b_cart[2])

    ev = aniso_scale_and_b.eigen_vectors

    orth_mat = numpy.array(miller_array.unit_cell().orthogonalization_matrix()).reshape(3,3)

    print >>log_out, "Eigenvalues/vectors:"
    for i, eg in enumerate(aniso_scale_and_b.eigen_values):
        v = ev[3*i:3*(i+1)]
        vs = ", ".join(map(lambda x: "% .4f"%x, v))
        vl = axis_label(v, orth_mat)
        print >>log_out, " %8.3f (%s) %s" % (eg, vs, vl)
    cs = miller_array.space_group().crystal_system()

    if cs == "Cubic":
        print >>log_out, "No anisotropy in this symmetry."
        return []
    elif cs == "Orthorhombic":
        return ([1.,0.,0.], "a*", False), ([0.,1.,0.], "b*", False), ([0.,0.,1.], "c*", False)
    elif cs in ("Triclinic", "Monoclinic"):
        return ((ev[:3], axis_label(ev[:3], orth_mat), False),
                (ev[3:6], axis_label(ev[3:6], orth_mat), False),
                (ev[6:], axis_label(ev[6:], orth_mat), False))
    else: # in "Tetragonal", "Hexagonal", "Trigonal", "Cubic"
        return ([0.,0.,1.], "c*", False), ([0.,0.,1.], "a*b*", True)
Exemple #7
0
def test_scaling_on_random_data(B_add):
    miller_array = random_data(B_add, n_residues=100.0)
    scale_object_iso = absolute_scaling.ml_iso_absolute_scaling(
        miller_array, n_residues=100.0)

    ## compare the results please
    assert approx_equal(B_add, scale_object_iso.b_wilson, eps=5)

    scale_object_aniso = absolute_scaling.ml_aniso_absolute_scaling(
        miller_array, n_residues=100.0)

    assert approx_equal(B_add, scale_object_aniso.b_cart[0], eps=5)
    assert approx_equal(B_add, scale_object_aniso.b_cart[1], eps=5)
    assert approx_equal(B_add, scale_object_aniso.b_cart[2], eps=5)
Exemple #8
0
def get_b_aniso_mean(i_obs):
  from mmtbx.scaling import absolute_scaling
  aniso_scale_and_b = absolute_scaling.ml_aniso_absolute_scaling(
        miller_array = i_obs,
        n_residues = 200,
        n_bases = 0)
  try: b_cart=aniso_scale_and_b.b_cart
  except AttributeError as e:
        raise Sorry("\nCannot correct the column %s for anisotropy\n"%(
          best_label))
  b_aniso_mean=0.
  for k in [0,1,2]:
    b_aniso_mean+=b_cart[k]
  return b_aniso_mean/3.0
def test_scaling_on_random_data(B_add):
  miller_array = random_data(B_add,n_residues=100.0)
  scale_object_iso = absolute_scaling.ml_iso_absolute_scaling(
    miller_array,
    n_residues=100.0)

  ## compare the results please
  assert approx_equal(B_add, scale_object_iso.b_wilson, eps=5)

  scale_object_aniso = absolute_scaling.ml_aniso_absolute_scaling(
    miller_array,
    n_residues=100.0)

  assert approx_equal(B_add, scale_object_aniso.b_cart[0], eps=5)
  assert approx_equal(B_add, scale_object_aniso.b_cart[1], eps=5)
  assert approx_equal(B_add, scale_object_aniso.b_cart[2], eps=5)
Exemple #10
0
 def anisotropic_correction(self):
   if not self.params.anisotropic_correction: return
   self.aniso_scale_and_b = None
   n_copies_solc = self.params.asu_contents.n_copies_per_asu
   n_residues = self.params.asu_contents.n_residues
   n_bases = self.params.asu_contents.n_bases
   self.aniso_scale_and_b = absolute_scaling.ml_aniso_absolute_scaling(
     miller_array=self.f_obs,
     n_residues=n_residues*self.f_obs.space_group().order_z()*n_copies_solc,
     n_bases=n_bases*self.f_obs.space_group().order_z()*n_copies_solc)
   self.aniso_scale_and_b.show(out=self.log)
   b_cart = self.aniso_scale_and_b.b_cart
   trace = sum(b_cart[:3])/3
   b_cart = [b_cart[0]-trace, b_cart[1]-trace, b_cart[2]-trace,
             b_cart[3], b_cart[4], b_cart[5]]
   u_star = adptbx.u_cart_as_u_star(self.f_obs.unit_cell(), adptbx.b_as_u(b_cart))
   self.f_obs = absolute_scaling.anisotropic_correction(
     self.f_obs, 0.0, u_star).set_observation_type(self.f_obs)
Exemple #11
0
 def anisotropic_correction(self):
   if not self.params.anisotropic_correction: return
   self.aniso_scale_and_b = None
   n_copies_solc = self.params.asu_contents.n_copies_per_asu
   n_residues = self.params.asu_contents.n_residues
   n_bases = self.params.asu_contents.n_bases
   self.aniso_scale_and_b = absolute_scaling.ml_aniso_absolute_scaling(
     miller_array=self.f_obs,
     n_residues=n_residues*self.f_obs.space_group().order_z()*n_copies_solc,
     n_bases=n_bases*self.f_obs.space_group().order_z()*n_copies_solc)
   self.aniso_scale_and_b.show(out=self.log)
   b_cart = self.aniso_scale_and_b.b_cart
   trace = sum(b_cart[:3])/3
   b_cart = [b_cart[0]-trace, b_cart[1]-trace, b_cart[2]-trace,
             b_cart[3], b_cart[4], b_cart[5]]
   u_star = adptbx.u_cart_as_u_star(self.f_obs.unit_cell(), adptbx.b_as_u(b_cart))
   self.f_obs = absolute_scaling.anisotropic_correction(
     self.f_obs, 0.0, u_star).set_observation_type(self.f_obs)
Exemple #12
0
def run(hklin, pdbin, wdir, anisotropy_correction=False):
    arrays = iotbx.file_reader.any_file(hklin).file_server.miller_arrays
    i_arrays = filter(
        lambda x: x.is_xray_intensity_array() and x.anomalous_flag(), arrays)
    f_arrays = filter(
        lambda x: x.is_xray_amplitude_array() and x.anomalous_flag(), arrays)

    if not i_arrays and not f_arrays:
        print "No anomalous observation data"
        return

    if os.path.exists(wdir):
        print "%s already exists. quiting." % wdir
        return

    os.mkdir(wdir)

    xs = crystal_symmetry_from_any.extract_from(pdbin)

    sh_out = open(os.path.join(wdir, "run_anode.sh"), "w")
    sh_out.write("#!/bin/sh\n\n")
    sh_out.write("shelxc anode <<+ > shelxc.log 2>&1\n")
    sh_out.write("cell %s\n" % format_unit_cell(xs.unit_cell()))
    sh_out.write("spag %s\n" % str(xs.space_group_info()).replace(" ", ""))

    if i_arrays:
        obs_array = i_arrays[0]
        infile = "%s.hkl" % os.path.splitext(os.path.basename(hklin))[0]
        in_opt = "%s" % infile
        print "Using intensity array:", obs_array.info().label_string()
    else:
        obs_array = f_arrays[0]
        infile = "%s_f.hkl" % os.path.splitext(os.path.basename(hklin))[0]
        in_opt = "-f %s" % infile
        print "No intensity arrays. Using amplitude arrays instead:", obs_array.info(
        ).label_string()

    sh_out.write("! data from %s : %s\n" %
                 (os.path.abspath(hklin), obs_array.info().label_string()))
    obs_array.crystal_symmetry().show_summary(sh_out, prefix="! ")
    check_symm(obs_array.crystal_symmetry(), xs)

    n_org = obs_array.size()
    obs_array = obs_array.eliminate_sys_absent()
    n_sys_abs = n_org - obs_array.size()
    if n_sys_abs > 0:
        print "  %d systematic absences removed." % n_sys_abs

    if anisotropy_correction:
        print "Correcting anisotropy.."
        n_residues = p_vm_calculator(obs_array, 1, 0).best_guess
        abss = ml_aniso_absolute_scaling(obs_array, n_residues=n_residues)
        abss.show()
        tmp = -2. if i_arrays else -1.
        b_cart = map(lambda x: x * tmp, abss.b_cart)
        obs_array = obs_array.apply_debye_waller_factors(b_cart=b_cart)

    sh_out.write("sad %s\n" % in_opt)
    iotbx.shelx.hklf.miller_array_export_as_shelx_hklf(
        obs_array,
        open(os.path.join(wdir, infile), "w"),
        normalise_if_format_overflow=True)
    sh_out.write("+\n\n")
    sh_out.write('ln -s "%s" anode.pdb\n\n' % os.path.relpath(pdbin, wdir))
    sh_out.write("anode anode\n")
    sh_out.close()

    call(cmd="sh", arg="./run_anode.sh", wdir=wdir)

    pha_file = os.path.join(wdir, "anode.pha")
    if os.path.isfile(pha_file):
        pha2mtz(pha_file, xs, os.path.join(wdir, "anode.pha.mtz"))

    print "Done. See %s/" % wdir

    fa_file = os.path.join(wdir, "anode_fa.hkl")
    if os.path.isfile(fa_file):
        r = iotbx.shelx.hklf.reader(open(fa_file))
        fa_array = r.as_miller_arrays(crystal_symmetry=xs)[0]
        print "\nData stats:"
        print " # Cmpl.o = Anomalous completeness in original data"
        print " # Cmpl.c = Anomalous completeness in shelxc result (rejections)"
        print " # SigAno = <d''/sigma> in shelxc result"
        print " d_max d_min Cmpl.o Cmpl.c SigAno"
        binner = obs_array.setup_binner(n_bins=12)
        for i_bin in binner.range_used():
            d_max_bin, d_min_bin = binner.bin_d_range(i_bin)
            obs_sel = obs_array.resolution_filter(d_max_bin, d_min_bin)
            obs_sel_ano = obs_sel.anomalous_differences()
            fa_sel = fa_array.resolution_filter(d_max_bin, d_min_bin)
            cmplset = obs_sel_ano.complete_set(
                d_max=d_max_bin, d_min=d_min_bin).select_acentric()
            n_acentric = cmplset.size()
            sigano = flex.mean(
                fa_sel.data() /
                fa_sel.sigmas()) if fa_sel.size() else float("nan")
            print " %5.2f %5.2f %6.2f %6.2f %6.2f" % (
                d_max_bin, d_min_bin, 100. * obs_sel_ano.size() / n_acentric,
                100. * fa_sel.size() / n_acentric, sigano)

    lsa_file = os.path.join(wdir, "anode.lsa")
    if os.path.isfile(lsa_file):
        print ""
        flag = False
        for l in open(lsa_file):
            if "Strongest unique anomalous peaks" in l:
                flag = True
            elif "Reflections written to" in l:
                flag = False
            if flag:
                print l.rstrip()

    if os.path.isfile(("anode_fa.res")):
        x = iotbx.shelx.cctbx_xray_structure_from(file=open("anode_fa.res"))
        open("anode_fa.pdb", "w").write(x.as_pdb_file())
Exemple #13
0
    def __init__(self,
                 miller_array,
                 phil_object,
                 out=None,
                 out_plot=None,
                 miller_calc=None,
                 original_intensities=None,
                 completeness_as_non_anomalous=None,
                 verbose=0):
        if out is None:
            out = sys.stdout
        if verbose > 0:
            print >> out
            print >> out
            print >> out, "Matthews coefficient and Solvent content statistics"
        n_copies_solc = 1.0
        self.nres_known = False
        if (phil_object.scaling.input.asu_contents.n_residues is not None
                or phil_object.scaling.input.asu_contents.n_bases is not None):
            self.nres_known = True
            if (phil_object.scaling.input.asu_contents.sequence_file
                    is not None):
                print >> out, "  warning: ignoring sequence file"
        elif (phil_object.scaling.input.asu_contents.sequence_file
              is not None):
            print >> out, "  determining composition from sequence file %s" % \
              phil_object.scaling.input.asu_contents.sequence_file
            seq_comp = iotbx.bioinformatics.composition_from_sequence_file(
                file_name=phil_object.scaling.input.asu_contents.sequence_file,
                log=out)
            if (seq_comp is not None):
                phil_object.scaling.input.asu_contents.n_residues = seq_comp.n_residues
                phil_object.scaling.input.asu_contents.n_bases = seq_comp.n_bases
                self.nres_known = True
        matthews_results = matthews.matthews_rupp(
            crystal_symmetry=miller_array,
            n_residues=phil_object.scaling.input.asu_contents.n_residues,
            n_bases=phil_object.scaling.input.asu_contents.n_bases,
            out=out,
            verbose=1)
        phil_object.scaling.input.asu_contents.n_residues = matthews_results[0]
        phil_object.scaling.input.asu_contents.n_bases = matthews_results[1]
        n_copies_solc = matthews_results[2]
        self.matthews_results = matthews_results

        if phil_object.scaling.input.asu_contents.n_copies_per_asu is not None:
            n_copies_solc = phil_object.scaling.input.asu_contents.n_copies_per_asu
            self.defined_copies = n_copies_solc
            if verbose > 0:
                print >> out, "Number of copies per asymmetric unit provided"
                print >> out, " Will use user specified value of ", n_copies_solc
        else:
            phil_object.scaling.input.asu_contents.n_copies_per_asu = n_copies_solc
            self.guessed_copies = n_copies_solc

        # first report on I over sigma
        miller_array_new = miller_array
        self.data_strength = None
        miller_array_intensities = miller_array
        if (original_intensities is not None):
            assert original_intensities.is_xray_intensity_array()
            miller_array_intensities = original_intensities
        if miller_array_intensities.sigmas() is not None:
            data_strength = data_statistics.i_sigi_completeness_stats(
                miller_array_intensities,
                isigi_cut=phil_object.scaling.input.parameters.
                misc_twin_parameters.twin_test_cuts.isigi_cut,
                completeness_cut=phil_object.scaling.input.parameters.
                misc_twin_parameters.twin_test_cuts.completeness_cut,
                completeness_as_non_anomalous=completeness_as_non_anomalous)
            data_strength.show(out)
            self.data_strength = data_strength
            if phil_object.scaling.input.parameters.misc_twin_parameters.twin_test_cuts.high_resolution is None:
                if data_strength.resolution_cut > data_strength.resolution_at_least:
                    phil_object.scaling.input.parameters.misc_twin_parameters.twin_test_cuts.high_resolution = data_strength.resolution_at_least
                else:
                    phil_object.scaling.input.parameters.misc_twin_parameters.twin_test_cuts.high_resolution = data_strength.resolution_cut

        ## Isotropic wilson scaling
        if verbose > 0:
            print >> out
            print >> out
            print >> out, "Maximum likelihood isotropic Wilson scaling "

        n_residues = phil_object.scaling.input.asu_contents.n_residues
        n_bases = phil_object.scaling.input.asu_contents.n_bases
        if n_residues is None:
            n_residues = 0
        if n_bases is None:
            n_bases = 0
        if n_bases + n_residues == 0:
            raise Sorry("No scatterers available")
        iso_scale_and_b = absolute_scaling.ml_iso_absolute_scaling(
            miller_array=miller_array_new,
            n_residues=n_residues * miller_array.space_group().order_z() *
            n_copies_solc,
            n_bases=n_bases * miller_array.space_group().order_z() *
            n_copies_solc)
        iso_scale_and_b.show(out=out, verbose=verbose)
        self.iso_scale_and_b = iso_scale_and_b
        ## Store the b and scale values from isotropic ML scaling
        self.iso_p_scale = iso_scale_and_b.p_scale
        self.iso_b_wilson = iso_scale_and_b.b_wilson

        ## Anisotropic ml wilson scaling
        if verbose > 0:
            print >> out
            print >> out
            print >> out, "Maximum likelihood anisotropic Wilson scaling "
        aniso_scale_and_b = absolute_scaling.ml_aniso_absolute_scaling(
            miller_array=miller_array_new,
            n_residues=n_residues * miller_array.space_group().order_z() *
            n_copies_solc,
            n_bases=n_bases * miller_array.space_group().order_z() *
            n_copies_solc)
        aniso_scale_and_b.show(out=out, verbose=1)

        self.aniso_scale_and_b = aniso_scale_and_b

        try:
            b_cart = aniso_scale_and_b.b_cart
        except AttributeError, e:
            print >> out, "*** ERROR ***"
            print >> out, str(e)
            show_exception_info_if_full_testing()
            return
Exemple #14
0
  def __init__(self,
               miller_array,
               pre_scaling_protocol,
               basic_info,
               out=None):
    ## Make deep copy of the miller array of interest
    self.x1 = miller_array.deep_copy()
    self.options=pre_scaling_protocol
    self.basic_info= basic_info

    ## Determine unit_cell contents
    print(file=out)
    print("Matthews analyses", file=out)
    print("-----------------", file=out)
    print(file=out)
    print("Inspired by: Kantardjieff and Rupp. Prot. Sci. 12(9): 1865-1871 (2003).", file=out)
    matthews_analyses = matthews.matthews_rupp(
      crystal_symmetry = self.x1,
      n_residues = self.basic_info.n_residues,
      n_bases = self.basic_info.n_bases,
      out=out, verbose=1)
    n_residues=matthews_analyses[0]
    n_bases=matthews_analyses[1]
    n_copies_solc=matthews_analyses[2]

    if (self.basic_info.n_residues==None):
      self.basic_info.n_residues = n_residues
    if (self.basic_info.n_bases == None):
      self.basic_info.n_bases = n_bases


    ## apply resolution cut
    print(file=out)
    print("Applying resolution cut", file=out)
    print("-----------------------", file=out)

    if self.options.low_resolution is None:
      if self.options.high_resolution is None:
        print("No resolution cut is made", file=out)

    low_cut=float(1e6)
    if self.options.low_resolution is not None:
      low_cut = self.options.low_resolution
      print("Specified low resolution limit: %3.2f"%(
       float(self.options.low_resolution) ), file=out)

    high_cut = 0
    if self.options.high_resolution is not None:
      high_cut = self.options.high_resolution
      print("Specified high resolution limit: %3.2f"%(
       float(self.options.high_resolution) ), file=out)

    ## perform outlier analyses
    ##
    ## Do a simple outlier analyses please
    print(file=out)
    print("Wilson statistics based outlier analyses", file=out)
    print("----------------------------------------", file=out)
    print(file=out)
    native_outlier = data_statistics.possible_outliers(
      miller_array = self.x1,
      prob_cut_ex = self.options.outlier_level_extreme,
      prob_cut_wil = self.options.outlier_level_wilson )
    native_outlier.show(out=out)

    self.x1 = native_outlier.remove_outliers(
      self.x1 )

    ## apply anisotropic scaling  (final B-value will be set to b_add)!
    if self.options.aniso_correction:

      b_final = self.options.b_add
      if b_final is None:
        b_final = 0.0

      print(file=out)
      print("Anisotropic absolute scaling of data", file=out)
      print("--------------------------------------", file=out)
      print(file=out)

      aniso_correct = absolute_scaling.ml_aniso_absolute_scaling(
        miller_array = self.x1,
        n_residues = n_residues*\
        self.x1.space_group().order_z()*n_copies_solc,
        n_bases = n_bases*\
        self.x1.space_group().order_z()*n_copies_solc)
      aniso_correct.show(out=out,verbose=1)
      print(file=out)
      print("  removing anisotropy for native  ", file=out)
      print(file=out)
      u_star_correct_nat = aniso_correct.u_star
      self.x1 = absolute_scaling.anisotropic_correction(
        self.x1,
        aniso_correct.p_scale,
        u_star_correct_nat  )
  def __init__(self,
               miller_array,
               phil_object,
               out=None,
               out_plot=None, miller_calc=None,
               original_intensities=None,
               completeness_as_non_anomalous=None,
               verbose=0):
    if out is None:
      out=sys.stdout
    if verbose>0:
      print >> out
      print >> out
      print >> out, "Matthews coefficient and Solvent content statistics"
    n_copies_solc = 1.0
    self.nres_known = False
    if (phil_object.scaling.input.asu_contents.n_residues is not None or
        phil_object.scaling.input.asu_contents.n_bases is not None) :
      self.nres_known = True
      if (phil_object.scaling.input.asu_contents.sequence_file is not None) :
        print >> out, "  warning: ignoring sequence file"
    elif (phil_object.scaling.input.asu_contents.sequence_file is not None) :
      print >> out, "  determining composition from sequence file %s" % \
        phil_object.scaling.input.asu_contents.sequence_file
      seq_comp = iotbx.bioinformatics.composition_from_sequence_file(
        file_name=phil_object.scaling.input.asu_contents.sequence_file,
        log=out)
      if (seq_comp is not None) :
        phil_object.scaling.input.asu_contents.n_residues = seq_comp.n_residues
        phil_object.scaling.input.asu_contents.n_bases = seq_comp.n_bases
        self.nres_known = True
    matthews_results =matthews.matthews_rupp(
      crystal_symmetry = miller_array,
      n_residues = phil_object.scaling.input.asu_contents.n_residues,
      n_bases = phil_object.scaling.input.asu_contents.n_bases,
      out=out,verbose=1)
    phil_object.scaling.input.asu_contents.n_residues = matthews_results[0]
    phil_object.scaling.input.asu_contents.n_bases = matthews_results[1]
    n_copies_solc = matthews_results[2]
    self.matthews_results = matthews_results

    if phil_object.scaling.input.asu_contents.n_copies_per_asu is not None:
      n_copies_solc = phil_object.scaling.input.asu_contents.n_copies_per_asu
      self.defined_copies = n_copies_solc
      if verbose>0:
        print >> out,"Number of copies per asymmetric unit provided"
        print >> out," Will use user specified value of ", n_copies_solc
    else:
      phil_object.scaling.input.asu_contents.n_copies_per_asu = n_copies_solc
      self.guessed_copies = n_copies_solc

    # first report on I over sigma
    miller_array_new = miller_array
    self.data_strength = None
    miller_array_intensities = miller_array
    if (original_intensities is not None) :
      assert original_intensities.is_xray_intensity_array()
      miller_array_intensities = original_intensities
    if miller_array_intensities.sigmas() is not None:
      data_strength=data_statistics.i_sigi_completeness_stats(
        miller_array_intensities,
        isigi_cut = phil_object.scaling.input.parameters.misc_twin_parameters.twin_test_cuts.isigi_cut,
        completeness_cut = phil_object.scaling.input.parameters.misc_twin_parameters.twin_test_cuts.completeness_cut,
      completeness_as_non_anomalous=completeness_as_non_anomalous)
      data_strength.show(out)
      self.data_strength = data_strength
      if phil_object.scaling.input.parameters.misc_twin_parameters.twin_test_cuts.high_resolution is None:
        if data_strength.resolution_cut > data_strength.resolution_at_least:
          phil_object.scaling.input.parameters.misc_twin_parameters.twin_test_cuts.high_resolution = data_strength.resolution_at_least
        else:
           phil_object.scaling.input.parameters.misc_twin_parameters.twin_test_cuts.high_resolution = data_strength.resolution_cut

    ## Isotropic wilson scaling
    if verbose>0:
      print >> out
      print >> out
      print >> out, "Maximum likelihood isotropic Wilson scaling "

    n_residues =  phil_object.scaling.input.asu_contents.n_residues
    n_bases = phil_object.scaling.input.asu_contents.n_bases
    if n_residues is None:
      n_residues = 0
    if n_bases is None:
      n_bases = 0
    if n_bases+n_residues==0:
      raise Sorry("No scatterers available")
    iso_scale_and_b = absolute_scaling.ml_iso_absolute_scaling(
      miller_array = miller_array_new,
      n_residues = n_residues*
      miller_array.space_group().order_z()*n_copies_solc,
      n_bases=n_bases*
      miller_array.space_group().order_z()*n_copies_solc)
    iso_scale_and_b.show(out=out,verbose=verbose)
    self.iso_scale_and_b = iso_scale_and_b
    ## Store the b and scale values from isotropic ML scaling
    self.iso_p_scale = iso_scale_and_b.p_scale
    self.iso_b_wilson =  iso_scale_and_b.b_wilson


    ## Anisotropic ml wilson scaling
    if verbose>0:
      print >> out
      print >> out
      print >> out, "Maximum likelihood anisotropic Wilson scaling "
    aniso_scale_and_b = absolute_scaling.ml_aniso_absolute_scaling(
      miller_array = miller_array_new,
      n_residues = n_residues*miller_array.space_group().order_z()*n_copies_solc,
      n_bases = n_bases*miller_array.space_group().order_z()*n_copies_solc)
    aniso_scale_and_b.show(out=out,verbose=1)

    self.aniso_scale_and_b = aniso_scale_and_b

    try: b_cart = aniso_scale_and_b.b_cart
    except AttributeError, e:
      print >> out, "*** ERROR ***"
      print >> out, str(e)
      show_exception_info_if_full_testing()
      return
  def __init__(self,
               miller_array,
               parameters,
               out=None,
               n_residues=100,
               n_bases=0):

    self.params=parameters
    self.miller_array=miller_array.deep_copy().set_observation_type(
      miller_array).merge_equivalents().array()
    self.out = out
    if self.out is None:
      self.out = sys.stdout
    if self.out == "silent":
      self.out = null_out()


    self.no_aniso_array = self.miller_array
    if self.params.aniso.action == "remove_aniso":
      # first perfom aniso scaling
      aniso_scale_and_b = absolute_scaling.ml_aniso_absolute_scaling(
        miller_array = self.miller_array,
        n_residues = n_residues,
        n_bases = n_bases)
      aniso_scale_and_b.p_scale = 0 # set the p_scale back to 0!
      aniso_scale_and_b.show(out=out)
      # now do aniso correction please
      self.aniso_p_scale = aniso_scale_and_b.p_scale
      self.aniso_u_star  = aniso_scale_and_b.u_star
      self.aniso_b_cart  = aniso_scale_and_b.b_cart
      if self.params.aniso.final_b == "eigen_min":
        b_use=aniso_scale_and_b.eigen_values[2]
      elif self.params.aniso.final_b == "eigen_mean" :
        b_use=flex.mean(aniso_scale_and_b.eigen_values)
      elif self.params.aniso.final_b == "user_b_iso":
        assert self.params.aniso.b_iso is not None
        b_use=self.params.aniso.b_iso
      else:
        b_use = 30

      b_cart_aniso_removed = [ -b_use,
                               -b_use,
                               -b_use,
                               0,
                               0,
                               0]
      u_star_aniso_removed = adptbx.u_cart_as_u_star(
        miller_array.unit_cell(),
        adptbx.b_as_u( b_cart_aniso_removed  ) )
      ## I do things in two steps, but can easely be done in 1 step
      ## just for clarity, thats all.
      self.no_aniso_array = absolute_scaling.anisotropic_correction(
        self.miller_array,0.0,aniso_scale_and_b.u_star )
      self.no_aniso_array = absolute_scaling.anisotropic_correction(
        self.no_aniso_array,0.0,u_star_aniso_removed)
      self.no_aniso_array = self.no_aniso_array.set_observation_type(
        miller_array )

    # that is done now, now we can do outlier detection if desired
    outlier_manager = outlier_rejection.outlier_manager(
      self.no_aniso_array,
      None,
      out=self.out)


    self.new_miller_array = self.no_aniso_array
    if self.params.outlier.action == "basic":
      print >> self.out, "Non-outliers found by the basic wilson statistics"
      print >> self.out, "protocol will be written out."
      basic_array = outlier_manager.basic_wilson_outliers(
        p_basic_wilson = self.params.outlier.parameters.basic_wilson.level,
        return_data = True)
      self.new_miller_array = basic_array

    if self.params.outlier.action == "extreme":
      print >> self.out, "Non-outliers found by the extreme value wilson statistics"
      print >> self.out, "protocol will be written out."
      extreme_array = outlier_manager.extreme_wilson_outliers(
      p_extreme_wilson = self.params.outlier.parameters.extreme_wilson.level,
      return_data = True)
      self.new_miller_array = extreme_array

    if self.params.outlier.action == "beamstop":
      print >> self.out, "Outliers found for the beamstop shadow"
      print >> self.out, "problems detection protocol will be written out."
      beamstop_array = outlier_manager.beamstop_shadow_outliers(
        level = self.params.outlier.parameters.beamstop.level,
        d_min = self.params.outlier.parameters.beamstop.d_min,
        return_data=True)
      self.new_miller_array = beamstop_array

    if self.params.outlier.action == "None":
      self.new_miller_array =  self.no_aniso_array



    # now we can twin or detwin the data if needed
    self.final_array = self.new_miller_array
    if self.params.symmetry.action == "twin":
      alpha = self.params.symmetry.twinning_parameters.fraction
      if (alpha is None):
        raise Sorry("Twin fraction not specified, not twinning data")
      elif not (0 <= alpha <= 0.5):
        raise Sorry("Twin fraction must be between 0 and 0.5.")
      print >> self.out
      print >> self.out, "Twinning given data"
      print >> self.out, "-------------------"
      print >> self.out
      print >> self.out, "Artifically twinning the data with fraction %3.2f" %\
        alpha

      self.final_array = self.new_miller_array.twin_data(
        twin_law = self.params.symmetry.twinning_parameters.twin_law,
        alpha=alpha).as_intensity_array()

    elif (self.params.symmetry.action == "detwin"):
      twin_law = self.params.symmetry.twinning_parameters.twin_law
      alpha = self.params.symmetry.twinning_parameters.fraction
      if (alpha is None):
        raise Sorry("Twin fraction not specified, not detwinning data")
      elif not (0 <= alpha <= 0.5):
        raise Sorry("Twin fraction must be between 0 and 0.5.")
      print >> self.out, """

Attempting to detwin data
-------------------------
Detwinning data with:
  - twin law:      %s
  - twin fraciton: %.2f

BE WARNED! DETWINNING OF DATA DOES NOT SOLVE YOUR TWINNING PROBLEM!
PREFERABLY, REFINEMENT SHOULD BE CARRIED OUT AGAINST ORIGINAL DATA
ONLY USING A TWIN SPECIFIC TARGET FUNCTION!

""" % (twin_law, alpha)
      self.final_array = self.new_miller_array.detwin_data(
        twin_law=twin_law,
        alpha=alpha).as_intensity_array()

    assert self.final_array is not None
Exemple #17
0
    def __init__(self,
                 miller_array,
                 phil_object,
                 out=None,
                 out_plot=None,
                 miller_calc=None,
                 original_intensities=None,
                 completeness_as_non_anomalous=None,
                 verbose=0):
        if out is None:
            out = sys.stdout
        if verbose > 0:
            print(file=out)
            print(file=out)
            print("Matthews coefficient and Solvent content statistics",
                  file=out)
        n_copies_solc = 1.0
        self.nres_known = False
        if (phil_object.scaling.input.asu_contents.n_residues is not None
                or phil_object.scaling.input.asu_contents.n_bases is not None):
            self.nres_known = True
            if (phil_object.scaling.input.asu_contents.sequence_file
                    is not None):
                print("  warning: ignoring sequence file", file=out)
        elif (phil_object.scaling.input.asu_contents.sequence_file
              is not None):
            print("  determining composition from sequence file %s" % \
              phil_object.scaling.input.asu_contents.sequence_file, file=out)
            seq_comp = iotbx.bioinformatics.composition_from_sequence_file(
                file_name=phil_object.scaling.input.asu_contents.sequence_file,
                log=out)
            if (seq_comp is not None):
                phil_object.scaling.input.asu_contents.n_residues = seq_comp.n_residues
                phil_object.scaling.input.asu_contents.n_bases = seq_comp.n_bases
                self.nres_known = True
        matthews_results = matthews.matthews_rupp(
            crystal_symmetry=miller_array,
            n_residues=phil_object.scaling.input.asu_contents.n_residues,
            n_bases=phil_object.scaling.input.asu_contents.n_bases,
            out=out,
            verbose=1)
        phil_object.scaling.input.asu_contents.n_residues = matthews_results[0]
        phil_object.scaling.input.asu_contents.n_bases = matthews_results[1]
        n_copies_solc = matthews_results[2]
        self.matthews_results = matthews_results

        if phil_object.scaling.input.asu_contents.n_copies_per_asu is not None:
            n_copies_solc = phil_object.scaling.input.asu_contents.n_copies_per_asu
            self.defined_copies = n_copies_solc
            if verbose > 0:
                print("Number of copies per asymmetric unit provided",
                      file=out)
                print(" Will use user specified value of ",
                      n_copies_solc,
                      file=out)
        else:
            phil_object.scaling.input.asu_contents.n_copies_per_asu = n_copies_solc
            self.guessed_copies = n_copies_solc

        # first report on I over sigma
        miller_array_new = miller_array
        self.data_strength = None
        miller_array_intensities = miller_array
        if (original_intensities is not None):
            assert original_intensities.is_xray_intensity_array()
            miller_array_intensities = original_intensities
        if miller_array_intensities.sigmas() is not None:
            data_strength = data_statistics.i_sigi_completeness_stats(
                miller_array_intensities,
                isigi_cut=phil_object.scaling.input.parameters.
                misc_twin_parameters.twin_test_cuts.isigi_cut,
                completeness_cut=phil_object.scaling.input.parameters.
                misc_twin_parameters.twin_test_cuts.completeness_cut,
                completeness_as_non_anomalous=completeness_as_non_anomalous)
            data_strength.show(out)
            self.data_strength = data_strength
            if phil_object.scaling.input.parameters.misc_twin_parameters.twin_test_cuts.high_resolution is None:
                if data_strength.resolution_cut > data_strength.resolution_at_least:
                    phil_object.scaling.input.parameters.misc_twin_parameters.twin_test_cuts.high_resolution = data_strength.resolution_at_least
                else:
                    phil_object.scaling.input.parameters.misc_twin_parameters.twin_test_cuts.high_resolution = data_strength.resolution_cut

        ## Isotropic wilson scaling
        if verbose > 0:
            print(file=out)
            print(file=out)
            print("Maximum likelihood isotropic Wilson scaling ", file=out)

        n_residues = phil_object.scaling.input.asu_contents.n_residues
        n_bases = phil_object.scaling.input.asu_contents.n_bases
        if n_residues is None:
            n_residues = 0
        if n_bases is None:
            n_bases = 0
        if n_bases + n_residues == 0:
            raise Sorry("No scatterers available")
        iso_scale_and_b = absolute_scaling.ml_iso_absolute_scaling(
            miller_array=miller_array_new,
            n_residues=n_residues * miller_array.space_group().order_z() *
            n_copies_solc,
            n_bases=n_bases * miller_array.space_group().order_z() *
            n_copies_solc)
        iso_scale_and_b.show(out=out, verbose=verbose)
        self.iso_scale_and_b = iso_scale_and_b
        ## Store the b and scale values from isotropic ML scaling
        self.iso_p_scale = iso_scale_and_b.p_scale
        self.iso_b_wilson = iso_scale_and_b.b_wilson

        ## Anisotropic ml wilson scaling
        if verbose > 0:
            print(file=out)
            print(file=out)
            print("Maximum likelihood anisotropic Wilson scaling ", file=out)
        aniso_scale_and_b = absolute_scaling.ml_aniso_absolute_scaling(
            miller_array=miller_array_new,
            n_residues=n_residues * miller_array.space_group().order_z() *
            n_copies_solc,
            n_bases=n_bases * miller_array.space_group().order_z() *
            n_copies_solc)
        aniso_scale_and_b.show(out=out, verbose=1)

        self.aniso_scale_and_b = aniso_scale_and_b

        try:
            b_cart = aniso_scale_and_b.b_cart
        except AttributeError as e:
            print("*** ERROR ***", file=out)
            print(str(e), file=out)
            show_exception_info_if_full_testing()
            return

        self.aniso_p_scale = aniso_scale_and_b.p_scale
        self.aniso_u_star = aniso_scale_and_b.u_star
        self.aniso_b_cart = aniso_scale_and_b.b_cart
        # XXX: for GUI
        self.overall_b_cart = getattr(aniso_scale_and_b, "overall_b_cart",
                                      None)

        ## Correcting for anisotropy
        if verbose > 0:
            print("Correcting for anisotropy in the data", file=out)
            print(file=out)

        b_cart_observed = aniso_scale_and_b.b_cart

        b_trace_average = (b_cart_observed[0] + b_cart_observed[1] +
                           b_cart_observed[2]) / 3.0
        b_trace_min = b_cart_observed[0]
        if b_cart_observed[1] < b_trace_min: b_trace_min = b_cart_observed[1]
        if b_cart_observed[2] < b_trace_min: b_trace_min = b_cart_observed[2]

        if phil_object.scaling.input.optional.aniso.final_b == "eigen_min":
            b_use = aniso_scale_and_b.eigen_values[2]
        elif phil_object.scaling.input.optional.aniso.final_b == "eigen_mean":
            b_use = flex.mean(aniso_scale_and_b.eigen_values)
        elif phil_object.scaling.input.optional.aniso.final_b == "user_b_iso":
            assert phil_object.scaling.input.optional.aniso.b_iso is not None
            b_use = phil_object.scaling.input.optional.aniso.b_iso
        else:
            b_use = 30

        b_cart_aniso_removed = [-b_use, -b_use, -b_use, 0, 0, 0]
        u_star_aniso_removed = adptbx.u_cart_as_u_star(
            miller_array.unit_cell(), adptbx.b_as_u(b_cart_aniso_removed))
        ## I do things in two steps, but can easely be done in 1 step
        ## just for clarity, thats all.
        self.no_aniso_array = absolute_scaling.anisotropic_correction(
            miller_array_new, 0.0, aniso_scale_and_b.u_star)
        self.no_aniso_array = absolute_scaling.anisotropic_correction(
            self.no_aniso_array, 0.0, u_star_aniso_removed)
        self.no_aniso_array = self.no_aniso_array.set_observation_type(
            miller_array)

        ## Make normalised structure factors please

        sel_big = self.no_aniso_array.data() > 1.e+50
        self.no_aniso_array = self.no_aniso_array.array(
            data=self.no_aniso_array.data().set_selected(sel_big, 0))
        self.no_aniso_array = self.no_aniso_array.set_observation_type(
            miller_array)

        normalistion = absolute_scaling.kernel_normalisation(
            self.no_aniso_array, auto_kernel=True)
        self.normalised_miller = normalistion.normalised_miller.deep_copy()

        self.phil_object = phil_object

        ## Some basic statistics and sanity checks follow
        if verbose > 0:
            print("Some basic intensity statistics follow.", file=out)
            print(file=out)

        basic_data_stats = data_statistics.basic_intensity_statistics(
            miller_array,
            aniso_scale_and_b.p_scale,
            aniso_scale_and_b.u_star,
            iso_scale_and_b.scat_info,
            out=out,
            out_plot=out_plot)
        self.basic_data_stats = basic_data_stats
        self.miller_array = basic_data_stats.new_miller

        #relative wilson plot
        self.rel_wilson = None
        if (miller_calc is not None) and (miller_calc.d_min() < 4.0):
            try:
                self.rel_wilson = relative_wilson.relative_wilson(
                    miller_obs=miller_array, miller_calc=miller_calc)
            except RuntimeError as e:
                print("*** Error calculating relative Wilson plot - skipping.",
                      file=out)
                print("", file=out)

        if verbose > 0:
            print("Basic analyses completed", file=out)
  def __init__(self,
               miller_array,
               parameters,
               out=None,
               n_residues=100,
               n_bases=0):

    self.params=parameters
    self.miller_array=miller_array.deep_copy().set_observation_type(
      miller_array).merge_equivalents().array()
    self.out = out
    if self.out is None:
      self.out = sys.stdout
    if self.out == "silent":
      self.out = null_out()


    self.no_aniso_array = self.miller_array
    if self.params.aniso.action == "remove_aniso":
      # first perfom aniso scaling
      aniso_scale_and_b = absolute_scaling.ml_aniso_absolute_scaling(
        miller_array = self.miller_array,
        n_residues = n_residues,
        n_bases = n_bases)
      aniso_scale_and_b.p_scale = 0 # set the p_scale back to 0!
      aniso_scale_and_b.show(out=out)
      # now do aniso correction please
      self.aniso_p_scale = aniso_scale_and_b.p_scale
      self.aniso_u_star  = aniso_scale_and_b.u_star
      self.aniso_b_cart  = aniso_scale_and_b.b_cart
      if self.params.aniso.final_b == "eigen_min":
        b_use=aniso_scale_and_b.eigen_values[2]
      elif self.params.aniso.final_b == "eigen_mean" :
        b_use=flex.mean(aniso_scale_and_b.eigen_values)
      elif self.params.aniso.final_b == "user_b_iso":
        assert self.params.aniso.b_iso is not None
        b_use=self.params.aniso.b_iso
      else:
        b_use = 30

      b_cart_aniso_removed = [ -b_use,
                               -b_use,
                               -b_use,
                               0,
                               0,
                               0]
      u_star_aniso_removed = adptbx.u_cart_as_u_star(
        miller_array.unit_cell(),
        adptbx.b_as_u( b_cart_aniso_removed  ) )
      ## I do things in two steps, but can easely be done in 1 step
      ## just for clarity, thats all.
      self.no_aniso_array = absolute_scaling.anisotropic_correction(
        self.miller_array,0.0,aniso_scale_and_b.u_star )
      self.no_aniso_array = absolute_scaling.anisotropic_correction(
        self.no_aniso_array,0.0,u_star_aniso_removed)
      self.no_aniso_array = self.no_aniso_array.set_observation_type(
        miller_array )

    # that is done now, now we can do outlier detection if desired
    outlier_manager = outlier_rejection.outlier_manager(
      self.no_aniso_array,
      None,
      out=self.out)


    self.new_miller_array = self.no_aniso_array
    if self.params.outlier.action == "basic":
      print >> self.out, "Non-outliers found by the basic wilson statistics"
      print >> self.out, "protocol will be written out."
      basic_array = outlier_manager.basic_wilson_outliers(
        p_basic_wilson = self.params.outlier.parameters.basic_wilson.level,
        return_data = True)
      self.new_miller_array = basic_array

    if self.params.outlier.action == "extreme":
      print >> self.out, "Non-outliers found by the extreme value wilson statistics"
      print >> self.out, "protocol will be written out."
      extreme_array = outlier_manager.extreme_wilson_outliers(
      p_extreme_wilson = self.params.outlier.parameters.extreme_wilson.level,
      return_data = True)
      self.new_miller_array = extreme_array

    if self.params.outlier.action == "beamstop":
      print >> self.out, "Outliers found for the beamstop shadow"
      print >> self.out, "problems detection protocol will be written out."
      beamstop_array = outlier_manager.beamstop_shadow_outliers(
        level = self.params.outlier.parameters.beamstop.level,
        d_min = self.params.outlier.parameters.beamstop.d_min,
        return_data=True)
      self.new_miller_array = beamstop_array

    if self.params.outlier.action == "None":
      self.new_miller_array =  self.no_aniso_array



    # now we can twin or detwin the data if needed
    self.final_array = self.new_miller_array
    if self.params.symmetry.action == "twin":
      alpha = self.params.symmetry.twinning_parameters.fraction
      if (alpha is None) :
        raise Sorry("Twin fraction not specified, not twinning data")
      elif not (0 <= alpha <= 0.5):
        raise Sorry("Twin fraction must be between 0 and 0.5.")
      print >> self.out
      print >> self.out, "Twinning given data"
      print >> self.out, "-------------------"
      print >> self.out
      print >> self.out, "Artifically twinning the data with fraction %3.2f" %\
        alpha

      self.final_array = self.new_miller_array.twin_data(
        twin_law = self.params.symmetry.twinning_parameters.twin_law,
        alpha=alpha).as_intensity_array()

    elif (self.params.symmetry.action == "detwin") :
      twin_law = self.params.symmetry.twinning_parameters.twin_law
      alpha = self.params.symmetry.twinning_parameters.fraction
      if (alpha is None) :
        raise Sorry("Twin fraction not specified, not detwinning data")
      elif not (0 <= alpha <= 0.5):
        raise Sorry("Twin fraction must be between 0 and 0.5.")
      print >> self.out, """

Attempting to detwin data
-------------------------
Detwinning data with:
  - twin law:      %s
  - twin fraciton: %.2f

BE WARNED! DETWINNING OF DATA DOES NOT SOLVE YOUR TWINNING PROBLEM!
PREFERABLY, REFINEMENT SHOULD BE CARRIED OUT AGAINST ORIGINAL DATA
ONLY USING A TWIN SPECIFIC TARGET FUNCTION!

""" % (twin_law, alpha)
      self.final_array = self.new_miller_array.detwin_data(
        twin_law=twin_law,
        alpha=alpha).as_intensity_array()

    assert self.final_array is not None
Exemple #19
0
  def __init__(self,
               miller_array,
               pre_scaling_protocol,
               basic_info,
               out=None):
    ## Make deep copy of the miller array of interest
    self.x1 = miller_array.deep_copy()
    self.options=pre_scaling_protocol
    self.basic_info= basic_info

    ## Determine unit_cell contents
    print >> out
    print >> out, "Matthews analyses"
    print >> out, "-----------------"
    print >> out
    print >> out, "Inspired by: Kantardjieff and Rupp. Prot. Sci. 12(9): 1865-1871 (2003)."
    matthews_analyses = matthews.matthews_rupp(
      crystal_symmetry = self.x1,
      n_residues = self.basic_info.n_residues,
      n_bases = self.basic_info.n_bases,
      out=out, verbose=1)
    n_residues=matthews_analyses[0]
    n_bases=matthews_analyses[1]
    n_copies_solc=matthews_analyses[2]

    if (self.basic_info.n_residues==None):
      self.basic_info.n_residues = n_residues
    if (self.basic_info.n_bases == None):
      self.basic_info.n_bases = n_bases


    ## apply resolution cut
    print >> out
    print >> out, "Applying resolution cut"
    print >> out, "-----------------------"

    if self.options.low_resolution is None:
      if self.options.high_resolution is None:
        print >> out, "No resolution cut is made"

    low_cut=float(1e6)
    if self.options.low_resolution is not None:
      low_cut = self.options.low_resolution
      print >> out, "Specified low resolution limit: %3.2f"%(
       float(self.options.low_resolution) )

    high_cut = 0
    if self.options.high_resolution is not None:
      high_cut = self.options.high_resolution
      print >> out, "Specified high resolution limit: %3.2f"%(
       float(self.options.high_resolution) )

    ## perform outlier analyses
    ##
    ## Do a simple outlier analyses please
    print >> out
    print >> out, "Wilson statistics based outlier analyses"
    print >> out, "----------------------------------------"
    print >> out
    native_outlier = data_statistics.possible_outliers(
      miller_array = self.x1,
      prob_cut_ex = self.options.outlier_level_extreme,
      prob_cut_wil = self.options.outlier_level_wilson )
    native_outlier.show(out=out)

    self.x1 = native_outlier.remove_outliers(
      self.x1 )

    ## apply anisotropic scaling  (final B-value will be set to b_add)!
    if self.options.aniso_correction:

      b_final = self.options.b_add
      if b_final is None:
        b_final = 0.0

      print >> out
      print >> out, "Anisotropic absolute scaling of data"
      print >> out, "--------------------------------------"
      print >> out

      aniso_correct = absolute_scaling.ml_aniso_absolute_scaling(
        miller_array = self.x1,
        n_residues = n_residues*\
        self.x1.space_group().order_z()*n_copies_solc,
        n_bases = n_bases*\
        self.x1.space_group().order_z()*n_copies_solc)
      aniso_correct.show(out=out,verbose=1)
      print >> out
      print >> out, "  removing anisotropy for native  "
      print >> out
      u_star_correct_nat = aniso_correct.u_star
      self.x1 = absolute_scaling.anisotropic_correction(
        self.x1,
        aniso_correct.p_scale,
        u_star_correct_nat  )