Example #1
0
class fixed_u_eq_adp_test_case(adp_restraints_test_case):
    proxies = fixed_u_eq_adp_restraints(
        xray_structure=smtbx.development.sucrose(), u_eq_ideal=0.025).proxies
    # no need to test all of them every time
    proxies = adp.shared_fixed_u_eq_adp_proxy(
        flex.select(proxies, flags=flex.random_bool(proxies.size(), 0.5)))
    manager = restraints.manager(fixed_u_eq_adp_proxies=proxies)

    def restraint(self, proxy, u_iso=None, u_cart=None):
        if u_cart is None:
            u_cart = self.xray_structure.scatterers().extract_u_cart(
                self.xray_structure.unit_cell())
        return adp.fixed_u_eq_adp(adp_restraint_params(u_cart=u_cart), proxy)
Example #2
0
class rigid_bond_test_case(adp_restraints_test_case):
    proxies = rigid_bond_restraints(
        xray_structure=smtbx.development.sucrose()).proxies
    # no need to test all of them every time
    proxies = adp.shared_rigid_bond_proxy(
        flex.select(proxies, flags=flex.random_bool(proxies.size(), 0.3)))
    manager = restraints.manager(rigid_bond_proxies=proxies)

    def restraint(self, proxy, u_iso=None, u_cart=None):
        if u_cart is None:
            u_cart = self.xray_structure.scatterers().extract_u_cart(
                self.xray_structure.unit_cell())
        sites_cart = self.xray_structure.sites_cart()
        return adp.rigid_bond(
            adp_restraint_params(sites_cart=sites_cart, u_cart=u_cart), proxy)
def exercise_automation_wrappers () :
  from iotbx.reflection_file_utils import process_raw_data, \
    change_space_group, load_f_obs_and_r_free
  from cctbx import sgtbx
  from libtbx.test_utils import approx_equal
  mtz_file = "tmp_iotbx_reflection_file_utils.mtz"
  crystal_symmetry = crystal.symmetry(
    unit_cell=(10,11,12,90,95,90),
    space_group_symbol="P 2")
  miller_set = miller.build_set(
    crystal_symmetry=crystal_symmetry,
    anomalous_flag=True,
    d_min=1.5)
  n_obs = miller_set.indices().size()
  i_obs = miller_set.array(
    data=flex.random_double(size=n_obs)).set_observation_type_xray_intensity()
  i_obs = i_obs.customized_copy(sigmas=flex.sqrt(i_obs.data()))
  r_free_flags = miller_set.generate_r_free_flags()
  r_free_flags_partial = r_free_flags.select(flex.random_bool(n_obs, 0.9))
  out = StringIO()
  processed = process_raw_data(
    obs=i_obs,
    r_free_flags=None,
    test_flag_value=None,
    log=out)
  assert ("""WARNING: R-free flags not supplied.""" in out.getvalue())
  assert (processed.data_labels() == "F(+),SIGF(+),F(-),SIGF(-)")
  assert (processed.phase_labels() is None)
  assert (processed.flags_are_new())
  out2 = StringIO()
  processed2 = process_raw_data(
    obs=i_obs,
    r_free_flags=r_free_flags_partial,
    test_flag_value=True,
    log=out2)
  assert ("""WARNING: R-free flags are incomplete""" in out2.getvalue())
  assert (not processed2.flags_are_new())
  assert (processed.n_obs() == processed2.n_obs())
  processed.write_mtz_file(mtz_file, title="tst_iotbx", wavelength=0.9792)
  f_obs, r_free = load_f_obs_and_r_free(mtz_file)
  change_space_group(mtz_file, sgtbx.space_group_info("P21"))
  f_obs_new, r_free_new = load_f_obs_and_r_free(mtz_file)
  assert (f_obs_new.size() == f_obs.size() - 4)
  f_obs_new, r_free_new = load_f_obs_and_r_free(mtz_file,
    anomalous_flag=True)
  assert (str(f_obs_new.space_group_info()) == "P 1 21 1")
  assert (approx_equal(f_obs_new.info().wavelength, 0.9792))
