Example #1
0
def check_adp_set_b_iso(cmd,
                        xrsp_init,
                        output,
                        selection,
                        selection_str,
                        verbose,
                        tolerance=1.e-3):
    remove_files(output)
    run_command(command=cmd, verbose=verbose)
    xrsp = xray_structure_plus(file_name=output)
    assert approx_equal(xrsp.occ, xrsp_init.occ, tolerance)
    assert approx_equal(xrsp.sites_cart, xrsp_init.sites_cart, tolerance)
    assert approx_equal(xrsp.use_u_iso, xrsp_init.use_u_iso, tolerance)
    assert approx_equal(xrsp.use_u_aniso, xrsp_init.use_u_aniso, tolerance)
    assert approx_equal(xrsp.u_iso_not_used, xrsp_init.u_iso_not_used,
                        tolerance)
    assert approx_equal(xrsp.u_cart_not_used, xrsp_init.u_cart_not_used,
                        tolerance)
    if (selection_str is None):
        assert not_approx_equal(xrsp.u_iso_used, xrsp_init.u_iso_used,
                                tolerance)
        for ucart in xrsp.u_cart:
            b_iso = adptbx.u_as_b(adptbx.u_cart_as_u_iso(ucart))
            if b_iso > 0: assert approx_equal(b_iso, 10, 0.005)
            else: assert approx_equal(b_iso, -78.956, 0.005)
    else:
        arg1 = xrsp.u_iso_used.select(selection.select(xrsp.use_u_iso))
        arg2 = xrsp_init.u_iso_used.select(
            selection.select(xrsp_init.use_u_iso))
        if (arg1.size() > 0): assert not_approx_equal(arg1, arg2, tolerance)
        for ucart in xrsp.u_cart:
            b_iso = adptbx.u_as_b(adptbx.u_cart_as_u_iso(ucart))
            if b_iso > 0: assert approx_equal(b_iso, 10, 0.005)
            else: assert approx_equal(b_iso, -78.956, 0.005)
Example #2
0
def check_adp_set_b_iso(
      cmd, xrsp_init, output, selection, selection_str, verbose,
      tolerance=1.e-3):
  remove_files(output)
  run_command(command=cmd, verbose=verbose)
  xrsp = xray_structure_plus(file_name = output)
  assert approx_equal(xrsp.occ,        xrsp_init.occ,tolerance)
  assert approx_equal(xrsp.sites_cart, xrsp_init.sites_cart,tolerance)
  assert approx_equal(xrsp.use_u_iso,  xrsp_init.use_u_iso,tolerance)
  assert approx_equal(xrsp.use_u_aniso,xrsp_init.use_u_aniso,tolerance)
  assert approx_equal(xrsp.u_iso_not_used,  xrsp_init.u_iso_not_used,tolerance)
  assert approx_equal(xrsp.u_cart_not_used,xrsp_init.u_cart_not_used,tolerance)
  if(selection_str is None):
    assert not_approx_equal(xrsp.u_iso_used,  xrsp_init.u_iso_used,tolerance)
    for ucart in xrsp.u_cart:
      b_iso = adptbx.u_as_b(adptbx.u_cart_as_u_iso(ucart))
      if b_iso > 0: assert approx_equal(b_iso, 10, 0.005)
      else: assert approx_equal(b_iso, -78.956, 0.005)
  else:
    arg1 = xrsp.u_iso_used.select(selection.select(xrsp.use_u_iso))
    arg2 = xrsp_init.u_iso_used.select(selection.select(xrsp_init.use_u_iso))
    if(arg1.size() > 0): assert not_approx_equal(arg1, arg2,tolerance)
    for ucart in xrsp.u_cart:
      b_iso = adptbx.u_as_b(adptbx.u_cart_as_u_iso(ucart))
      if b_iso > 0: assert approx_equal(b_iso, 10, 0.005)
      else: assert approx_equal(b_iso, -78.956, 0.005)
