Esempio n. 1
0
def exercise_gruber_1973_example():
    start = ucgmx((4, 136, 76, -155, -31, 44))
    assert start.is_similar_to(
        uctbx.unit_cell(
            (2, 11.66, 8.718, 139 + 40 / 60., 152 + 45 / 60., 19 + 24 / 60.)))
    buerger = ucgmx((4, 16, 16, -16, -1, -3))
    assert buerger.is_similar_to(
        uctbx.unit_cell((2, 4, 4, 120, 93.5833, 100.807)))
    niggli = ucgmx((4, 16, 16, 16, 3, 4))
    assert niggli.is_similar_to(
        uctbx.unit_cell((2, 4, 4, 60, 79.1931, 75.5225)))
    red = reduction_base.gruber_parameterization(start)
    assert not red.is_buerger_cell()
    assert approx_equal(red.as_gruber_matrix(), (4, 136, 76, -155, -31, 44))
    assert approx_equal(red.as_niggli_matrix(),
                        (4, 136, 76, -155 / 2., -31 / 2., 44 / 2.))
    assert approx_equal(red.as_sym_mat3(),
                        (4, 136, 76, 44 / 2., -31 / 2., -155 / 2.))
    assert red.as_unit_cell().is_similar_to(start)
    red = reduction_base.gruber_parameterization(buerger)
    assert red.is_buerger_cell()
    assert not red.is_niggli_cell()
    red = reduction_base.gruber_parameterization(niggli)
    assert red.is_niggli_cell()
    red = reduce(start)
    assert red.as_unit_cell().is_similar_to(niggli)
    assert red.r_inv().elems == (-1, 5, 9, 0, -1, -1, 0, 0, 1)
    assert red.n_iterations() == 29
    red = reduce(buerger)
    assert red.as_unit_cell().is_similar_to(niggli)
    assert red.r_inv().elems == (-1, 0, 0, 0, 1, 1, 0, 1, 0)
    assert red.n_iterations() == 4
    red = reduce(niggli)
    assert red.as_unit_cell().is_similar_to(niggli)
    assert red.r_inv().elems == (1, 0, 0, 0, 1, 0, 0, 0, 1)
    assert red.n_iterations() == 1
    try:
        red = krivy_gruber_1976.reduction(buerger, iteration_limit=1)
    except krivy_gruber_1976.iteration_limit_exceeded:
        pass
    else:
        raise Exception_expected
    assert not start.is_buerger_cell()
    assert not start.is_niggli_cell()
    assert buerger.is_buerger_cell()
    assert not buerger.is_niggli_cell()
    assert niggli.is_buerger_cell()
    assert niggli.is_niggli_cell()
    red = start.niggli_reduction()
    assert red.n_iterations() == 29
    assert start.niggli_cell().is_similar_to(niggli)
Esempio n. 2
0
def exercise_gruber_1973_example():
  start = ucgmx((4,136,76,-155,-31,44))
  assert start.is_similar_to(uctbx.unit_cell(
    (2, 11.66, 8.718, 139+40/60., 152+45/60., 19+24/60.)))
  buerger = ucgmx((4,16,16,-16,-1,-3))
  assert buerger.is_similar_to(uctbx.unit_cell(
    (2, 4, 4, 120, 93.5833, 100.807)))
  niggli = ucgmx((4,16,16,16,3,4))
  assert niggli.is_similar_to(uctbx.unit_cell(
    (2, 4, 4, 60, 79.1931, 75.5225)))
  red = reduction_base.gruber_parameterization(start)
  assert not red.is_buerger_cell()
  assert approx_equal(red.as_gruber_matrix(), (4,136,76,-155,-31,44))
  assert approx_equal(red.as_niggli_matrix(), (4,136,76,-155/2.,-31/2.,44/2.))
  assert approx_equal(red.as_sym_mat3(), (4,136,76,44/2.,-31/2.,-155/2.))
  assert red.as_unit_cell().is_similar_to(start)
  red = reduction_base.gruber_parameterization(buerger)
  assert red.is_buerger_cell()
  assert not red.is_niggli_cell()
  red = reduction_base.gruber_parameterization(niggli)
  assert red.is_niggli_cell()
  red = reduce(start)
  assert red.as_unit_cell().is_similar_to(niggli)
  assert red.r_inv().elems == (-1, 5, 9, 0, -1, -1, 0, 0, 1)
  assert red.n_iterations() == 29
  red = reduce(buerger)
  assert red.as_unit_cell().is_similar_to(niggli)
  assert red.r_inv().elems == (-1, 0, 0, 0, 1, 1, 0, 1, 0)
  assert red.n_iterations() == 4
  red = reduce(niggli)
  assert red.as_unit_cell().is_similar_to(niggli)
  assert red.r_inv().elems == (1, 0, 0, 0, 1, 0, 0, 0, 1)
  assert red.n_iterations() == 1
  try:
    red = krivy_gruber_1976.reduction(buerger, iteration_limit=1)
  except krivy_gruber_1976.iteration_limit_exceeded:
    pass
  else:
    raise Exception_expected
  assert not start.is_buerger_cell()
  assert not start.is_niggli_cell()
  assert buerger.is_buerger_cell()
  assert not buerger.is_niggli_cell()
  assert niggli.is_buerger_cell()
  assert niggli.is_niggli_cell()
  red = start.niggli_reduction()
  assert red.n_iterations() == 29
  assert start.niggli_cell().is_similar_to(niggli)