def exercise_automation_wrappers():
  from iotbx.reflection_file_utils import process_raw_data, \
    change_space_group, load_f_obs_and_r_free
  from cctbx import sgtbx
  from libtbx.test_utils import approx_equal
  mtz_file = "tmp_iotbx_reflection_file_utils.mtz"
  crystal_symmetry = crystal.symmetry(
    unit_cell=(10,11,12,90,95,90),
    space_group_symbol="P 2")
  miller_set = miller.build_set(
    crystal_symmetry=crystal_symmetry,
    anomalous_flag=True,
    d_min=1.5)
  n_obs = miller_set.indices().size()
  i_obs = miller_set.array(
    data=flex.random_double(size=n_obs)).set_observation_type_xray_intensity()
  i_obs = i_obs.customized_copy(sigmas=flex.sqrt(i_obs.data()))
  r_free_flags = miller_set.generate_r_free_flags()
  r_free_flags_partial = r_free_flags.select(flex.random_bool(n_obs, 0.9))
  out = StringIO()
  processed = process_raw_data(
    obs=i_obs,
    r_free_flags=None,
    test_flag_value=None,
    log=out)
  assert ("""WARNING: R-free flags not supplied.""" in out.getvalue())
  assert (processed.data_labels() == "F(+),SIGF(+),F(-),SIGF(-)")
  assert (processed.phase_labels() is None)
  assert (processed.flags_are_new())
  out2 = StringIO()
  processed2 = process_raw_data(
    obs=i_obs,
    r_free_flags=r_free_flags_partial,
    test_flag_value=True,
    log=out2)
  assert ("""WARNING: R-free flags are incomplete""" in out2.getvalue())
  assert (not processed2.flags_are_new())
  assert (processed.n_obs() == processed2.n_obs())
  processed.write_mtz_file(mtz_file, title="tst_iotbx", wavelength=0.9792)
  f_obs, r_free = load_f_obs_and_r_free(mtz_file)
  change_space_group(mtz_file, sgtbx.space_group_info("P21"))
  f_obs_new, r_free_new = load_f_obs_and_r_free(mtz_file)
  assert (f_obs_new.size() == f_obs.size() - 4)
  f_obs_new, r_free_new = load_f_obs_and_r_free(mtz_file,
    anomalous_flag=True)
  assert (str(f_obs_new.space_group_info()) == "P 1 21 1")
  assert (approx_equal(f_obs_new.info().wavelength, 0.9792))
Example #5
0
class adp_similarity_test_case(adp_restraints_test_case):
  proxies = adp_similarity_restraints(
    xray_structure=smtbx.development.sucrose()).proxies
  # no need to test all of them every time
  proxies = adp.shared_adp_similarity_proxy(
    flex.select(proxies, flags=flex.random_bool(proxies.size(), 0.5)))
  manager = restraints.manager(adp_similarity_proxies=proxies)

  def restraint(self, proxy, u_iso=None, u_cart=None):
    if u_cart is None:
      u_cart=self.xray_structure.scatterers().extract_u_cart(
        self.xray_structure.unit_cell())
    if u_iso is None:
      u_iso=self.xray_structure.scatterers().extract_u_iso()
    use_u_aniso=self.xray_structure.use_u_aniso()
    return adp.adp_similarity(
      adp_restraint_params(u_cart=u_cart, u_iso=u_iso, use_u_aniso=use_u_aniso),
      proxy)
def exercise_shake_sites_in_place(structure):
    for target_difference in [0, 0.7, 1.0, 1.3]:
        for selection in [
                None,
                flex.random_bool(size=structure.scatterers().size(),
                                 threshold=0.5)
        ]:
            if (target_difference == 0
                ):  # the structure is not changed in this case
                n_variable = 1  # any value except 0 (the flex.sum() below must be 0)
            else:
                if (selection is None):
                    n_variable = structure.scatterers().size()
                else:
                    n_variable = selection.count(True)
                n_variable -= structure.coordinate_degrees_of_freedom_counts(
                    selection=selection)[0]
            shaken = structure.deep_copy_scatterers()
            try:
                shaken.shake_sites_in_place(rms_difference=target_difference,
                                            selection=selection)
            except RuntimeError, e:
                if (selection is not None):
                    if (selection.count(True) == 0):
                        assert str(e) == "No scatterers selected."
                    else:
                        assert str(e) \
                            == "All selected scatterers are fixed on special positions."
                else:
                    assert str(e) \
                        == "All scatterers are fixed on special positions."
            else:
                assert approx_equal((flex.sum(
                    (structure.sites_cart() - shaken.sites_cart()).dot()) /
                                     n_variable)**0.5, target_difference)
                #
                shaken = structure.deep_copy_scatterers()
                shaken.shake_sites_in_place(mean_distance=target_difference,
                                            selection=selection)
                assert approx_equal(
                    flex.sum(
                        flex.sqrt((structure.sites_cart() -
                                   shaken.sites_cart()).dot())) / n_variable,
                    target_difference)
