Exemplo n.º 1
0
def exercise_interface():
  episq = 8*(math.pi**2)
  assert approx_equal(adptbx.u_as_b(2.3), 2.3*episq)
  assert approx_equal(adptbx.b_as_u(adptbx.u_as_b(2.3)), 2.3)
  u = (3,4,9, 2,1,7)
  assert approx_equal(adptbx.u_as_b(u), [x*episq for x in u])
  assert approx_equal(adptbx.b_as_u(adptbx.u_as_b(u)), u)
  uc = uctbx.unit_cell((5,4,7,80,110,100))
  for fw,bw in ((adptbx.u_cif_as_u_star, adptbx.u_star_as_u_cif),
                (adptbx.u_cart_as_u_star, adptbx.u_star_as_u_cart),
                (adptbx.u_cart_as_u_cif, adptbx.u_cif_as_u_cart),
                (adptbx.u_cart_as_beta, adptbx.beta_as_u_cart),
                (adptbx.u_cif_as_beta, adptbx.beta_as_u_cif)):
    assert approx_equal(bw(uc, fw(uc, u)), u)
  assert approx_equal(adptbx.beta_as_u_star(adptbx.u_star_as_beta(u)), u)
  assert approx_equal(adptbx.u_cart_as_u_iso(adptbx.u_iso_as_u_cart(2.3)), 2.3)
  for fw,bw in ((adptbx.u_iso_as_u_star, adptbx.u_star_as_u_iso),
                (adptbx.u_iso_as_u_cif, adptbx.u_cif_as_u_iso),
                (adptbx.u_iso_as_beta, adptbx.beta_as_u_iso)):
    assert approx_equal(bw(uc, fw(uc, 2.3)), 2.3)
  fc = adptbx.factor_u_cart_u_iso(u_cart=u)
  assert approx_equal(fc.u_iso, adptbx.u_cart_as_u_iso(u))
  assert approx_equal(
    fc.u_cart_minus_u_iso,
    [uii-fc.u_iso for uii in u[:3]]+list(u[3:]))
  f = adptbx.factor_u_star_u_iso(
    unit_cell=uc, u_star=adptbx.u_cart_as_u_star(uc, u))
  assert approx_equal(f.u_iso, fc.u_iso)
  assert approx_equal(
    f.u_star_minus_u_iso,
    adptbx.u_cart_as_u_star(uc, fc.u_cart_minus_u_iso))
  f = adptbx.factor_u_cif_u_iso(
    unit_cell=uc, u_cif=adptbx.u_cart_as_u_cif(uc, u))
  assert approx_equal(f.u_iso, fc.u_iso)
  assert approx_equal(
    f.u_cif_minus_u_iso,
    adptbx.u_cart_as_u_cif(uc, fc.u_cart_minus_u_iso))
  f = adptbx.factor_beta_u_iso(
    unit_cell=uc, beta=adptbx.u_cart_as_beta(uc, u))
  assert approx_equal(f.u_iso, fc.u_iso)
  assert approx_equal(
    f.beta_minus_u_iso,
    adptbx.u_cart_as_beta(uc, fc.u_cart_minus_u_iso))
  assert approx_equal(adptbx.debye_waller_factor_b_iso(0.25,2.3),
                      math.exp(-2.3*0.25))
  assert approx_equal(adptbx.debye_waller_factor_u_iso(0.25,2.3),
                      math.exp(-2.3*episq*0.25))
  assert approx_equal(adptbx.debye_waller_factor_b_iso(uc, (1,2,3), 2.3),
                      adptbx.debye_waller_factor_u_iso(uc, (1,2,3), 2.3/episq))
  u_star = adptbx.u_cart_as_u_star(uc, u)
  dw = adptbx.debye_waller_factor_u_star((1,2,3), u_star)
  assert approx_equal(dw, adptbx.debye_waller_factor_beta((1,2,3),
                            adptbx.u_star_as_beta(u_star)))
  assert approx_equal(dw, adptbx.debye_waller_factor_u_cif(uc, (1,2,3),
                            adptbx.u_star_as_u_cif(uc, u_star)))
  assert approx_equal(dw, adptbx.debye_waller_factor_u_cart(uc, (1,2,3),
                            adptbx.u_star_as_u_cart(uc, u_star)))
  for e in adptbx.eigenvalues(u):
    check_eigenvalue(u, e)
  assert not adptbx.is_positive_definite(adptbx.eigenvalues(u))
  assert not adptbx.is_positive_definite(adptbx.eigenvalues(u), 0)
  assert adptbx.is_positive_definite(adptbx.eigenvalues(u), 1.22)
  assert not adptbx.is_positive_definite(u)
  assert not adptbx.is_positive_definite(u, 0)
  assert adptbx.is_positive_definite(u, 1.22)
  up = (0.534, 0.812, 0.613, 0.0166, 0.134, -0.0124)
  s = adptbx.eigensystem(up)
  assert approx_equal(s.values(), (0.813132, 0.713201, 0.432668))
  for i in xrange(3):
    check_eigenvector(up, s.values()[i], s.vectors(i))
  c = (1,2,3, 3,-4,5, 4,5,6)
  v = (198,18,1020,116,447,269)
  assert approx_equal(adptbx.c_u_c_transpose(c, u), v)
  assert approx_equal(adptbx.eigensystem(u).values(),
    (14.279201519086316, 2.9369143826320214, -1.2161159017183376))
  s = adptbx.eigensystem(up)
  try: s.vectors(4)
  except RuntimeError, e: assert str(e).endswith("Index out of range.")
  else: raise Exception_expected
  uf = adptbx.eigenvalue_filtering(u_cart=u, u_min=0)
  assert approx_equal(uf, (3.0810418, 4.7950710, 9.3400030,
                           1.7461615, 1.1659954, 6.4800706))
  uf = adptbx.eigenvalue_filtering(u_cart=u, u_min=0, u_max=3)
  assert approx_equal(uf, (2.7430890, 1.0378360, 2.1559895,
                           0.6193215, -0.3921632, 1.2846854))
  uf = adptbx.eigenvalue_filtering(u_cart=u, u_min=0, u_max=3)
  assert approx_equal(scitbx.linalg.eigensystem.real_symmetric(u).values(),
                      (14.2792015, 2.9369144, -1.2161159))
  assert approx_equal(scitbx.linalg.eigensystem.real_symmetric(uf).values(),
                      (3, 2.9369144, 0))
  uf = adptbx.eigenvalue_filtering(up)
  assert approx_equal(uf, up)
