def exercise():
    from scitbx.array_family import flex
    from scitbx import matrix
    from libtbx.test_utils import approx_equal, show_diff
    import libtbx.load_env
    if (libtbx.env.has_module(name="iotbx")):
        from iotbx.shelx.parsers import decode_variables
        import iotbx.shelx.errors
    else:
        decode_variables = None
    mt = flex.mersenne_twister(seed=0)
    for sgi, site, expected_expr, no_fvar in test_case_generator():
        sps = sgi.any_compatible_crystal_symmetry(volume=1000) \
          .special_position_settings()
        ss = sps.site_symmetry(site)
        assert approx_equal(ss.exact_site(), site)
        sos = ss.special_op_simplified()
        expr = str(sos)
        assert not show_diff(expr, expected_expr)

        def check(site):
            ns = dict(zip("xyz", site))
            expr_site = eval(expr, ns, {})
            assert approx_equal(expr_site, site, 1e-4)
            #
            shifted_site = (matrix.col(site) +
                            matrix.col(mt.random_double_point_on_sphere()))
            ns = dict(zip("xyz", shifted_site))
            expr_shifted_site = eval(expr, ns, {})
            expr_shifted_site_exact = ss.special_op() * expr_shifted_site
            assert approx_equal(expr_shifted_site, expr_shifted_site_exact)

        check(site)
        for i_trial in range(3):
            shifted_site = ss.special_op() * (matrix.col(site) + matrix.col(
                mt.random_double_point_on_sphere()))
            check(shifted_site)
        fvars = [None]  # placeholder for scale factor
        if (decode_variables is not None):
            try:
                coded_variables = ss.shelx_fvar_encoding(site=site,
                                                         fvars=fvars)
            except iotbx.shelx.errors.error:
                if (not no_fvar): raise
            else:
                assert not no_fvar
            if (not no_fvar):
                values, behaviors = decode_variables(
                    free_variable=fvars, coded_variables=coded_variables)
                mismatch = sps.unit_cell().mod_short_distance(site, values)
                assert mismatch < 1e-10
def exercise():
  from scitbx.array_family import flex
  from scitbx import matrix
  from libtbx.test_utils import approx_equal, show_diff
  import libtbx.load_env
  if (libtbx.env.has_module(name="iotbx")):
    from iotbx.shelx.parsers import decode_variables
    import iotbx.shelx.errors
  else:
    decode_variables = None
  mt = flex.mersenne_twister(seed=0)
  for sgi,site,expected_expr,no_fvar in test_case_generator():
    sps = sgi.any_compatible_crystal_symmetry(volume=1000) \
      .special_position_settings()
    ss = sps.site_symmetry(site)
    assert approx_equal(ss.exact_site(), site)
    sos = ss.special_op_simplified()
    expr = str(sos)
    assert not show_diff(expr, expected_expr)
    def check(site):
      ns = dict(zip("xyz", site))
      expr_site = eval(expr, ns, {})
      assert approx_equal(expr_site, site, 1e-4)
      #
      shifted_site = (
        matrix.col(site) + matrix.col(mt.random_double_point_on_sphere()))
      ns = dict(zip("xyz", shifted_site))
      expr_shifted_site = eval(expr, ns, {})
      expr_shifted_site_exact = ss.special_op() * expr_shifted_site
      assert approx_equal(expr_shifted_site, expr_shifted_site_exact)
    check(site)
    for i_trial in xrange(3):
      shifted_site = ss.special_op() * (
        matrix.col(site) + matrix.col(mt.random_double_point_on_sphere()))
      check(shifted_site)
    fvars = [None] # placeholder for scale factor
    if (decode_variables is not None):
      try:
        coded_variables = ss.shelx_fvar_encoding(site=site, fvars=fvars)
      except iotbx.shelx.errors.error:
        if (not no_fvar): raise
      else:
        assert not no_fvar
      if (not no_fvar):
        values, behaviors = decode_variables(
          free_variable=fvars, coded_variables=coded_variables)
        mismatch = sps.unit_cell().mod_short_distance(site, values)
        assert mismatch < 1e-10
Exemplo n.º 3
0
def dev_build_shelx76_fvars(xray_structure, validation_tolerance=1e-10):
    from iotbx.shelx.parsers import decode_variables
    fvars = [1]
    encoded_sites = []
    scs = xray_structure.scatterers()
    sstab = xray_structure.site_symmetry_table()
    for i_sc in xray_structure.special_position_indices():
        site = scs[i_sc].site
        ss = sstab.get(i_sc)
        coded_variables = ss.shelx_fvar_encoding(site=site, fvars=fvars)
        if (validation_tolerance is not None):
            values, behaviors = decode_variables(
                free_variable=fvars, coded_variables=coded_variables)
            mismatch = xray_structure.unit_cell().distance(site, values)
            assert mismatch < validation_tolerance
        encoded_sites.append(coded_variables)
    return fvars, encoded_sites
Exemplo n.º 4
0
def dev_build_shelx76_fvars(xray_structure, validation_tolerance=1e-10):
    from iotbx.shelx.parsers import decode_variables

    fvars = [1]
    encoded_sites = []
    scs = xray_structure.scatterers()
    sstab = xray_structure.site_symmetry_table()
    for i_sc in xray_structure.special_position_indices():
        site = scs[i_sc].site
        ss = sstab.get(i_sc)
        coded_variables = ss.shelx_fvar_encoding(site=site, fvars=fvars)
        if validation_tolerance is not None:
            values, behaviors = decode_variables(free_variable=fvars, coded_variables=coded_variables)
            mismatch = xray_structure.unit_cell().distance(site, values)
            assert mismatch < validation_tolerance
        encoded_sites.append(coded_variables)
    return fvars, encoded_sites