Beispiel #1
0
 def optimize(self):
   rsos = list(self.reciprocal_space_objects.values())
   for i in range(len(rsos)-1):
     h_i = rsos[i].indices
     for j in range(i+1, len(rsos)):
       h_j = rsos[j].indices
       if (flex.order(h_i, h_j) == 0):
         rsos[j].indices = h_i
 def optimize(self):
   rsos = self.reciprocal_space_objects.values()
   for i in xrange(len(rsos)-1):
     h_i = rsos[i].indices
     for j in xrange(i+1, len(rsos)):
       h_j = rsos[j].indices
       if (flex.order(h_i, h_j) == 0):
         rsos[j].indices = h_i
Beispiel #3
0
def exercise(space_group_info,
             anomalous_flag,
             use_u_aniso,
             n_elements=3,
             d_min=3.,
             verbose=0):
    structure_z = random_structure.xray_structure(
        space_group_info,
        elements=("Se", ) * n_elements,
        volume_per_atom=200,
        random_f_prime_d_min=1.0,
        random_f_double_prime=anomalous_flag,
        random_u_iso=True,
        use_u_aniso=use_u_aniso,
        random_occupancy=True)
    check_weight_without_occupancy(structure_z)
    f_z = structure_z.structure_factors(anomalous_flag=anomalous_flag,
                                        d_min=d_min,
                                        algorithm="direct").f_calc()
    f_abs_z = abs(f_z)
    f_rad_z = f_z.phases()
    f_deg_z = f_z.phases(deg=True)
    hl_z = generate_random_hl(miller_set=f_z)
    hl_z_rad = hl_z.phase_integrals()
    if (0 or verbose):
        structure_z.show_summary().show_scatterers()
        print("n_special_positions:", \
              structure_z.special_position_indices().size())
    z2p_op = structure_z.space_group().z2p_op()
    z2p_op = sgtbx.change_of_basis_op(z2p_op.c() + sgtbx.tr_vec(
        (2, -1, 3), 12).new_denominator(z2p_op.c().t().den()))
    for change_hand in [False, True]:
        if (change_hand):
            z2p_op = z2p_op * sgtbx.change_of_basis_op("-x,-y,-z")
        structure_p = structure_z.change_basis(z2p_op)
        check_weight_without_occupancy(structure_p)
        check_site_symmetry_table(structure_z, z2p_op, structure_p)
        if (0 or verbose):
            structure_p.show_summary().show_scatterers()
            print("n_special_positions:", \
                  structure_p.special_position_indices().size())
        assert tuple(structure_p.special_position_indices()) \
            == tuple(structure_z.special_position_indices())
        structure_pz = structure_p.change_basis(z2p_op.inverse())
        check_weight_without_occupancy(structure_pz)
        check_site_symmetry_table(structure_p, z2p_op.inverse(), structure_pz)
        assert structure_pz.unit_cell().is_similar_to(structure_z.unit_cell())
        assert structure_pz.space_group() == structure_z.space_group()
        f_pz = f_z.structure_factors_from_scatterers(
            xray_structure=structure_pz, algorithm="direct").f_calc()
        f_abs_pz = abs(f_pz)
        f_rad_pz = f_pz.phases()
        f_deg_pz = f_pz.phases(deg=True)
        c = flex.linear_correlation(f_abs_z.data(), f_abs_pz.data())
        assert c.is_well_defined()
        if (0 or verbose):
            print("correlation:", c.coefficient())
        assert c.coefficient() > 0.999
        f_p_cb = f_z.change_basis(z2p_op)
        f_abs_p_cb = f_abs_z.change_basis(z2p_op)
        f_rad_p_cb = f_rad_z.change_basis(z2p_op, deg=False)
        f_deg_p_cb = f_deg_z.change_basis(z2p_op, deg=True)
        hl_p_cb = hl_z.change_basis(z2p_op)
        hl_p_cb_rad = hl_p_cb.phase_integrals()
        assert approx_equal(
            hl_z_rad.change_basis(z2p_op).data(), hl_p_cb_rad.data())
        assert f_abs_p_cb.indices().all_eq(f_p_cb.indices())
        if (not change_hand):
            o = flex.order(f_abs_p_cb.indices(), f_abs_z.indices())
        else:
            o = flex.order(-f_abs_p_cb.indices(), f_abs_z.indices())
        if (f_abs_z.space_group().n_ltr() == 1):
            assert o == 0
        else:
            assert o != 0
        f_pz = f_p_cb.change_basis(z2p_op.inverse())
        f_abs_pz = f_abs_p_cb.change_basis(z2p_op.inverse())
        f_rad_pz = f_rad_p_cb.change_basis(z2p_op.inverse(), deg=False)
        f_deg_pz = f_deg_p_cb.change_basis(z2p_op.inverse(), deg=True)
        hl_pz = hl_p_cb.change_basis(z2p_op.inverse())
        hl_pz_rad = hl_pz.phase_integrals()
        assert approx_equal(hl_z_rad.data(), hl_pz_rad.data())
        for i, o in zip(hl_z.data(), hl_pz.data()):
            assert approx_equal(i, o)
        assert approx_equal(flex.max(flex.abs(f_pz.data() - f_z.data())), 0)
        assert flex.order(f_abs_pz.indices(), f_abs_z.indices()) == 0
        assert f_abs_pz.indices().all_eq(f_pz.indices())
        assert approx_equal(
            flex.max(
                scitbx.math.phase_error(phi1=f_rad_pz.data(),
                                        phi2=f_rad_z.data())), 0)
        assert approx_equal(
            flex.max(
                scitbx.math.phase_error(phi1=f_deg_pz.data(),
                                        phi2=f_deg_z.data(),
                                        deg=True)), 0)
        assert approx_equal(f_deg_pz.data(), f_rad_pz.data() * (180 / math.pi))
        f_p_sf = f_p_cb.structure_factors_from_scatterers(
            xray_structure=structure_p, algorithm="direct").f_calc()
        det = abs(z2p_op.c().r().determinant())
        assert approx_equal(
            flex.max(flex.abs(f_p_sf.data() * complex(det) - f_p_cb.data())),
            0)
        f_abs_p_sf = abs(f_p_sf)
        f_rad_p_sf = f_p_sf.phases()
        f_deg_p_sf = f_p_sf.phases(deg=True)
        assert approx_equal(
            flex.max(
                scitbx.math.phase_error(phi1=f_rad_p_sf.data(),
                                        phi2=f_rad_p_cb.data())), 0)
        assert approx_equal(
            flex.max(
                scitbx.math.phase_error(phi1=f_deg_p_sf.data(),
                                        phi2=f_deg_p_cb.data(),
                                        deg=True)), 0)
        c = flex.linear_correlation(f_abs_p_sf.data(), f_abs_p_cb.data())
        assert c.is_well_defined()
        if (0 or verbose):
            print("correlation:", c.coefficient())
        assert c.coefficient() > 0.999
