From 1bd043203f25a26d5d806ed847f87a4fd7df5f22 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Mon, 11 Jul 2011 10:53:08 +0200 Subject: Get rid of ReflItemList - it's only used by the symmetry module now --- src/symmetry.c | 203 +++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 191 insertions(+), 12 deletions(-) (limited to 'src/symmetry.c') diff --git a/src/symmetry.c b/src/symmetry.c index a066ca47..3a9d505e 100644 --- a/src/symmetry.c +++ b/src/symmetry.c @@ -16,10 +16,13 @@ #include #include +#include #include +#include "symmetry.h" #include "utils.h" + #ifdef DEBUG #define SYM_DEBUG STATUS #else /* DEBUG */ @@ -39,6 +42,181 @@ */ +struct sym_op { + signed int h; + signed int k; + signed int l; + int op; +}; + + +/** + * SECTION:symoplist + * @short_description: A list of point symmetry operations + * @title: SymOpList + * @section_id: + * @see_also: + * @include: "symmetry.h" + * @Image: + * + * Wibble + */ + +struct _symoplist { + struct sym_op *items; + int n_ops; + int max_ops; +}; + + + +static void alloc_items(SymOpList *items) +{ + items->items = realloc(items->items, + items->max_ops*sizeof(struct sym_op)); +} + + +/** + * new_items: + * + * Creates a new %SymOpList. + * + * Returns: The new list, or NULL. + **/ +SymOpList *new_items() +{ + SymOpList *new; + new = malloc(sizeof(SymOpList)); + if ( new == NULL ) return NULL; + new->max_ops = 1024; + new->n_ops = 0; + new->items = NULL; + alloc_items(new); + return new; +} + + +void delete_items(SymOpList *items) +{ + if ( items == NULL ) return; + if ( items->items != NULL ) free(items->items); + free(items); +} + + +void add_item_with_op(SymOpList *items, signed int h, signed int k, + signed int l, int op) +{ + if ( items->n_ops == items->max_ops ) { + items->max_ops += 1024; + alloc_items(items); + } + + items->items[items->n_ops].h = h; + items->items[items->n_ops].k = k; + items->items[items->n_ops].l = l; + items->items[items->n_ops].op = op; + items->n_ops++; +} + + +void add_item(SymOpList *items, signed int h, signed int k, signed int l) +{ + add_item_with_op(items, h, k, l, 0); +} + + +int find_item(SymOpList *items, + signed int h, signed int k, signed int l) +{ + int i; + + for ( i=0; in_ops; i++ ) { + if ( items->items[i].h != h ) continue; + if ( items->items[i].k != k ) continue; + if ( items->items[i].l != l ) continue; + return 1; + } + return 0; +} + + +static int find_op(SymOpList *items, int op) +{ + int i; + + for ( i=0; in_ops; i++ ) { + if ( items->items[i].op == op ) return 1; + } + return 0; +} + + +struct sym_op *get_item(SymOpList *items, int i) +{ + if ( i >= items->n_ops ) return NULL; + return &items->items[i]; +} + + +int num_items(const SymOpList *items) +{ + return items->n_ops; +} + + +void union_op_items(SymOpList *items, SymOpList *newi) +{ + int n, i; + + n = num_items(newi); + for ( i=0; iop) ) continue; + + add_item_with_op(items, r->h, r->k, r->l, r->op); + + } +} + + +void union_ops(SymOpList *items, SymOpList *newi) +{ + int n, i; + + n = num_items(newi); + for ( i=0; ih, r->k, r->l) ) continue; + + add_item_with_op(items, r->h, r->k, r->l, r->op); + + } +} + + +SymOpList *intersection_ops(SymOpList *i1, SymOpList *i2) +{ + int n, i; + SymOpList *res = new_items(); + + n = num_items(i1); + for ( i=0; ih, r->k, r->l) ) { + add_item_with_op(res, r->h, r->k, r->l, r->op); + } + + } + + return res; +} + + /* Check if a reflection is in the asymmetric unit cell */ static int check_cond(signed int h, signed int k, signed int l, const char *sym) { @@ -294,7 +472,7 @@ static int special_position(signed int hs, signed int ks, signed int ls, { int n_general; int i; - ReflItemList *equivs; + SymOpList *equivs; int n_equivs = 0; if ( idx == 0 ) { @@ -374,13 +552,13 @@ void get_asymm(signed int h, signed int k, signed int l, * * To count the number of possibilities, use num_items() on the result. */ -static ReflItemList *coset_decomp(signed int hs, signed int ks, signed int ls, - const char *holo, const char *mero) +static SymOpList *coset_decomp(signed int hs, signed int ks, signed int ls, + const char *holo, const char *mero) { int n_mero, n_holo; int i; signed int h, k, l; - ReflItemList *twins = new_items(); + SymOpList *twins = new_items(); /* Start by putting the given reflection into the asymmetric cell * for its (probably merohedral) point group. */ @@ -422,11 +600,12 @@ static ReflItemList *coset_decomp(signed int hs, signed int ks, signed int ls, * To use the result, call get_general_equiv() on each reflection using * the holohedral point group (use get_holohedral() for this), and for "idx" * give each "op" field from the list returned by this function. */ -ReflItemList *get_twins(ReflItemList *items, const char *holo, const char *mero) +SymOpList *get_twins(const char *holo, const char *mero) { int i; - ReflItemList *ops = new_items(); + SymOpList *ops = new_items(); int expected, actual; + SymOpList *items; /* Run the coset decomposition for every reflection in the "pattern", * and see which gives the highest number of possibilities. This @@ -435,8 +614,8 @@ ReflItemList *get_twins(ReflItemList *items, const char *holo, const char *mero) for ( i=0; ih, it->k, it->l, 1); } for ( i=0; ih, it->k, it->l, sym); j++ ) { -- cgit v1.2.3