aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2015-11-27 13:05:33 +0100
committerThomas White <taw@physics.org>2015-11-27 13:18:29 +0100
commit6fc80febf119f9f3183c918f3137a396cbe06e40 (patch)
tree9b0aa1c9eb5ad43aba38d8513efe5d4daf6b61c2 /libcrystfel
parente81e335daf509166fc234c8835203a80d5b21e0d (diff)
indexamajig: Write target unit cell into stream
Diffstat (limited to 'libcrystfel')
-rw-r--r--libcrystfel/src/cell-utils.c32
-rw-r--r--libcrystfel/src/cell-utils.h1
-rw-r--r--libcrystfel/src/stream.c65
-rw-r--r--libcrystfel/src/stream.h6
4 files changed, 104 insertions, 0 deletions
diff --git a/libcrystfel/src/cell-utils.c b/libcrystfel/src/cell-utils.c
index 3b3c5fe3..69d4174a 100644
--- a/libcrystfel/src/cell-utils.c
+++ b/libcrystfel/src/cell-utils.c
@@ -1230,6 +1230,38 @@ static int get_angle_rad(char **bits, int nbits, double *pl)
return 0;
}
+/**
+ * write_cell:
+ * @cell: a %UnitCell
+ * @fh: a file handle
+ *
+ * Writes @cell to @fh, in CrystFEL unit cell file format
+ *
+ */
+void write_cell(UnitCell *cell, FILE *fh)
+{
+ double a, b, c, al, be, ga;
+ LatticeType lt;
+
+ fprintf(fh, "CrystFEL unit cell file version 1.0\n\n");
+ lt = cell_get_lattice_type(cell);
+ fprintf(fh, "lattice_type = %s\n", str_lattice(lt));
+ if ( (lt == L_MONOCLINIC)
+ || (lt == L_TETRAGONAL)
+ || (lt == L_HEXAGONAL) )
+ {
+ fprintf(fh, "unique_axis = %c\n", cell_get_unique_axis(cell));
+ }
+ fprintf(fh, "centering = %c\n", cell_get_centering(cell));
+ cell_get_parameters(cell, &a, &b, &c, &al, &be, &ga);
+ fprintf(fh, "a = %.2f A\n", a*1e10);
+ fprintf(fh, "b = %.2f A\n", b*1e10);
+ fprintf(fh, "c = %.2f A\n", c*1e10);
+ fprintf(fh, "al = %.2f deg\n", rad2deg(al));
+ fprintf(fh, "be = %.2f deg\n", rad2deg(be));
+ fprintf(fh, "ga = %.2f deg\n", rad2deg(ga));
+}
+
/**
* load_cell_from_file:
diff --git a/libcrystfel/src/cell-utils.h b/libcrystfel/src/cell-utils.h
index 98bc667c..000c863a 100644
--- a/libcrystfel/src/cell-utils.h
+++ b/libcrystfel/src/cell-utils.h
@@ -57,6 +57,7 @@ extern UnitCell *match_cell_ab(UnitCell *cell, UnitCell *tempcell);
extern UnitCell *load_cell_from_pdb(const char *filename);
extern UnitCell *load_cell_from_file(const char *filename);
+extern void write_cell(UnitCell *cell, FILE *fh);
extern int cell_is_sensible(UnitCell *cell);
diff --git a/libcrystfel/src/stream.c b/libcrystfel/src/stream.c
index c5ab6626..43fd273c 100644
--- a/libcrystfel/src/stream.c
+++ b/libcrystfel/src/stream.c
@@ -1390,6 +1390,71 @@ Stream *open_stream_fd_for_write(int fd)
}
+static void write_cell_to_stream(Stream *st, UnitCell *cell)
+{
+ fprintf(st->fh, CELL_START_MARKER"\n");
+ write_cell(cell, st->fh);
+ fprintf(st->fh, "; Please note: this is the target unit cell.\n");
+ fprintf(st->fh, "; The actual unit cells produced by indexing "
+ "depend on many other factors.\n");
+ fprintf(st->fh, CELL_END_MARKER"\n");
+ fflush(st->fh);
+}
+
+
+/**
+ * open_stream_for_write_3
+ * @filename: Filename of new stream
+ * @geom_filename: The geometry filename to copy
+ * @cell: A %UnitCell to write into the stream
+ * @argc: The number of arguments to the program
+ * @argv: The arguments to the program
+ *
+ * Creates a new stream with name @filename, and adds the stream format
+ * and version header, plus a verbatim copy of the geometry file and the unit
+ * cell in CrystFEL format.
+ *
+ * Returns: a %Stream, or NULL on failure.
+ */
+Stream *open_stream_for_write_3(const char *filename,
+ const char *geom_filename, UnitCell *cell,
+ int argc, char *argv[])
+
+{
+ Stream *st;
+
+ st = malloc(sizeof(struct _stream));
+ if ( st == NULL ) return NULL;
+
+ st->fh = fopen(filename, "w");
+ if ( st->fh == NULL ) {
+ ERROR("Failed to open stream.\n");
+ free(st);
+ return NULL;
+ }
+
+ st->major_version = LATEST_MAJOR_VERSION;
+ st->minor_version = LATEST_MINOR_VERSION;
+
+ fprintf(st->fh, "CrystFEL stream format %i.%i\n",
+ st->major_version, st->minor_version);
+ fprintf(st->fh, "Generated by CrystFEL "CRYSTFEL_VERSIONSTRING"\n");
+ fflush(st->fh);
+
+ if ( (argc > 0) && (argv != NULL) ) {
+ write_command(st, argc, argv);
+ }
+ if ( geom_filename != NULL ) {
+ write_geometry_file(st, geom_filename);
+ }
+ if ( cell != NULL ) {
+ write_cell_to_stream(st, cell);
+ }
+
+ return st;
+}
+
+
/**
* open_stream_for_write_2
* @filename: Filename of new stream
diff --git a/libcrystfel/src/stream.h b/libcrystfel/src/stream.h
index a8cf4639..ff8628c0 100644
--- a/libcrystfel/src/stream.h
+++ b/libcrystfel/src/stream.h
@@ -39,9 +39,12 @@
struct image;
struct hdfile;
struct event;
+#include "cell.h"
#define GEOM_START_MARKER "----- Begin geometry file -----"
#define GEOM_END_MARKER "----- End geometry file -----"
+#define CELL_START_MARKER "----- Begin unit cell -----"
+#define CELL_END_MARKER "----- End unit cell -----"
#define CHUNK_START_MARKER "----- Begin chunk -----"
#define CHUNK_END_MARKER "----- End chunk -----"
#define PEAK_LIST_START_MARKER "Peaks from peak search"
@@ -92,6 +95,9 @@ extern Stream *open_stream_for_write(const char *filename);
extern Stream *open_stream_for_write_2(const char *filename,
const char* geom_filename, int argc,
char *argv[]);
+extern Stream *open_stream_for_write_3(const char *filename,
+ const char* geom_filename, UnitCell *cell,
+ int argc, char *argv[]);
extern Stream *open_stream_fd_for_write(int fd);
extern int get_stream_fd(Stream *st);
extern void close_stream(Stream *st);