예제 #1
0
def adp_volume_similarity_as_cif_loops(xray_structure, proxies):
    site_labels = xray_structure.scatterers().extract_labels()
    fmt = "%.4e"
    loop = model.loop(header=(
        "_restr_U_volume_similar_atom_site_label_1",
        "_restr_U_volume_similar_diff",
        "_restr_U_volume_similar_class_id",
    ))
    class_loop = model.loop(header=(
        "_restr_U_volume_similar_class_class_id",
        "_restr_U_volume_similar_class_target_weight_param",
        "_restr_U_volume_similar_class_average",
        "_restr_U_volume_similar_class_esd",
        "_restr_U_volume_similar_class_diff_max",
    ))
    unit_cell = xray_structure.unit_cell()
    params = adp_restraints.adp_restraint_params(
        u_cart=xray_structure.scatterers().extract_u_cart(unit_cell),
        u_iso=xray_structure.scatterers().extract_u_iso(),
        use_u_aniso=xray_structure.use_u_aniso())
    class_id = 0
    for proxy in proxies:
        restraint = adp_restraints.adp_volume_similarity(params=params,
                                                         proxy=proxy)
        class_id += 1
        class_loop.add_row(
            (class_id, fmt % math.sqrt(1 / proxy.weight),
             fmt % restraint.mean_u_volume, fmt % restraint.rms_deltas(),
             fmt % flex.max_absolute(restraint.deltas())))
        for i, i_seq in enumerate(proxy.i_seqs):
            loop.add_row(
                (site_labels[i_seq], fmt % restraint.deltas()[i], class_id))
    return class_loop, loop
