aboutsummaryrefslogtreecommitdiff
path: root/src/mosflm.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mosflm.c')
-rw-r--r--src/mosflm.c121
1 files changed, 121 insertions, 0 deletions
diff --git a/src/mosflm.c b/src/mosflm.c
index 40780451..974b82c5 100644
--- a/src/mosflm.c
+++ b/src/mosflm.c
@@ -102,6 +102,124 @@ static int read_newmat(const char * filename, struct image *image)
}
+/* write .spt file for mosflm */
+/* need to sort mosflm peaks by intensity... */
+struct sptline {
+ double x; /* x coordinate of peak */
+ double y; /* y coordinate of peak */
+ double h; /* height of peak */
+ double s; /* sigma of peak */
+};
+
+
+static int compare_vals(const void *ap, const void *bp)
+{
+ const struct sptline a = *(struct sptline *)ap;
+ const struct sptline b = *(struct sptline *)bp;
+
+ if ( a.h < b.h ) return 1;
+ if ( a.h > b.h ) return -1;
+ return 0;
+}
+
+
+static void write_spt(struct image *image)
+{
+ FILE *fh;
+ int i;
+ char filename[1024];
+ double fclen=67.8; /* fake camera length in mm */
+ double fpix=0.075; /* fake pixel size in mm */
+ double pix;
+ double height=100;
+ double sigma=1;
+ int nPeaks = image_feature_count(image->features);
+
+ snprintf(filename, 1023, "xfel-%i.spt", image->id);
+
+ fh = fopen(filename, "w");
+ if ( !fh ) {
+ ERROR("Couldn't open temporary file xfel.spt\n");
+ return;
+ }
+
+ fprintf(fh, "%10d %10d %10.8f %10.6f %10.6f\n", 1, 1, fpix, 1.0, 0.0);
+ fprintf(fh, "%10d %10d\n", 1, 1);
+ fprintf(fh, "%10.5f %10.5f\n", 0.0, 0.0);
+
+ struct sptline *sptlines;
+ sptlines = malloc(sizeof(struct sptline)*nPeaks);
+
+ for ( i=0; i<nPeaks; i++ ) {
+
+ struct imagefeature *f;
+
+ f = image_get_feature(image->features, i);
+ if ( f == NULL ) continue;
+
+ struct panel *pan;
+ pan = find_panel(image->det,f->x,f->y);
+ if ( pan == NULL ) continue;
+
+ pix = 1000/pan->res; /* pixel size in mm */
+ height = f->intensity;
+
+ sptlines[i].x = (f->y - pan->cy)*pix*fclen/pan->clen/1000;
+ sptlines[i].y = -(f->x - pan->cx)*pix*fclen/pan->clen/1000;
+ sptlines[i].h = height;
+ sptlines[i].s = sigma;
+
+ }
+
+ qsort(sptlines, nPeaks, sizeof(struct sptline), compare_vals);
+
+ for ( i=0; i<nPeaks; i++ ) {
+
+ fprintf(fh, "%10.2f %10.2f %10.2f %10.2f %10.2f %10.2f\n",
+ sptlines[i].x, sptlines[i].y,
+ 0.0, 0.0,
+ sptlines[i].h, sptlines[i].s);
+
+ }
+
+ fprintf(fh,"%10.2f %10.2f %10.2f %10.2f %10.2f %10.2f\n",
+ -999.0,-999.0,-999.0,-999.0,-999.0,-999.0);
+ fclose(fh);
+}
+
+
+/* Write a dummy 1x1 pixel image file for mosflm. Without post refinement,
+ * mosflm will ignore this, but it must be present. */
+static void write_img(struct image *image)
+{
+ FILE *fh;
+ char filename[1024];
+ unsigned short int * intimage;
+
+ intimage = malloc(sizeof(unsigned short int));
+ intimage[0] = 1;
+
+ snprintf(filename, 1023, "xfel-%i_001.img", image->id);
+
+ fh = fopen(filename, "w");
+ if ( !fh ) {
+ ERROR("Couldn't open temporary file xfel.spt\n");
+ return;
+ }
+
+ fprintf(fh,"{\nHEADER_BYTES=512;\n");
+ fprintf(fh,"BYTE_ORDER=little_endian;\n");
+ fprintf(fh,"TYPE=unsigned_short;\n");
+ fprintf(fh,"DIM=2;\n");
+ fprintf(fh,"SIZE1=1;\n");
+ fprintf(fh,"SIZE2=1;\n");
+ fprintf(fh,"}\n");
+ while ( ftell(fh) < 512 ) { fprintf(fh," "); };
+ fwrite(intimage,sizeof(unsigned short int),1,fh);
+ fclose(fh);
+}
+
+
void run_mosflm(struct image *image, UnitCell *cell)
{
int i,j;
@@ -113,6 +231,9 @@ void run_mosflm(struct image *image, UnitCell *cell)
char newmatfile[128];
int fail;
+ write_spt(image);
+ write_img(image); /* dummy image */
+
wavelength = image->lambda*1e10;
cell_get_parameters(cell, &a, &b, &c, &alpha, &beta, &gamma);
sg = cell_get_spacegroup(cell);