aboutsummaryrefslogtreecommitdiff
path: root/src/reflections.c
diff options
context:
space:
mode:
authorThomas White <taw27@cam.ac.uk>2009-04-08 20:12:55 +0100
committerThomas White <taw27@cam.ac.uk>2009-04-08 20:12:55 +0100
commite9cb3c4fe04f2099807a0ac0f74f4f7c41bddb80 (patch)
tree2fcb650ef5e065a38a1ef40e77e6faeae846851b /src/reflections.c
parent260a88fd253ff23cc2c4c723b67e010c62d2e1d6 (diff)
parent6a9b94d74b0d96f901d7a6baa885c306151ae0f4 (diff)
Merge branch 'master' into simple-search
Diffstat (limited to 'src/reflections.c')
-rw-r--r--src/reflections.c109
1 files changed, 56 insertions, 53 deletions
diff --git a/src/reflections.c b/src/reflections.c
index a589231..ce5f7a9 100644
--- a/src/reflections.c
+++ b/src/reflections.c
@@ -32,9 +32,9 @@ static void reflectionlist_init(ReflectionList *reflectionlist) {
ReflectionList *reflectionlist_new() {
ReflectionList *reflectionlist = malloc(sizeof(ReflectionList));
-
+
reflectionlist_init(reflectionlist);
-
+
return reflectionlist;
}
@@ -44,10 +44,10 @@ void reflectionlist_clear_markers(ReflectionList *reflectionlist) {
Reflection *reflection = reflectionlist->reflections;
Reflection *prev = NULL;
int del = 0;
-
+
while ( reflection ) {
Reflection *next = reflection->next;
-
+
if ( (reflection->type == REFLECTION_MARKER) || (reflection->type == REFLECTION_GENERATED)
|| (reflection->type == REFLECTION_VECTOR_MARKER_1) || (reflection->type == REFLECTION_VECTOR_MARKER_2)
|| (reflection->type == REFLECTION_VECTOR_MARKER_3) ) {
@@ -61,14 +61,14 @@ void reflectionlist_clear_markers(ReflectionList *reflectionlist) {
} else {
prev = reflection;
}
-
+
reflection = next;
-
+
};
-
+
reflectionlist->n_reflections -= del;
reflectionlist->last_reflection = prev;
-
+
}
void reflectionlist_clear(ReflectionList *reflectionlist) {
@@ -78,7 +78,7 @@ void reflectionlist_clear(ReflectionList *reflectionlist) {
free(reflection);
reflection = next;
};
-
+
reflectionlist_init(reflectionlist);
}
@@ -92,27 +92,32 @@ Reflection *reflection_add(ReflectionList *reflectionlist, double x, double y, d
Reflection *new_reflection;
Reflection *nearest;
-
+
if ( reflectionlist->list_capped ) return NULL;
-
+
if ( reflectionlist->n_reflections > 1e7 ) {
fprintf(stderr, "More than 10 million reflections on list. I think this is silly.\n");
fprintf(stderr, "No further reflections will be stored. Go and fix the peak detection.\n");
reflectionlist->list_capped = 1;
}
-
- nearest = reflectionlist_find_nearest_type(reflectionlist, x, y, z, type);
- if ( nearest && distance3d(x, y, z, nearest->x, nearest->y, nearest->z) < 0.1e9 ) return NULL;
-
+
+// nearest = reflectionlist_find_nearest_type(reflectionlist, x, y, z, type);
+// if ( nearest && distance3d(x, y, z, nearest->x, nearest->y, nearest->z) < 0.1e9 ) {
+// printf("Too close\n");
+// return NULL;
+//}
new_reflection = malloc(sizeof(Reflection));
new_reflection->next = NULL;
new_reflection->x = x;
new_reflection->y = y;
new_reflection->z = z;
+ new_reflection->h = 999;
+ new_reflection->k = 333;
+ new_reflection->l = 111;
new_reflection->intensity = intensity;
new_reflection->type = type;
new_reflection->found = 0;
-
+
if ( reflectionlist->last_reflection ) {
reflectionlist->last_reflection->next = new_reflection;
reflectionlist->last_reflection = new_reflection;
@@ -121,16 +126,16 @@ Reflection *reflection_add(ReflectionList *reflectionlist, double x, double y, d
reflectionlist->last_reflection = new_reflection;
}
reflectionlist->n_reflections++;
-
+
return new_reflection;
-
+
}
double reflectionlist_largest_g(ReflectionList *reflectionlist) {
double max = 0.0;
Reflection *reflection;
-
+
reflection = reflectionlist->reflections;
while ( reflection ) {
if ( reflection->type == REFLECTION_NORMAL ) {
@@ -140,7 +145,7 @@ double reflectionlist_largest_g(ReflectionList *reflectionlist) {
}
reflection = reflection->next;
};
-
+
return max;
}
@@ -150,7 +155,7 @@ Reflection *reflectionlist_find_nearest(ReflectionList *reflectionlist, double x
double max = +INFINITY;
Reflection *reflection;
Reflection *best = NULL;
-
+
reflection = reflectionlist->reflections;
while ( reflection ) {
if ( reflection->type == REFLECTION_NORMAL ) {
@@ -163,7 +168,7 @@ Reflection *reflectionlist_find_nearest(ReflectionList *reflectionlist, double x
}
reflection = reflection->next;
};
-
+
return best;
}
@@ -174,7 +179,7 @@ Reflection *reflectionlist_find_nearest_longer_unknown(ReflectionList *reflectio
double max = +INFINITY;
Reflection *reflection;
Reflection *best = NULL;
-
+
reflection = reflectionlist->reflections;
while ( reflection ) {
if ( (reflection->type == REFLECTION_NORMAL) && (!reflection->found) ) {
@@ -187,7 +192,7 @@ Reflection *reflectionlist_find_nearest_longer_unknown(ReflectionList *reflectio
}
reflection = reflection->next;
};
-
+
return best;
}
@@ -198,7 +203,7 @@ Reflection *reflectionlist_find_nearest_type(ReflectionList *reflectionlist, dou
double max = +INFINITY;
Reflection *reflection;
Reflection *best = NULL;
-
+
reflection = reflectionlist->reflections;
while ( reflection ) {
if ( reflection->type == type ) {
@@ -211,7 +216,7 @@ Reflection *reflectionlist_find_nearest_type(ReflectionList *reflectionlist, dou
}
reflection = reflection->next;
};
-
+
return best;
}
@@ -223,9 +228,9 @@ ReflectionList *reflection_list_from_cell(Basis *basis) {
double max_res;
signed int h, k, l;
int max_order_a, max_order_b, max_order_c;
-
+
ordered = reflectionlist_new();
-
+
max_res = 21e9;
do {
max_order_a = max_res/modulus(basis->a.x, basis->a.y, basis->a.z);
@@ -234,36 +239,35 @@ ReflectionList *reflection_list_from_cell(Basis *basis) {
max_res -= 1e9;
} while ( (max_order_a * max_order_b * max_order_c * 8) > 1e4 );
printf("Selected maximum resolution %8.5f nm^-1\n", max_res/1e9);
-
+
for ( h=-max_order_a; h<=max_order_a; h++ ) {
for ( k=-max_order_b; k<=max_order_b; k++ ) {
for ( l=-max_order_c; l<=max_order_c; l++ ) {
double x, y, z;
-
- /* Test mode */
- //if ( h != 0 ) continue;
-
+
x = h*basis->a.x + k*basis->b.x + l*basis->c.x;
y = h*basis->a.y + k*basis->b.y + l*basis->c.y;
z = h*basis->a.z + k*basis->b.z + l*basis->c.z;
-
+
if ( ( x*x + y*y + z*z ) <= max_res*max_res ) {
- Reflection *ref;
- ref = reflection_add(ordered, x, y, z, 1.0, REFLECTION_GENERATED);
- if ( ref ) { /* Check it's not NULL */
- ref->h = h; ref->k = k; ref->l = l;
- }
if ( (h!=0) || (k!=0) || (l!=0) ) {
- // reflection_add(ctx->reflectionlist, x, y, z, 1.0, REFLECTION_GENERATED);
- reflection_add(ordered, x, y, z, 1.0, REFLECTION_GENERATED);
+ Reflection *ref;
+ ref = reflection_add(ordered,
+ x, y, z, 1.0,
+ REFLECTION_GENERATED);
+ if ( ref ) {
+ ref->h = h;
+ ref->k = k;
+ ref->l = l;
+ }
}
}
-
+
}
}
}
-
+
return ordered;
}
@@ -271,19 +275,19 @@ ReflectionList *reflection_list_from_cell(Basis *basis) {
void reflection_list_from_new_cell(ReflectionList *ordered, Basis *basis) {
Reflection *ref;
-
+
ref = ordered->reflections;
-
+
while ( ref ) {
-
+
signed int h, k, l;
-
+
h = ref->h; k = ref->k; l = ref->l;
-
+
ref->x = h*basis->a.x + k*basis->b.x + l*basis->c.x;
ref->y = h*basis->a.y + k*basis->b.y + l*basis->c.y;
ref->z = h*basis->a.z + k*basis->b.z + l*basis->c.z;
-
+
ref = ref->next;
}
@@ -296,7 +300,7 @@ int reflection_is_easy(Reflection *reflection) {
if ( reflection->h ) return !(reflection->k || reflection->l);
if ( reflection->k ) return !(reflection->h || reflection->l);
if ( reflection->l ) return !(reflection->h || reflection->k);
-
+
return 0; /* 000 */
}
@@ -304,7 +308,7 @@ int reflection_is_easy(Reflection *reflection) {
Reflection *reflectionlist_find(ReflectionList *reflectionlist, signed int h, signed int k, signed int l) {
Reflection *reflection;
-
+
reflection = reflectionlist->reflections;
while ( reflection ) {
if ( (reflection->h==h) && (reflection->k==k) && (reflection->l==l) ) {
@@ -312,8 +316,7 @@ Reflection *reflectionlist_find(ReflectionList *reflectionlist, signed int h, si
}
reflection = reflection->next;
};
-
+
return NULL;
}
-