/* * transformation_check.c * * Check that unit cell transformations work * * Copyright © 2012-2014 Deutsches Elektronen-Synchrotron DESY, * a research centre of the Helmholtz Association. * * Authors: * 2012-2014 Thomas White * * This file is part of CrystFEL. * * CrystFEL is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * CrystFEL is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with CrystFEL. If not, see . * */ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include #define MAX_REFLS (10*1024) static struct rvec *all_refls(UnitCell *cell, double max_r, int *n) { double asx, asy, asz; double bsx, bsy, bsz; double csx, csy, csz; double ax, ay, az; double bx, by, bz; double cx, cy, cz; signed int h, k, l; int hmax, kmax, lmax; struct rvec *r; int i = 0; r = malloc(sizeof(struct rvec)*MAX_REFLS); if ( r == NULL ) return NULL; cell_get_cartesian(cell, &ax, &ay, &az, &bx, &by, &bz, &cx, &cy, &cz); hmax = max_r * modulus(ax, ay, az); kmax = max_r * modulus(bx, by, bz); lmax = max_r * modulus(cx, cy, cz); cell_get_reciprocal(cell, &asx, &asy, &asz, &bsx, &bsy, &bsz, &csx, &csy, &csz); for ( h=-hmax; h<=hmax; h++ ) { for ( k=-kmax; k<=kmax; k++ ) { for ( l=-lmax; l<=lmax; l++ ) { if ( (h==0) && (k==0) && (l==0) ) continue; if ( forbidden_reflection(cell, h, k, l) ) continue; if ( 2.0*resolution(cell, h, k, l) > max_r ) continue; r[i].u = h*asx + k*bsx + l*csx; r[i].v = h*asy + k*bsy + l*csy; r[i].w = h*asz + k*bsz + l*csz; i++; if ( i == MAX_REFLS ) { ERROR("Too many reflections.\n"); return NULL; } } } } *n = i; return r; } static int tolerance(double a, double b) { if ( fabs(a-b) < 1e6 ) return 1; return 0; } static int find_rvec(struct rvec *l, int n, struct rvec f) { int i; for ( i=0; i na ) return 1; return 0; } static int check_transformation(UnitCell *cell, UnitCellTransformation *tfn, int pred_test, UnitCell *ct) { UnitCell *cnew, *cback; UnitCellTransformation *inv; double a[9], b[9]; int i; int fail = 0; struct rvec *vecs; struct rvec *tvecs; int na, nb; STATUS("-----------------------\n"); if ( ct == NULL ) { cnew = cell_transform(cell, tfn); } else { cnew = ct; } cback = cell_transform_inverse(cnew, tfn); cell_print(cell); tfn_print(tfn); cell_print(cnew); if ( pred_test ) { /* Check that the two cells predict the same reflections */ vecs = all_refls(cell, 1e9, &na); tvecs = all_refls(cnew, 1e9, &nb); if ( compare_rvecs(vecs, na, tvecs, nb) || compare_rvecs(tvecs, nb, vecs, na) ) { ERROR("Transformed cell didn't predict the same reflections\n"); //printf("---\n"); //for ( i=0; i