aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2012-10-12 11:17:29 +0200
committerThomas White <taw@physics.org>2012-10-12 11:17:29 +0200
commit5018c8eff5a1ce350aa80946707e69e032b249a8 (patch)
treece375068556d8889d290b989b6bfc5f415728b8a /tests
parentc7712c20c3977af8eccf9a7951b9f494e5ba14c4 (diff)
Add missing file
Diffstat (limited to 'tests')
-rw-r--r--tests/cell_check.c117
1 files changed, 117 insertions, 0 deletions
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 <taw@physics.org>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <fenv.h>
+
+#include <cell.h>
+#include <cell-utils.h>
+
+
+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;
+}