aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel/src
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2013-04-18 18:11:48 +0200
committerThomas White <taw@physics.org>2013-04-18 18:11:48 +0200
commit7df069a4b8f8ae1431d46a166e9d81d2ce68b213 (patch)
tree2efb61b7edb96babec82e78148cfb78bace94ecd /libcrystfel/src
parent7cdb05aa7f3b7df0f31cbd79a4799c5e60ec3d3f (diff)
Read/write lattice type, centering and unique axis information from/to stream
Diffstat (limited to 'libcrystfel/src')
-rw-r--r--libcrystfel/src/cell-utils.c15
-rw-r--r--libcrystfel/src/cell-utils.h1
-rw-r--r--libcrystfel/src/stream.c76
3 files changed, 78 insertions, 14 deletions
diff --git a/libcrystfel/src/cell-utils.c b/libcrystfel/src/cell-utils.c
index b1604815..8b881178 100644
--- a/libcrystfel/src/cell-utils.c
+++ b/libcrystfel/src/cell-utils.c
@@ -113,6 +113,21 @@ const char *str_lattice(LatticeType l)
}
+LatticeType lattice_from_str(const char *s)
+{
+ if ( strcmp(s, "triclinic") == 0 ) return L_TRICLINIC;
+ if ( strcmp(s, "monoclinic") == 0 ) return L_MONOCLINIC;
+ if ( strcmp(s, "orthorhombic") == 0 ) return L_ORTHORHOMBIC;
+ if ( strcmp(s, "tetragonal") == 0 ) return L_TETRAGONAL;
+ if ( strcmp(s, "rhombohedral") == 0 ) return L_RHOMBOHEDRAL;
+ if ( strcmp(s, "hexagonal") == 0 ) return L_HEXAGONAL;
+ if ( strcmp(s, "cubic") == 0 ) return L_CUBIC;
+
+ ERROR("Unrecognised lattice type '%s'\n", s);
+ return L_TRICLINIC;
+}
+
+
int right_handed(UnitCell *cell)
{
double asx, asy, asz;
diff --git a/libcrystfel/src/cell-utils.h b/libcrystfel/src/cell-utils.h
index 8eb08ca7..e816e2b2 100644
--- a/libcrystfel/src/cell-utils.h
+++ b/libcrystfel/src/cell-utils.h
@@ -62,6 +62,7 @@ extern int bravais_lattice(UnitCell *cell);
extern int right_handed(UnitCell *cell);
extern const char *str_lattice(LatticeType l);
+extern LatticeType lattice_from_str(const char *s);
extern int forbidden_reflection(UnitCell *cell,
signed int h, signed int k, signed int l);
diff --git a/libcrystfel/src/stream.c b/libcrystfel/src/stream.c
index c6d88629..03f969f8 100644
--- a/libcrystfel/src/stream.c
+++ b/libcrystfel/src/stream.c
@@ -43,6 +43,7 @@
#include <fcntl.h>
#include "cell.h"
+#include "cell-utils.h"
#include "utils.h"
#include "image.h"
#include "stream.h"
@@ -159,6 +160,11 @@ static void write_crystal(Stream *st, Crystal *cr, int include_reflections)
fprintf(st->fh, "cstar = %+9.7f %+9.7f %+9.7f nm^-1\n",
csx/1e9, csy/1e9, csz/1e9);
+ fprintf(st->fh, "lattice_type = %s\n",
+ str_lattice(cell_get_lattice_type(cell)));
+ fprintf(st->fh, "centering = %c\n", cell_get_centering(cell));
+ fprintf(st->fh, "unique_axis = %c\n", cell_get_unique_axis(cell));
+
reflist = crystal_get_reflections(cr);
if ( reflist != NULL ) {
@@ -261,6 +267,12 @@ void read_crystal(Stream *st, struct image *image)
int have_as = 0;
int have_bs = 0;
int have_cs = 0;
+ int have_latt = 0;
+ int have_cen = 0;
+ int have_ua = 0;
+ char centering = 'P';
+ char unique_axis = '*';
+ LatticeType lattice_type = L_TRICLINIC;
Crystal *cr;
int n;
Crystal **crystals_new;
@@ -274,6 +286,7 @@ void read_crystal(Stream *st, struct image *image)
do {
float u, v, w;
+ char c;
rval = fgets(line, 1023, st->fh);
@@ -296,23 +309,31 @@ void read_crystal(Stream *st, struct image *image)
have_cs = 1;
}
- if ( have_as && have_bs && have_cs ) {
-
- UnitCell *cell;
-
- cell = crystal_get_cell(cr);
-
- if ( cell != NULL ) {
- ERROR("Duplicate cell found in stream!\n");
- ERROR("I'll use the most recent one.\n");
- cell_free(cell);
+ if ( sscanf(line, "centering = %c", &c) == 1 ) {
+ if ( !have_cen ) {
+ centering = c;
+ have_cen = 1;
+ } else {
+ ERROR("Duplicate centering ignored.\n");
}
+ }
- cell = cell_new_from_reciprocal_axes(as, bs, cs);
- crystal_set_cell(cr, cell);
-
- have_as = 0; have_bs = 0; have_cs = 0;
+ if ( sscanf(line, "unique_axis = %c", &c) == 1 ) {
+ if ( !have_ua ) {
+ unique_axis = c;
+ have_ua = 1;
+ } else {
+ ERROR("Duplicate unique axis ignored.\n");
+ }
+ }
+ if ( strncmp(line, "lattice_type = ", 15) == 0 ) {
+ if ( !have_latt ) {
+ lattice_type = lattice_from_str(line+15);
+ have_latt = 1;
+ } else {
+ ERROR("Duplicate lattice type ignored.\n");
+ }
}
if ( strncmp(line, "num_saturated_reflections = ", 28) == 0 ) {
@@ -339,6 +360,33 @@ void read_crystal(Stream *st, struct image *image)
} while ( 1 );
+ if ( have_as && have_bs && have_cs ) {
+
+ UnitCell *cell;
+
+ cell = crystal_get_cell(cr);
+
+ if ( cell != NULL ) {
+ ERROR("Duplicate cell found in stream!\n");
+ ERROR("I'll use the most recent one.\n");
+ cell_free(cell);
+ }
+
+ cell = cell_new_from_reciprocal_axes(as, bs, cs);
+
+ if ( have_cen && have_ua && have_latt ) {
+ cell_set_centering(cell, centering);
+ cell_set_unique_axis(cell, unique_axis);
+ cell_set_lattice_type(cell, lattice_type);
+ } /* else keep default triclinic P */
+
+ crystal_set_cell(cr, cell);
+
+ have_as = 0; have_bs = 0; have_cs = 0;
+ have_latt = 0; have_ua = 0; have_cen = 0;
+
+ }
+
/* Add crystal to the list for this image */
n = image->n_crystals+1;
crystals_new = realloc(image->crystals, n*sizeof(Crystal *));