Exemplo n.º 2
0
def u_star_minus_u_iso_airlie(unit_cell, u_star):
  u_iso = adptbx.u_star_as_u_iso(unit_cell,u_star)
  u_star_as_beta = adptbx.u_star_as_beta(u_star)
  u_iso_as_beta = adptbx.u_iso_as_beta(unit_cell,u_iso)
  beta_minus_u_iso = [a-i for a,i in zip(u_star_as_beta,u_iso_as_beta)]
  return adptbx.beta_as_u_star(beta_minus_u_iso)
Exemplo n.º 3
0
def exercise_interface():
    episq = 8 * (math.pi ** 2)
    assert approx_equal(adptbx.u_as_b(2.3), 2.3 * episq)
    assert approx_equal(adptbx.b_as_u(adptbx.u_as_b(2.3)), 2.3)
    u = (3, 4, 9, 2, 1, 7)
    assert approx_equal(adptbx.u_as_b(u), [x * episq for x in u])
    assert approx_equal(adptbx.b_as_u(adptbx.u_as_b(u)), u)
    uc = uctbx.unit_cell((5, 4, 7, 80, 110, 100))
    for fw, bw in (
        (adptbx.u_cif_as_u_star, adptbx.u_star_as_u_cif),
        (adptbx.u_cart_as_u_star, adptbx.u_star_as_u_cart),
        (adptbx.u_cart_as_u_cif, adptbx.u_cif_as_u_cart),
        (adptbx.u_cart_as_beta, adptbx.beta_as_u_cart),
        (adptbx.u_cif_as_beta, adptbx.beta_as_u_cif),
    ):
        assert approx_equal(bw(uc, fw(uc, u)), u)
    assert approx_equal(adptbx.beta_as_u_star(adptbx.u_star_as_beta(u)), u)
    assert approx_equal(adptbx.u_cart_as_u_iso(adptbx.u_iso_as_u_cart(2.3)), 2.3)
    for fw, bw in (
        (adptbx.u_iso_as_u_star, adptbx.u_star_as_u_iso),
        (adptbx.u_iso_as_u_cif, adptbx.u_cif_as_u_iso),
        (adptbx.u_iso_as_beta, adptbx.beta_as_u_iso),
    ):
        assert approx_equal(bw(uc, fw(uc, 2.3)), 2.3)
    fc = adptbx.factor_u_cart_u_iso(u_cart=u)
    assert approx_equal(fc.u_iso, adptbx.u_cart_as_u_iso(u))
    assert approx_equal(fc.u_cart_minus_u_iso, [uii - fc.u_iso for uii in u[:3]] + list(u[3:]))
    f = adptbx.factor_u_star_u_iso(unit_cell=uc, u_star=adptbx.u_cart_as_u_star(uc, u))
    assert approx_equal(f.u_iso, fc.u_iso)
    assert approx_equal(f.u_star_minus_u_iso, adptbx.u_cart_as_u_star(uc, fc.u_cart_minus_u_iso))
    f = adptbx.factor_u_cif_u_iso(unit_cell=uc, u_cif=adptbx.u_cart_as_u_cif(uc, u))
    assert approx_equal(f.u_iso, fc.u_iso)
    assert approx_equal(f.u_cif_minus_u_iso, adptbx.u_cart_as_u_cif(uc, fc.u_cart_minus_u_iso))
    f = adptbx.factor_beta_u_iso(unit_cell=uc, beta=adptbx.u_cart_as_beta(uc, u))
    assert approx_equal(f.u_iso, fc.u_iso)
    assert approx_equal(f.beta_minus_u_iso, adptbx.u_cart_as_beta(uc, fc.u_cart_minus_u_iso))
    assert approx_equal(adptbx.debye_waller_factor_b_iso(0.25, 2.3), math.exp(-2.3 * 0.25))
    assert approx_equal(adptbx.debye_waller_factor_u_iso(0.25, 2.3), math.exp(-2.3 * episq * 0.25))
    assert approx_equal(
        adptbx.debye_waller_factor_b_iso(uc, (1, 2, 3), 2.3),
        adptbx.debye_waller_factor_u_iso(uc, (1, 2, 3), 2.3 / episq),
    )
    u_star = adptbx.u_cart_as_u_star(uc, u)
    dw = adptbx.debye_waller_factor_u_star((1, 2, 3), u_star)
    assert approx_equal(dw, adptbx.debye_waller_factor_beta((1, 2, 3), adptbx.u_star_as_beta(u_star)))
    assert approx_equal(dw, adptbx.debye_waller_factor_u_cif(uc, (1, 2, 3), adptbx.u_star_as_u_cif(uc, u_star)))
    assert approx_equal(dw, adptbx.debye_waller_factor_u_cart(uc, (1, 2, 3), adptbx.u_star_as_u_cart(uc, u_star)))
    for e in adptbx.eigenvalues(u):
        check_eigenvalue(u, e)
    assert not adptbx.is_positive_definite(adptbx.eigenvalues(u))
    assert not adptbx.is_positive_definite(adptbx.eigenvalues(u), 0)
    assert adptbx.is_positive_definite(adptbx.eigenvalues(u), 1.22)
    assert not adptbx.is_positive_definite(u)
    assert not adptbx.is_positive_definite(u, 0)
    assert adptbx.is_positive_definite(u, 1.22)
    up = (0.534, 0.812, 0.613, 0.0166, 0.134, -0.0124)
    s = adptbx.eigensystem(up)
    assert approx_equal(s.values(), (0.813132, 0.713201, 0.432668))
    for i in xrange(3):
        check_eigenvector(up, s.values()[i], s.vectors(i))
    c = (1, 2, 3, 3, -4, 5, 4, 5, 6)
    v = (198, 18, 1020, 116, 447, 269)
    assert approx_equal(adptbx.c_u_c_transpose(c, u), v)
    assert approx_equal(adptbx.eigensystem(u).values(), (14.279201519086316, 2.9369143826320214, -1.2161159017183376))
    s = adptbx.eigensystem(up)
    try:
        s.vectors(4)
    except RuntimeError, e:
        assert str(e).endswith("Index out of range.")
