From 4f11a9f8530178cfb510f11c7bc4b1829bbd0be4 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 6 Mar 2019 11:40:37 +0100 Subject: Keep track of the "un-centering" matrix, as well as the "centering" This makes it easy to reverse the transformation, if required, which it is when comparing centered cells. --- tests/centering_check.c | 9 +++++---- tests/transformation_check.c | 35 ++++++++++++++++++++++++++++++----- 2 files changed, 35 insertions(+), 9 deletions(-) (limited to 'tests') diff --git a/tests/centering_check.c b/tests/centering_check.c index 774af66b..cc553dd0 100644 --- a/tests/centering_check.c +++ b/tests/centering_check.c @@ -61,7 +61,8 @@ static int check_centering(double a, double b, double c, { UnitCell *cell, *cref; UnitCell *n; - IntegerMatrix *t; + IntegerMatrix *C; + RationalMatrix *Ci; int fail = 0; int i; double asx, asy, asz; @@ -86,12 +87,12 @@ static int check_centering(double a, double b, double c, cell_free(cref); check_cell(cell, "Input"); - n = uncenter_cell(cell, &t); + n = uncenter_cell(cell, &C, &Ci); if ( n != NULL ) { STATUS("The back transformation is:\n"); - intmat_print(t); + intmat_print(C); if ( check_cell(n, "Output") ) fail = 1; - if ( intmat_is_identity(t) && ((cen=='P') || (cen=='R')) ) { + if ( intmat_is_identity(C) && ((cen=='P') || (cen=='R')) ) { STATUS("Identity, as expected.\n"); } else { cell_print(n); diff --git a/tests/transformation_check.c b/tests/transformation_check.c index c5dad16c..06521061 100644 --- a/tests/transformation_check.c +++ b/tests/transformation_check.c @@ -224,25 +224,50 @@ static int check_transformation(UnitCell *cell, IntegerMatrix *tfn, static int check_uncentering(UnitCell *cell) { UnitCell *ct; - IntegerMatrix *tr; + IntegerMatrix *C; + RationalMatrix *Ci; + UnitCell *cback; + double a[9], b[9]; + int i; int fail = 0; STATUS("-----------------------\n"); STATUS("----> Before transformation:\n"); - cell_print(cell); + cell_print_full(cell); - ct = uncenter_cell(cell, &tr); + ct = uncenter_cell(cell, &C, &Ci); if ( ct == NULL ) return 1; STATUS("----> The primitive unit cell:\n"); cell_print(ct); STATUS("----> The matrix to put the centering back:\n"); - intmat_print(tr); + intmat_print(C); + + STATUS("----> The recovered centered cell:\n"); + cback = cell_transform_intmat(ct, C); + cell_print(cback); + + cell_get_cartesian(cell, &a[0], &a[1], &a[2], + &a[3], &a[4], &a[5], + &a[6], &a[7], &a[8]); + cell_get_cartesian(cback, &b[0], &b[1], &b[2], + &b[3], &b[4], &b[5], + &b[6], &b[7], &b[8]); + for ( i=0; i<9; i++ ) { + if ( fabs(a[i] - b[i]) > 1e-12 ) { + fail = 1; + } + } + + if ( fail ) { + ERROR("Original cell not recovered after back transformation\n"); + } - fail = check_same_reflections(cell, ct); + fail += check_same_reflections(cell, ct); cell_free(ct); + cell_free(cback); return fail; } -- cgit v1.2.3