def test_change_of_basis_ops_to_minimum_cell_mpro(): input_ucs = [ (46.023, 55.001, 64.452, 64.744, 78.659, 89.824), (44.747, 53.916, 62.554, 114.985, 99.610, 90.736), ] # Setup the input experiments and reflection tables expts = ExperimentList() for uc in input_ucs: uc = uctbx.unit_cell(uc) sg = sgtbx.space_group_info("P1").group() B = scitbx.matrix.sqr(uc.fractionalization_matrix()).transpose() expts.append( Experiment(crystal=Crystal(B, space_group=sg, reciprocal=True))) # Actually run the method we are testing cb_ops = change_of_basis_ops_to_minimum_cell( expts, max_delta=5, relative_length_tolerance=0.05, absolute_angle_tolerance=2) expts.change_basis(cb_ops, in_place=True) assert symmetry.unit_cells_are_similar_to( expts, median_unit_cell(expts), relative_length_tolerance=0.05, absolute_angle_tolerance=2, )
def test_experimentlist_change_basis(dials_data): experiments = ExperimentList() for i in range(4): experiments.extend( ExperimentList.from_file( dials_data("vmxi_proteinase_k_sweeps") / ("experiments_%i.expt" % i), check_format=False, )) reindexed_uc = (68.368, 103.968, 68.368, 90.000, 90.000, 90.000) reindexed_sg = sgtbx.space_group_info("P 4 2 2 (b,c,a)").group() cb_op = sgtbx.change_of_basis_op("-a,-c,-b") for cb_op in (cb_op, [cb_op] * len(experiments)): expts_rdx = experiments.change_basis(cb_op) for expt in expts_rdx: assert expt.crystal.get_unit_cell().parameters() == pytest.approx( reindexed_uc, abs=0.1) assert expt.crystal.get_space_group() == reindexed_sg experiments.change_basis(cb_op, in_place=True) for expt in experiments: assert expt.crystal.get_unit_cell().parameters() == pytest.approx( reindexed_uc, abs=0.1) assert expt.crystal.get_space_group() == reindexed_sg with pytest.raises(AssertionError): experiments.change_basis([cb_op, cb_op])
def test_change_of_basis_ops_to_minimum_cell_with_outlier(): symmetries = [ crystal.symmetry(unit_cell=uc, space_group="P1") for uc in ( (52.8868, 52.8868, 333.522, 90, 90, 120), (52.6503, 53.0292, 333.783, 89.9872, 89.2247, 60.8078), (52.9571, 53.0005, 334.255, 90.0493, 90.0042, 119.893), ( 54.4465, 56.5677, 355.775, 93.4376, 90.0999, 118.256, ), # This is an outlier (52.9235, 52.9235, 335.296, 90, 90, 120), (53.4531, 53.4531, 322.909, 90, 90, 120), ) ] # Setup the input experiments and reflection tables expts = ExperimentList() for cs in symmetries: B = scitbx.matrix.sqr( cs.unit_cell().fractionalization_matrix()).transpose() expts.append( Experiment(crystal=Crystal( B, space_group=cs.space_group(), reciprocal=True))) # Actually run the method we are testing cb_ops = change_of_basis_ops_to_minimum_cell( expts, max_delta=5, relative_length_tolerance=0.05, absolute_angle_tolerance=2) assert cb_ops.count(None) == 1 assert cb_ops[3] is None expts = ExperimentList( [expt for expt, cb_op in zip(expts, cb_ops) if cb_op]) cb_ops = [cb_op for cb_op in cb_ops if cb_op] expts.change_basis(cb_ops, in_place=True) assert symmetry.unit_cells_are_similar_to( expts, median_unit_cell(expts), relative_length_tolerance=0.05, absolute_angle_tolerance=2, )