예제 #2
0
    def check_refinement_stability(self):
        xs = self.xray_structure
        xs0 = self.reference_xray_structure = xs.deep_copy_scatterers()
        mi = xs0.build_miller_set(anomalous_flag=True, d_min=0.5)
        fo_sq = mi.structure_factors_from_scatterers(
            xs0, algorithm="direct").f_calc().norm()
        fo_sq = fo_sq.customized_copy(sigmas=flex.double(fo_sq.size(), 1))

        self.shake_selection = flex.bool([
            True if sc.element_symbol() == 'O' else False
            for sc in self.xray_structure.scatterers()
        ])
        xs.shake_fps(selection=self.shake_selection)
        xs.shake_fdps(selection=self.shake_selection)

        self.reparametrisation = constraints.reparametrisation(
            xs,
            self.constraints,
            self.connectivity_table,
            temperature=self.t_celsius)
        self.obs = fo_sq.as_xray_observations()
        ls = least_squares.crystallographic_ls(
            self.obs,
            self.reparametrisation,
            weighting_scheme=least_squares.mainstream_shelx_weighting())
        self.cycles = self.normal_eqns_solving_method(ls)
        print("%i %s iterations to recover from shaking" %
              (self.cycles.n_iterations, self.cycles))

        delta_fp = flex.double([
            sc.fp - sc0.fp
            for sc, sc0 in zip(xs.scatterers(), xs0.scatterers())
        ])

        delta_fdp = flex.double([
            sc.fdp - sc0.fdp
            for sc, sc0 in zip(xs.scatterers(), xs0.scatterers())
        ])

        assert flex.max_absolute(delta_fp) < self.fp_refinement_tolerance,\
               self.__class__.__name__

        assert flex.max_absolute(delta_fdp) < self.fdp_refinement_tolerance,\
               self.__class__.__name__
    def check_refinement_stability(self):
        if not self.shall_refine_thermal_displacements:
            for sc in self.xray_structure.scatterers():
                sc.flags.set_grad_site(True)
                if sc.flags.use_u_aniso(): sc.flags.set_grad_u_aniso(False)
                if sc.flags.use_u_iso(): sc.flags.set_grad_u_iso(False)

        xs = self.xray_structure
        xs0 = self.reference_xray_structure = xs.deep_copy_scatterers()
        mi = xs0.build_miller_set(anomalous_flag=False, d_min=0.5)
        fo_sq = mi.structure_factors_from_scatterers(
            xs0, algorithm="direct").f_calc().norm()
        fo_sq = fo_sq.customized_copy(sigmas=flex.double(fo_sq.size(), 1))

        xs.shake_sites_in_place(rms_difference=0.1)
        if self.shall_refine_thermal_displacements:
            # a spread of 10 for u_iso's would be enormous for our low temperature
            # test structures if those u_iso's were not constrained
            xs.shake_adp(
                spread=10,  # absolute
                aniso_spread=0.2)  # relative

        self.reparametrisation = constraints.reparametrisation(
            xs,
            self.constraints,
            self.connectivity_table,
            temperature=self.t_celsius)
        obs = fo_sq.as_xray_observations()
        ls = least_squares.crystallographic_ls(
            obs,
            self.reparametrisation,
            weighting_scheme=least_squares.mainstream_shelx_weighting())
        self.cycles = self.normal_eqns_solving_method(ls)
        print("%i %s iterations to recover from shaking" %
              (self.cycles.n_iterations, self.cycles))
        if 0:
            from crys3d.qttbx.xray_structure_viewer import display
            display(xray_structure=xs)

        diff = xray.meaningful_site_cart_differences(xs0, xs)
        assert diff.max_absolute() < self.site_refinement_tolerance,\
               self.__class__.__name__

        if self.shall_refine_thermal_displacements:
            delta_u = []
            for sc, sc0 in itertools.izip(xs.scatterers(), xs0.scatterers()):
                if not sc.flags.use_u_aniso() or not sc0.flags.use_u_aniso():
                    continue
                delta_u.extend(matrix.col(sc.u_star) - matrix.col(sc0.u_star))
            delta_u = flex.double(delta_u)

            assert flex.max_absolute(delta_u) < self.u_star_refinement_tolerance,\
                   self.__class__.__name__
  def check_refinement_stability(self):
    if not self.shall_refine_thermal_displacements:
      for sc in self.xray_structure.scatterers():
        sc.flags.set_grad_site(True)
        if sc.flags.use_u_aniso(): sc.flags.set_grad_u_aniso(False)
        if sc.flags.use_u_iso(): sc.flags.set_grad_u_iso(False)

    xs = self.xray_structure
    xs0 = self.reference_xray_structure = xs.deep_copy_scatterers()
    mi = xs0.build_miller_set(anomalous_flag=False, d_min=0.5)
    fo_sq = mi.structure_factors_from_scatterers(
      xs0, algorithm="direct").f_calc().norm()
    fo_sq = fo_sq.customized_copy(sigmas=flex.double(fo_sq.size(), 1))

    xs.shake_sites_in_place(rms_difference=0.1)
    if self.shall_refine_thermal_displacements:
      # a spread of 10 for u_iso's would be enormous for our low temperature
      # test structures if those u_iso's were not constrained
      xs.shake_adp(spread=10, # absolute
                   aniso_spread=0.2) # relative

    self.reparametrisation = constraints.reparametrisation(
      xs, self.constraints, self.connectivity_table,
      temperature=self.t_celsius)
    obs = fo_sq.as_xray_observations()
    ls = least_squares.crystallographic_ls(
      obs,
      self.reparametrisation,
      weighting_scheme=least_squares.mainstream_shelx_weighting())
    self.cycles = self.normal_eqns_solving_method(ls)
    print ("%i %s iterations to recover from shaking"
           % (self.cycles.n_iterations,
              self.cycles))
    if 0:
      from crys3d.qttbx.xray_structure_viewer import display
      display(xray_structure=xs)

    diff = xray.meaningful_site_cart_differences(xs0, xs)
    assert diff.max_absolute() < self.site_refinement_tolerance,\
           self.__class__.__name__

    if self.shall_refine_thermal_displacements:
      delta_u = []
      for sc, sc0 in itertools.izip(xs.scatterers(), xs0.scatterers()):
        if not sc.flags.use_u_aniso() or not sc0.flags.use_u_aniso(): continue
        delta_u.extend(matrix.col(sc.u_star) - matrix.col(sc0.u_star))
      delta_u = flex.double(delta_u)

      assert flex.max_absolute(delta_u) < self.u_star_refinement_tolerance,\
             self.__class__.__name__