Exemplo n.º 4
0
def exercise_interface():
    episq = 8 * (math.pi**2)
    assert approx_equal(adptbx.u_as_b(2.3), 2.3 * episq)
    assert approx_equal(adptbx.b_as_u(adptbx.u_as_b(2.3)), 2.3)
    u = (3, 4, 9, 2, 1, 7)
    assert approx_equal(adptbx.u_as_b(u), [x * episq for x in u])
    assert approx_equal(adptbx.b_as_u(adptbx.u_as_b(u)), u)
    uc = uctbx.unit_cell((5, 4, 7, 80, 110, 100))
    for fw, bw in ((adptbx.u_cif_as_u_star, adptbx.u_star_as_u_cif),
                   (adptbx.u_cart_as_u_star, adptbx.u_star_as_u_cart),
                   (adptbx.u_cart_as_u_cif, adptbx.u_cif_as_u_cart),
                   (adptbx.u_cart_as_beta, adptbx.beta_as_u_cart),
                   (adptbx.u_cif_as_beta, adptbx.beta_as_u_cif)):
        assert approx_equal(bw(uc, fw(uc, u)), u)
    assert approx_equal(adptbx.beta_as_u_star(adptbx.u_star_as_beta(u)), u)
    assert approx_equal(adptbx.u_cart_as_u_iso(adptbx.u_iso_as_u_cart(2.3)),
                        2.3)
    for fw, bw in ((adptbx.u_iso_as_u_star, adptbx.u_star_as_u_iso),
                   (adptbx.u_iso_as_u_cif, adptbx.u_cif_as_u_iso),
                   (adptbx.u_iso_as_beta, adptbx.beta_as_u_iso)):
        assert approx_equal(bw(uc, fw(uc, 2.3)), 2.3)
    fc = adptbx.factor_u_cart_u_iso(u_cart=u)
    assert approx_equal(fc.u_iso, adptbx.u_cart_as_u_iso(u))
    assert approx_equal(fc.u_cart_minus_u_iso,
                        [uii - fc.u_iso for uii in u[:3]] + list(u[3:]))
    f = adptbx.factor_u_star_u_iso(unit_cell=uc,
                                   u_star=adptbx.u_cart_as_u_star(uc, u))
    assert approx_equal(f.u_iso, fc.u_iso)
    assert approx_equal(f.u_star_minus_u_iso,
                        adptbx.u_cart_as_u_star(uc, fc.u_cart_minus_u_iso))
    f = adptbx.factor_u_cif_u_iso(unit_cell=uc,
                                  u_cif=adptbx.u_cart_as_u_cif(uc, u))
    assert approx_equal(f.u_iso, fc.u_iso)
    assert approx_equal(f.u_cif_minus_u_iso,
                        adptbx.u_cart_as_u_cif(uc, fc.u_cart_minus_u_iso))
    f = adptbx.factor_beta_u_iso(unit_cell=uc,
                                 beta=adptbx.u_cart_as_beta(uc, u))
    assert approx_equal(f.u_iso, fc.u_iso)
    assert approx_equal(f.beta_minus_u_iso,
                        adptbx.u_cart_as_beta(uc, fc.u_cart_minus_u_iso))
    assert approx_equal(adptbx.debye_waller_factor_b_iso(0.25, 2.3),
                        math.exp(-2.3 * 0.25))
    assert approx_equal(adptbx.debye_waller_factor_u_iso(0.25, 2.3),
                        math.exp(-2.3 * episq * 0.25))
    assert approx_equal(
        adptbx.debye_waller_factor_b_iso(uc, (1, 2, 3), 2.3),
        adptbx.debye_waller_factor_u_iso(uc, (1, 2, 3), 2.3 / episq))
    u_star = adptbx.u_cart_as_u_star(uc, u)
    dw = adptbx.debye_waller_factor_u_star((1, 2, 3), u_star)
    assert approx_equal(
        dw,
        adptbx.debye_waller_factor_beta((1, 2, 3),
                                        adptbx.u_star_as_beta(u_star)))
    assert approx_equal(
        dw,
        adptbx.debye_waller_factor_u_cif(uc, (1, 2, 3),
                                         adptbx.u_star_as_u_cif(uc, u_star)))
    assert approx_equal(
        dw,
        adptbx.debye_waller_factor_u_cart(uc, (1, 2, 3),
                                          adptbx.u_star_as_u_cart(uc, u_star)))
    for e in adptbx.eigenvalues(u):
        check_eigenvalue(u, e)
    assert not adptbx.is_positive_definite(adptbx.eigenvalues(u))
    assert not adptbx.is_positive_definite(adptbx.eigenvalues(u), 0)
    assert adptbx.is_positive_definite(adptbx.eigenvalues(u), 1.22)
    assert not adptbx.is_positive_definite(u)
    assert not adptbx.is_positive_definite(u, 0)
    assert adptbx.is_positive_definite(u, 1.22)
    up = (0.534, 0.812, 0.613, 0.0166, 0.134, -0.0124)
    s = adptbx.eigensystem(up)
    assert approx_equal(s.values(), (0.813132, 0.713201, 0.432668))
    for i in xrange(3):
        check_eigenvector(up, s.values()[i], s.vectors(i))
    c = (1, 2, 3, 3, -4, 5, 4, 5, 6)
    v = (198, 18, 1020, 116, 447, 269)
    assert approx_equal(adptbx.c_u_c_transpose(c, u), v)
    assert approx_equal(
        adptbx.eigensystem(u).values(),
        (14.279201519086316, 2.9369143826320214, -1.2161159017183376))
    s = adptbx.eigensystem(up)
    try:
        s.vectors(4)
    except RuntimeError, e:
        assert str(e).endswith("Index out of range.")
Exemplo n.º 5
0
def u_star_minus_u_iso_airlie(unit_cell, u_star):
    u_iso = adptbx.u_star_as_u_iso(unit_cell, u_star)
    u_star_as_beta = adptbx.u_star_as_beta(u_star)
    u_iso_as_beta = adptbx.u_iso_as_beta(unit_cell, u_iso)
    beta_minus_u_iso = [a - i for a, i in zip(u_star_as_beta, u_iso_as_beta)]
    return adptbx.beta_as_u_star(beta_minus_u_iso)