Esempio n. 3
0
 def niggli_reduction(self, relative_epsilon=None, iteration_limit=None):
   from cctbx.uctbx import krivy_gruber_1976
   return krivy_gruber_1976.reduction(self, relative_epsilon, iteration_limit)
Esempio n. 4
0
 def niggli_reduction(self, relative_epsilon=None, iteration_limit=None):
   from cctbx.uctbx import krivy_gruber_1976
   return krivy_gruber_1976.reduction(self, relative_epsilon, iteration_limit)
Esempio n. 5
0
def do_reduce(inp):
    assert not inp.is_degenerate()
    time_krivy_gruber_1976.start()
    red = krivy_gruber_1976.reduction(inp, relative_epsilon=relative_epsilon)
    time_krivy_gruber_1976.stop()
    assert red.is_niggli_cell()
    red_cell = red.as_unit_cell()
    assert inp.change_basis(red.r_inv().elems).is_similar_to(red_cell)
    if (relative_epsilon is None):
        assert check_is_niggli_cell(red_cell).itva_is_niggli_cell()
    time_gruber_1973.start()
    gruber_reduction = gruber_1973.reduction(inp,
                                             relative_epsilon=relative_epsilon)
    time_gruber_1973.stop()
    assert gruber_reduction.is_buerger_cell()
    buerger_cell = gruber_reduction.as_unit_cell()
    assert inp.change_basis(
        gruber_reduction.r_inv().elems).is_similar_to(buerger_cell)
    time_krivy_gruber_1976_minimum.start()
    min_reduction = krivy_gruber_1976.minimum_reduction(inp)
    time_krivy_gruber_1976_minimum.stop()
    assert min_reduction.type() in (1, 2)
    min_cell = min_reduction.as_unit_cell()
    assert approx_equal(min_cell.parameters()[:3], red_cell.parameters()[:3])
    assert inp.change_basis(
        min_reduction.r_inv().elems).is_similar_to(min_cell)
    time_gruber_1973_minimum.start()
    min_reduction = gruber_1973.minimum_reduction(inp)
    time_gruber_1973_minimum.stop()
    assert min_reduction.type() in (1, 2)
    min_cell = min_reduction.as_unit_cell()
    assert approx_equal(min_cell.parameters()[:3], red_cell.parameters()[:3])
    assert inp.change_basis(
        min_reduction.r_inv().elems).is_similar_to(min_cell)
    time_gruber_1973_fast_minimum.start()
    min_reduction = gruber_1973.fast_minimum_reduction(inp)
    time_gruber_1973_fast_minimum.stop()
    assert min_reduction.type() in (1, 2)
    min_cell = min_reduction.as_unit_cell()
    assert approx_equal(min_cell.parameters()[:3], red_cell.parameters()[:3])
    assert inp.change_basis(
        min_reduction.r_inv().elems).is_similar_to(min_cell)
    time_uctbx_fast_minimum.start()
    min_reduction = uctbx.fast_minimum_reduction(inp)
    time_uctbx_fast_minimum.stop()
    assert min_reduction.type() in (1, 2)
    min_cell = min_reduction.as_unit_cell()
    assert approx_equal(min_cell.parameters()[:3], red_cell.parameters()[:3])
    assert inp.change_basis(min_reduction.r_inv()).is_similar_to(min_cell)
    global fast_minimum_reduction_max_n_iterations
    fast_minimum_reduction_max_n_iterations = max(
        fast_minimum_reduction_max_n_iterations, min_reduction.n_iterations())
    if (track_infinite):
        if (eq_always_false):
            red0 = reduction_with_tracking_and_eq_always_false(inp)
        else:
            red0 = reduction_with_tracking(inp)
        if (red0.iteration_limit_exceeded):
            n = 20
            print(inp)
            print("red0.action_log:", red0.action_log[-n:])
            print("red0.type_log:", red0.type_log[-n:])
            print("red0.meets_primary_conditions_log:", \
                   red0.meets_primary_conditions_log[-n:])
            print("red0.meets_main_conditions_log:", \
                   red0.meets_main_conditions_log[-n:])
            print("red0.is_niggli_cell_log:", red0.is_niggli_cell_log[-n:])
            if (1):
                for cell in red0.cell_log[-n:]:
                    print(cell)
                print()
            sys.stdout.flush()
    return red