예제 #5
0
def bond_similarity_as_cif_loops(xray_structure, proxies):
    space_group_info = sgtbx.space_group_info(
        group=xray_structure.space_group())
    unit_cell = xray_structure.unit_cell()
    sites_cart = xray_structure.sites_cart()
    site_labels = xray_structure.scatterers().extract_labels()
    fmt = "%.4f"
    loop = model.loop(header=(
        "_restr_equal_distance_atom_site_label_1",
        "_restr_equal_distance_atom_site_label_2",
        "_restr_equal_distance_site_symmetry_2",
        "_restr_equal_distance_class_id",
    ))
    class_loop = model.loop(header=(
        "_restr_equal_distance_class_class_id",
        "_restr_equal_distance_class_target_weight_param",
        "_restr_equal_distance_class_average",
        "_restr_equal_distance_class_esd",
        "_restr_equal_distance_class_diff_max",
    ))
    class_id = 0
    for proxy in proxies:
        restraint = geometry_restraints.bond_similarity(unit_cell=unit_cell,
                                                        sites_cart=sites_cart,
                                                        proxy=proxy)
        class_id += 1
        esd = math.sqrt(
            flex.sum(flex.pow2(restraint.deltas())) *
            (1. / proxy.i_seqs.size()))
        class_loop.add_row((
            class_id,
            fmt % math.sqrt(1 / proxy.weights[0]),  # assume equal weights
            fmt % restraint.mean_distance(),
            fmt % esd,
            fmt % flex.max_absolute(restraint.deltas())))
        for i in range(proxy.i_seqs.size()):
            i_seq, j_seq = proxy.i_seqs[i]
            if proxy.sym_ops is None:
                sym_op = sgtbx.rt_mx()
            else:
                sym_op = proxy.sym_ops[i]
            loop.add_row(
                (site_labels[i_seq], site_labels[j_seq],
                 space_group_info.cif_symmetry_code(sym_op), class_id))
    return class_loop, loop
예제 #6
0
def bond_similarity_as_cif_loops(xray_structure, proxies):
  space_group_info = sgtbx.space_group_info(group=xray_structure.space_group())
  unit_cell = xray_structure.unit_cell()
  sites_cart = xray_structure.sites_cart()
  site_labels = xray_structure.scatterers().extract_labels()
  fmt = "%.4f"
  loop = model.loop(header=(
    "_restr_equal_distance_atom_site_label_1",
    "_restr_equal_distance_atom_site_label_2",
    "_restr_equal_distance_site_symmetry_2",
    "_restr_equal_distance_class_id",
  ))
  class_loop = model.loop(header=(
    "_restr_equal_distance_class_class_id",
    "_restr_equal_distance_class_target_weight_param",
    "_restr_equal_distance_class_average",
    "_restr_equal_distance_class_esd",
    "_restr_equal_distance_class_diff_max",
  ))
  class_id = 0
  for proxy in proxies:
    restraint = geometry_restraints.bond_similarity(
      unit_cell=unit_cell,
      sites_cart=sites_cart,
      proxy=proxy)
    class_id += 1
    esd = math.sqrt(flex.sum(flex.pow2(restraint.deltas())) *
                    (1./proxy.i_seqs.size()))
    class_loop.add_row((class_id,
                        fmt % math.sqrt(1/proxy.weights[0]),# assume equal weights
                        fmt % restraint.mean_distance(),
                        fmt % esd,
                        fmt % flex.max_absolute(restraint.deltas())))
    for i in range(proxy.i_seqs.size()):
      i_seq, j_seq = proxy.i_seqs[i]
      if proxy.sym_ops is None:
        sym_op = sgtbx.rt_mx()
      else:
        sym_op = proxy.sym_ops[i]
      loop.add_row((site_labels[i_seq],
                    site_labels[j_seq],
                    space_group_info.cif_symmetry_code(sym_op),
                    class_id))
  return class_loop, loop
예제 #7
0
def adp_volume_similarity_as_cif_loops(xray_structure, proxies):
  site_labels = xray_structure.scatterers().extract_labels()
  fmt = "%.4e"
  loop = model.loop(header=(
    "_restr_U_volume_similar_atom_site_label_1",
    "_restr_U_volume_similar_diff",
    "_restr_U_volume_similar_class_id",
  ))
  class_loop = model.loop(header=(
    "_restr_U_volume_similar_class_class_id",
    "_restr_U_volume_similar_class_target_weight_param",
    "_restr_U_volume_similar_class_average",
    "_restr_U_volume_similar_class_esd",
    "_restr_U_volume_similar_class_diff_max",
  ))
  unit_cell = xray_structure.unit_cell()
  params = adp_restraints.adp_restraint_params(
    u_cart=xray_structure.scatterers().extract_u_cart(unit_cell),
    u_iso=xray_structure.scatterers().extract_u_iso(),
    use_u_aniso=xray_structure.use_u_aniso()
    )
  class_id = 0
  for proxy in proxies:
    restraint = adp_restraints.adp_volume_similarity(
      params=params,
      proxy=proxy)
    class_id += 1
    class_loop.add_row((class_id,
                        fmt % math.sqrt(1/proxy.weight),
                        fmt % restraint.mean_u_volume,
                        fmt % restraint.rms_deltas(),
                        fmt % flex.max_absolute(restraint.deltas())))
    for i, i_seq in enumerate(proxy.i_seqs):
      loop.add_row((site_labels[i_seq],
                    fmt % restraint.deltas()[i],
                    class_id))
  return class_loop, loop