aboutsummaryrefslogtreecommitdiff
path: root/src/symmetry.c
blob: bedc146ca3635d3197c33132b6c84ef1b9b12890 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
 * symmetry.c
 *
 * Symmetry
 *
 * (c) 2006-2010 Thomas White <taw@physics.org>
 *
 * Part of CrystFEL - crystallography with a FEL
 *
 */


#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdlib.h>
#include <stdio.h>
#include <math.h>

#include "utils.h"


/* 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))) )
/* 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)) ) {   \
		*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                                             \
	ERROR("No match in %s for %i %i %i\n", sym, h, k, l); \
	abort();


/* 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)
{
	if ( strcmp(sym, "6/mmm") == 0 ) return 24;
	/* 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)
{
	if ( strcmp(sym, "6/mmm") == 0 ) {
		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;
		}
	}

	*he = h;  *ke = k;  *ie = i;  *le = l;
}


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;
	}

	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 */

	ERROR("Unknown point group '%s'\n", sym);
	abort();
}