Exemplo n.º 1
0
  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())
Exemplo n.º 2
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,
            ),
        )
Exemplo n.º 3
0
def dummy_structure(space_group_info, volume, n_scatterers):
  structure = xray.structure(
    special_position_settings=crystal.special_position_settings(
      crystal_symmetry=crystal.symmetry(
        unit_cell=space_group_info.any_compatible_unit_cell(volume=volume),
        space_group_info=space_group_info)))
  b_iso = 20
  u_iso = adptbx.b_as_u(b_iso)
  u_star = adptbx.u_iso_as_u_star(structure.unit_cell(), u_iso)
  scatterer = xray.scatterer(label="C", site=(0.123,0.234,0.345), u=u_star)
  for i in xrange(n_scatterers):
    structure.add_scatterer(scatterer)
  return structure
Exemplo n.º 4
0
 def add_new_solvent(self):
     if (self.params.b_iso is None):
         sol_sel = self.model.solvent_selection()
         xrs_mac_h = self.model.get_xray_structure().select(~sol_sel)
         hd_mac = self.model.get_hd_selection().select(~sol_sel)
         xrs_mac = xrs_mac_h.select(~hd_mac)
         b = xrs_mac.extract_u_iso_or_u_equiv() * math.pi**2 * 8
         b_solv = flex.mean_default(b, None)
         if (b_solv is not None and b_solv < self.params.b_iso_min
                 or b_solv > self.params.b_iso_max):
             b_solv = (self.params.b_iso_min + self.params.b_iso_max) / 2.
     else:
         b_solv = self.params.b_iso
     if (self.params.new_solvent == "isotropic"):
         new_scatterers = flex.xray_scatterer(
             self.sites.size(),
             xray.scatterer(occupancy=self.params.occupancy,
                            b=b_solv,
                            scattering_type=self.params.scattering_type))
     elif (self.params.new_solvent == "anisotropic"):
         u_star = adptbx.u_iso_as_u_star(
             self.model.get_xray_structure().unit_cell(),
             adptbx.b_as_u(b_solv))
         new_scatterers = flex.xray_scatterer(
             self.sites.size(),
             xray.scatterer(occupancy=self.params.occupancy,
                            u=u_star,
                            scattering_type=self.params.scattering_type))
     else:
         raise RuntimeError
     new_scatterers.set_sites(self.sites)
     solvent_xray_structure = xray.structure(
         special_position_settings=self.model.get_xray_structure(),
         scatterers=new_scatterers)
     xrs_sol = self.model.get_xray_structure().select(
         self.model.solvent_selection())
     xrs_mac = self.model.get_xray_structure().select(
         ~self.model.solvent_selection())
     xrs_sol = xrs_sol.concatenate(other=solvent_xray_structure)
     sol_sel = flex.bool(xrs_mac.scatterers().size(), False)
     sol_sel.extend(flex.bool(xrs_sol.scatterers().size(), True))
     self.model.add_solvent(
         solvent_xray_structure=solvent_xray_structure,
         residue_name=self.params.output_residue_name,
         atom_name=self.params.output_atom_name,
         chain_id=self.params.output_chain_id,
         refine_occupancies=self.params.refine_occupancies,
         refine_adp=self.params.new_solvent)
     self.fmodel.update_xray_structure(
         xray_structure=self.model.get_xray_structure(), update_f_calc=True)