def exercise(
      space_group_info,
      anomalous_flag,
      use_u_aniso,
      n_elements=3,
      d_min=3.,
      verbose=0):
  structure_z = random_structure.xray_structure(
    space_group_info,
    elements=("Se",)*n_elements,
    volume_per_atom=200,
    random_f_prime_d_min=1.0,
    random_f_double_prime=anomalous_flag,
    random_u_iso=True,
    use_u_aniso=use_u_aniso,
    random_occupancy=True)
  check_weight_without_occupancy(structure_z)
  f_z = structure_z.structure_factors(
    anomalous_flag=anomalous_flag, d_min=d_min, algorithm="direct").f_calc()
  f_abs_z = abs(f_z)
  f_rad_z = f_z.phases()
  f_deg_z = f_z.phases(deg=True)
  hl_z = generate_random_hl(miller_set=f_z)
  hl_z_rad = hl_z.phase_integrals()
  if (0 or verbose):
    structure_z.show_summary().show_scatterers()
    print "n_special_positions:", \
          structure_z.special_position_indices().size()
  z2p_op = structure_z.space_group().z2p_op()
  z2p_op = sgtbx.change_of_basis_op(
      z2p_op.c()
    + sgtbx.tr_vec((2,-1,3), 12).new_denominator(z2p_op.c().t().den()))
  for change_hand in [False, True]:
    if (change_hand):
      z2p_op = z2p_op * sgtbx.change_of_basis_op("-x,-y,-z")
    structure_p = structure_z.change_basis(z2p_op)
    check_weight_without_occupancy(structure_p)
    check_site_symmetry_table(structure_z, z2p_op, structure_p)
    if (0 or verbose):
      structure_p.show_summary().show_scatterers()
      print "n_special_positions:", \
            structure_p.special_position_indices().size()
    assert tuple(structure_p.special_position_indices()) \
        == tuple(structure_z.special_position_indices())
    structure_pz = structure_p.change_basis(z2p_op.inverse())
    check_weight_without_occupancy(structure_pz)
    check_site_symmetry_table(structure_p, z2p_op.inverse(), structure_pz)
    assert structure_pz.unit_cell().is_similar_to(structure_z.unit_cell())
    assert structure_pz.space_group() == structure_z.space_group()
    f_pz = f_z.structure_factors_from_scatterers(
      xray_structure=structure_pz,
      algorithm="direct").f_calc()
    f_abs_pz = abs(f_pz)
    f_rad_pz = f_pz.phases()
    f_deg_pz = f_pz.phases(deg=True)
    c = flex.linear_correlation(f_abs_z.data(), f_abs_pz.data())
    assert c.is_well_defined()
    if (0 or verbose):
      print "correlation:", c.coefficient()
    assert c.coefficient() > 0.999
    f_p_cb = f_z.change_basis(z2p_op)
    f_abs_p_cb = f_abs_z.change_basis(z2p_op)
    f_rad_p_cb = f_rad_z.change_basis(z2p_op, deg=False)
    f_deg_p_cb = f_deg_z.change_basis(z2p_op, deg=True)
    hl_p_cb = hl_z.change_basis(z2p_op)
    hl_p_cb_rad = hl_p_cb.phase_integrals()
    assert approx_equal(
      hl_z_rad.change_basis(z2p_op).data(), hl_p_cb_rad.data())
    assert f_abs_p_cb.indices().all_eq(f_p_cb.indices())
    if (not change_hand):
      o = flex.order(f_abs_p_cb.indices(), f_abs_z.indices())
    else:
      o = flex.order(-f_abs_p_cb.indices(), f_abs_z.indices())
    if (f_abs_z.space_group().n_ltr() == 1):
      assert o == 0
    else:
      assert o != 0
    f_pz = f_p_cb.change_basis(z2p_op.inverse())
    f_abs_pz = f_abs_p_cb.change_basis(z2p_op.inverse())
    f_rad_pz = f_rad_p_cb.change_basis(z2p_op.inverse(), deg=False)
    f_deg_pz = f_deg_p_cb.change_basis(z2p_op.inverse(), deg=True)
    hl_pz = hl_p_cb.change_basis(z2p_op.inverse())
    hl_pz_rad = hl_pz.phase_integrals()
    assert approx_equal(hl_z_rad.data(), hl_pz_rad.data())
    for i,o in zip(hl_z.data(), hl_pz.data()):
      assert approx_equal(i, o)
    assert approx_equal(
      flex.max(flex.abs(f_pz.data() - f_z.data())), 0)
    assert flex.order(f_abs_pz.indices(), f_abs_z.indices()) == 0
    assert f_abs_pz.indices().all_eq(f_pz.indices())
    assert approx_equal(flex.max(scitbx.math.phase_error(
      phi1=f_rad_pz.data(), phi2=f_rad_z.data())), 0)
    assert approx_equal(flex.max(scitbx.math.phase_error(
      phi1=f_deg_pz.data(), phi2=f_deg_z.data(), deg=True)), 0)
    assert approx_equal(f_deg_pz.data(), f_rad_pz.data()*(180/math.pi))
    f_p_sf = f_p_cb.structure_factors_from_scatterers(
      xray_structure=structure_p,
      algorithm="direct").f_calc()
    det = abs(z2p_op.c().r().determinant())
    assert approx_equal(
      flex.max(flex.abs(f_p_sf.data()*complex(det) - f_p_cb.data())), 0)
    f_abs_p_sf = abs(f_p_sf)
    f_rad_p_sf = f_p_sf.phases()
    f_deg_p_sf = f_p_sf.phases(deg=True)
    assert approx_equal(flex.max(scitbx.math.phase_error(
      phi1=f_rad_p_sf.data(), phi2=f_rad_p_cb.data())), 0)
    assert approx_equal(flex.max(scitbx.math.phase_error(
      phi1=f_deg_p_sf.data(), phi2=f_deg_p_cb.data(), deg=True)), 0)
    c = flex.linear_correlation(f_abs_p_sf.data(), f_abs_p_cb.data())
    assert c.is_well_defined()
    if (0 or verbose):
      print "correlation:", c.coefficient()
    assert c.coefficient() > 0.999
