Exemplo n.º 1
0
def exercise_debye_waller():
  ucell = uctbx.unit_cell((5,7,9,80,100,130))
  assert abs(adptbx.debye_waller_factor_u_iso(ucell.d_star_sq((7,8,9))/4,0.025)
             - 0.006625427) < 1.e-6
  assert abs(adptbx.debye_waller_factor_u_iso(ucell, (7, 8, 9), 0.025)
             - 0.006625427) < 1.e-6
  u = (0.1, 0.2, 0.3, -0.04, 0.05, -0.06)
  assert abs(adptbx.debye_waller_factor_u_cif(ucell, (1, 2, 3), u)
             - 0.335822877927) < 1.e-6
  #
  u_star=(0.000002, 0.000001, 0.000003, 0.0000005, 0.0000004, 0.0000006)
  assert approx_equal(
    adptbx.debye_waller_factor_u_star_gradient_coefficients(h=(5,2,-1)),
    [25, 4, 1, 20, -10, -4])
  g = adptbx.debye_waller_factor_u_star_gradients(h=(5,2,-1), u_star=u_star)
  assert approx_equal(g*1.e-3,
    [-0.49289027387879081, -0.078862443820606531, -0.019715610955151633,
     -0.39431221910303266, 0.19715610955151633, 0.078862443820606531])
  assert approx_equal(
    adptbx.debye_waller_factor_u_star_curvature_coefficients(h=(5,2,-1)),
    [625,100,25,500,-250,-100,
       16,4,80,-40,-16,
         1,20,-10,-4,
           400,-200,-80,
             100,40,
               16])
  c = adptbx.debye_waller_factor_u_star_curvatures(h=(5,2,-1), u_star=u_star)
  assert approx_equal(c*1.e-6,
    [0.24323160081641265, 0.038917056130626029, 0.0097292640326565073,
     0.1945852806531301, -0.097292640326565052, -0.038917056130626029,
     0.006226728980900164, 0.001556682245225041, 0.031133644904500817,
     -0.015566822452250408, -0.006226728980900164, 0.00038917056130626025,
     0.0077834112261252041, -0.0038917056130626021, -0.001556682245225041,
     0.15566822452250412, -0.077834112261252059, -0.031133644904500817,
     0.038917056130626029, 0.015566822452250408, 0.006226728980900164])
Exemplo n.º 2
0
def exercise_debye_waller():
    ucell = uctbx.unit_cell((5, 7, 9, 80, 100, 130))
    assert abs(adptbx.debye_waller_factor_u_iso(ucell.d_star_sq((7, 8, 9)) / 4, 0.025) - 0.006625427) < 1.0e-6
    assert abs(adptbx.debye_waller_factor_u_iso(ucell, (7, 8, 9), 0.025) - 0.006625427) < 1.0e-6
    u = (0.1, 0.2, 0.3, -0.04, 0.05, -0.06)
    assert abs(adptbx.debye_waller_factor_u_cif(ucell, (1, 2, 3), u) - 0.335822877927) < 1.0e-6
    #
    u_star = (0.000002, 0.000001, 0.000003, 0.0000005, 0.0000004, 0.0000006)
    assert approx_equal(adptbx.debye_waller_factor_u_star_gradient_coefficients(h=(5, 2, -1)), [25, 4, 1, 20, -10, -4])
    g = adptbx.debye_waller_factor_u_star_gradients(h=(5, 2, -1), u_star=u_star)
    assert approx_equal(
        g * 1.0e-3,
        [
            -0.49289027387879081,
            -0.078862443820606531,
            -0.019715610955151633,
            -0.39431221910303266,
            0.19715610955151633,
            0.078862443820606531,
        ],
    )
    assert approx_equal(
        adptbx.debye_waller_factor_u_star_curvature_coefficients(h=(5, 2, -1)),
        [625, 100, 25, 500, -250, -100, 16, 4, 80, -40, -16, 1, 20, -10, -4, 400, -200, -80, 100, 40, 16],
    )
    c = adptbx.debye_waller_factor_u_star_curvatures(h=(5, 2, -1), u_star=u_star)
    assert approx_equal(
        c * 1.0e-6,
        [
            0.24323160081641265,
            0.038917056130626029,
            0.0097292640326565073,
            0.1945852806531301,
            -0.097292640326565052,
            -0.038917056130626029,
            0.006226728980900164,
            0.001556682245225041,
            0.031133644904500817,
            -0.015566822452250408,
            -0.006226728980900164,
            0.00038917056130626025,
            0.0077834112261252041,
            -0.0038917056130626021,
            -0.001556682245225041,
            0.15566822452250412,
            -0.077834112261252059,
            -0.031133644904500817,
            0.038917056130626029,
            0.015566822452250408,
            0.006226728980900164,
        ],
    )
Exemplo n.º 3
0
def d_dw_d_u_star_analytical(h, u_star):
  dw = adptbx.debye_waller_factor_u_star(h, u_star)
  gc = flex.double(adptbx.debye_waller_factor_u_star_gradient_coefficients(h))
  return -2*math.pi**2 * gc * dw