Example #3
0
def check_adp_to_iso(
      cmd, xrsp_init, output, selection, selection_str, verbose,
      tolerance=1.e-3):
  remove_files(output)
  run_command(command=cmd, verbose=verbose)
  xrsp = xray_structure_plus(file_name = output)
  assert approx_equal(xrsp.occ,        xrsp_init.occ,tolerance)
  assert approx_equal(xrsp.sites_cart, xrsp_init.sites_cart,tolerance)
  assert not_approx_equal(xrsp.use_u_iso,  xrsp_init.use_u_iso,tolerance)
  assert not_approx_equal(xrsp.use_u_aniso,xrsp_init.use_u_aniso,tolerance)
  assert xrsp.u_iso_not_used.size() == 0
  assert xrsp_init.u_iso_not_used.size() > 0
  assert xrsp.u_cart_used.size() == 0
  assert xrsp_init.u_cart_used.size() > 0
Example #4
0
def check_adp_to_iso(cmd,
                     xrsp_init,
                     output,
                     selection,
                     selection_str,
                     verbose,
                     tolerance=1.e-3):
    remove_files(output)
    run_command(command=cmd, verbose=verbose)
    xrsp = xray_structure_plus(file_name=output)
    assert approx_equal(xrsp.occ, xrsp_init.occ, tolerance)
    assert approx_equal(xrsp.sites_cart, xrsp_init.sites_cart, tolerance)
    assert not_approx_equal(xrsp.use_u_iso, xrsp_init.use_u_iso, tolerance)
    assert not_approx_equal(xrsp.use_u_aniso, xrsp_init.use_u_aniso, tolerance)
    assert xrsp.u_iso_not_used.size() == 0
    assert xrsp_init.u_iso_not_used.size() > 0
    assert xrsp.u_cart_used.size() == 0
    assert xrsp_init.u_cart_used.size() > 0
def exercise_nonbonded(nonbonded_type, repulsion_function):
  for i_trial in xrange(5):
    sites = random_sites(n_sites=2)
    r = nonbonded_type(
      sites=sites,
      vdw_distance=1,
      function=repulsion_function)
    vdw_distance = r.delta
    residual_obj = residual_functor(
      restraint_type=nonbonded_type,
      vdw_distance=vdw_distance,
      function=repulsion_function)
    for i_pert in xrange(5):
      if (i_pert == 0):
        sites_mod = sites
      else:
        sites_mod = []
        for site in sites:
          shift = col([random.uniform(-1,1)*vdw_distance*0.05
            for i in xrange(3)])
          sites_mod.append(site+shift)
      r = nonbonded_type(
        sites=sites_mod,
        vdw_distance=vdw_distance,
        function=repulsion_function)
      if (   not hasattr(repulsion_function, "irexp")
          or repulsion_function.irexp <= 2
          or not_approx_equal(r.residual(), 0)):
        fg = flex.vec3_double(finite_differences(sites_mod, residual_obj)) \
          .as_double()
        ag = flex.vec3_double(r.gradients()).as_double()
        scale = max(1, flex.mean(flex.abs(fg)))
        assert approx_equal(ag/scale, fg/scale, eps=1.e-2)
  sites = [[0,0,0], [0,0,0]]
  vdw_distance = 1.8
  for i_step in xrange(1,100):
    delta = i_step/50.
    sites[1][0] = delta
    r = nonbonded_type(
      sites=[col(site) for site in sites],
      vdw_distance=vdw_distance,
      function=repulsion_function)
    assert approx_equal(delta, r.delta)