def exercise_shake_sites_in_place(structure):
  for target_difference in [0, 0.7, 1.0, 1.3]:
    for selection in [None,
                      flex.random_bool(
                        size=structure.scatterers().size(), threshold=0.5)]:
      if (target_difference == 0): # the structure is not changed in this case
        n_variable = 1 # any value except 0 (the flex.sum() below must be 0)
      else:
        if (selection is None):
          n_variable = structure.scatterers().size()
        else:
          n_variable = selection.count(True)
        n_variable -= structure.coordinate_degrees_of_freedom_counts(
          selection=selection)[0]
      shaken = structure.deep_copy_scatterers()
      try:
        shaken.shake_sites_in_place(
          rms_difference=target_difference,
          selection=selection)
      except RuntimeError, e:
        if (selection is not None):
          if (selection.count(True) == 0):
            assert str(e) == "No scatterers selected."
          else:
            assert str(e) \
                == "All selected scatterers are fixed on special positions."
        else:
          assert str(e) \
              == "All scatterers are fixed on special positions."
      else:
        assert approx_equal(
          (flex.sum((  structure.sites_cart()
                     - shaken.sites_cart()).dot()) / n_variable) ** 0.5,
          target_difference)
        #
        shaken = structure.deep_copy_scatterers()
        shaken.shake_sites_in_place(
          mean_distance=target_difference,
          selection=selection)
        assert approx_equal(
          flex.sum(flex.sqrt((  structure.sites_cart()
                              - shaken.sites_cart()).dot())) / n_variable,
          target_difference)
Example #8
0
 def get_missing(self, deterministic=False):
   if(deterministic):
     xrs = self.xray_structure_cut
   else:
     sel = flex.random_bool(self.xray_structure_cut.scatterers().size(), 0.9)
     xrs = self.xray_structure_cut.select(sel)
   if(deterministic):
     # XXX This may result in very bad maps at low resolution
     #fm = mmtbx.f_model.manager(
     #  f_obs          = self.complete_set,
     #  xray_structure = xrs,
     #  k_sol          = 0.35,
     #  b_sol          = 46.0)
     #result = fm.f_model_no_scales()
     # This is slower but better
     # Never change this unless checked with CK case
     fm = self.fmodel.deep_copy()
     r = fm.update_all_scales(fast=False, refine_hd_scattering=False)
     fm = mmtbx.f_model.manager(
       f_obs          = self.complete_set,
       xray_structure = xrs,
       k_sol          = r.k_sol[0],
       b_sol          = r.b_sol[0],
       b_cart         = r.b_cart)
     result = fm.f_model_no_scales()
   else:
     if(random.choice([True, False])):
       k_sol = random.choice([i/100. for i in range(20,41)])
       b_sol = random.choice([i for i in range(20,85, 5)])
       fm = mmtbx.f_model.manager(
         f_obs          = self.complete_set,
         xray_structure = xrs,
         k_sol          = k_sol,
         b_sol          = b_sol)
       result = fm.f_model_no_scales()
     else:
       result = xrs.structure_factors(d_min = self.d_min).f_calc()
   return result
Example #9
0
 def get_missing(self, deterministic=False):
   if(deterministic):
     xrs = self.xray_structure_cut
   else:
     sel = flex.random_bool(self.xray_structure_cut.scatterers().size(), 0.9)
     xrs = self.xray_structure_cut.select(sel)
   if(deterministic):
     # XXX This may result in very bad maps at low resolution
     #fm = mmtbx.f_model.manager(
     #  f_obs          = self.complete_set,
     #  xray_structure = xrs,
     #  k_sol          = 0.35,
     #  b_sol          = 46.0)
     #result = fm.f_model_no_scales()
     # This is slower but better
     # Never change this unless checked with CK case
     fm = self.fmodel.deep_copy()
     r = fm.update_solvent_and_scale(fast=False)
     fm = mmtbx.f_model.manager(
       f_obs          = self.complete_set,
       xray_structure = xrs,
       k_sol          = r.k_sols()[0],
       b_sol          = r.b_sol(),
       b_cart         = r.b_cart())
     result = fm.f_model_no_scales()
   else:
     if(random.choice([True, False])):
       k_sol = random.choice([i/100. for i in range(20,41)])
       b_sol = random.choice([i for i in range(20,85, 5)])
       fm = mmtbx.f_model.manager(
         f_obs          = self.complete_set,
         xray_structure = xrs,
         k_sol          = k_sol,
         b_sol          = b_sol)
       result = fm.f_model_no_scales()
     else:
       result = xrs.structure_factors(d_min = self.d_min).f_calc()
   return result