aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/symmetry.c131
-rw-r--r--tests/.gitignore1
-rw-r--r--tests/symmetry_check.c56
3 files changed, 98 insertions, 90 deletions
diff --git a/src/symmetry.c b/src/symmetry.c
index 3b995967..b0e430b5 100644
--- a/src/symmetry.c
+++ b/src/symmetry.c
@@ -235,71 +235,41 @@ static void combine_ops(signed int *h1, signed int *k1, signed int *l1,
}
-static void expand_all_ops(signed int *hs, signed int *ks, signed int *ls,
- int skip, SymOpList *s, SymOpList *expanded)
+static void combine_and_add_symop(struct sym_op *opi, int oi,
+ struct sym_op *opj,
+ SymOpList *s)
{
- int i, n;
-
- n = num_ops(s);
-
- for ( i=0; i<n; i++ ) {
-
- int oi;
- struct sym_op *opi = &s->ops[i];
-
- for ( oi=0; oi<opi->order; oi++ ) {
-
- int oi_it;
- signed int *h_ordered, *k_ordered, *l_ordered;
-
- h_ordered = malloc(3*sizeof(signed int));
- k_ordered = malloc(3*sizeof(signed int));
- l_ordered = malloc(3*sizeof(signed int));
- assert(h_ordered != NULL);
- assert(k_ordered != NULL);
- assert(l_ordered != NULL);
-
- memcpy(h_ordered, hs, 3*sizeof(signed int));
- memcpy(k_ordered, ks, 3*sizeof(signed int));
- memcpy(l_ordered, ls, 3*sizeof(signed int));
+ int i;
+ signed int *h, *k, *l;
- /* Apply "opi" this number of times */
- for ( oi_it=0; oi_it<oi; oi_it++ ) {
+ h = malloc(3*sizeof(signed int));
+ k = malloc(3*sizeof(signed int));
+ l = malloc(3*sizeof(signed int));
+ assert(h != NULL);
+ assert(k != NULL);
+ assert(l != NULL);
- signed int hfs[3], kfs[3], lfs[3];
+ memcpy(h, opj->h, 3*sizeof(signed int));
+ memcpy(k, opj->k, 3*sizeof(signed int));
+ memcpy(l, opj->l, 3*sizeof(signed int));
- combine_ops(h_ordered, k_ordered, l_ordered,
- opi->h, opi->k, opi->l,
- hfs, kfs, lfs);
+ for ( i=0; i<oi; i++ ) {
- if ( i != skip ) {
+ signed int hfs[3], kfs[3], lfs[3];
- memcpy(h_ordered, hfs,
- 3*sizeof(signed int));
- memcpy(k_ordered, kfs,
- 3*sizeof(signed int));
- memcpy(l_ordered, lfs,
- 3*sizeof(signed int));
+ combine_ops(h, k, l, opi->h, opi->k, opi->l, hfs, kfs, lfs);
- }
- }
+ memcpy(h, hfs, 3*sizeof(signed int));
+ memcpy(k, kfs, 3*sizeof(signed int));
+ memcpy(l, lfs, 3*sizeof(signed int));
- STATUS("i=%i, oi=%i\n", i, oi);
- STATUS("Creating %3i %3i %3i\n", h_ordered[0],
- h_ordered[1],
- h_ordered[2]);
- STATUS(" %3i %3i %3i\n", k_ordered[0],
- k_ordered[1],
- k_ordered[2]);
- STATUS(" %3i %3i %3i\n", l_ordered[0],
- l_ordered[1],
- l_ordered[2]);
- STATUS("\n");
- add_symop(expanded, h_ordered, k_ordered, l_ordered, 1);
+ }
- }
+// STATUS("Creating %3i %3i %3i\n", h[0], h[1], h[2]);
+// STATUS(" %3i %3i %3i\n", k[0], k[1], k[2]);
+// STATUS(" %3i %3i %3i\n", l[0], l[1], l[2]);
- }
+ add_symop(s, h, k, l, 1);
}
@@ -308,55 +278,37 @@ static void expand_all_ops(signed int *hs, signed int *ks, signed int *ls,
static SymOpList *expand_ops(SymOpList *s)
{
int n, i;
- SymOpList *expanded;
+ SymOpList *e;
- n = num_ops(s);
- expanded = new_symoplist();
- if ( expanded == NULL ) return NULL;
- expanded->name = strdup(symmetry_name(s));
- STATUS("%i ops to expand.\n", n);
+ e = new_symoplist();
+ if ( e == NULL ) return NULL;
+ e->name = strdup(symmetry_name(s));
+
+ add_symop(e, v(1,0,0,0), v(0,1,0,0), v(0,0,0,1), 1); /* I */
+ n = num_ops(s);
for ( i=0; i<n; i++ ) {
- int oi;
+ int j, nj;
struct sym_op *opi = &s->ops[i];
- STATUS("Op %i, order=%i\n", i, opi->order);
- for ( oi=0; oi<opi->order; oi++ ) {
+ /* Apply op 'i' to all the current ops in the list */
+ nj = num_ops(e);
+ for ( j=0; j<nj; j++ ) {
- int oi_it;
- signed int h_ordered[3], k_ordered[3], l_ordered[3];
-
- h_ordered[0] = 1; h_ordered[1] = 0; h_ordered[2] = 0;
- k_ordered[0] = 0; k_ordered[1] = 1; k_ordered[2] = 0;
- l_ordered[0] = 0; l_ordered[1] = 0; l_ordered[2] = 1;
-
- /* Apply "opi" this number of times */
- for ( oi_it=0; oi_it<oi; oi_it++ ) {
-
- signed int hfs[3], kfs[3], lfs[3];
-
- combine_ops(h_ordered, k_ordered, l_ordered,
- opi->h, opi->k, opi->l,
- hfs, kfs, lfs);
-
- memcpy(h_ordered, hfs, 3*sizeof(signed int));
- memcpy(k_ordered, kfs, 3*sizeof(signed int));
- memcpy(l_ordered, lfs, 3*sizeof(signed int));
+ int oi;
+ for ( oi=0; oi<opi->order-1; oi++ ) {
+ combine_and_add_symop(opi, oi+1, &e->ops[j], e);
}
- STATUS("Upper: i=%i, oi=%i\n", i, oi);
- expand_all_ops(h_ordered, k_ordered, l_ordered, i,
- s, expanded);
-
}
}
free_symoplist(s);
- return expanded;
+ return e;
}
@@ -365,7 +317,7 @@ static SymOpList *expand_ops(SymOpList *s)
static SymOpList *make_1bar()
{
SymOpList *new = new_symoplist();
- add_symop(new, v(1,0,0,0), v(0,1,0,0), v(0,0,0,1), 2); /* -I */
+ add_symop(new, v(-1,0,0,0), v(0,-1,0,0), v(0,0,0,-1), 2); /* -I */
new->name = strdup("-1");
return expand_ops(new);
}
@@ -374,7 +326,6 @@ static SymOpList *make_1bar()
static SymOpList *make_1()
{
SymOpList *new = new_symoplist();
- add_symop(new, v(1,0,0,0), v(0,1,0,0), v(0,0,0,1), 1); /* I */
new->name = strdup("1");
return expand_ops(new);
}
diff --git a/tests/.gitignore b/tests/.gitignore
index 898fcd89..c2a45f5a 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -4,4 +4,5 @@ list_check
gpu_sim_check
integration_check
pr_gradient_check
+symmetry_check
.dirstamp
diff --git a/tests/symmetry_check.c b/tests/symmetry_check.c
new file mode 100644
index 00000000..bda6961e
--- /dev/null
+++ b/tests/symmetry_check.c
@@ -0,0 +1,56 @@
+/*
+ * symmetry_check.c
+ *
+ * Check symmetry
+ *
+ * (c) 2011 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 "../src/symmetry.h"
+#include "../src/utils.h"
+
+
+static void check_nequiv(const char *pg, int answer, int *fail)
+{
+ SymOpList *sym;
+ int n;
+
+ //STATUS("**************************************** Testing '%s'\n", pg);
+
+ sym = get_pointgroup(pg);
+ n = num_equivs(sym, NULL);
+
+ if ( n != answer ) {
+ ERROR("Number of equivalents in '%s' is %i (not %i)\n",
+ pg, n, answer);
+ *fail = 1;
+ }
+
+ free_symoplist(sym);
+}
+
+
+int main(int argc, char *argv[])
+{
+ int fail = 0;
+
+ check_nequiv( "1", 1, &fail);
+ check_nequiv( "-1", 2, &fail);
+ check_nequiv( "2", 2, &fail);
+ check_nequiv( "m", 2, &fail);
+ check_nequiv("2/m", 4, &fail);
+
+ return fail;
+}