Example #6
0
def exercise_basic():
  d = (1,1,1,90,90,90)
  u = uctbx.unit_cell()
  assert approx_equal(u.parameters(), d)
  u = uctbx.unit_cell(d)
  assert u.parameters() == d
  assert approx_equal(u.parameters(), u.reciprocal_parameters())
  assert approx_equal(u.volume(), 1)
  assert approx_equal(u.longest_vector_sq(), 3)
  assert approx_equal(u.shortest_vector_sq(), 1)
  p = (2,3,4,80,100,110)
  for i in xrange(7):
    u = uctbx.unit_cell(p[:i])
    assert u.parameters() == p[:i] + d[i:]
    v = uctbx.unit_cell(p[:i])
    assert v.parameters() == u.parameters()
    if (i):
      assert not_approx_equal(u.parameters(), u.reciprocal_parameters())
      assert not u.is_similar_to(u.reciprocal())
      assert not u.is_similar_to(u.reciprocal(), 1.e-3)
      assert not u.is_similar_to(u.reciprocal(), 1.e-3, 1.e-3)
      assert u.is_similar_to(u.reciprocal(), 1000, 180)
    assert approx_equal(
      u.reciprocal_parameters(), u.reciprocal().parameters())
    assert approx_equal(
      u.parameters(), u.reciprocal().reciprocal_parameters())
    assert approx_equal(
      u.reciprocal_metrical_matrix(), u.reciprocal().metrical_matrix())
    assert approx_equal(
      u.metrical_matrix(), u.reciprocal().reciprocal_metrical_matrix())
    v = u.reciprocal().reciprocal()
    assert u.is_similar_to(v, 1.e-3, 1.e-3)
    assert approx_equal(u.volume(), 1/u.reciprocal().volume())
  u = uctbx.unit_cell(p)
  assert not u.is_degenerate()
  assert not u.is_degenerate(1.e-10)
  assert not u.is_degenerate(1.e-10, 1.e-5)
  assert u.is_degenerate(10)
  assert u.is_degenerate(1.e-10, 20)
  m = u.metrical_matrix()
  n = (2*2, 3*3, 4*4,
       2*3*cos(110*pi/180), 2*4*cos(100*pi/180), 3*4*cos(80*pi/180))
  assert approx_equal(m, n)
  v = uctbx.unit_cell(metrical_matrix=m)
  assert approx_equal(u.parameters(), v.parameters())
  u = uctbx.unit_cell((2,3,4))
  assert approx_equal(u.volume(), 2*3*4)
  assert approx_equal(u.longest_vector_sq(), 2*2+3*3+4*4)
  assert approx_equal(u.shortest_vector_sq(), 2*2)
  u = uctbx.unit_cell(p)
  assert approx_equal(u.volume(), 22.04006625)
  assert approx_equal(
    u.d_volume_d_params(),
    (11.020033123326023, 7.3466887488840156, 5.5100165616630115,
     0.051324088220620838, -0.051324088220620769, -0.13367230402431379))
  for alpha in xrange(70,121,10):
    for beta in xrange(70,121,10):
      for gamma in xrange(70,121,10):
        u = uctbx.unit_cell([7,11,13,alpha, beta, gamma])
        v = uctbx.unit_cell(
          orthogonalization_matrix=u.orthogonalization_matrix())
        assert v.is_similar_to(u)
Example #7
0
def exercise_box_frac_around_sites():
  unit_cell = uctbx.unit_cell((10,10,10,90,90,120))
  buffer = 2
  sites_frac = flex.vec3_double([
    (1/2., 2/3., 0.),
    (1/2., 1/3., 0.)])
  min_, max_ = unit_cell.box_frac_around_sites(
    sites_frac=sites_frac, buffer=buffer)
  assert approx_equal(min_, (0.26905989232414967, 0.10239322565748302, -0.2))
  assert approx_equal(max_, (0.73094010767585038, 0.8976067743425169, 0.2))
  sites_cart = unit_cell.orthogonalize(sites_frac=sites_frac)
  min_, max_ = sites_cart.min(), sites_cart.max()
  min_ = unit_cell.fractionalize([m-buffer for m in min_])
  max_ = unit_cell.fractionalize([m+buffer for m in max_])
  assert approx_equal(min_, (0.017863279495408259, 0.10239322565748302, -0.2))
  assert approx_equal(max_, (0.98213672050459189, 0.8976067743425169, 0.2))
  unit_cells = [uctbx.unit_cell(params) for params in [
    (10, 15, 20, 90,  90,  90),
    (10, 10, 20, 90,  90, 120),
    (10, 10, 10, 60,  60,  60)]]
  sites_cart = flex.vec3_double([
    (2.23474, 8.72834, 4.70562),
    (3.72656, 3.28621, 9.19121),
    (-6.83519, -7.5707, 4.62386)])
  c_inv_rs = [(1,0,0, 0,1,0, 0,0,1),
              (0,1,0, 0,0,1, 1,0,0),
              (0,0,1, 1,0,0, 0,1,0)]
  for unit_cell_0 in unit_cells:
    for c_inv_r in c_inv_rs:
      unit_cell = unit_cell_0.change_basis(c_inv_r)
      sites_frac = unit_cell.fractionalize(sites_cart=sites_cart)
      min0, max0 = unit_cell.box_frac_around_sites(
        sites_cart=sites_cart)
      for x,y in zip(min0, max0): assert x < y
      for buffer in [None, 0]:
        min_, max_ = unit_cell.box_frac_around_sites(
          sites_cart=sites_cart, buffer=buffer)
        assert approx_equal(min_, min0)
        assert approx_equal(max_, max0)
        min_, max_ = unit_cell.box_frac_around_sites(
          sites_frac=sites_frac, buffer=buffer)
        assert approx_equal(min_, min0)
        assert approx_equal(max_, max0)
      for buffer in [0,3,5,7]:
        min0, max0 = unit_cell.box_frac_around_sites(
          sites_cart=sites_cart, buffer=buffer)
        for x,y in zip(min0, max0): assert x < y
        min_, max_ = unit_cell.box_frac_around_sites(
          sites_frac=sites_frac, buffer=buffer)
        assert approx_equal(min_, min0)
        assert approx_equal(max_, max0)
        min_, max_ = sites_cart.min(), sites_cart.max()
        min_ = unit_cell.fractionalize([m-buffer for m in min_])
        max_ = unit_cell.fractionalize([m+buffer for m in max_])
        if (unit_cell_0 is unit_cells[0]):
          assert approx_equal(min_, min0)
          assert approx_equal(max_, max0)
        elif (buffer == 0 and unit_cell_0 is unit_cells[1]):
          assert approx_equal(min_, min0)
          if (c_inv_r is c_inv_rs[2]):
            assert approx_equal(max_, max0)
          else:
            assert not_approx_equal(max_, max0)
        else:
          assert not_approx_equal(min_, min0)
          assert not_approx_equal(max_, max0)