def exercise(
      space_group_info,
      use_primitive_setting,
      anomalous_flag,
      use_u_aniso,
      n_elements=3,
      d_min=3.,
      verbose=0):
  if (use_primitive_setting):
    space_group_info = space_group_info.primitive_setting()
  structure = random_structure.xray_structure(
    space_group_info,
    elements=("Se",)*n_elements,
    volume_per_atom=200,
    random_f_prime_d_min=1.0,
    random_f_double_prime=anomalous_flag,
    random_u_iso=True,
    use_u_aniso=use_u_aniso,
    random_occupancy=True)
  if (0 or verbose):
    structure.show_summary().show_scatterers()
    print "n_special_positions:", \
          structure.special_position_indices().size()
  structure_p1 = structure.expand_to_p1()
  assert structure_p1.scatterers()[0].label == "Se1"
  assert structure_p1.scatterers()[-1].label == ("Se%d" % n_elements)
  structure_p1 = structure.expand_to_p1(append_number_to_labels=True)
  if (0 or verbose):
    structure_p1.show_summary().show_scatterers()
  l,i = structure_p1.scatterers()[0].label.split("_")
  assert l == "Se1"
  assert int(i) == 0
  l,i = structure_p1.scatterers()[-1].label.split("_")
  assert l == ("Se%d" % n_elements)
  assert int(i) \
      == structure.site_symmetry_table().get(n_elements-1).multiplicity()-1
  assert structure_p1.special_position_indices().size() == 0
  f_calc = structure.structure_factors(
    anomalous_flag=anomalous_flag, d_min=d_min, algorithm="direct").f_calc()
  miller_set_p1 = miller.set.expand_to_p1(f_calc)
  f_calc_p1 = f_calc.expand_to_p1()
  assert flex.order(miller_set_p1.indices(), f_calc_p1.indices()) == 0
  amplitudes = abs(f_calc)
  amplitudes_p1 = amplitudes.expand_to_p1()
  assert flex.order(miller_set_p1.indices(), amplitudes_p1.indices()) == 0
  c = flex.linear_correlation(abs(f_calc_p1).data(), amplitudes_p1.data())
  assert c.is_well_defined()
  assert c.n() > 20
  if (0 or verbose):
    print "correlation:", c.coefficient()
  assert c.coefficient() > 0.999
  for phase_deg in (False, True):
    phases = f_calc.arg(phase_deg)
    phases_p1 = phases.expand_to_p1(phase_deg)
    assert flex.order(miller_set_p1.indices(), phases_p1.indices()) == 0
    f_calc_p1_phases = f_calc_p1.arg(phase_deg)
    for i,phase in enumerate(f_calc_p1_phases.data()):
      e = scitbx.math.phase_error(phase, phases_p1.data()[i], deg=phase_deg)
      assert e < 1.e-6
  ctrl_amplitudes_p1 = abs(miller_set_p1.structure_factors_from_scatterers(
    xray_structure=structure_p1,
    algorithm="direct").f_calc())
  c = flex.linear_correlation(amplitudes_p1.data(), ctrl_amplitudes_p1.data())
  assert c.is_well_defined()
  if (0 or verbose):
    print "correlation:", c.coefficient()
  assert c.coefficient() > 0.999
