def test_symmetry_handler_c2_i2(crystal_symmetry): cs_ref = crystal_symmetry.as_reference_setting() cs_ref = cs_ref.change_basis( cs_ref.change_of_basis_op_to_best_cell(best_monoclinic_beta=False) ) cs_best = cs_ref.best_cell() # best -> ref is different to cs_ref above cs_best_ref = cs_best.as_reference_setting() assert not cs_ref.is_similar_symmetry(cs_best_ref) B = scitbx.matrix.sqr( crystal_symmetry.unit_cell().fractionalization_matrix() ).transpose() cryst = Crystal(B, sgtbx.space_group()) for cs in (crystal_symmetry, cs_ref, cs_best): print(cs) handler = symmetry.SymmetryHandler(space_group=cs.space_group()) new_cryst, cb_op = handler.apply_symmetry(cryst) assert ( new_cryst.change_basis(cb_op).get_crystal_symmetry().is_similar_symmetry(cs) ) for cs in (crystal_symmetry, cs_ref, cs_best, cs_best_ref): print(cs) handler = symmetry.SymmetryHandler( unit_cell=cs.unit_cell(), space_group=cs.space_group() ) new_cryst, cb_op = handler.apply_symmetry(cryst) assert ( new_cryst.change_basis(cb_op).get_crystal_symmetry().is_similar_symmetry(cs) )
def test_SymmetryHandler(space_group_symbol): sgi = sgtbx.space_group_info(symbol=space_group_symbol) sg = sgi.group() cs = sgi.any_compatible_crystal_symmetry(volume=10000) uc = cs.unit_cell() handler = symmetry.SymmetryHandler(unit_cell=uc, space_group=sg) assert (handler.target_symmetry_primitive.space_group() == sg. build_derived_patterson_group().info().primitive_setting().group()) assert (handler.target_symmetry_reference_setting.space_group() == sg. build_derived_patterson_group().info().reference_setting().group()) # test apply_symmetry on the primitive setting cs_primitive = cs.primitive_setting() B = scitbx.matrix.sqr( cs_primitive.unit_cell().fractionalization_matrix()).transpose() crystal = Crystal(B, sgtbx.space_group()) crystal_new, cb_op = handler.apply_symmetry(crystal) crystal_new.get_crystal_symmetry(assert_is_compatible_unit_cell=True) # test apply_symmetry on the minimum cell setting cs_min_cell = cs.minimum_cell() B = scitbx.matrix.sqr( cs_min_cell.unit_cell().fractionalization_matrix()).transpose() crystal = Crystal(B, sgtbx.space_group()) crystal_new, cb_op = handler.apply_symmetry(crystal) crystal_new.get_crystal_symmetry(assert_is_compatible_unit_cell=True) handler = symmetry.SymmetryHandler(space_group=sg) assert handler.target_symmetry_primitive.unit_cell() is None assert (handler.target_symmetry_primitive.space_group() == sg. build_derived_patterson_group().info().primitive_setting().group()) assert handler.target_symmetry_reference_setting.unit_cell() is None assert (handler.target_symmetry_reference_setting.space_group() == sg. build_derived_patterson_group().info().reference_setting().group()) # test apply_symmetry on the primitive setting cs_primitive = cs.primitive_setting() B = scitbx.matrix.sqr( cs_primitive.unit_cell().fractionalization_matrix()).transpose() crystal = Crystal(B, sgtbx.space_group()) crystal_new, cb_op = handler.apply_symmetry(crystal) crystal_new.get_crystal_symmetry(assert_is_compatible_unit_cell=True) handler = symmetry.SymmetryHandler( unit_cell=cs.minimum_cell().unit_cell(), space_group=sgtbx.space_group(), ) assert handler.target_symmetry_primitive.unit_cell().parameters( ) == pytest.approx(cs.minimum_cell().unit_cell().parameters()) assert handler.target_symmetry_primitive.space_group( ) == sgtbx.space_group("P-1") assert (handler.target_symmetry_reference_setting.unit_cell().parameters() == pytest.approx(cs.minimum_cell().unit_cell().parameters())) assert handler.target_symmetry_reference_setting.space_group( ) == sgtbx.space_group("P-1")
def test_SymmetryHandler_no_match(): sgi = sgtbx.space_group_info(symbol="P422") cs = sgi.any_compatible_crystal_symmetry(volume=10000) B = scitbx.matrix.sqr(cs.unit_cell().fractionalization_matrix()).transpose() crystal = Crystal(B, sgtbx.space_group()) handler = symmetry.SymmetryHandler( unit_cell=None, space_group=sgtbx.space_group_info("I23").group() ) assert handler.apply_symmetry(crystal) == (None, None)