Exemplo n.º 5
0
 def add_new_solvent(self):
   if(self.params.b_iso is None):
     sol_sel = self.model.solvent_selection()
     xrs_mac_h = self.model.xray_structure.select(~sol_sel)
     hd_mac = self.model.xray_structure.hd_selection().select(~sol_sel)
     xrs_mac = xrs_mac_h.select(~hd_mac)
     b = xrs_mac.extract_u_iso_or_u_equiv() * math.pi**2*8
     b_solv = flex.mean_default(b, None)
     if(b_solv is not None and b_solv < self.params.b_iso_min or
        b_solv > self.params.b_iso_max):
       b_solv = (self.params.b_iso_min + self.params.b_iso_max) / 2.
   else:
     b_solv = self.params.b_iso
   if(self.params.new_solvent == "isotropic"):
     new_scatterers = flex.xray_scatterer(
       self.sites.size(),
       xray.scatterer(occupancy       = self.params.occupancy,
                      b               = b_solv,
                      scattering_type = self.params.scattering_type))
   elif(self.params.new_solvent == "anisotropic"):
     u_star = adptbx.u_iso_as_u_star(self.model.xray_structure.unit_cell(),
       adptbx.b_as_u(b_solv))
     new_scatterers = flex.xray_scatterer(
       self.sites.size(),
       xray.scatterer(
         occupancy       = self.params.occupancy,
         u               = u_star,
         scattering_type = self.params.scattering_type))
   else: raise RuntimeError
   new_scatterers.set_sites(self.sites)
   solvent_xray_structure = xray.structure(
     special_position_settings = self.model.xray_structure,
     scatterers                = new_scatterers)
   xrs_sol = self.model.xray_structure.select(self.model.solvent_selection())
   xrs_mac = self.model.xray_structure.select(~self.model.solvent_selection())
   xrs_sol = xrs_sol.concatenate(other = solvent_xray_structure)
   sol_sel = flex.bool(xrs_mac.scatterers().size(), False)
   sol_sel.extend( flex.bool(xrs_sol.scatterers().size(), True) )
   self.model.add_solvent(
     solvent_xray_structure = solvent_xray_structure,
     residue_name           = self.params.output_residue_name,
     atom_name              = self.params.output_atom_name,
     chain_id               = self.params.output_chain_id,
     refine_occupancies     = self.params.refine_occupancies,
     refine_adp             = self.params.new_solvent)
   self.fmodel.update_xray_structure(
     xray_structure = self.model.xray_structure,
     update_f_calc  = True)
Exemplo n.º 6
0
def split_u(xray_structure, tls_selections, offset):
    global time_split_u
    timer = user_plus_sys_time()
    uc = xray_structure.unit_cell()
    u_iso = xray_structure.scatterers().extract_u_iso()
    u_eq_1 = xray_structure.extract_u_iso_or_u_equiv()
    for tls_selection in tls_selections:
        u_iso_sel = u_iso.select(tls_selection)
        u_iso_min = flex.min(u_iso_sel)
        if (offset):
            offset_ = adptbx.b_as_u(5.0)
        else:
            offset_ = 0.0
        if u_iso_min >= offset_:
            u_iso_min = u_iso_min - offset_
        t = adptbx.u_iso_as_u_star(uc, u_iso_min)
        for i_seq in tls_selection:
            sc = xray_structure.scatterers()[i_seq]
            assert sc.u_iso == u_iso[i_seq]
            u_iso_new = sc.u_iso - u_iso_min
            assert u_iso_new >= 0.0
            sc.u_iso = u_iso_new
            assert sc.flags.use_u_aniso()
            assert sc.flags.use_u_iso()
            if (sc.u_star == (-1.0, -1.0, -1.0, -1.0, -1.0, -1.0)):
                sc.u_star = t
            else:
                x = flex.double(sc.u_star)
                y = flex.double(t)
                z = list(x + y)
                sc.u_star = z
    u_iso = xray_structure.scatterers().extract_u_iso().select(
        xray_structure.use_u_iso())
    assert (u_iso < 0.0).count(True) == 0
    u_eq_2 = xray_structure.extract_u_iso_or_u_equiv()
    assert approx_equal(u_eq_1, u_eq_2)
    time_split_u += timer.elapsed()
Exemplo n.º 7
0
def split_u(xray_structure, tls_selections, offset):
  global time_split_u
  timer = user_plus_sys_time()
  uc = xray_structure.unit_cell()
  u_iso = xray_structure.scatterers().extract_u_iso()
  u_eq_1  = xray_structure.extract_u_iso_or_u_equiv()
  for tls_selection in tls_selections:
    u_iso_sel = u_iso.select(tls_selection)
    u_iso_min = flex.min(u_iso_sel)
    if(offset):
      offset_ = adptbx.b_as_u(5.0)
    else: offset_ = 0.0
    if u_iso_min >= offset_:
      u_iso_min = u_iso_min - offset_
    t = adptbx.u_iso_as_u_star(uc, u_iso_min)
    for i_seq in tls_selection:
      sc = xray_structure.scatterers()[i_seq]
      assert sc.u_iso == u_iso[i_seq]
      u_iso_new = sc.u_iso - u_iso_min
      assert u_iso_new >= 0.0
      sc.u_iso = u_iso_new
      assert sc.flags.use_u_aniso()
      assert sc.flags.use_u_iso()
      if(sc.u_star == (-1.0,-1.0,-1.0,-1.0,-1.0,-1.0)):
        sc.u_star = t
      else:
        x = flex.double(sc.u_star)
        y = flex.double(t)
        z = list(x + y)
        sc.u_star = z
  u_iso = xray_structure.scatterers().extract_u_iso().select(
    xray_structure.use_u_iso())
  assert (u_iso < 0.0).count(True) == 0
  u_eq_2  = xray_structure.extract_u_iso_or_u_equiv()
  assert approx_equal(u_eq_1, u_eq_2)
  time_split_u += timer.elapsed()