Exemplo n.º 4
0
def run():
    #
    # try these Hall symbols:
    #   "P 1", "P 2", "P 3", "P 3*", "P 4", "P 6", "P 2 2 3"
    #
    space_group = sgtbx.space_group("P 3*")  # Hall symbol

    #
    # initialization of space group symmetry constraints
    #
    adp_constraints = sgtbx.tensor_rank_2_constraints(space_group=space_group,
                                                      reciprocal_space=True)

    #
    # number of independent u_star parameters
    #
    n_indep = adp_constraints.n_independent_params()

    #
    # arbitrary Miller index and u_star tensor
    #
    h = (3, 1, 2)
    u_star = (0.000004, 0.000004, 0.000007, 0.000002, 0.0000000, 0.0000000)
    # optional: enforce symmetry at the beginning
    u_star = space_group.average_u_star(u_star)

    #
    # pass u_indep to the minimizer
    #
    u_indep = adp_constraints.independent_params(all_params=u_star)
    assert len(u_indep) == n_indep

    #
    # "expand" the independent parameters modified by the minimizer
    #
    u_star = adp_constraints.all_params(independent_params=u_indep)
    assert len(u_star) == 6

    #
    # these calculations are completely independent of the symmetry
    #
    dwf = adptbx.debye_waller_factor_u_star(h, u_star)
    gc = adptbx.debye_waller_factor_u_star_gradient_coefficients(h)
    # all_gradients is an array of six values
    all_gradients = [-2 * math.pi**2 * dwf * c for c in gc]
    assert len(all_gradients) == 6
    cc = adptbx.debye_waller_factor_u_star_curvature_coefficients(h)
    # all_curvatures is an array of 21 values (upper triangle of 6x6 matrix)
    all_curvatures = (-2 * math.pi**2)**2 * dwf * cc
    assert len(all_curvatures) == 6 * (6 + 1) // 2

    #
    # here we apply the symmetry constraints to the gradients and curvatures
    #
    # g_indep is an array of n_indep values
    g_indep = adp_constraints.independent_gradients(
        all_gradients=all_gradients)
    assert len(g_indep) == n_indep
    # c_indep is an array of n_indep*(n_indep+1)/2 values (upper triangle)
    c_indep = adp_constraints.independent_curvatures(
        all_curvatures=all_curvatures)
    assert len(c_indep) == n_indep * (n_indep + 1) // 2
    # feed g_indep and c_indep to the minimizer

    #
    # initialization of site symmetry constraints
    # (for sites on special positions)
    #
    unit_cell = uctbx.unit_cell((12, 12, 15, 90, 90, 120))
    space_group = sgtbx.space_group_info("P 6").group()
    site_symmetry = sgtbx.site_symmetry(
        unit_cell=unit_cell,
        space_group=space_group,
        original_site=(1 / 3., 2 / 3., 0),  # site on 3-fold axis
        min_distance_sym_equiv=0.5)
    assert len(site_symmetry.matrices()) == 3
    adp_constraints = site_symmetry.adp_constraints()
    # use adp_constraints as before

    print("OK")
def run():
  #
  # try these Hall symbols:
  #   "P 1", "P 2", "P 3", "P 3*", "P 4", "P 6", "P 2 2 3"
  #
  space_group = sgtbx.space_group("P 3*") # Hall symbol

  #
  # initialization of space group symmetry constraints
  #
  adp_constraints = sgtbx.tensor_rank_2_constraints(
    space_group=space_group,
    reciprocal_space=True)

  #
  # number of independent u_star parameters
  #
  n_indep = adp_constraints.n_independent_params()

  #
  # arbitrary Miller index and u_star tensor
  #
  h = (3,1,2)
  u_star=(0.000004, 0.000004, 0.000007, 0.000002, 0.0000000, 0.0000000)
  # optional: enforce symmetry at the beginning
  u_star = space_group.average_u_star(u_star)

  #
  # pass u_indep to the minimizer
  #
  u_indep = adp_constraints.independent_params(all_params=u_star)
  assert len(u_indep) == n_indep

  #
  # "expand" the independent parameters modified by the minimizer
  #
  u_star = adp_constraints.all_params(independent_params=u_indep)
  assert len(u_star) == 6

  #
  # these calculations are completely independent of the symmetry
  #
  dwf = adptbx.debye_waller_factor_u_star(h, u_star)
  gc = adptbx.debye_waller_factor_u_star_gradient_coefficients(h)
  # all_gradients is an array of six values
  all_gradients = [-2*math.pi**2 * dwf * c for c in gc]
  assert len(all_gradients) == 6
  cc = adptbx.debye_waller_factor_u_star_curvature_coefficients(h)
  # all_curvatures is an array of 21 values (upper triangle of 6x6 matrix)
  all_curvatures = (-2*math.pi**2)**2 * dwf * cc
  assert len(all_curvatures) == 6*(6+1)//2

  #
  # here we apply the symmetry constraints to the gradients and curvatures
  #
  # g_indep is an array of n_indep values
  g_indep = adp_constraints.independent_gradients(
    all_gradients=all_gradients)
  assert len(g_indep) == n_indep
  # c_indep is an array of n_indep*(n_indep+1)/2 values (upper triangle)
  c_indep = adp_constraints.independent_curvatures(
    all_curvatures=all_curvatures)
  assert len(c_indep) == n_indep*(n_indep+1)//2
  # feed g_indep and c_indep to the minimizer

  #
  # initialization of site symmetry constraints
  # (for sites on special positions)
  #
  unit_cell = uctbx.unit_cell((12,12,15,90,90,120))
  space_group = sgtbx.space_group_info("P 6").group()
  site_symmetry = sgtbx.site_symmetry(
    unit_cell=unit_cell,
    space_group=space_group,
    original_site=(1/3.,2/3.,0), # site on 3-fold axis
    min_distance_sym_equiv=0.5)
  assert len(site_symmetry.matrices()) == 3
  adp_constraints = site_symmetry.adp_constraints()
  # use adp_constraints as before

  print "OK"