From 5018c8eff5a1ce350aa80946707e69e032b249a8 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Fri, 12 Oct 2012 11:17:29 +0200 Subject: Add missing file --- tests/cell_check.c | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 tests/cell_check.c (limited to 'tests') diff --git a/tests/cell_check.c b/tests/cell_check.c new file mode 100644 index 00000000..f62cd7be --- /dev/null +++ b/tests/cell_check.c @@ -0,0 +1,117 @@ +/* + * cell_check.c + * + * Check that unit cells work correctly + * + * Copyright © 2012 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 +#include + + +int main(int argc, char *argv[]) +{ + int fail = 0; + struct quaternion orientation; + UnitCell *cell; + double asx, asy, asz; + double bsx, bsy, bsz; + double csx, csy, csz; + double asmag, bsmag, csmag; + double als, bes, gas; + double ax, ay, az; + double bx, by, bz; + double cx, cy, cz; + + cell = cell_new_from_parameters(27.155e-9, 28.155e-9, 10.987e-9, + deg2rad(90.0), + deg2rad(90.0), + deg2rad(120.0)); + if ( cell == NULL ) return 1; + + orientation = random_quaternion(); + cell = cell_rotate(cell, orientation); + + cell_get_reciprocal(cell, &asx, &asy, &asz, + &bsx, &bsy, &bsz, + &csx, &csy, &csz); + + asmag = sqrt(pow(asx, 2.0) + pow(asy, 2.0) + pow(asz, 2.0)); + bsmag = sqrt(pow(bsx, 2.0) + pow(bsy, 2.0) + pow(bsz, 2.0)); + csmag = sqrt(pow(csx, 2.0) + pow(csy, 2.0) + pow(csz, 2.0)); + + als = angle_between(bsx, bsy, bsz, csx, csy, csz); + bes = angle_between(asx, asy, asz, csx, csy, csz); + gas = angle_between(asx, asy, asz, bsx, bsy, bsz); + + STATUS("Separation between (100) planes = %5.2f nm\n", 1e9/asmag); + STATUS("Separation between (010) planes = %5.2f nm\n", 1e9/bsmag); + STATUS("Separation between (001) planes = %5.2f nm\n", 1e9/csmag); + STATUS("Angle between (100) and (010) planes = %5.2f deg\n", + rad2deg(gas)); + STATUS("Angle between (100) and (001) planes = %5.2f deg\n", + rad2deg(bes)); + STATUS("Angle between (010) and (001) planes = %5.2f deg\n", + rad2deg(als)); + + cell_free(cell); + + cell = cell_new(); + if ( cell == NULL ) return 1; + + cell_set_reciprocal(cell, asx, asy, asz, bsx, bsy, bsz, csx, csy, csz); + cell_print(cell); + + cell_get_cartesian(cell, &ax, &ay, &az, + &bx, &by, &bz, + &cx, &cy, &cz); + + STATUS("Cell choice 1:\n"); + cell_set_cartesian(cell, ax, ay, az, + bx, by, bz, + cx, cy, cz); + cell_print(cell); + + STATUS("Cell choice 2:\n"); + cell_set_cartesian(cell, bx, by, bz, + -ax-bx, -ay-by, -az-bz, + cx, cy, cz); + cell_print(cell); + + + STATUS("Cell choice 3:\n"); + cell_set_cartesian(cell, -ax-bx, -ay-by, -az-bz, + ax, ay, az, + cx, cy, cz); + cell_print(cell); + + + return fail; +} -- cgit v1.2.3