Esempio n. 6
0
def do_reduce(inp):
  assert not inp.is_degenerate()
  time_krivy_gruber_1976.start()
  red = krivy_gruber_1976.reduction(
    inp, relative_epsilon=relative_epsilon)
  time_krivy_gruber_1976.stop()
  assert red.is_niggli_cell()
  red_cell = red.as_unit_cell()
  assert inp.change_basis(red.r_inv().elems).is_similar_to(red_cell)
  if (relative_epsilon is None):
    assert check_is_niggli_cell(red_cell).itva_is_niggli_cell()
  time_gruber_1973.start()
  gruber_reduction = gruber_1973.reduction(
    inp, relative_epsilon=relative_epsilon)
  time_gruber_1973.stop()
  assert gruber_reduction.is_buerger_cell()
  buerger_cell = gruber_reduction.as_unit_cell()
  assert inp.change_basis(gruber_reduction.r_inv().elems).is_similar_to(
    buerger_cell)
  time_krivy_gruber_1976_minimum.start()
  min_reduction = krivy_gruber_1976.minimum_reduction(inp)
  time_krivy_gruber_1976_minimum.stop()
  assert min_reduction.type() in (1,2)
  min_cell = min_reduction.as_unit_cell()
  assert approx_equal(min_cell.parameters()[:3], red_cell.parameters()[:3])
  assert inp.change_basis(min_reduction.r_inv().elems).is_similar_to(min_cell)
  time_gruber_1973_minimum.start()
  min_reduction = gruber_1973.minimum_reduction(inp)
  time_gruber_1973_minimum.stop()
  assert min_reduction.type() in (1,2)
  min_cell = min_reduction.as_unit_cell()
  assert approx_equal(min_cell.parameters()[:3], red_cell.parameters()[:3])
  assert inp.change_basis(min_reduction.r_inv().elems).is_similar_to(min_cell)
  time_gruber_1973_fast_minimum.start()
  min_reduction = gruber_1973.fast_minimum_reduction(inp)
  time_gruber_1973_fast_minimum.stop()
  assert min_reduction.type() in (1,2)
  min_cell = min_reduction.as_unit_cell()
  assert approx_equal(min_cell.parameters()[:3], red_cell.parameters()[:3])
  assert inp.change_basis(min_reduction.r_inv().elems).is_similar_to(min_cell)
  time_uctbx_fast_minimum.start()
  min_reduction = uctbx.fast_minimum_reduction(inp)
  time_uctbx_fast_minimum.stop()
  assert min_reduction.type() in (1,2)
  min_cell = min_reduction.as_unit_cell()
  assert approx_equal(min_cell.parameters()[:3], red_cell.parameters()[:3])
  assert inp.change_basis(min_reduction.r_inv()).is_similar_to(min_cell)
  global fast_minimum_reduction_max_n_iterations
  fast_minimum_reduction_max_n_iterations = max(
    fast_minimum_reduction_max_n_iterations, min_reduction.n_iterations())
  if (track_infinite):
    if (eq_always_false):
      red0 = reduction_with_tracking_and_eq_always_false(inp)
    else:
      red0 = reduction_with_tracking(inp)
    if (red0.iteration_limit_exceeded):
      n = 20
      print inp
      print "red0.action_log:", red0.action_log[-n:]
      print "red0.type_log:", red0.type_log[-n:]
      print "red0.meets_primary_conditions_log:", \
             red0.meets_primary_conditions_log[-n:]
      print "red0.meets_main_conditions_log:", \
             red0.meets_main_conditions_log[-n:]
      print "red0.is_niggli_cell_log:", red0.is_niggli_cell_log[-n:]
      if (1):
        for cell in red0.cell_log[-n:]:
          print cell
        print
      sys.stdout.flush()
  return red