aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRichard Kirian <rkirian@asu.edu>2010-12-09 17:38:56 -0700
committerThomas White <taw@physics.org>2012-02-22 15:27:09 +0100
commitc19fc76592d457991f38e5e34539772501a05fb6 (patch)
tree78db6b7060b7a557c98c804806193809a2b05e41 /src
parent9e70c834460f622bce015a01e795024a2d15e247 (diff)
mosflm almost functional
Diffstat (limited to 'src')
-rw-r--r--src/index.c16
-rw-r--r--src/mosflm.c101
-rw-r--r--src/mosflm.h2
3 files changed, 108 insertions, 11 deletions
diff --git a/src/index.c b/src/index.c
index 01e7aa4b..5a2704f4 100644
--- a/src/index.c
+++ b/src/index.c
@@ -109,6 +109,8 @@ static void write_drx(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 */
@@ -116,7 +118,7 @@ struct sptline {
double s; /* sigma of peak */
};
-/* need to sort mosflm peaks by intensity... */
+
static int compare_vals(const void *ap, const void *bp)
{
const struct sptline a = *(struct sptline *)ap;
@@ -127,7 +129,7 @@ static int compare_vals(const void *ap, const void *bp)
return 0;
}
-/* write .spt file for mosflm */
+
static void write_spt(struct image *image)
{
FILE *fh;
@@ -201,9 +203,9 @@ void write_img(struct image *image)
unsigned short int * intimage;
intimage = malloc(sizeof(unsigned short int));
- intimage[0] = 0;
+ intimage[0] = 1;
- snprintf(filename, 1023, "xfel-%i.img", image->id);
+ snprintf(filename, 1023, "xfel-%i_001.img", image->id);
fh = fopen(filename, "w");
if ( !fh ) {
@@ -219,7 +221,7 @@ void write_img(struct image *image)
fprintf(fh,"SIZE2=1;\n");
fprintf(fh,"}\n");
while ( ftell(fh) < 512 ) { fprintf(fh," "); };
- fwrite(fh,sizeof(unsigned short int),1,fh);
+ fwrite(intimage,sizeof(unsigned short int),1,fh);
fclose(fh);
}
@@ -262,8 +264,8 @@ void index_pattern(struct image *image, UnitCell *cell, IndexingMethod indm,
break;
case INDEXING_MOSFLM :
write_spt(image);
- write_img(image); /* don't do this every time? */
- run_mosflm(image);
+ write_img(image); /* dummy image. not needed for each frame.*/
+ run_mosflm(image,cell);
break;
case INDEXING_TEMPLATE :
match_templates(image, ipriv);
diff --git a/src/mosflm.c b/src/mosflm.c
index aed22720..1a2beb7b 100644
--- a/src/mosflm.c
+++ b/src/mosflm.c
@@ -391,17 +391,112 @@ static int dirax_readable(struct image *image)
}
+static int read_newmat(const char * filename, struct image *image)
+{
+ FILE * fh;
+ float asx, asy, asz;
+ float bsx, bsy, bsz;
+ float csx, csy, csz;
+ int n;
+ double c;
+
+ fh = fopen(filename,"r");
+ if (fh == NULL){
+ return 1;
+ }
+ n = fscanf(fh,"%f %f %f\n",&asx,&bsx,&csx);
+ n += fscanf(fh,"%f %f %f\n",&asy,&bsy,&csy);
+ n += fscanf(fh,"%f %f %f\n",&asz,&bsz,&csz);
+ if (n != 9) {
+ return 1;
+ }
+ fclose(fh);
+
+ /* mosflm A matrix is multiplied by lambda, so fix this */
+ c = 1e-10/image->lambda;
+
+ cell_set_reciprocal(image->candidate_cells[0],
+ asz*c, asy*c, asx*c,
+ bsz*c, bsy*c, bsx*c,
+ csz*c, csy*c, csx*c);
+
+ image->ncells = 1;
+
+ return 0;
+}
-
-void run_mosflm(struct image *image)
+void run_mosflm(struct image *image, UnitCell *cell)
{
unsigned int opts;
int status;
int rval;
+ int i,j;
+ char mos_cmd[1024];
+ char symm[64];
+ const char *sg;
+ double a,b,c,alpha,beta,gamma;
+ double wavelength; /* angstrom */
+ const char newmatfile[128];
+ int fail;
+
+ printf("Mosflm is not fully implemented. Using DirAx for now.\n");
+
+ wavelength = image->lambda*1e10;
+ cell_get_parameters(cell, &a, &b, &c, &alpha, &beta, &gamma);
+ sg = cell_get_spacegroup(cell);
+ sprintf(newmatfile,"xfel-%i.newmat",image->id);
+
+ /* need to remove white space from spacegroup... */
+ j = 0;
+ for(i = 0; i < strlen(sg);i++)
+ {
+ if (sg[i] != ' ') {
+ symm[j] = sg[i];
+ j++;
+ }
+ }
+ symm[j] = '\0';
+
+
+ /* build a script to run mosflm */
+ sprintf(mos_cmd,"%s","ipmosflm << eof-mosflm >> /dev/null\n");
+ sprintf(mos_cmd,"%s%s",mos_cmd,
+ "DETECTOR ROTATION HORIZONTAL ANTICLOCKWISE"
+ " ORIGIN LL FAST HORIZONTAL RECTANGULAR\n");
+ sprintf(mos_cmd,"%sCELL %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f\n",
+ mos_cmd,
+ a*1e10,b*1e10,c*1e10,
+ rad2deg(alpha),rad2deg(beta),rad2deg(gamma));
+ sprintf(mos_cmd,"%sSYMM %s\n",mos_cmd,symm);
+ sprintf(mos_cmd,"%sDISTANCE %8.4f\n",mos_cmd,67.8);
+ sprintf(mos_cmd,"%sBEAM %8.4f %8.4f\n",mos_cmd,0.0,0.0);
+ sprintf(mos_cmd,"%sWAVELENGTH %10.5f\n",mos_cmd,wavelength);
+ sprintf(mos_cmd,"%sNEWMAT %s\n",mos_cmd,newmatfile);
+ sprintf(mos_cmd,"%sIMAGE xfel-%i_001.img phi 0 0\n",mos_cmd,image->id);
+ sprintf(mos_cmd,"%sAUTOINDEX DPS FILE xfel-%i.spt IMAGE 1\n",
+ mos_cmd,image->id);
+ sprintf(mos_cmd,"%sGO\n",mos_cmd);
+ sprintf(mos_cmd,"%s%s",mos_cmd,"eof-mosflm\n");
+
+ /* Run the mosflm script */
+ fail = system(mos_cmd);
+ if (fail) {
+ ERROR("mosflm execution failed.\n");
+ return;
+ }
- printf("Mosflm is not yet implemented. Using DirAx for now.\n");
+ /* Read the mosflm NEWMAT file and set cell candidate */
+ /* Existence of this file means possible success. Pretty shady. */
+ fail = read_newmat(newmatfile,image);
+ if (fail) {
+ printf("Failed to read mosflm NEWMAT file.\n");
+ return;
+ }
+ /* remove the mosflm NEWMAT file */
+ remove(newmatfile);
+
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/mosflm.h b/src/mosflm.h
index 8d09d8d5..53939902 100644
--- a/src/mosflm.h
+++ b/src/mosflm.h
@@ -22,7 +22,7 @@
#include "utils.h"
-extern void run_mosflm(struct image *image);
+extern void run_mosflm(struct image *image, UnitCell *cell);
#endif /* MOSFLM_H */