From 865809d07a25b70b4ae0697d509a8f5e7a17c625 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 28 Aug 2019 16:49:55 +0200 Subject: compare_reindexed_cell_parameters: (Sort of) intelligent choice of solution --- libcrystfel/src/cell-utils.c | 134 ++++++++++++++++++++++++++++++++----------- 1 file changed, 99 insertions(+), 35 deletions(-) (limited to 'libcrystfel') diff --git a/libcrystfel/src/cell-utils.c b/libcrystfel/src/cell-utils.c index de8fe7ae..d92bd6a9 100644 --- a/libcrystfel/src/cell-utils.c +++ b/libcrystfel/src/cell-utils.c @@ -2059,32 +2059,33 @@ static double cell_diff(UnitCell *cell, double a, double b, double c, } -static IntegerMatrix *check_permutations(UnitCell *cell, UnitCell *reference, - IntegerMatrix *RB, IntegerMatrix *CB, +static int random_int(int max) +{ + int r; + int limit = RAND_MAX; + while ( limit % max ) limit--; + do { + r = rand(); + } while ( r > limit ); + return rand() % max; +} + + +static IntegerMatrix *check_permutations(UnitCell *cell_reduced, UnitCell *reference, + RationalMatrix *CiARA, IntegerMatrix *RiBCB, const double *tols) { IntegerMatrix *m; int i[9]; double a, b, c, al, be, ga; double min_dist = +INFINITY; - IntegerMatrix *best_m = NULL; - RationalMatrix *RiBCB; - RationalMatrix *rRiB; - RationalMatrix *rCB; - IntegerMatrix *RiB; + int s, sel; + IntegerMatrix *best_m[5] = {NULL, NULL, NULL, NULL, NULL}; + int n_best = 0; m = intmat_new(3, 3); cell_get_parameters(reference, &a, &b, &c, &al, &be, &ga); - RiBCB = rtnl_mtx_new(3, 3); - RiB = intmat_inverse(RB); - rRiB = rtnl_mtx_from_intmat(RiB); - rCB = rtnl_mtx_from_intmat(CB); - rtnl_mtx_mtxmult(rRiB, rCB, RiBCB); - intmat_free(RiB); - rtnl_mtx_free(rRiB); - rtnl_mtx_free(rCB); - for ( i[0]=-1; i[0]<=+1; i[0]++ ) { for ( i[1]=-1; i[1]<=+1; i[1]++ ) { for ( i[2]=-1; i[2]<=+1; i[2]++ ) { @@ -2108,16 +2109,34 @@ static IntegerMatrix *check_permutations(UnitCell *cell, UnitCell *reference, det = intmat_det(m); if ( det != +1 ) continue; - tmp = cell_transform_intmat(cell, m); - nc = cell_transform_rational(tmp, RiBCB); + tmp = cell_transform_intmat(cell_reduced, m); + nc = cell_transform_intmat(tmp, RiBCB); cell_free(tmp); if ( compare_cell_parameters(nc, reference, tols) ) { double dist = cell_diff(nc, a, b, c, al, be, ga); if ( dist < min_dist ) { - intmat_free(best_m); + + /* If the new solution is significantly better, + * dump all the previous ones */ + for ( s=0; s