Example #8
0
def exercise_basic():
    d = (1, 1, 1, 90, 90, 90)
    u = uctbx.unit_cell()
    assert approx_equal(u.parameters(), d)
    u = uctbx.unit_cell(d)
    assert u.parameters() == d
    assert approx_equal(u.parameters(), u.reciprocal_parameters())
    assert approx_equal(u.volume(), 1)
    assert approx_equal(u.longest_vector_sq(), 3)
    assert approx_equal(u.shortest_vector_sq(), 1)
    p = (2, 3, 4, 80, 100, 110)
    for i in range(7):
        u = uctbx.unit_cell(p[:i])
        assert u.parameters() == p[:i] + d[i:]
        v = uctbx.unit_cell(p[:i])
        assert v.parameters() == u.parameters()
        if (i):
            assert not_approx_equal(u.parameters(), u.reciprocal_parameters())
            assert not u.is_similar_to(u.reciprocal())
            assert not u.is_similar_to(u.reciprocal(), 1.e-3)
            assert not u.is_similar_to(u.reciprocal(), 1.e-3, 1.e-3)
            assert u.is_similar_to(u.reciprocal(), 1000, 180)
        assert approx_equal(u.reciprocal_parameters(),
                            u.reciprocal().parameters())
        assert approx_equal(u.parameters(),
                            u.reciprocal().reciprocal_parameters())
        assert approx_equal(u.reciprocal_metrical_matrix(),
                            u.reciprocal().metrical_matrix())
        assert approx_equal(u.metrical_matrix(),
                            u.reciprocal().reciprocal_metrical_matrix())
        v = u.reciprocal().reciprocal()
        assert u.is_similar_to(v, 1.e-3, 1.e-3)
        assert approx_equal(u.volume(), 1 / u.reciprocal().volume())
    u = uctbx.unit_cell(p)
    assert not u.is_degenerate()
    assert not u.is_degenerate(1.e-10)
    assert not u.is_degenerate(1.e-10, 1.e-5)
    assert u.is_degenerate(10)
    assert u.is_degenerate(1.e-10, 20)
    m = u.metrical_matrix()
    n = (2 * 2, 3 * 3, 4 * 4, 2 * 3 * cos(110 * pi / 180),
         2 * 4 * cos(100 * pi / 180), 3 * 4 * cos(80 * pi / 180))
    assert approx_equal(m, n)
    v = uctbx.unit_cell(metrical_matrix=m)
    assert approx_equal(u.parameters(), v.parameters())
    u = uctbx.unit_cell((2, 3, 4))
    assert approx_equal(u.volume(), 2 * 3 * 4)
    assert approx_equal(u.longest_vector_sq(), 2 * 2 + 3 * 3 + 4 * 4)
    assert approx_equal(u.shortest_vector_sq(), 2 * 2)
    u = uctbx.unit_cell(p)
    assert approx_equal(u.volume(), 22.04006625)
    assert approx_equal(
        u.d_volume_d_params(),
        (11.020033123326023, 7.3466887488840156, 5.5100165616630115,
         0.051324088220620838, -0.051324088220620769, -0.13367230402431379))
    for alpha in range(70, 121, 10):
        for beta in range(70, 121, 10):
            for gamma in range(70, 121, 10):
                u = uctbx.unit_cell([7, 11, 13, alpha, beta, gamma])
                v = uctbx.unit_cell(
                    orthogonalization_matrix=u.orthogonalization_matrix())
                assert v.is_similar_to(u)
