diff options
-rw-r--r-- | src/dirax.c | 33 | ||||
-rw-r--r-- | src/index.c | 149 | ||||
-rw-r--r-- | src/indexamajig.c | 22 | ||||
-rw-r--r-- | src/mosflm.c | 121 |
4 files changed, 158 insertions, 167 deletions
diff --git a/src/dirax.c b/src/dirax.c index 0930f8f9..ebb53f25 100644 --- a/src/dirax.c +++ b/src/dirax.c @@ -385,12 +385,45 @@ static int dirax_readable(struct image *image) } +static void write_drx(struct image *image) +{ + FILE *fh; + int i; + char filename[1024]; + + snprintf(filename, 1023, "xfel-%i.drx", image->id); + + fh = fopen(filename, "w"); + if ( !fh ) { + ERROR("Couldn't open temporary file xfel.drx\n"); + return; + } + fprintf(fh, "%f\n", 0.5); /* Lie about the wavelength. */ + + for ( i=0; i<image_feature_count(image->features); i++ ) { + + struct imagefeature *f; + + f = image_get_feature(image->features, i); + if ( f == NULL ) continue; + + fprintf(fh, "%10f %10f %10f %8f\n", + f->rx/1e10, f->ry/1e10, f->rz/1e10, 1.0); + + } + fclose(fh); +} + + + void run_dirax(struct image *image) { unsigned int opts; int status; int rval; + write_drx(image); + image->dirax_pid = forkpty(&image->dirax_pty, NULL, NULL, NULL); if ( image->dirax_pid == -1 ) { ERROR("Failed to fork for DirAx\n"); diff --git a/src/index.c b/src/index.c index 4d2a158f..69711b42 100644 --- a/src/index.c +++ b/src/index.c @@ -108,152 +108,6 @@ void cleanup_indexing(IndexingPrivate **priv) } -static void write_drx(struct image *image) -{ - FILE *fh; - int i; - char filename[1024]; - - snprintf(filename, 1023, "xfel-%i.drx", image->id); - - fh = fopen(filename, "w"); - if ( !fh ) { - ERROR("Couldn't open temporary file xfel.drx\n"); - return; - } - fprintf(fh, "%f\n", 0.5); /* Lie about the wavelength. */ - - for ( i=0; i<image_feature_count(image->features); i++ ) { - - struct imagefeature *f; - - f = image_get_feature(image->features, i); - if ( f == NULL ) continue; - - fprintf(fh, "%10f %10f %10f %8f\n", - f->rx/1e10, f->ry/1e10, f->rz/1e10, 1.0); - - } - fclose(fh); -} - - -/* 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.*/ -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 map_all_peaks(struct image *image) { int i; @@ -292,13 +146,10 @@ void index_pattern(struct image *image, UnitCell *cell, IndexingMethod *indm, return; case INDEXING_DIRAX : STATUS("Running DirAx...\n"); - write_drx(image); run_dirax(image); break; case INDEXING_MOSFLM : STATUS("Running MOSFLM...\n"); - write_spt(image); - write_img(image); /* dummy image */ run_mosflm(image, cell); break; case INDEXING_TEMPLATE : diff --git a/src/indexamajig.c b/src/indexamajig.c index de50383c..83eee4d1 100644 --- a/src/indexamajig.c +++ b/src/indexamajig.c @@ -53,7 +53,6 @@ struct static_index_args UnitCell *cell; int config_cmfilter; int config_noisefilter; - int config_writedrx; int config_dumpfound; int config_verbose; int config_alternate; @@ -161,10 +160,6 @@ static void show_help(const char *s) " as \"simulated.h5\". You can TRY to combine this\n" " with \"-j <n>\" with n greater than 1, but it's\n" " not a good idea.\n" -" --write-drx Write 'xfel.drx' for visualisation of reciprocal\n" -" space. Implied by any indexing method other than\n" -" 'none'. Beware: the units in this file are\n" -" reciprocal Angstroms.\n" " --dump-peaks Write the results of the peak search to stdout.\n" " The intensities in this list are from the\n" " centroid/integration procedure.\n" @@ -318,7 +313,6 @@ static void process_image(void *pp, int cookie) UnitCell *cell = pargs->static_args.cell; int config_cmfilter = pargs->static_args.config_cmfilter; int config_noisefilter = pargs->static_args.config_noisefilter; - int config_writedrx = pargs->static_args.config_writedrx; int config_dumpfound = pargs->static_args.config_dumpfound; int config_verbose = pargs->static_args.config_verbose; int config_alternate = pargs->static_args.config_alternate; @@ -397,17 +391,12 @@ static void process_image(void *pp, int cookie) pargs->static_args.output_mutex); } - /* Not indexing nor writing xfel.drx? - * Then there's nothing left to do. */ - if ( (!config_writedrx) && (indm == INDEXING_NONE) ) { - goto done; - } + /* Not indexing? Then there's nothing left to do. */ + if ( indm == NULL ) goto done; /* Calculate orientation matrix (by magic) */ - if ( config_writedrx || (indm != INDEXING_NONE) ) { - index_pattern(&image, cell, indm, pargs->static_args.cellr, - config_verbose, pargs->static_args.ipriv); - } + index_pattern(&image, cell, indm, pargs->static_args.cellr, + config_verbose, pargs->static_args.ipriv); /* No cell at this point? Then we're done. */ if ( image.indexed_cell == NULL ) goto done; @@ -527,7 +516,6 @@ int main(int argc, char *argv[]) int config_noindex = 0; int config_dumpfound = 0; int config_nearbragg = 0; - int config_writedrx = 0; int config_simulate = 0; int config_cmfilter = 0; int config_noisefilter = 0; @@ -582,7 +570,6 @@ int main(int argc, char *argv[]) {"peaks", 1, NULL, 2}, {"cell-reduction", 1, NULL, 3}, {"near-bragg", 0, &config_nearbragg, 1}, - {"write-drx", 0, &config_writedrx, 1}, {"indexing", 1, NULL, 'z'}, {"geometry", 1, NULL, 'g'}, {"beam", 1, NULL, 'b'}, @@ -886,7 +873,6 @@ int main(int argc, char *argv[]) qargs.static_args.cell = cell; qargs.static_args.config_cmfilter = config_cmfilter; qargs.static_args.config_noisefilter = config_noisefilter; - qargs.static_args.config_writedrx = config_writedrx; qargs.static_args.config_dumpfound = config_dumpfound; qargs.static_args.config_verbose = config_verbose; qargs.static_args.config_alternate = config_alternate; 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); |