From c9a551b872ae4eb16a606d46a7cf118af24f75f5 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 12 Nov 2009 18:03:12 +0100 Subject: Loads of lattice stuff --- src/ewald.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/ewald.c (limited to 'src/ewald.c') diff --git a/src/ewald.c b/src/ewald.c new file mode 100644 index 00000000..9d8a0450 --- /dev/null +++ b/src/ewald.c @@ -0,0 +1,57 @@ +/* + * ewald.c + * + * Calculate q-vector arrays + * + * (c) 2007-2009 Thomas White + * + * pattern_sim - Simulate diffraction patterns from small crystals + * + */ + + +#include +#include +#include + +#include "image.h" +#include "utils.h" +#include "cell.h" + + +void get_ewald(struct image *image) +{ + int x, y; + double k; /* Wavenumber */ + + k = 1/image->lambda; + + image->qvecs = malloc(image->width * image->height + * sizeof(struct threevec)); + + for ( x=0; xwidth; x++ ) { + for ( y=0; yheight; y++ ) { + + double rx, ry, r; + double twothetax, twothetay, twotheta; + double qx, qy, qz; + + rx = ((double)x - image->x_centre) / image->resolution; + ry = ((double)y - image->y_centre) / image->resolution; + r = sqrt(pow(rx, 2.0) + pow(ry, 2.0)); + + twothetax = atan2(rx, image->camera_len); + twothetay = atan2(ry, image->camera_len); + twotheta = atan2(r, image->camera_len); + + qx = k * sin(twothetax); + qy = k * sin(twothetay); + qz = k - k * cos(twotheta); + + image->qvecs[x + image->width*y].u = qx; + image->qvecs[x + image->width*y].v = qy; + image->qvecs[x + image->width*y].w = qz; + + } + } +} -- cgit v1.2.3