Example #9
0
def exercise_box_frac_around_sites():
    unit_cell = uctbx.unit_cell((10, 10, 10, 90, 90, 120))
    buffer = 2
    sites_frac = flex.vec3_double([(1 / 2., 2 / 3., 0.), (1 / 2., 1 / 3., 0.)])
    min_, max_ = unit_cell.box_frac_around_sites(sites_frac=sites_frac,
                                                 buffer=buffer)
    assert approx_equal(min_, (0.26905989232414967, 0.10239322565748302, -0.2))
    assert approx_equal(max_, (0.73094010767585038, 0.8976067743425169, 0.2))
    sites_cart = unit_cell.orthogonalize(sites_frac=sites_frac)
    min_, max_ = sites_cart.min(), sites_cart.max()
    min_ = unit_cell.fractionalize([m - buffer for m in min_])
    max_ = unit_cell.fractionalize([m + buffer for m in max_])
    assert approx_equal(min_,
                        (0.017863279495408259, 0.10239322565748302, -0.2))
    assert approx_equal(max_, (0.98213672050459189, 0.8976067743425169, 0.2))
    unit_cells = [
        uctbx.unit_cell(params)
        for params in [(10, 15, 20, 90, 90, 90), (10, 10, 20, 90, 90,
                                                  120), (10, 10, 10, 60, 60,
                                                         60)]
    ]
    sites_cart = flex.vec3_double([(2.23474, 8.72834, 4.70562),
                                   (3.72656, 3.28621, 9.19121),
                                   (-6.83519, -7.5707, 4.62386)])
    c_inv_rs = [(1, 0, 0, 0, 1, 0, 0, 0, 1), (0, 1, 0, 0, 0, 1, 1, 0, 0),
                (0, 0, 1, 1, 0, 0, 0, 1, 0)]
    for unit_cell_0 in unit_cells:
        for c_inv_r in c_inv_rs:
            unit_cell = unit_cell_0.change_basis(c_inv_r)
            sites_frac = unit_cell.fractionalize(sites_cart=sites_cart)
            min0, max0 = unit_cell.box_frac_around_sites(sites_cart=sites_cart)
            for x, y in zip(min0, max0):
                assert x < y
            for buffer in [None, 0]:
                min_, max_ = unit_cell.box_frac_around_sites(
                    sites_cart=sites_cart, buffer=buffer)
                assert approx_equal(min_, min0)
                assert approx_equal(max_, max0)
                min_, max_ = unit_cell.box_frac_around_sites(
                    sites_frac=sites_frac, buffer=buffer)
                assert approx_equal(min_, min0)
                assert approx_equal(max_, max0)
            for buffer in [0, 3, 5, 7]:
                min0, max0 = unit_cell.box_frac_around_sites(
                    sites_cart=sites_cart, buffer=buffer)
                for x, y in zip(min0, max0):
                    assert x < y
                min_, max_ = unit_cell.box_frac_around_sites(
                    sites_frac=sites_frac, buffer=buffer)
                assert approx_equal(min_, min0)
                assert approx_equal(max_, max0)
                min_, max_ = sites_cart.min(), sites_cart.max()
                min_ = unit_cell.fractionalize([m - buffer for m in min_])
                max_ = unit_cell.fractionalize([m + buffer for m in max_])
                if (unit_cell_0 is unit_cells[0]):
                    assert approx_equal(min_, min0)
                    assert approx_equal(max_, max0)
                elif (buffer == 0 and unit_cell_0 is unit_cells[1]):
                    assert approx_equal(min_, min0)
                    if (c_inv_r is c_inv_rs[2]):
                        assert approx_equal(max_, max0)
                    else:
                        assert not_approx_equal(max_, max0)
                else:
                    assert not_approx_equal(min_, min0)
                    assert not_approx_equal(max_, max0)
