diff options
36 files changed, 716 insertions, 176 deletions
diff --git a/configure.ac b/configure.ac index 62358b61..30e803f7 100644 --- a/configure.ac +++ b/configure.ac @@ -23,11 +23,36 @@ AC_FUNC_MALLOC gl_INIT +dnl Find HDF5 AC_ARG_WITH(hdf5, -[AS_HELP_STRING([--with-hdf5], [specify location of HDF5 library])], -[HDF5_CFLAGS="-I$withval/include" - HDF5_LIBS="-L$withval/lib -lhdf5"], -[HDF5_LIBS="-lhdf5"]) +[AS_HELP_STRING([--with-hdf5], + [specify location of HDF5 (instead of trying pkg-config)])], +[ + AC_MSG_NOTICE([Using your specified location for HDF5]) + HDF5_CFLAGS="-I$withval/include" + HDF5_LIBS="-L$withval/lib -lhdf5" +], +[ + AC_MSG_NOTICE([checking for HDF5 using pkg-config]) + PKG_CHECK_MODULES([HDF5], [hdf5], + [ + AC_MSG_NOTICE([Found HDF5 using pkg-config]) + ], + [ + AC_MSG_NOTICE([Did not find HDF5 using pkg-config. Assuming default location.]) + HDF5_CFLAGS="" + HDF5_LIBS="-lhdf5" + ]) +]) + +dnl Check that HDF5 *actually* works... +LIBS_SAVE=$LIBS +LIBS=$HDF5_LIBS +AC_CHECK_LIB([hdf5], [H5Fcreate], [], +[ + AC_MSG_ERROR([HDF5 not found!]) +]) +LIBS=$LIBS_SAVE AC_ARG_WITH(gsl, @@ -69,6 +94,7 @@ AS_IF([test "x$enable_cbf" != "xno"], AS_IF([test x$have_cbflib = xtrue], [ AC_DEFINE([HAVE_CBFLIB], [1], [Define to 1 if CBFlib is available]) + AC_MSG_NOTICE([CBFlib found.]) ]) AC_ARG_WITH(opencl, AS_HELP_STRING([--with-opencl], [Use OpenCL])) @@ -291,15 +317,6 @@ AC_CHECK_LIB([pthread], [sched_setaffinity], [ ]) -LIBS_SAVE=$LIBS -LIBS=$HDF5_LIBS -AC_CHECK_LIB([hdf5], [H5Fcreate], [], -[ - AC_MSG_ERROR([HDF5 not found!]) -]) -LIBS=$LIBS_SAVE - - AC_CHECK_LIB([rt], [clock_gettime], [ AC_DEFINE([HAVE_CLOCK_GETTIME], [1], diff --git a/doc/reference/libcrystfel/CrystFEL-sections.txt b/doc/reference/libcrystfel/CrystFEL-sections.txt index 34cebc9b..206ba4df 100644 --- a/doc/reference/libcrystfel/CrystFEL-sections.txt +++ b/doc/reference/libcrystfel/CrystFEL-sections.txt @@ -69,7 +69,7 @@ SERIAL write_reflist write_reflist_2 read_reflections -read_reflections_from_file +read_reflections_2 asymmetric_indices res_cutoff check_list_symmetry diff --git a/libcrystfel/src/asdf.c b/libcrystfel/src/asdf.c index 869d9256..9dc5f9d5 100644 --- a/libcrystfel/src/asdf.c +++ b/libcrystfel/src/asdf.c @@ -1188,3 +1188,9 @@ void asdf_cleanup(void *pp) fftw_vars_free(p->fftw); free(p); } + + +const char *asdf_probe(UnitCell *cell) +{ + return "asdf"; +} diff --git a/libcrystfel/src/asdf.h b/libcrystfel/src/asdf.h index 7f110960..896f65a8 100644 --- a/libcrystfel/src/asdf.h +++ b/libcrystfel/src/asdf.h @@ -46,6 +46,7 @@ extern "C" { extern int run_asdf(struct image *image, void *ipriv); extern void *asdf_prepare(IndexingMethod *indm, UnitCell *cell); +extern const char *asdf_probe(UnitCell *cell); extern void asdf_cleanup(void *pp); @@ -65,6 +66,13 @@ void *asdf_prepare(IndexingMethod *indm, UnitCell *cell) return NULL; } + +const char *asdf_probe(UnitCell *cell) +{ + return NULL; +} + + void asdf_cleanup(void *pp) { } diff --git a/libcrystfel/src/dirax.c b/libcrystfel/src/dirax.c index f781d7e2..512a61e1 100644 --- a/libcrystfel/src/dirax.c +++ b/libcrystfel/src/dirax.c @@ -604,6 +604,12 @@ void *dirax_prepare(IndexingMethod *indm, UnitCell *cell) { struct dirax_private *dp; + if ( dirax_probe(cell) == NULL ) { + ERROR("DirAx does not appear to run properly.\n"); + ERROR("Please check your DirAx installation.\n"); + return NULL; + } + /* Flags that DirAx knows about */ *indm &= INDEXING_METHOD_MASK; @@ -623,3 +629,49 @@ void dirax_cleanup(void *pp) p = (struct dirax_private *)pp; free(p); } + + +const char *dirax_probe(UnitCell *cell) +{ + pid_t pid; + int pty; + int status; + FILE *fh; + char line[1024]; + int ok = 0; + + pid = forkpty(&pty, NULL, NULL, NULL); + if ( pid == -1 ) { + return NULL; + } + if ( pid == 0 ) { + + /* Child process: invoke DirAx */ + struct termios t; + + /* Turn echo off */ + tcgetattr(STDIN_FILENO, &t); + t.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL); + tcsetattr(STDIN_FILENO, TCSANOW, &t); + + execlp("dirax", "dirax", (char *)NULL); + _exit(1); + + } + + fh = fdopen(pty, "r"); + if ( fgets(line, 1024, fh) == NULL ) { + ERROR("Failed to probe for DirAx\n"); + } else { + if ( strncmp(line, "dirax", 5) == 0 ) { + ok = 1; + } + } + + fclose(fh); + close(pty); + waitpid(pid, &status, 0); + + if ( ok ) return "dirax"; + return NULL; +} diff --git a/libcrystfel/src/dirax.h b/libcrystfel/src/dirax.h index db03abf8..dce27c57 100644 --- a/libcrystfel/src/dirax.h +++ b/libcrystfel/src/dirax.h @@ -42,6 +42,7 @@ extern "C" { extern int run_dirax(struct image *image, void *ipriv); extern void *dirax_prepare(IndexingMethod *indm, UnitCell *cell); +extern const char *dirax_probe(UnitCell *cell); extern void dirax_cleanup(void *pp); diff --git a/libcrystfel/src/felix.c b/libcrystfel/src/felix.c index 9de926f6..bbd82b0e 100644 --- a/libcrystfel/src/felix.c +++ b/libcrystfel/src/felix.c @@ -610,6 +610,12 @@ void *felix_prepare(IndexingMethod *indm, UnitCell *cell, { struct felix_private *gp; + if ( felix_probe(cell) == NULL ) { + ERROR("Felix does not appear to run properly.\n"); + ERROR("Please check your Felix installation.\n"); + return NULL; + } + if ( !cell_has_parameters(cell) ) { ERROR("Felix needs a unit cell.\n"); return NULL; @@ -695,3 +701,53 @@ void felix_cleanup(IndexingPrivate *pp) free(p->readhkl_file); free(p); } + + +const char *felix_probe(UnitCell *cell) +{ + pid_t pid; + int pty; + int status; + FILE *fh; + char line[1024]; + int ok = 0; + + if ( !cell_has_parameters(cell) ) { + return NULL; + } + + pid = forkpty(&pty, NULL, NULL, NULL); + if ( pid == -1 ) { + return NULL; + } + if ( pid == 0 ) { + + /* Child process: invoke DirAx */ + struct termios t; + + /* Turn echo off */ + tcgetattr(STDIN_FILENO, &t); + t.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL); + tcsetattr(STDIN_FILENO, TCSANOW, &t); + + execlp("Felix", "Felix", (char *)NULL); + _exit(1); + + } + + fh = fdopen(pty, "r"); + if ( fgets(line, 1024, fh) == NULL ) { + ERROR("Failed to probe for Felix\n"); + } else { + if ( strncmp(line, "Felix", 5) == 0 ) { + ok = 1; + } + } + + fclose(fh); + close(pty); + waitpid(pid, &status, 0); + + if ( ok ) return "felix"; + return NULL; +} diff --git a/libcrystfel/src/felix.h b/libcrystfel/src/felix.h index ab9ba744..48ffbe9c 100644 --- a/libcrystfel/src/felix.h +++ b/libcrystfel/src/felix.h @@ -51,6 +51,8 @@ struct felix_options extern void *felix_prepare(IndexingMethod *indm, UnitCell *cell, struct felix_options *opts); +extern const char *felix_probe(UnitCell *cell); + extern void felix_cleanup(IndexingPrivate *pp); extern int felix_index(struct image *image, IndexingPrivate *p); diff --git a/libcrystfel/src/index.c b/libcrystfel/src/index.c index 03bd6ae3..62f22c13 100644 --- a/libcrystfel/src/index.c +++ b/libcrystfel/src/index.c @@ -284,10 +284,13 @@ IndexingPrivate *setup_indexing(const char *method_list, UnitCell *cell, } for ( i=0; i<n; i++ ) { - methods[i] = get_indm_from_string(method_strings[i]); - if ( methods[i] == INDEXING_ERROR ) { + int err = 0; + methods[i] = get_indm_from_string_2(method_strings[i], &err); + if ( err ) { ERROR("----- Notice -----\n"); - ERROR("The way indexing options are used has changed in this CrystFEL version.\n"); + ERROR("The way indexing options are given has changed in this CrystFEL version.\n"); + ERROR("The indexing method should contain only the method itself and "); + ERROR("prior information modifiers ('cell' or 'latt')\n"); ERROR("To disable prediction refinement ('norefine'), use --no-refine.\n"); ERROR("To check cell axes only ('axes'), use --no-cell-combinations.\n"); ERROR("To disable all unit cell checks ('raw'), use --no-check-cell.\n"); @@ -298,6 +301,7 @@ IndexingPrivate *setup_indexing(const char *method_list, UnitCell *cell, free(methods); return NULL; } + } /* No cell parameters -> no cell checking, no prior cell */ @@ -878,13 +882,15 @@ static IndexingMethod warn_method(const char *str) } -IndexingMethod get_indm_from_string(const char *str) +IndexingMethod get_indm_from_string_2(const char *str, int *err) { int n, i; char **bits; IndexingMethod method = INDEXING_NONE; int have_method = 0; + if ( err != NULL ) *err = 0; + n = assplode(str, "-", &bits, ASSPLODE_NONE); for ( i=0; i<n; i++ ) { @@ -946,6 +952,28 @@ IndexingMethod get_indm_from_string(const char *str) } else if ( strcmp(bits[i], "nocell") == 0) { method = set_nocellparams(method); + /* Deprecated options */ + } else if ( strcmp(bits[i], "retry") == 0) { + if ( err != NULL ) *err = 1; + } else if ( strcmp(bits[i], "noretry") == 0) { + if ( err != NULL ) *err = 1; + } else if ( strcmp(bits[i], "multi") == 0) { + if ( err != NULL ) *err = 1; + } else if ( strcmp(bits[i], "nomulti") == 0) { + if ( err != NULL ) *err = 1; + } else if ( strcmp(bits[i], "refine") == 0) { + if ( err != NULL ) *err = 1; + } else if ( strcmp(bits[i], "norefine") == 0) { + if ( err != NULL ) *err = 1; + } else if ( strcmp(bits[i], "raw") == 0) { + if ( err != NULL ) *err = 1; + } else if ( strcmp(bits[i], "bad") == 0) { + if ( err != NULL ) *err = 1; + } else if ( strcmp(bits[i], "comb") == 0) { + if ( err != NULL ) *err = 1; + } else if ( strcmp(bits[i], "axes") == 0) { + if ( err != NULL ) *err = 1; + } else { ERROR("Bad list of indexing methods: '%s'\n", str); return INDEXING_ERROR; @@ -960,3 +988,48 @@ IndexingMethod get_indm_from_string(const char *str) return method; } + + +IndexingMethod get_indm_from_string(const char *str) +{ + return get_indm_from_string_2(str, NULL); +} + + +static void do_probe(const char *(*func)(UnitCell *cell), + UnitCell *cell, char *methods) +{ + const char *probe; + probe = func(cell); + if ( probe != NULL ) { + if ( methods[0] != '\0' ) { + strcat(methods, ","); + } + strcat(methods, probe); + } +} + + +char *detect_indexing_methods(UnitCell *cell) +{ + char *methods; + + methods = malloc(1024); + if ( methods == NULL ) return NULL; + methods[0] = '\0'; + + do_probe(mosflm_probe, cell, methods); + do_probe(dirax_probe, cell, methods); + do_probe(asdf_probe, cell, methods); + do_probe(xds_probe, cell, methods); + do_probe(taketwo_probe, cell, methods); + /* Don't automatically use Felix (yet) */ + //do_probe(felix_probe, cell, methods); + + if ( strlen(methods) == 0 ) { + free(methods); + return NULL; + } + + return methods; +} diff --git a/libcrystfel/src/index.h b/libcrystfel/src/index.h index 15843b2a..8ece9227 100644 --- a/libcrystfel/src/index.h +++ b/libcrystfel/src/index.h @@ -130,6 +130,7 @@ typedef struct _indexingprivate IndexingPrivate; /* Convert indexing methods to/from text */ extern char *indexer_str(IndexingMethod indm); extern IndexingMethod get_indm_from_string(const char *method); +extern IndexingMethod get_indm_from_string_2(const char *method, int *err); #include "detector.h" #include "cell.h" @@ -144,6 +145,8 @@ extern IndexingPrivate *setup_indexing(const char *methods, UnitCell *cell, struct taketwo_options *ttopts, struct felix_options *felix_opts); +extern char *detect_indexing_methods(UnitCell *cell); + extern void index_pattern(struct image *image, IndexingPrivate *ipriv); extern void index_pattern_2(struct image *image, IndexingPrivate *ipriv, diff --git a/libcrystfel/src/mosflm.c b/libcrystfel/src/mosflm.c index 4cf21103..7ebf6e19 100644 --- a/libcrystfel/src/mosflm.c +++ b/libcrystfel/src/mosflm.c @@ -821,6 +821,12 @@ void *mosflm_prepare(IndexingMethod *indm, UnitCell *cell) { struct mosflm_private *mp; + if ( mosflm_probe(cell) == NULL ) { + ERROR("Mosflm does not appear to run properly.\n"); + ERROR("Please check your Mosflm installation.\n"); + return NULL; + } + /* Flags that MOSFLM knows about */ *indm &= INDEXING_METHOD_MASK | INDEXING_USE_LATTICE_TYPE | INDEXING_USE_CELL_PARAMETERS; @@ -841,3 +847,75 @@ void mosflm_cleanup(void *pp) p = (struct mosflm_private *)pp; free(p); } + + +static void chop_word(char *s) +{ + int i; + size_t l = strlen(s); + for ( i=0; i<l; i++ ) { + if ( s[i] == ' ' ) { + s[i] = '\0'; + return; + } + } +} + + +const char *mosflm_probe(UnitCell *cell) +{ + pid_t pid; + int pty; + int status; + FILE *fh; + char line[1024]; + int ok = 0; + int l; + + pid = forkpty(&pty, NULL, NULL, NULL); + if ( pid == -1 ) { + return NULL; + } + if ( pid == 0 ) { + + /* Child process */ + struct termios t; + + /* Turn echo off */ + tcgetattr(STDIN_FILENO, &t); + t.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL); + tcsetattr(STDIN_FILENO, TCSANOW, &t); + + execlp("mosflm", "mosflm", (char *)NULL); + execlp("ipmosflm", "ipmosflm", (char *)NULL); + _exit(1); + + } + + fh = fdopen(pty, "r"); + + for ( l=0; l<10; l++ ) { + char *pos; + if ( fgets(line, 1024, fh) == NULL ) { + ERROR("Failed to probe for Mosflm\n"); + } else { + pos = strstr(line, "Mosflm version "); + if ( pos != NULL ) { + char *vers = pos+15; + ok = 1; + chop_word(vers); + /* FIXME: Set capabilities based on version */ + } + } + } + + fclose(fh); + close(pty); + waitpid(pid, &status, 0); + + if ( !ok ) return NULL; + + if ( cell_has_parameters(cell) ) return "mosflm-cell-nolatt,mosflm-latt-nocell"; + if ( cell != NULL ) return "mosflm-latt-nocell"; + return "mosflm-nolatt-nocell"; +} diff --git a/libcrystfel/src/mosflm.h b/libcrystfel/src/mosflm.h index cd7804a8..9339b856 100644 --- a/libcrystfel/src/mosflm.h +++ b/libcrystfel/src/mosflm.h @@ -44,6 +44,7 @@ extern "C" { extern int run_mosflm(struct image *image, void *ipriv); extern void *mosflm_prepare(IndexingMethod *indm, UnitCell *cell); +extern const char *mosflm_probe(UnitCell *cell); extern void mosflm_cleanup(void *pp); diff --git a/libcrystfel/src/reflist-utils.c b/libcrystfel/src/reflist-utils.c index 1aee6018..7ff78f52 100644 --- a/libcrystfel/src/reflist-utils.c +++ b/libcrystfel/src/reflist-utils.c @@ -3,11 +3,11 @@ * * Utilities to complement the core reflist.c * - * Copyright © 2012-2016 Deutsches Elektronen-Synchrotron DESY, + * Copyright © 2012-2017 Deutsches Elektronen-Synchrotron DESY, * a research centre of the Helmholtz Association. * * Authors: - * 2011-2016 Thomas White <taw@physics.org> + * 2011-2017 Thomas White <taw@physics.org> * 2014 Valerio Mariani * * This file is part of CrystFEL. @@ -283,15 +283,13 @@ int write_reflist(const char *filename, RefList *list) #define HEADER_2_0 "CrystFEL reflection list version 2.0" -/** - * read_reflections_from_file: - * @fh: File handle to read from - * - * This function reads a reflection list from @fh. +/* fh: File handle to read from + * sym: Location at which to store pointer to symmetry, or NULL if you don't + * need it * * Returns: a %RefList read from the file, or NULL on error - **/ -RefList *read_reflections_from_file(FILE *fh) + */ +static RefList *read_reflections_from_file(FILE *fh, char **sym) { char *rval = NULL; RefList *out; @@ -317,7 +315,9 @@ RefList *read_reflections_from_file(FILE *fh) chomp(line); if ( strncmp(line, "Symmetry: ", 10) != 0 ) return NULL; - /* FIXME: Do something with the symmetry */ + if ( sym != NULL ) { + *sym = strdup(line+10); + } /* Read (and ignore) the header */ rval = fgets(line, 1023, fh); @@ -418,7 +418,17 @@ RefList *read_reflections_from_file(FILE *fh) } -RefList *read_reflections(const char *filename) +/** + * read_reflections_2: + * @filename: Filename to read from + * @sym: Pointer to a "char *" at which to store the symmetry + * + * This function reads a reflection list from a file, including the + * symmetry from the header (e.g. "Symmetry: 4/mmm"). + * + * Returns: A %RefList read from the file, or NULL on error + */ +RefList *read_reflections_2(const char *filename, char **sym) { FILE *fh; RefList *out; @@ -434,7 +444,7 @@ RefList *read_reflections(const char *filename) return NULL; } - out = read_reflections_from_file(fh); + out = read_reflections_from_file(fh, sym); fclose(fh); @@ -443,6 +453,20 @@ RefList *read_reflections(const char *filename) /** + * read_reflections: + * @filename: Filename to read from + * + * This function reads a reflection list from a file. + * + * Returns: A %RefList read from the file, or NULL on error + */ +RefList *read_reflections(const char *filename) +{ + return read_reflections_2(filename, NULL); +} + + +/** * asymmetric_indices: * @in: A %RefList * @sym: A %SymOpList diff --git a/libcrystfel/src/reflist-utils.h b/libcrystfel/src/reflist-utils.h index 50838b86..f64e9f51 100644 --- a/libcrystfel/src/reflist-utils.h +++ b/libcrystfel/src/reflist-utils.h @@ -3,11 +3,11 @@ * * Utilities to complement the core reflist.c * - * Copyright © 2012-2016 Deutsches Elektronen-Synchrotron DESY, + * Copyright © 2012-2017 Deutsches Elektronen-Synchrotron DESY, * a research centre of the Helmholtz Association. * * Authors: - * 2011-2016 Thomas White <taw@physics.org> + * 2011-2017 Thomas White <taw@physics.org> * 2014 Valerio Mariani * * This file is part of CrystFEL. @@ -49,8 +49,8 @@ extern "C" { extern int write_reflist(const char *filename, RefList *list); extern int write_reflist_2(const char *filename, RefList *list, SymOpList *sym); -extern RefList *read_reflections_from_file(FILE *fh); extern RefList *read_reflections(const char *filename); +extern RefList *read_reflections_2(const char *filename, char **sym); extern int check_list_symmetry(RefList *list, const SymOpList *sym); extern int find_equiv_in_list(RefList *list, signed int h, signed int k, diff --git a/libcrystfel/src/stream.c b/libcrystfel/src/stream.c index fb4b0c70..d7d997cf 100644 --- a/libcrystfel/src/stream.c +++ b/libcrystfel/src/stream.c @@ -67,8 +67,18 @@ struct _stream int minor_version; long long int ln; + + int old_indexers; /* True if the stream reader encountered a deprecated + * indexing method */ }; + +int stream_has_old_indexers(Stream *st) +{ + return st->old_indexers; +} + + static int read_peaks(Stream *st, struct image *image) { char *rval = NULL; @@ -1196,10 +1206,14 @@ int read_chunk_2(Stream *st, struct image *image, StreamReadFlags srf) } if ( strncmp(line, "indexed_by = ", 13) == 0 ) { - image->indexed_by = get_indm_from_string(line+13); + int err = 0; + image->indexed_by = get_indm_from_string_2(line+13, &err); if ( image->indexed_by == INDEXING_ERROR ) { ERROR("Failed to read indexer list\n"); } + if ( err ) { + st->old_indexers = 1; + } } if ( strncmp(line, "photon_energy_eV = ", 19) == 0 ) { @@ -1327,6 +1341,7 @@ Stream *open_stream_for_read(const char *filename) st = malloc(sizeof(struct _stream)); if ( st == NULL ) return NULL; + st->old_indexers = 0; if ( strcmp(filename, "-") == 0 ) { st->fh = stdin; @@ -1393,6 +1408,7 @@ Stream *open_stream_fd_for_write(int fd) st = malloc(sizeof(struct _stream)); if ( st == NULL ) return NULL; + st->old_indexers = 0; st->fh = fdopen(fd, "w"); if ( st->fh == NULL ) { @@ -1442,6 +1458,7 @@ Stream *open_stream_for_write_3(const char *filename, st = malloc(sizeof(struct _stream)); if ( st == NULL ) return NULL; + st->old_indexers = 0; st->fh = fopen(filename, "w"); if ( st->fh == NULL ) { @@ -1493,6 +1510,7 @@ Stream *open_stream_for_write_2(const char *filename, st = malloc(sizeof(struct _stream)); if ( st == NULL ) return NULL; + st->old_indexers = 0; st->fh = fopen(filename, "w"); if ( st->fh == NULL ) { diff --git a/libcrystfel/src/stream.h b/libcrystfel/src/stream.h index 764e3e36..2ed7b050 100644 --- a/libcrystfel/src/stream.h +++ b/libcrystfel/src/stream.h @@ -106,6 +106,7 @@ extern void close_stream(Stream *st); extern int read_chunk(Stream *st, struct image *image); extern int read_chunk_2(Stream *st, struct image *image, StreamReadFlags srf); +extern int stream_has_old_indexers(Stream *st); extern int write_chunk(Stream *st, struct image *image, struct imagefile *imfile, int include_peaks, int include_reflections, diff --git a/libcrystfel/src/taketwo.c b/libcrystfel/src/taketwo.c index 757c6c52..0857f813 100644 --- a/libcrystfel/src/taketwo.c +++ b/libcrystfel/src/taketwo.c @@ -1642,3 +1642,9 @@ void taketwo_cleanup(IndexingPrivate *pp) free(tp); } + +const char *taketwo_probe(UnitCell *cell) +{ + if ( cell_has_parameters(cell) ) return "taketwo"; + return NULL; +} diff --git a/libcrystfel/src/taketwo.h b/libcrystfel/src/taketwo.h index e82dda68..fcd7aebc 100644 --- a/libcrystfel/src/taketwo.h +++ b/libcrystfel/src/taketwo.h @@ -44,6 +44,7 @@ struct taketwo_options extern void *taketwo_prepare(IndexingMethod *indm, UnitCell *cell); +extern const char *taketwo_probe(UnitCell *cell); extern int taketwo_index(struct image *image, const struct taketwo_options *opts, void *priv); extern void taketwo_cleanup(IndexingPrivate *pp); diff --git a/libcrystfel/src/xds.c b/libcrystfel/src/xds.c index ba053d2f..bfb977ea 100644 --- a/libcrystfel/src/xds.c +++ b/libcrystfel/src/xds.c @@ -45,6 +45,7 @@ #include <sys/ioctl.h> #include <errno.h> +#include "xds.h" #include "cell.h" #include "image.h" #include "utils.h" @@ -596,6 +597,12 @@ void *xds_prepare(IndexingMethod *indm, UnitCell *cell) { struct xds_private *xp; + if ( xds_probe(cell) == NULL ) { + ERROR("XDS does not appear to run properly.\n"); + ERROR("Please check your XDS installation.\n"); + return NULL; + } + /* Either cell,latt and cell provided, or nocell-nolatt and no cell * - complain about anything else. Could figure this out automatically, * but we'd have to decide whether the user just forgot the cell, or @@ -637,3 +644,57 @@ void xds_cleanup(void *pp) xp = (struct xds_private *)pp; free(xp); } + + +const char *xds_probe(UnitCell *cell) +{ + pid_t pid; + int pty; + int status; + FILE *fh; + char line[1024]; + int ok = 0; + int l; + + pid = forkpty(&pty, NULL, NULL, NULL); + if ( pid == -1 ) { + return NULL; + } + if ( pid == 0 ) { + + /* Child process */ + struct termios t; + + /* Turn echo off */ + tcgetattr(STDIN_FILENO, &t); + t.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL); + tcsetattr(STDIN_FILENO, TCSANOW, &t); + + execlp("xds", "xds", (char *)NULL); + _exit(1); + + } + + fh = fdopen(pty, "r"); + + for ( l=0; l<10; l++ ) { + char *pos; + if ( fgets(line, 1024, fh) == NULL ) { + ERROR("Failed to probe for XDS\n"); + } else { + pos = strstr(line, "** XDS **"); + if ( pos != NULL ) { + ok = 1; + } + } + } + + fclose(fh); + close(pty); + waitpid(pid, &status, 0); + + if ( !ok ) return NULL; + + if ( cell_has_parameters(cell) ) return "xds-cell-latt"; + return "xds-nocell-nolatt"; +} diff --git a/libcrystfel/src/xds.h b/libcrystfel/src/xds.h index 8777df10..c89b615c 100644 --- a/libcrystfel/src/xds.h +++ b/libcrystfel/src/xds.h @@ -46,6 +46,8 @@ extern int run_xds(struct image *image, void *ipriv); extern void *xds_prepare(IndexingMethod *indm, UnitCell *cell); +extern const char *xds_probe(UnitCell *cell); + extern void xds_cleanup(void *pp); #ifdef __cplusplus diff --git a/scripts/move-entire-detector b/scripts/move-entire-detector index 3d06c408..ffd6120f 100755 --- a/scripts/move-entire-detector +++ b/scripts/move-entire-detector @@ -46,7 +46,7 @@ args = op.parse_args() if not args.ofn: out = os.path.splitext(args.ifn)[0]+'-shifted.geom' else: - out = opt.ofn + out = args.ofn if args.px: units = 'px' diff --git a/scripts/peakogram-stream b/scripts/peakogram-stream index 1f67b39c..a17670ce 100755 --- a/scripts/peakogram-stream +++ b/scripts/peakogram-stream @@ -47,8 +47,8 @@ def resolution(scell, shkl): c = float(scell[2])*10.0 # nm -> Angstroms al = m.radians(float(scell[3])) - be = m.radians(float(scell[3])) - ga = m.radians(float(scell[3])) # in degrees + be = m.radians(float(scell[4])) + ga = m.radians(float(scell[5])) # in degrees h = int(shkl[0]) k = int(shkl[1]) @@ -102,7 +102,11 @@ with open(args.i) as f: # Add reflection to list columns = line.split() n += 1 - data.append([resolution(cell, columns[0:3]),columns[5]]) + try: + data.append([resolution(cell, columns[0:3]),columns[5]]) + except: + print("Error with line: "+line.rstrip("\r\n")) + print("Cell: "+str(cell)) if n%1000==0: sys.stdout.write("\r%i peaks found" % n) @@ -137,7 +141,7 @@ if args.imin is not None: if args.imax is not None: ymax = args.imax -keepers = np.where((x>xmin) & (x<xmax) & (y>ymin) & (y<ymax)) +keepers = np.where((x>=xmin) & (x<=xmax) & (y>=ymin) & (y<=ymax)) x = x[keepers] y = y[keepers] diff --git a/scripts/sum-peaks b/scripts/sum-peaks index eccb9fc6..5b528661 100755 --- a/scripts/sum-peaks +++ b/scripts/sum-peaks @@ -7,41 +7,46 @@ # a research centre of the Helmholtz Association. # # Author: -# 2017 Thomas White <taw@physics.org> +# 2017 Alexandra Tolstikova <alexandra.tolstikova@desy.de> # +import sys import numpy as np import h5py -import sys -import re - -f = open(sys.argv[1], 'r') -powder = np.zeros((512,1024), dtype=float) -peaks = [] - -prog1 = re.compile("^\s*([\d\-\.]+)\s+([\d\-\.]+)\s+[\d\-\.]+\s+([\d\-\.]+)\s+\S+$") - -while True: - - fline = f.readline() - if not fline: - break - - if fline == '----- End chunk -----\n': - if len(peaks) > 10: - for p in peaks: - powder[p[1],p[0]] += p[2] - peaks = [] - - match = prog1.match(fline) - if match: - fs = int(float(match.group(1))) - ss = int(float(match.group(2))) - intensity = float(match.group(3)) - peaks.append((fs,ss,intensity)) - +from os.path import basename, splitext + +with open(sys.argv[1], 'r') as stream: + reading_geometry = False + reading_chunks = False + reading_peaks = False + max_fs = -100500 + max_ss = -100500 + for line in stream: + if reading_chunks: + if line.startswith('End of peak list'): + reading_peaks = False + elif line.startswith(' fs/px ss/px (1/d)/nm^-1 Intensity Panel'): + reading_peaks = True + elif reading_peaks: + fs, ss, dump, intensity = [float(i) for i in line.split()[:4]] + powder[int(ss), int(fs)] += intensity + elif line.startswith('----- End geometry file -----'): + reading_geometry = False + powder = np.zeros((max_ss + 1, max_fs + 1)) + elif reading_geometry: + try: + par, val = line.split('=') + if par.split('/')[-1].strip() == 'max_fs' and int(val) > max_fs: + max_fs = int(val) + elif par.split('/')[-1].strip() == 'max_ss' and int(val) > max_ss: + max_ss = int(val) + except ValueError: + pass + elif line.startswith('----- Begin geometry file -----'): + reading_geometry = True + elif line.startswith('----- Begin chunk -----'): + reading_chunks = True + +f = h5py.File(splitext(basename(sys.argv[1]))[0]+'-powder.h5', 'w') +f.create_dataset('/data/data', data=powder) f.close() - -fh = h5py.File("summed-peaks.h5", "w") -fh.create_dataset("/data", (512,1024), data=powder) -fh.close() diff --git a/src/ambigator.c b/src/ambigator.c index f7837721..3df66f3b 100644 --- a/src/ambigator.c +++ b/src/ambigator.c @@ -1254,8 +1254,11 @@ int main(int argc, char *argv[]) return 1; } - fread(&seed, sizeof(seed), 1, fh); - gsl_rng_set(rng, seed); + if ( fread(&seed, sizeof(seed), 1, fh) == 1 ) { + gsl_rng_set(rng, seed); + } else { + ERROR("Failed to seed RNG\n"); + } fclose(fh); } diff --git a/src/cell_explorer.c b/src/cell_explorer.c index a8a8a7dc..f3ec7cb7 100644 --- a/src/cell_explorer.c +++ b/src/cell_explorer.c @@ -1638,6 +1638,17 @@ int main(int argc, char *argv[]) fprintf(stderr, "\n"); + if ( stream_has_old_indexers(st) ) { + ERROR("----- Notice -----\n"); + ERROR("This stream contains indexing methods specified in an old way.\n"); + ERROR("The full indexing method names will not be shown by cell_explorer, \n"); + ERROR("only the methods themselves and prior information modifiers "); + ERROR("('cell' or 'latt').\n"); + ERROR("Similar indexing methods will be combined. For example\n"); + ERROR("'mosflm-raw' and 'mosflm-axes' will both show up as 'mosflm'\n"); + ERROR("To simplify matters, it's best to re-run indexamajig.\n"); + ERROR("------------------\n"); + } close_stream(st); w.cols_on[0] = 1; diff --git a/src/check_hkl.c b/src/check_hkl.c index c7afb6cc..3c71d4cc 100644 --- a/src/check_hkl.c +++ b/src/check_hkl.c @@ -3,11 +3,11 @@ * * Characterise reflection lists * - * Copyright © 2012-2016 Deutsches Elektronen-Synchrotron DESY, + * Copyright © 2012-2017 Deutsches Elektronen-Synchrotron DESY, * a research centre of the Helmholtz Association. * * Authors: - * 2010-2016 Thomas White <taw@physics.org> + * 2010-2017 Thomas White <taw@physics.org> * * This file is part of CrystFEL. * @@ -690,6 +690,7 @@ int main(int argc, char *argv[]) UnitCell *cell; char *file = NULL; char *sym_str = NULL; + char *sym_str_fromfile = NULL; SymOpList *sym; RefList *raw_list; RefList *list; @@ -838,12 +839,6 @@ int main(int argc, char *argv[]) "set!\n"); } - if ( sym_str == NULL ) { - sym_str = strdup("1"); - } - sym = get_pointgroup(sym_str); - free(sym_str); - file = strdup(argv[optind++]); if ( cellfile == NULL ) { @@ -857,13 +852,25 @@ int main(int argc, char *argv[]) } free(cellfile); - raw_list = read_reflections(file); + raw_list = read_reflections_2(file, &sym_str_fromfile); if ( raw_list == NULL ) { ERROR("Couldn't read file '%s'\n", file); return 1; } free(file); + if ( sym_str == NULL ) { + if ( sym_str_fromfile != NULL ) { + STATUS("Using symmetry from reflection file: %s\n", + sym_str_fromfile); + sym_str = sym_str_fromfile; + } else { + sym_str = strdup("1"); + } + } + sym = get_pointgroup(sym_str); + free(sym_str); + if ( shell_file == NULL ) shell_file = strdup("shells.dat"); /* Check that the intensities have the correct symmetry */ diff --git a/src/compare_hkl.c b/src/compare_hkl.c index 81f12c94..fd988b89 100644 --- a/src/compare_hkl.c +++ b/src/compare_hkl.c @@ -3,11 +3,11 @@ * * Compare reflection lists * - * Copyright © 2012-2016 Deutsches Elektronen-Synchrotron DESY, + * Copyright © 2012-2017 Deutsches Elektronen-Synchrotron DESY, * a research centre of the Helmholtz Association. * * Authors: - * 2010-2016 Thomas White <taw@physics.org> + * 2010-2017 Thomas White <taw@physics.org> * 2013 Lorenzo Galli <lorenzo.galli@desy.de> * * This file is part of CrystFEL. @@ -1124,6 +1124,9 @@ int main(int argc, char *argv[]) char *afile = NULL; char *bfile = NULL; char *sym_str = NULL; + char *sym_str_fromfile = NULL; + char *sym_str_fromfile1 = NULL; + char *sym_str_fromfile2 = NULL; SymOpList *sym; int ncom, nrej, nmul, nneg, nres, nbij, ncen; RefList *list1_acc; @@ -1320,8 +1323,53 @@ int main(int argc, char *argv[]) "set!\n"); } + afile = strdup(argv[optind++]); + bfile = strdup(argv[optind]); + + if ( shell_file == NULL ) shell_file = strdup("shells.dat"); + + cell = load_cell_from_file(cellfile); + if ( cellfile == NULL ) { + ERROR("You must provide a unit cell.\n"); + exit(1); + } + if ( cell == NULL ) { + ERROR("Failed to load cell.\n"); + return 1; + } + free(cellfile); + + list1_raw = read_reflections_2(afile, &sym_str_fromfile1); + if ( list1_raw == NULL ) { + ERROR("Couldn't read file '%s'\n", afile); + return 1; + } + + list2_raw = read_reflections_2(bfile, &sym_str_fromfile2); + if ( list2_raw == NULL ) { + ERROR("Couldn't read file '%s'\n", bfile); + return 1; + } + + if ( (sym_str_fromfile1 != NULL) && (sym_str_fromfile2 != NULL) ) { + if ( strcmp(sym_str_fromfile1, sym_str_fromfile2) != 0 ) { + ERROR("The symmetries of the two list do not match:\n"); + ERROR(" %s: %s\n", afile, sym_str_fromfile1); + ERROR(" %s: %s\n", bfile, sym_str_fromfile2); + return 1; + } + sym_str_fromfile = sym_str_fromfile1; + free(sym_str_fromfile2); + } + if ( sym_str == NULL ) { - sym_str = strdup("1"); + if ( sym_str_fromfile != NULL ) { + STATUS("Using symmetry from reflection files: %s\n", + sym_str_fromfile); + sym_str = sym_str_fromfile; + } else { + sym_str = strdup("1"); + } } sym = get_pointgroup(sym_str); free(sym_str); @@ -1354,33 +1402,6 @@ int main(int argc, char *argv[]) } } - afile = strdup(argv[optind++]); - bfile = strdup(argv[optind]); - - if ( shell_file == NULL ) shell_file = strdup("shells.dat"); - - cell = load_cell_from_file(cellfile); - if ( cellfile == NULL ) { - ERROR("You must provide a unit cell.\n"); - exit(1); - } - if ( cell == NULL ) { - ERROR("Failed to load cell.\n"); - return 1; - } - free(cellfile); - - list1_raw = read_reflections(afile); - if ( list1_raw == NULL ) { - ERROR("Couldn't read file '%s'\n", afile); - return 1; - } - - list2_raw = read_reflections(bfile); - if ( list2_raw == NULL ) { - ERROR("Couldn't read file '%s'\n", bfile); - return 1; - } /* Check that the intensities have the correct symmetry */ if ( check_list_symmetry(list1_raw, sym) ) { diff --git a/src/get_hkl.c b/src/get_hkl.c index 77f34da2..5dddc5be 100644 --- a/src/get_hkl.c +++ b/src/get_hkl.c @@ -3,11 +3,11 @@ * * Small program to manipulate reflection lists * - * Copyright © 2013-2016 Deutsches Elektronen-Synchrotron DESY, + * Copyright © 2013-2017 Deutsches Elektronen-Synchrotron DESY, * a research centre of the Helmholtz Association. * * Authors: - * 2009-2016 Thomas White <taw@physics.org> + * 2009-2017 Thomas White <taw@physics.org> * * This file is part of CrystFEL. * @@ -415,6 +415,7 @@ int main(int argc, char *argv[]) int config_nap = 1; char *holo_str = NULL; char *mero_str = NULL; + char *sym_str_fromfile = NULL; char *expand_str = NULL; SymOpList *holo = NULL; SymOpList *mero = NULL; @@ -569,13 +570,6 @@ int main(int argc, char *argv[]) } else { holo = NULL; } - if ( mero_str != NULL ) { - pointgroup_warning(mero_str); - mero = get_pointgroup(mero_str); - free(mero_str); - } else { - mero = NULL; - } if ( expand_str != NULL ) { pointgroup_warning(expand_str); expand = get_pointgroup(expand_str); @@ -590,6 +584,30 @@ int main(int argc, char *argv[]) set_symmetry_name(reindex, "Reindex"); } + input = read_reflections_2(input_file, &sym_str_fromfile); + if ( input == NULL ) { + ERROR("Problem reading input file %s\n", input_file); + return 1; + } + free(input_file); + + if ( mero_str == NULL ) { + if ( sym_str_fromfile != NULL ) { + STATUS("Using symmetry from reflection file: %s\n", + sym_str_fromfile); + mero_str = sym_str_fromfile; + } else { + mero_str = strdup("1"); + } + } + if ( mero_str != NULL ) { + pointgroup_warning(mero_str); + mero = get_pointgroup(mero_str); + free(mero_str); + } else { + mero = NULL; + } + if ( (expand != NULL) || (holo != NULL) || config_trimc || config_multi ) { if ( mero == NULL ) { @@ -597,13 +615,6 @@ int main(int argc, char *argv[]) } } - input = read_reflections(input_file); - if ( input == NULL ) { - ERROR("Problem reading input file %s\n", input_file); - return 1; - } - free(input_file); - STATUS("%i reflections in input.\n", num_reflections(input)); if ( (mero != NULL) && !config_trimc diff --git a/src/indexamajig.c b/src/indexamajig.c index 88b61563..04022441 100644 --- a/src/indexamajig.c +++ b/src/indexamajig.c @@ -924,17 +924,25 @@ int main(int argc, char *argv[]) } free(outfile); + if ( indm_str == NULL ) { + + STATUS("No indexing methods specified. I will try to "); + STATUS("automatically detect the available methods.\n"); + STATUS("To disable auto-detection of indexing methods, specify "); + STATUS("which methods to use with --indexing=<methods>.\n"); + STATUS("Use --indexing=none to disable indexing and integration.\n"); + indm_str = detect_indexing_methods(iargs.cell); + + } + /* Prepare the indexing system */ if ( indm_str == NULL ) { - STATUS("You didn't specify an indexing method, so I won't try " - " to index anything.\n" - "If that isn't what you wanted, re-run with" - " --indexing=<methods>.\n"); - if ( iargs.cell != NULL ) { - STATUS("Ignoring your unit cell.\n"); - } - iargs.ipriv = NULL; + ERROR("No indexing method specified, and no usable indexing "); + ERROR("methods auto-detected.\n"); + ERROR("Install some indexing programs (mosflm,dirax etc), or "); + ERROR("try again with --indexing=none.\n"); + return 1; } else if ( strcmp(indm_str, "none") == 0 ) { diff --git a/src/partial_sim.c b/src/partial_sim.c index c5084955..2f0a0277 100644 --- a/src/partial_sim.c +++ b/src/partial_sim.c @@ -3,11 +3,11 @@ * * Generate partials for testing scaling * - * Copyright © 2012-2016 Deutsches Elektronen-Synchrotron DESY, + * Copyright © 2012-2017 Deutsches Elektronen-Synchrotron DESY, * a research centre of the Helmholtz Association. * * Authors: - * 2011-2016 Thomas White <taw@physics.org> + * 2011-2017 Thomas White <taw@physics.org> * 2014 Valerio Mariani * * This file is part of CrystFEL. @@ -763,23 +763,35 @@ int main(int argc, char *argv[]) } fixup_geom(det); - if ( sym_str == NULL ) sym_str = strdup("1"); - sym = get_pointgroup(sym_str); - free(sym_str); - if ( save_file == NULL ) save_file = strdup("partial_sim.hkl"); /* Load (full) reflections */ if ( input_file != NULL ) { RefList *as; + char *sym_str_fromfile = NULL; - full = read_reflections(input_file); + full = read_reflections_2(input_file, &sym_str_fromfile); if ( full == NULL ) { ERROR("Failed to read reflections from '%s'\n", input_file); return 1; } + + /* If we don't have a point group yet, and if the file provides + * one, use the one from the file */ + if ( (sym_str == NULL) && (sym_str_fromfile != NULL) ) { + sym_str = sym_str_fromfile; + STATUS("Using symmetry from reflection file: %s\n", + sym_str); + } + + /* If we still don't have a point group, use "1" */ + if ( sym_str == NULL ) sym_str = strdup("1"); + + pointgroup_warning(sym_str); + sym = get_pointgroup(sym_str); + if ( check_list_symmetry(full, sym) ) { ERROR("The input reflection list does not appear to" " have symmetry %s\n", symmetry_name(sym)); @@ -798,6 +810,8 @@ int main(int argc, char *argv[]) } else { random_intensities = 1; + if ( sym_str == NULL ) sym_str = strdup("1"); + sym = get_pointgroup(sym_str); } if ( n < 1 ) { @@ -852,10 +866,11 @@ int main(int argc, char *argv[]) noise_stddev); if ( random_intensities ) { STATUS(" Full intensities: randomly generated: " - "abs(Gaussian(sigma=%.2f))\n", full_stddev); + "abs(Gaussian(sigma=%.2f)), symmetry %s\n", + full_stddev, sym_str); } else { - STATUS(" Full intensities: from %s\n", - input_file); + STATUS(" Full intensities: from %s (symmetry %s)\n", + input_file, sym_str); } STATUS(" Max error in cell components: %.2f %%\n", cnoise); @@ -902,10 +917,13 @@ int main(int argc, char *argv[]) for ( i=0; i<n_threads; i++ ) { unsigned long int seed; - - fread(&seed, sizeof(seed), 1, fh); qargs.rngs[i] = gsl_rng_alloc(gsl_rng_mt19937); - gsl_rng_set(qargs.rngs[i], seed); + + if ( fread(&seed, sizeof(seed), 1, fh) == 1 ) { + gsl_rng_set(qargs.rngs[i], seed); + } else { + ERROR("Failed to seed RNG %i\n", i); + } } @@ -931,7 +949,7 @@ int main(int argc, char *argv[]) if ( random_intensities ) { STATUS("Writing full intensities to %s\n", save_file); - write_reflist(save_file, full); + write_reflist_2(save_file, full, sym); } if ( phist_file != NULL ) { diff --git a/src/partialator.c b/src/partialator.c index 569145e8..142ca892 100644 --- a/src/partialator.c +++ b/src/partialator.c @@ -1018,7 +1018,10 @@ int main(int argc, char *argv[]) ERROR("Failed to open '%s'\n", sparams_fn); return 1; } - fgets(line, 1024, sparams_fh); + if ( fgets(line, 1024, sparams_fh) == NULL ) { + ERROR("Failed to read header from %s\n", sparams_fn); + return 1; + } STATUS("Reading initial scaling factors (G,B) from '%s'\n", sparams_fn); free(sparams_fn); diff --git a/src/pattern_sim.c b/src/pattern_sim.c index 347dd618..a3fea8e3 100644 --- a/src/pattern_sim.c +++ b/src/pattern_sim.c @@ -633,11 +633,6 @@ int main(int argc, char *argv[]) free(template_file); } - if ( sym_str == NULL ) sym_str = strdup("1"); - pointgroup_warning(sym_str); - sym = get_pointgroup(sym_str); - /* sym_str is used below */ - if ( grad_str == NULL ) { STATUS("You didn't specify a gradient calculation method, so" " I'm using the 'mosaic' method, which is fastest.\n"); @@ -720,16 +715,35 @@ int main(int argc, char *argv[]) phases = NULL; flags = NULL; + if ( sym_str == NULL ) sym_str = strdup("1"); + pointgroup_warning(sym_str); + sym = get_pointgroup(sym_str); + } else { RefList *reflections; + char *sym_str_fromfile = NULL; - reflections = read_reflections(intfile); + reflections = read_reflections_2(intfile, &sym_str_fromfile); if ( reflections == NULL ) { ERROR("Problem reading input file %s\n", intfile); return 1; } + /* If we don't have a point group yet, and if the file provides + * one, use the one from the file */ + if ( (sym_str == NULL) && (sym_str_fromfile != NULL) ) { + sym_str = sym_str_fromfile; + STATUS("Using symmetry from reflection file: %s\n", + sym_str); + } + + /* If we still don't have a point group, use "1" */ + if ( sym_str == NULL ) sym_str = strdup("1"); + + pointgroup_warning(sym_str); + sym = get_pointgroup(sym_str); + if ( grad == GRADIENT_PHASED ) { phases = phases_from_list(reflections); } else { @@ -785,9 +799,12 @@ int main(int argc, char *argv[]) FILE *fh; unsigned long int seed; fh = fopen("/dev/urandom", "r"); - fread(&seed, sizeof(seed), 1, fh); + if ( fread(&seed, sizeof(seed), 1, fh) == 1 ) { + gsl_rng_set(rng, seed); + } else { + ERROR("Failed to seed random number generator\n"); + } fclose(fh); - gsl_rng_set(rng, seed); } powder.det = image.det; @@ -848,7 +865,8 @@ int main(int argc, char *argv[]) if ( intfile == NULL ) { STATUS(" Full intensities: all equal\n"); } else { - STATUS(" Full intensities: from %s\n", intfile); + STATUS(" Full intensities: from %s (symmetry %s)\n", + intfile, sym_str); } do { diff --git a/src/render_hkl.c b/src/render_hkl.c index 3996814a..3952940e 100644 --- a/src/render_hkl.c +++ b/src/render_hkl.c @@ -3,11 +3,11 @@ * * Draw pretty renderings of reflection lists * - * Copyright © 2012-2015 Deutsches Elektronen-Synchrotron DESY, + * Copyright © 2012-2017 Deutsches Elektronen-Synchrotron DESY, * a research centre of the Helmholtz Association. * * Authors: - * 2010-2015 Thomas White <taw@physics.org> + * 2010-2017 Thomas White <taw@physics.org> * * This file is part of CrystFEL. * @@ -757,6 +757,7 @@ int main(int argc, char *argv[]) int r = 0; double boost = 1.0; char *sym_str = NULL; + char *sym_str_fromfile = NULL; SymOpList *sym; char *weighting = NULL; int wght; @@ -916,13 +917,6 @@ int main(int argc, char *argv[]) return 1; } - if ( sym_str == NULL ) { - sym_str = strdup("1"); - } - pointgroup_warning(sym_str); - sym = get_pointgroup(sym_str); - free(sym_str); - if ( weighting == NULL ) { weighting = strdup("I"); } @@ -1003,11 +997,28 @@ int main(int argc, char *argv[]) ERROR("Couldn't load unit cell from %s\n", cellfile); return 1; } - list = read_reflections(infile); + + list = read_reflections_2(infile, &sym_str_fromfile); if ( list == NULL ) { ERROR("Couldn't read file '%s'\n", infile); return 1; } + + if ( sym_str == NULL ) { + if ( sym_str_fromfile != NULL ) { + STATUS("Using symmetry from reflection file: %s\n", + sym_str_fromfile); + sym_str = sym_str_fromfile; + } else { + sym_str = strdup("1"); + } + } + + pointgroup_warning(sym_str); + sym = get_pointgroup(sym_str); + if ( sym == NULL ) return 1; + free(sym_str); + if ( check_list_symmetry(list, sym) ) { ERROR("The input reflection list does not appear to" " have symmetry %s\n", symmetry_name(sym)); diff --git a/tests/integration_check.c b/tests/integration_check.c index 0713d837..65241612 100644 --- a/tests/integration_check.c +++ b/tests/integration_check.c @@ -65,9 +65,12 @@ int main(int argc, char *argv[]) rng = gsl_rng_alloc(gsl_rng_mt19937); fh = fopen("/dev/urandom", "r"); - fread(&seed, sizeof(seed), 1, fh); + if ( fread(&seed, sizeof(seed), 1, fh) == 1 ) { + gsl_rng_set(rng, seed); + } else { + ERROR("Failed to seed RNG\n"); + } fclose(fh); - gsl_rng_set(rng, seed); image.beam = NULL; image.lambda = ph_eV_to_lambda(9000.0); diff --git a/tests/prof2d_check.c b/tests/prof2d_check.c index 8081748c..9fe8b356 100644 --- a/tests/prof2d_check.c +++ b/tests/prof2d_check.c @@ -73,9 +73,12 @@ int main(int argc, char *argv[]) rng = gsl_rng_alloc(gsl_rng_mt19937); fh = fopen("/dev/urandom", "r"); - fread(&seed, sizeof(seed), 1, fh); + if ( fread(&seed, sizeof(seed), 1, fh) == 1 ) { + gsl_rng_set(rng, seed); + } else { + ERROR("Failed to seed RNG\n"); + } fclose(fh); - gsl_rng_set(rng, seed); image.beam = NULL; image.lambda = ph_eV_to_lambda(9000.0); diff --git a/tests/ring_check.c b/tests/ring_check.c index cc8a1c8e..0997447f 100644 --- a/tests/ring_check.c +++ b/tests/ring_check.c @@ -176,7 +176,11 @@ int main(int argc, char *argv[]) rng = gsl_rng_alloc(gsl_rng_mt19937); fh = fopen("/dev/urandom", "r"); - fread(&seed, sizeof(seed), 1, fh); + if ( fread(&seed, sizeof(seed), 1, fh) == 1 ) { + gsl_rng_set(rng, seed); + } else { + ERROR("Failed to seed RNG\n"); + } fclose(fh); gsl_rng_set(rng, seed); |