diff options
author | Thomas White <taw@physics.org> | 2013-02-19 18:14:25 +0100 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2013-02-19 18:14:25 +0100 |
commit | 5fbf0a6ff8031a82ba7517044b5828106bb85f3c (patch) | |
tree | 47f4247fc3b14a5b42831d46971125fcad556f61 | |
parent | 8d28f13e79dbec60a6f95a85ecfcf16ba47a73c7 (diff) | |
parent | e4616b7007239e4b56dc293a832144d6f3cb5350 (diff) |
Merge remote-tracking branch 'bitwiz/cornelius/xds' into tom/multicrystal
-rw-r--r-- | libcrystfel/src/xds.c | 119 |
1 files changed, 95 insertions, 24 deletions
diff --git a/libcrystfel/src/xds.c b/libcrystfel/src/xds.c index 9660b5bc..92619d65 100644 --- a/libcrystfel/src/xds.c +++ b/libcrystfel/src/xds.c @@ -253,25 +253,30 @@ static int read_cell(const char *filename, struct image *image, do { rval = fgets(line, 1023, fh); + if ( rval == NULL ) return 0; } while ( strcmp(line, " # COORDINATES OF REC. BASIS VECTOR" " LENGTH 1/LENGTH\n") != 0 ); /* Free line after chunk */ rval = fgets(line, 1023, fh); + if ( rval == NULL ) return 0; rval = fgets(line, 1023, fh); + if ( rval == NULL ) return 0; memcpy(asx, line+7, 10); asx[10] = '\0'; memcpy(asy, line+17, 10); asy[10] = '\0'; memcpy(asz, line+27, 10); asz[10] = '\0'; rval = fgets(line, 1023, fh); + if ( rval == NULL ) return 0; memcpy(bsx, line+7, 10); bsx[10] = '\0'; memcpy(bsy, line+17, 10); bsy[10] = '\0'; memcpy(bsz, line+27, 10); bsz[10] = '\0'; rval = fgets(line, 1023, fh); + if ( rval == NULL ) return 0; memcpy(csx, line+7, 10); csx[10] = '\0'; memcpy(csy, line+17, 10); csy[10] = '\0'; @@ -377,21 +382,88 @@ static void write_spot(struct image *image, const char *filename) } -static char *write_inp(struct image *image) +/* Turn what we know about the unit cell into something which we can give to + * XDS to make it give us only indexing results compatible with the cell. */ +static const char *spacegroup_for_lattice(UnitCell *cell) { - FILE *fh; - char *filename; + LatticeType latt; + char centering; + char *g = NULL; + + latt = cell_get_lattice_type(cell); + centering = cell_get_centering(cell); + + switch ( latt ) + { + case L_TRICLINIC : + g = "1"; + break; + + case L_MONOCLINIC : + if ( centering == 'P' ) { + g = "3"; + } else { + g = "5"; + } + break; + + case L_ORTHORHOMBIC : + if ( centering == 'P' ) { + g = "16"; + } else if ( centering == 'C' ) { + g = "20"; + } else if ( centering == 'F' ) { + g = "22"; + } else { + g = "23"; + } + break; + + case L_TETRAGONAL : + if ( centering == 'P' ) { + g = "75"; + } else { + g = "79"; + } + break; + + case L_RHOMBOHEDRAL : + if ( centering == 'P' ) { + g = "143"; + } else { + g = "146"; + } + break; + + case L_HEXAGONAL : + g = "168"; + break; + + case L_CUBIC : + if ( centering == 'P' ) { + g = "195"; + } else if ( centering == 'F' ) { + g = "196"; + } else { + g = "197"; + } + break; + } + assert(g != NULL); + + return g; +} - filename = malloc(1024); - if ( filename == NULL ) return NULL; - snprintf(filename, 1023, "XDS.INP"); +static int write_inp(struct image *image, struct xds_private *xp) +{ + FILE *fh; + double a, b, c, al, be, ga; - fh = fopen(filename, "w"); + fh = fopen("XDS.INP", "w"); if ( !fh ) { - ERROR("Couldn't open temporary file '%s'\n", filename); - free(filename); - return NULL; + ERROR("Couldn't open XDS.INP\n"); + return 0; } fprintf(fh, "JOB= IDXREF\n"); @@ -399,16 +471,17 @@ static char *write_inp(struct image *image) fprintf(fh, "ORGY= 1500\n"); fprintf(fh, "DETECTOR_DISTANCE= 99.00\n"); //IMPORTANT fprintf(fh, "OSCILLATION_RANGE= 0.300\n"); - fprintf(fh, "X-RAY_WAVELENGTH= 1.32\n"); // IMPORTANT - fprintf(fh, "NAME_TEMPLATE_OF_DATA_FRAMES=/home/dikay/insu/data_exp1/ins_ssad_1_???.img \n"); + fprintf(fh, "X-RAY_WAVELENGTH= %.6f\n", image->lambda*1e10); + fprintf(fh, "NAME_TEMPLATE_OF_DATA_FRAMES=/home/ins_ssad_1_???.img \n"); fprintf(fh, "DATA_RANGE=1 1\n"); fprintf(fh, "SPOT_RANGE=1 1\n"); - fprintf(fh, "SPACE_GROUP_NUMBER= 94\n"); //CatB 94 - fprintf(fh, "UNIT_CELL_CONSTANTS= 126.2 126.2 54.2 90 90 90\n"); //CatB 125.4 125.4 54.56 90 90 90 - //fprintf(fh, "SPACE_GROUP_NUMBER=194\n"); //PS1 194 - //fprintf(fh, "UNIT_CELL_CONSTANTS=281 281 165.2 90 90 120\n"); //PS1 281 281 165.2 90 90 120 - //fprintf(fh, "SPACE_GROUP_NUMBER= 0\n"); //LYS 96 - //fprintf(fh, "UNIT_CELL_CONSTANTS= 0 0 0 0 0 0\n"); //LYS 77.32 77.32 38.16 90 90 90 + fprintf(fh, "SPACE_GROUP_NUMBER= %s\n", + spacegroup_for_lattice(xp->cell)); + cell_get_parameters(xp->cell, &a, &b, &c, &al, &be, &ga); + fprintf(fh, "UNIT_CELL_CONSTANTS= %.2f %.2f %.2f %.2f %.2f %.2f\n", + a*1e10, b*1e10, c*1e10,rad2deg(al), rad2deg(be), rad2deg(ga)); + //fprintf(fh, "SPACE_GROUP_NUMBER= 0\n"); + //fprintf(fh, "UNIT_CELL_CONSTANTS= 0 0 0 0 0 0\n"); fprintf(fh, "NX= 3000\n"); fprintf(fh, "NY= 3000\n"); fprintf(fh, "QX= 0.07\n"); @@ -429,7 +502,7 @@ static char *write_inp(struct image *image) fclose(fh); - return filename; + return 0; } @@ -440,7 +513,6 @@ int run_xds(struct image *image, IndexingPrivate *priv) int rval; int n; struct xds_data *xds; - char *inp_filename; struct xds_private *xp = (struct xds_private *)priv; xds = malloc(sizeof(struct xds_data)); @@ -451,10 +523,9 @@ int run_xds(struct image *image, IndexingPrivate *priv) xds->target_cell = xp->cell; - write_inp(image); - inp_filename = write_inp(image); - - if ( inp_filename == NULL ) { + write_inp(image, xp); + + if ( write_inp == NULL ) { ERROR("Failed to write XDS.INP file for XDS.\n"); return 0; } |