Example #10
0
def exercise_statistics():
  import scitbx.math
  for flex_type in flex_types():
    a = flex_type(flex.grid((3,5)))
    s = maptbx.statistics(a)
    assert s.min() == 0
    assert s.max() == 0
    assert s.mean() == 0
    assert s.mean_sq() == 0
    assert s.sigma() == 0
    a = flex_type([random.random() for i in xrange(3*5)])
    a.resize(flex.grid((3,5)))
    s = maptbx.statistics(a)
    assert approx_equal(flex.min(a), s.min())
    assert approx_equal(flex.max(a), s.max())
    assert approx_equal(flex.mean(a), s.mean())
    assert approx_equal(flex.mean_sq(a), s.mean_sq())
    assert approx_equal(flex.mean_sq(a)-flex.mean(a)**2, s.sigma()**2)
    b = flex_type(flex.grid((4,6)).set_focus((3,5)))
    for i in xrange(3):
      for j in xrange(5):
        b[(i,j)] = a[(i,j)]
    b[(3,5)] = -1
    b[(2,5)] = 2
    b.resize(flex.grid((-2,3), (2,9)).set_focus((1,8)))
    t = maptbx.statistics(b)
    assert not_approx_equal(flex.min(b), t.min())
    assert not_approx_equal(flex.max(b), t.max())
    assert not_approx_equal(flex.mean(b), t.mean())
    assert not_approx_equal(flex.mean_sq(b), t.mean_sq())
    assert not_approx_equal(flex.mean_sq(b)-flex.mean(b)**2, t.sigma()**2)
    assert approx_equal(s.min(), t.min())
    assert approx_equal(s.max(), t.max())
    assert approx_equal(s.mean(), t.mean())
    assert approx_equal(s.mean_sq(), t.mean_sq())
    assert approx_equal(s.sigma(), t.sigma())
  a = flex.double(flex.grid(5,3))
  s = maptbx.more_statistics(a)
  assert s.min() == 0
  assert s.max() == 0
  assert s.mean() == 0
  assert s.mean_sq() == 0
  assert s.sigma() == 0
  assert s.skewness() == 0
  assert s.kurtosis() == 0
  a = flex.random_double(5*3)
  reference = scitbx.math.basic_statistics(a)
  a.resize(flex.grid(5,3))
  s = maptbx.more_statistics(a)
  assert approx_equal(s.min(), reference.min)
  assert approx_equal(s.max(), reference.max)
  assert approx_equal(s.mean(), reference.mean)
  assert approx_equal(s.sigma(), reference.biased_standard_deviation)
  assert approx_equal(s.skewness(), reference.skew)
  assert approx_equal(s.kurtosis(), reference.kurtosis)
  b = flex.double(flex.grid((6,4)).set_focus((5,3)))
  for i in xrange(5):
    for j in xrange(3):
      b[(i,j)] = a[(i,j)]
  b[(5,3)] = -1
  b[(5,2)] = 2
  b.resize(flex.grid((3,-2), (9,2)).set_focus((8,1)))
  t = maptbx.statistics(b)
  assert approx_equal(s.min(), reference.min)
  assert approx_equal(s.max(), reference.max)
  assert approx_equal(s.mean(), reference.mean)
  assert approx_equal(s.sigma(), reference.biased_standard_deviation)
  assert approx_equal(s.skewness(), reference.skew)
  assert approx_equal(s.kurtosis(), reference.kurtosis)
  m = flex.double(flex.grid((6,4,8)).set_focus((5,3,7)))