Beispiel #6
0
def exercise(space_group_info,
             use_primitive_setting,
             anomalous_flag,
             use_u_aniso,
             n_elements=3,
             d_min=3.,
             verbose=0):
    if (use_primitive_setting):
        space_group_info = space_group_info.primitive_setting()
    structure = random_structure.xray_structure(
        space_group_info,
        elements=("Se", ) * n_elements,
        volume_per_atom=200,
        random_f_prime_d_min=1.0,
        random_f_double_prime=anomalous_flag,
        random_u_iso=True,
        use_u_aniso=use_u_aniso,
        random_occupancy=True)
    if (0 or verbose):
        structure.show_summary().show_scatterers()
        print "n_special_positions:", \
              structure.special_position_indices().size()
    structure_p1 = structure.expand_to_p1()
    assert structure_p1.scatterers()[0].label == "Se1"
    assert structure_p1.scatterers()[-1].label == ("Se%d" % n_elements)
    structure_p1 = structure.expand_to_p1(append_number_to_labels=True)
    if (0 or verbose):
        structure_p1.show_summary().show_scatterers()
    l, i = structure_p1.scatterers()[0].label.split("_")
    assert l == "Se1"
    assert int(i) == 0
    l, i = structure_p1.scatterers()[-1].label.split("_")
    assert l == ("Se%d" % n_elements)
    assert int(i) \
        == structure.site_symmetry_table().get(n_elements-1).multiplicity()-1
    assert structure_p1.special_position_indices().size() == 0
    f_calc = structure.structure_factors(anomalous_flag=anomalous_flag,
                                         d_min=d_min,
                                         algorithm="direct").f_calc()
    miller_set_p1 = miller.set.expand_to_p1(f_calc)
    f_calc_p1 = f_calc.expand_to_p1()
    assert flex.order(miller_set_p1.indices(), f_calc_p1.indices()) == 0
    amplitudes = abs(f_calc)
    amplitudes_p1 = amplitudes.expand_to_p1()
    assert flex.order(miller_set_p1.indices(), amplitudes_p1.indices()) == 0
    c = flex.linear_correlation(abs(f_calc_p1).data(), amplitudes_p1.data())
    assert c.is_well_defined()
    assert c.n() > 20
    if (0 or verbose):
        print "correlation:", c.coefficient()
    assert c.coefficient() > 0.999
    for phase_deg in (False, True):
        phases = f_calc.arg(phase_deg)
        phases_p1 = phases.expand_to_p1(phase_deg)
        assert flex.order(miller_set_p1.indices(), phases_p1.indices()) == 0
        f_calc_p1_phases = f_calc_p1.arg(phase_deg)
        for i, phase in enumerate(f_calc_p1_phases.data()):
            e = scitbx.math.phase_error(phase,
                                        phases_p1.data()[i],
                                        deg=phase_deg)
            assert e < 1.e-6
    ctrl_amplitudes_p1 = abs(
        miller_set_p1.structure_factors_from_scatterers(
            xray_structure=structure_p1, algorithm="direct").f_calc())
    c = flex.linear_correlation(amplitudes_p1.data(),
                                ctrl_amplitudes_p1.data())
    assert c.is_well_defined()
    if (0 or verbose):
        print "correlation:", c.coefficient()
    assert c.coefficient() > 0.999