aboutsummaryrefslogtreecommitdiff
path: root/src/diffraction.c
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2009-11-24 18:31:48 +0100
committerThomas White <taw@physics.org>2009-11-24 18:31:48 +0100
commit2fdca1853b945192db7e82a3396c70573ed4a677 (patch)
treeed4ecc945f867cdb8e849dd37bf640a15eb922be /src/diffraction.c
parent6062423d9a94433a228ae822fe2017e4ee103a21 (diff)
Tidy up, fix things
Diffstat (limited to 'src/diffraction.c')
-rw-r--r--src/diffraction.c60
1 files changed, 6 insertions, 54 deletions
diff --git a/src/diffraction.c b/src/diffraction.c
index e112e7ce..9a9e31b6 100644
--- a/src/diffraction.c
+++ b/src/diffraction.c
@@ -84,6 +84,7 @@ static double complex molecule_factor(struct molecule *mol, struct threevec q,
{
double hd, kd, ld;
signed int h, k, l;
+ double complex r;
hd = q.u * ax + q.v * ay + q.w * az;
kd = q.u * bx + q.v * by + q.w * bz;
@@ -92,7 +93,9 @@ static double complex molecule_factor(struct molecule *mol, struct threevec q,
k = (signed int)nearbyint(kd);
l = (signed int)nearbyint(ld);
- return get_integral(mol->reflections, h, k, l);
+ r = get_integral(mol->reflections, h, k, l);
+
+ return r;
}
@@ -102,51 +105,6 @@ static double complex water_factor(struct threevec q, double en)
}
-static void get_reflections_cached(struct molecule *mol, double en)
-{
- char s[1024];
- FILE *fh;
- size_t r;
-
- snprintf(s, 1023, "reflections-%ieV.cache", (int)J_to_eV(en));
- fh = fopen(s, "rb");
- if ( fh == NULL ) {
- printf("No cache file found (looked for %s)\n", s);
- goto calc;
- }
-
- mol->reflections = reflist_new();
- r = fread(mol->reflections, sizeof(double complex), IDIM*IDIM*IDIM, fh);
- if ( r < IDIM*IDIM*IDIM ) {
- printf("Found cache file (%s), but failed to read.\n", s);
- goto calc;
- }
-
- printf("Read structure factors (at Bragg positions) from %s\n", s);
- return;
-
-calc:
- printf("Calculating structure factors at Bragg positions...\n");
- mol->reflections = get_reflections(mol, en);
- fh = fopen(s, "wb");
- if ( fh == NULL ) {
- printf("Failed to write cache file (%s)\n", s);
- return;
- }
-
- r = fwrite(mol->reflections, sizeof(double complex),
- IDIM*IDIM*IDIM, fh);
- if ( r < IDIM*IDIM*IDIM ) {
- printf("Failed to write cache file (%s)\n", s);
- return;
- }
- fclose(fh);
-
- printf("Successfully saved structure factors at Bragg positions to"
- " file %s\n", s);
-}
-
-
void get_diffraction(struct image *image)
{
int x, y;
@@ -189,14 +147,8 @@ void get_diffraction(struct image *image)
f_molecule = molecule_factor(image->molecule, q,
ax,ay,az,bx,by,bz,cx,cy,cz);
- /* Nasty approximation follows */
- if ( y == image->height/2 ) {
- f_water = water_factor(q, image->xray_energy);
- } else {
- f_water = 0.0;
- }
-
- val = (f_molecule) + f_water;
+ f_water = water_factor(q, image->xray_energy);
+ val = (f_molecule * f_lattice) + f_water;
image->sfacs[x + image->width*y] = val;
}