diff options
author | Thomas White <taw@physics.org> | 2014-03-24 12:00:51 +0100 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2014-03-24 12:06:02 +0100 |
commit | f50355434a331e1480f30086789fa61a2c1af991 (patch) | |
tree | 7c5beeeddb9f4163476dcf1bda48867ec02e3423 | |
parent | ce8e55506a558b20caeb59957e5df509b8cada1a (diff) |
Add parse_symmetry_operations()
-rw-r--r-- | libcrystfel/src/symmetry.c | 82 | ||||
-rw-r--r-- | libcrystfel/src/symmetry.h | 7 |
2 files changed, 83 insertions, 6 deletions
diff --git a/libcrystfel/src/symmetry.c b/libcrystfel/src/symmetry.c index dec8a520..47ba088b 100644 --- a/libcrystfel/src/symmetry.c +++ b/libcrystfel/src/symmetry.c @@ -3,11 +3,11 @@ * * Symmetry * - * Copyright © 2012 Deutsches Elektronen-Synchrotron DESY, - * a research centre of the Helmholtz Association. + * Copyright © 2012-2014 Deutsches Elektronen-Synchrotron DESY, + * a research centre of the Helmholtz Association. * * Authors: - * 2010-2012 Thomas White <taw@physics.org> + * 2010-2014 Thomas White <taw@physics.org> * * This file is part of CrystFEL. * @@ -1585,6 +1585,82 @@ SymOpList *get_ambiguities(const SymOpList *source, const SymOpList *target) } +static IntegerMatrix *parse_symmetry_operation(const char *s) +{ + IntegerMatrix *m; + char **els; + int n, i; + + + n = assplode(s, ",", &els, ASSPLODE_NONE); + if ( n != 3 ) { + for ( i=0; i<n; i++ ) free(els[i]); + free(els); + return NULL; + } + + m = intmat_new(3, 3); + if ( m == NULL ) return NULL; + + for ( i=0; i<n; i++ ) { + + int c; + size_t cl; + int sign = +1; + int nh = 0; + int nk = 0; + int nl = 0; + + cl = strlen(els[i]); + + for ( c=0; c<cl; c++ ) { + if ( els[i][c] == '-' ) sign = -1; + if ( els[i][c] == '+' ) sign = +1; + if ( els[i][c] == 'h' ) nh += sign; + if ( els[i][c] == 'k' ) nk += sign; + if ( els[i][c] == 'l' ) nl += sign; + } + + intmat_set(m, i, 0, nh); + intmat_set(m, i, 1, nk); + intmat_set(m, i, 2, nl); + + free(els[i]); + + } + free(els); + + return m; +} + + +SymOpList *parse_symmetry_operations(const char *s) +{ + SymOpList *sol; + char **ops; + int n, i; + + sol = new_symoplist(); + if ( sol == NULL ) return NULL; + + n = assplode(s, ";:", &ops, ASSPLODE_NONE); + for ( i=0; i<n; i++ ) { + IntegerMatrix *m; + m = parse_symmetry_operation(ops[i]); + if ( m != NULL ) { + add_symop(sol, m); + } else { + ERROR("Invalid symmetry operation '%s'\n", ops[i]); + /* Try the next one */ + } + free(ops[i]); + } + free(ops); + + return sol; +} + + static void add_chars(char *t, const char *s, int max_len) { char *tmp; diff --git a/libcrystfel/src/symmetry.h b/libcrystfel/src/symmetry.h index 6bb6210e..a16f523e 100644 --- a/libcrystfel/src/symmetry.h +++ b/libcrystfel/src/symmetry.h @@ -3,11 +3,11 @@ * * Symmetry * - * Copyright © 2012 Deutsches Elektronen-Synchrotron DESY, - * a research centre of the Helmholtz Association. + * Copyright © 2012-2014 Deutsches Elektronen-Synchrotron DESY, + * a research centre of the Helmholtz Association. * * Authors: - * 2010-2012 Thomas White <taw@physics.org> + * 2010-2014 Thomas White <taw@physics.org> * * This file is part of CrystFEL. * @@ -84,5 +84,6 @@ extern int is_centric(signed int h, signed int k, signed int l, const SymOpList *ops); extern void add_symop(SymOpList *ops, IntegerMatrix *m); +extern SymOpList *parse_symmetry_operations(const char *s); #endif /* SYMMETRY_H */ |