diff options
author | Thomas White <taw@physics.org> | 2010-06-30 14:35:00 +0200 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2012-02-22 15:26:51 +0100 |
commit | 7b4161e498b0ab392b7b26c3ad33bb7f8f1c5506 (patch) | |
tree | 0f46b534a50738072dad6172cd63304c4b94983b /src/symmetry.c | |
parent | da7591b21895dd274ffffac916f71bd84b9cd783 (diff) |
Fix symmetry so that it works, and use it in render_hkl
Diffstat (limited to 'src/symmetry.c')
-rw-r--r-- | src/symmetry.c | 154 |
1 files changed, 94 insertions, 60 deletions
diff --git a/src/symmetry.c b/src/symmetry.c index bedc146c..06148de7 100644 --- a/src/symmetry.c +++ b/src/symmetry.c @@ -21,25 +21,29 @@ #include "utils.h" +#ifdef DEBUG +#define SYM_DEBUG STATUS +#else /* DEBUG */ +#define SYM_DEBUG(...) +#endif /* DEBUG */ + + /* Conditions for a reflection to be in the asymmetric unit cell */ #define COND_1(h, k, l) (1) -#define COND_6MMM(h, k, i, l) ( (h>=0) && (k>=0) && (l>=0) \ - && ((h>k)||((h==0)&&(k==0))) ) +#define COND_6(h, k, l) ( (h>=0) && (k>=0) ) +#define COND_6M(h, k, l) ( (h>=0) && (k>=0) && (l>=0) ) +#define COND_6MMM(h, k, l) ( (h>=0) && (k>=0) && (l>=0) \ + && (h>=k) ) /* TODO: Add more groups here */ + /* Macros for checking the above conditions and returning if satisfied */ -#define CHECK_COND_FOURIDX(h, k, i, l, cond) \ - if ( COND_##cond((h), (k), (i), (l)) ) { \ +#define CHECK_COND(h, k, l, cond) \ + if ( COND_##cond((h), (k), (l)) ) { \ *hp = (h); *kp = (k); *lp = (l); \ return; \ } -#define CHECK_COND_THREEIDX(h, k, l, cond) \ - if ( COND_##cond((h), (k), (l)) ) { \ - *hp = (h); *kp = (k); *lp = (l); \ - return; \ - } - /* Abort macro if no match found */ #define SYM_ABORT \ @@ -49,50 +53,87 @@ /* FIXME: Should take into account special indices * e.g. l==0 has fewer equivalent reflections */ -static int num_equivs4(signed int h, signed int k, signed int i, signed int l, - const char *sym) +int num_equivs(signed int h, signed int k, signed int l, const char *sym) { if ( strcmp(sym, "6/mmm") == 0 ) return 24; + if ( strcmp(sym, "6") == 0 ) return 6; + if ( strcmp(sym, "6/m") == 0 ) return 12; /* TODO: Add more groups here */ return 1; } -static void get_equiv4(signed int h, signed int k, signed int i, signed int l, - signed int *he, signed int *ke, signed int *ie, - signed int *le, const char *sym, int idx) +void get_equiv(signed int h, signed int k, signed int l, + signed int *he, signed int *ke, signed int *le, + const char *sym, int idx) { + if ( strcmp(sym, "1") == 0 ) { + *he = h; *ke = k; *le = l; return; + } + + if ( strcmp(sym, "6") == 0 ) { + signed int i = -h-k; + switch ( idx ) { + case 0 : *he = h; *ke = k; *le = l; return; + case 1 : *he = i; *ke = h; *le = l; return; + case 2 : *he = k; *ke = i; *le = l; return; + case 3 : *he = -h; *ke = -k; *le = l; return; + case 4 : *he = -i; *ke = -h; *le = l; return; + case 5 : *he = -k; *ke = -i; *le = l; return; + } + } + + if ( strcmp(sym, "6/m") == 0 ) { + signed int i = -h-k; + switch ( idx ) { + case 0 : *he = h; *ke = k; *le = l; return; + case 1 : *he = i; *ke = h; *le = l; return; + case 2 : *he = k; *ke = i; *le = l; return; + case 3 : *he = -h; *ke = -k; *le = l; return; + case 4 : *he = -i; *ke = -h; *le = l; return; + case 5 : *he = -k; *ke = -i; *le = l; return; + case 6 : *he = h; *ke = k; *le = -l; return; + case 7 : *he = i; *ke = h; *le = -l; return; + case 8 : *he = k; *ke = i; *le = -l; return; + case 9 : *he = -h; *ke = -k; *le = -l; return; + case 10 : *he = -i; *ke = -h; *le = -l; return; + case 11 : *he = -k; *ke = -i; *le = -l; return; + } + } + if ( strcmp(sym, "6/mmm") == 0 ) { + signed int i = -h-k; switch ( idx ) { - case 0 : *he = h; *ke = k; *ie = i; *le = l; return; - case 1 : *he = h; *ke = i; *ie = k; *le = l; return; - case 2 : *he = k; *ke = h; *ie = i; *le = l; return; - case 3 : *he = k; *ke = i; *ie = h; *le = l; return; - case 4 : *he = i; *ke = h; *ie = k; *le = l; return; - case 5 : *he = i; *ke = k; *ie = h; *le = l; return; - case 6 : *he = h; *ke = k; *ie = i; *le = -l; return; - case 7 : *he = h; *ke = i; *ie = k; *le = -l; return; - case 8 : *he = k; *ke = h; *ie = i; *le = -l; return; - case 9 : *he = k; *ke = i; *ie = h; *le = -l; return; - case 10 : *he = i; *ke = h; *ie = k; *le = -l; return; - case 11 : *he = i; *ke = k; *ie = h; *le = -l; return; - case 12 : *he = -h; *ke = -k; *ie = -i; *le = l; return; - case 13 : *he = -h; *ke = -i; *ie = -k; *le = l; return; - case 14 : *he = -k; *ke = -h; *ie = -i; *le = l; return; - case 15 : *he = -k; *ke = -i; *ie = -h; *le = l; return; - case 16 : *he = -i; *ke = -h; *ie = -k; *le = l; return; - case 17 : *he = -i; *ke = -k; *ie = -h; *le = l; return; - case 18 : *he = -h; *ke = -k; *ie = -i; *le = -l; return; - case 19 : *he = -h; *ke = -i; *ie = -k; *le = -l; return; - case 20 : *he = -k; *ke = -h; *ie = -i; *le = -l; return; - case 21 : *he = -k; *ke = -i; *ie = -h; *le = -l; return; - case 22 : *he = -i; *ke = -h; *ie = -k; *le = -l; return; - case 23 : *he = -i; *ke = -k; *ie = -h; *le = -l; return; + case 0 : *he = h; *ke = k; *le = l; return; + case 1 : *he = i; *ke = h; *le = l; return; + case 2 : *he = k; *ke = i; *le = l; return; + case 3 : *he = -h; *ke = -k; *le = l; return; + case 4 : *he = -i; *ke = -h; *le = l; return; + case 5 : *he = -k; *ke = -i; *le = l; return; + case 6 : *he = k; *ke = h; *le = -l; return; + case 7 : *he = h; *ke = i; *le = -l; return; + case 8 : *he = i; *ke = k; *le = -l; return; + case 9 : *he = -k; *ke = -h; *le = -l; return; + case 10 : *he = -h; *ke = -i; *le = -l; return; + case 11 : *he = -i; *ke = -k; *le = -l; return; + case 12 : *he = -h; *ke = -k; *le = -l; return; + case 13 : *he = -i; *ke = -h; *le = -l; return; + case 14 : *he = -k; *ke = -i; *le = -l; return; + case 15 : *he = h; *ke = k; *le = -l; return; + case 16 : *he = i; *ke = h; *le = -l; return; + case 17 : *he = k; *ke = i; *le = -l; return; + case 18 : *he = -k; *ke = -h; *le = l; return; + case 19 : *he = -h; *ke = -i; *le = l; return; + case 20 : *he = -i; *ke = -k; *le = l; return; + case 21 : *he = k; *ke = h; *le = l; return; + case 22 : *he = h; *ke = i; *le = l; return; + case 23 : *he = i; *ke = k; *le = l; return; } } - *he = h; *ke = k; *ie = i; *le = l; + /* Fallback for unrecognised groups */ + *he = h; *ke = k; *le = l; } @@ -100,28 +141,21 @@ void get_asymm(signed int h, signed int k, signed int l, signed int *hp, signed int *kp, signed int *lp, const char *sym) { - if ( strcmp(sym, "1") == 0 ) { - CHECK_COND_THREEIDX(h, k, l, 1); - SYM_ABORT; + int nequiv = num_equivs(h, k, l, sym); + int p; + + SYM_DEBUG("------ %i %i %i\n", h, k, l); + for ( p=0; p<nequiv; p++ ) { + signed int he, ke, le; + get_equiv(h, k, l, &he, &ke, &le, sym, p); + SYM_DEBUG("%i : %i %i %i\n", p, he, ke, le); + if ( strcmp(sym, "1") == 0 ) CHECK_COND(he, ke, le, 1); + if ( strcmp(sym, "6") == 0 ) CHECK_COND(he, ke, le, 6); + if ( strcmp(sym, "6/m") == 0 ) CHECK_COND(he, ke, le, 6M); + if ( strcmp(sym, "6/mmm") == 0 ) CHECK_COND(he, ke, le, 6MMM); } - if ( strcmp(sym, "6/mmm") == 0 ) { - - const signed int i = h+k; - int nequiv = num_equivs4(h, k, i, l, sym); - int p; - - for ( p=0; p<nequiv; p++ ) { - signed int he, ke, ie, le; - get_equiv4(h, k, i, l, &he, &ke, &ie, &le, sym, p); - CHECK_COND_FOURIDX(he, ke, ie, le, 6MMM); - } - - SYM_ABORT; /* Should never reach here */ - - } - - /* TODO: Add more groups here */ + SYM_ABORT; /* Should never reach here */ ERROR("Unknown point group '%s'\n", sym); abort(); |