Exemplo n.º 8
0
 def __init__ (self, residue_group, xray_structure, ignore_hydrogens=True) :
   from cctbx import adptbx
   from scitbx.array_family import flex
   from scitbx.matrix import col
   self.sites = []
   self.u_isos = []
   self.u_stars = []
   self.atom_names = []
   self.id_str = residue_group.id_str()
   unit_cell = xray_structure.unit_cell()
   atom_name_dict = {}
   for atom_group in residue_group.atom_groups() :
     b_isos = atom_group.atoms().extract_b()
     if (len(b_isos) > 1) and (b_isos.all_eq(b_isos[0])) :
       raise RuntimeError("B-factors for atom_group '%s' are identical" %
         atom_group.id_str())
     for atom in atom_group.atoms() :
       if (atom.element.strip() in ["H", "D"]) and (ignore_hydrogens) :
         continue
       if (not atom.name in atom_name_dict) :
         atom_name_dict[atom.name] = []
       atom_name_dict[atom.name].append(atom)
   self.n_confs = 1
   for atom_name in sorted(atom_name_dict.keys()) :
     n_atom_confs = len(atom_name_dict[atom_name])
     if (n_atom_confs > 1) :
       if (self.n_confs > 1) :
         if (self.n_confs != n_atom_confs) :
           raise RuntimeError(("Inconsistent conformers for '%s': atom %s "+
             "has %d confs but previously %d conformations were seen") %
             (self.id_str, atom_name, n_atom_confs, self.n_confs))
       else :
         self.n_confs = n_atom_confs
         for n in range(n_atom_confs) :
           self.sites.append(flex.vec3_double())
           self.u_isos.append(flex.double())
           self.u_stars.append([])
       self.atom_names.append(atom_name)
       for i_conf in range(n_atom_confs) :
         atom = atom_name_dict[atom_name][i_conf]
         scatterer = xray_structure.scatterers()[atom.i_seq]
         assert scatterer.label == atom.id_str()
         self.sites[i_conf].append(atom.xyz)
         if (scatterer.flags.use_u_aniso()) :
           self.u_isos[i_conf].append(adptbx.b_as_u(atom.b))
           self.u_stars[i_conf].append(scatterer.u_star)
         else :
           self.u_isos[i_conf].append(scatterer.u_iso)
           self.u_stars[i_conf].append(
             adptbx.u_iso_as_u_star(unit_cell, scatterer.u_iso))
   self.max_rmsd = 0
   self.max_distance_over_u = 0
   self.dxyz_save = self.u_iso_save = self.atom_name_save = None
   for i_conf, sites in enumerate(self.sites) :
     if (i_conf < self.n_confs - 1) :
       for j_conf in range(i_conf+1, self.n_confs) :
         sites_next = self.sites[j_conf]
         rmsd = sites.rms_difference(sites_next)
         if (rmsd > self.max_rmsd) :
           self.max_rmsd = rmsd
         for k_site, (site1, site2) in enumerate(zip(sites, sites_next)) :
           distance = abs(col(site1) - col(site2))
           #u = max(self.u_isos[i_conf][k_site], self.u_isos[j_conf][k_site])
           proj_sum = adptbx.projection_sum(
             ustar1=self.u_stars[i_conf][k_site],
             ustar2=self.u_stars[j_conf][k_site],
             site1=site1,
             site2=site2,
             unit_cell=unit_cell)
           u_proj = max(proj_sum.z_12(), proj_sum.z_21())
           if (u_proj <= 0) :
             continue
           ratio = distance / u_proj
           if (ratio > self.max_distance_over_u) :
             self.max_distance_over_u = ratio
             self.dxyz_save = distance
             self.u_iso_save = u_proj
             self.atom_name_save = self.atom_names[k_site]