diff options
-rw-r--r-- | libcrystfel/src/geometry.c | 50 | ||||
-rw-r--r-- | libcrystfel/src/geometry.h | 6 | ||||
-rw-r--r-- | libcrystfel/src/predict-refine.c | 14 |
3 files changed, 30 insertions, 40 deletions
diff --git a/libcrystfel/src/geometry.c b/libcrystfel/src/geometry.c index 32da348a..10a7fa19 100644 --- a/libcrystfel/src/geometry.c +++ b/libcrystfel/src/geometry.c @@ -512,13 +512,11 @@ RefList *predict_to_res(Crystal *cryst, struct image *image, double max_res) } -static void set_unity_partialities(Crystal *cryst) +static void set_unity_partialities(RefList *list) { - RefList *list; Reflection *refl; RefListIterator *iter; - list = crystal_get_reflections(cryst); if ( list == NULL ) { ERROR("No reflections for partiality calculation!\n"); return; @@ -533,13 +531,11 @@ static void set_unity_partialities(Crystal *cryst) } -static void set_random_partialities(Crystal *cryst, int image_serial) +static void set_random_partialities(RefList *list, int image_serial) { - RefList *list; Reflection *refl; RefListIterator *iter; - list = crystal_get_reflections(cryst); if ( list == NULL ) { ERROR("No reflections for partiality calculation!\n"); return; @@ -674,16 +670,14 @@ static double do_integral(double q2, double zl, double R, } -static void ginn_spectrum_partialities(Crystal *cryst, struct image *image) +static void ginn_spectrum_partialities(RefList *list, Crystal *cryst, struct image *image) { - RefList *list; Reflection *refl; RefListIterator *iter; double r0, m; UnitCell *cell; double asx, asy, asz, bsx, bsy, bsz, csx, csy, csz; - list = crystal_get_reflections(cryst); if ( list == NULL ) { ERROR("No reflections for partiality calculation!\n"); return; @@ -701,7 +695,7 @@ static void ginn_spectrum_partialities(Crystal *cryst, struct image *image) r0 = fabs(crystal_get_profile_radius(cryst)); m = crystal_get_mosaicity(cryst); - for ( refl = first_refl(crystal_get_reflections(cryst), &iter); + for ( refl = first_refl(list, &iter); refl != NULL; refl = next_refl(refl, iter) ) { @@ -738,16 +732,14 @@ static void ginn_spectrum_partialities(Crystal *cryst, struct image *image) } -static void ewald_offset_partialities(Crystal *cryst, struct image *image) +static void ewald_offset_partialities(RefList *list, Crystal *cryst, struct image *image) { - RefList *list; Reflection *refl; RefListIterator *iter; double r0, m; UnitCell *cell; double asx, asy, asz, bsx, bsy, bsz, csx, csy, csz; - list = crystal_get_reflections(cryst); if ( list == NULL ) { ERROR("No reflections for partiality calculation!\n"); return; @@ -765,7 +757,7 @@ static void ewald_offset_partialities(Crystal *cryst, struct image *image) r0 = fabs(crystal_get_profile_radius(cryst)); m = crystal_get_mosaicity(cryst); - for ( refl = first_refl(crystal_get_reflections(cryst), &iter); + for ( refl = first_refl(list, &iter); refl != NULL; refl = next_refl(refl, iter) ) { @@ -793,36 +785,40 @@ static void ewald_offset_partialities(Crystal *cryst, struct image *image) /** + * \param list A \ref RefList * \param cryst A \ref Crystal + * \param image An image structure * \param pmodel A \ref PartialityModel * - * Calculates the partialities for the reflections in \p cryst, given the current - * crystal and image parameters. The crystal's image and reflection lists - * must be set. The specified \ref PartialityModel will be used. + * Calculates the partialities for the reflections in \p list, given the current + * state of \p cryst and \p image. + * + * If \p pmodel is PMODEL_RANDOM or PMODEL_UNITY, then \p cryst can be NULL. + * If \p pmodel is PMODEL_UNITY, then \p image can also be NULL. * * You must not have changed the crystal or image parameters since you last * called \ref predict_to_res or \ref update_predictions, because this function * relies on the limiting wavelength values calculated by those functions. */ -void calculate_partialities(Crystal *cryst, struct image *image, +void calculate_partialities(RefList *list, Crystal *cryst, struct image *image, PartialityModel pmodel) { switch ( pmodel ) { case PMODEL_UNITY : - set_unity_partialities(cryst); + set_unity_partialities(list); break; case PMODEL_XSPHERE : - ginn_spectrum_partialities(cryst, image); + ginn_spectrum_partialities(list, cryst, image); break; case PMODEL_OFFSET : - ewald_offset_partialities(cryst, image); + ewald_offset_partialities(list, cryst, image); break; case PMODEL_RANDOM : - set_random_partialities(cryst, image->serial); + set_random_partialities(list, image->serial); break; case PMODEL_GGPM : @@ -839,18 +835,18 @@ void calculate_partialities(Crystal *cryst, struct image *image, /** + * \param list A \ref RefList * \param cryst A \ref Crystal * \param image An image structure * * Updates the predicted reflections (positions and excitation errors, but not - * the actual partialities) of \p cryst's reflections as seen in \p image, - * according to the current state of the crystal (e.g. its unit cell - * parameters). + * the actual partialities) in \p list, to match the current statea of + * \p crys as seen in \p image. * * If you need to update the partialities as well, call * \ref calculate_partialities afterwards. */ -void update_predictions(Crystal *cryst, struct image *image) +void update_predictions(RefList *list, Crystal *cryst, struct image *image) { Reflection *refl; RefListIterator *iter; @@ -861,7 +857,7 @@ void update_predictions(Crystal *cryst, struct image *image) cell_get_reciprocal(crystal_get_cell(cryst), &asx, &asy, &asz, &bsx, &bsy, &bsz, &csx, &csy, &csz); - for ( refl = first_refl(crystal_get_reflections(cryst), &iter); + for ( refl = first_refl(list, &iter); refl != NULL; refl = next_refl(refl, iter) ) { diff --git a/libcrystfel/src/geometry.h b/libcrystfel/src/geometry.h index b9f98694..217cb9ea 100644 --- a/libcrystfel/src/geometry.h +++ b/libcrystfel/src/geometry.h @@ -80,10 +80,12 @@ struct polarisation extern RefList *predict_to_res(Crystal *cryst, struct image *image, double max_res); -extern void calculate_partialities(Crystal *cryst, struct image *image, +extern void calculate_partialities(RefList *list, + Crystal *cryst, + struct image *image, PartialityModel pmodel); -extern void update_predictions(Crystal *cryst, struct image *image); +extern void update_predictions(RefList *list, Crystal *cryst, struct image *image); extern struct polarisation parse_polarisation(const char *text); extern void polarisation_correction(RefList *list, UnitCell *cell, struct polarisation p); diff --git a/libcrystfel/src/predict-refine.c b/libcrystfel/src/predict-refine.c index 4cd0e54e..5fb9b4cc 100644 --- a/libcrystfel/src/predict-refine.c +++ b/libcrystfel/src/predict-refine.c @@ -488,8 +488,7 @@ static int pair_peaks(struct image *image, Crystal *cr, /* Get the excitation errors and detector positions for the candidate * reflections */ - crystal_set_reflections(cr, all_reflist); - update_predictions(cr, image); + update_predictions(all_reflist, cr, image); /* Pass over the peaks again, keeping only the ones which look like * good pairings */ @@ -529,7 +528,6 @@ static int pair_peaks(struct image *image, Crystal *cr, } reflist_free(all_reflist); - crystal_set_reflections(cr, NULL); /* Sort the pairings by excitation error and look for a transition * between good pairings and outliers */ @@ -569,9 +567,7 @@ int refine_radius(Crystal *cr, struct image *image) reflist_free(reflist); return 1; } - crystal_set_reflections(cr, reflist); - update_predictions(cr, image); - crystal_set_reflections(cr, NULL); + update_predictions(reflist, cr, image); qsort(rps, n_acc, sizeof(struct reflpeak), cmpd2); n = (n_acc-1) - n_acc/50; @@ -820,7 +816,6 @@ int refine_prediction(struct image *image, Crystal *cr, reflist_free(reflist); return 1; } - crystal_set_reflections(cr, reflist); Minvs = make_panel_minvs(image->detgeom); @@ -833,7 +828,6 @@ int refine_prediction(struct image *image, Crystal *cr, if ( max_I <= 0.0 ) { ERROR("All peaks negative?\n"); cffree(rps); - crystal_set_reflections(cr, NULL); return 1; } for ( i=0; i<n; i++ ) { @@ -855,10 +849,9 @@ int refine_prediction(struct image *image, Crystal *cr, /* Refine (max 5 cycles) */ for ( i=0; i<5; i++ ) { - update_predictions(cr, image); + update_predictions(reflist, cr, image); if ( iterate(rps, n, crystal_get_cell(cr), image, Minvs, total_shifts) ) { - crystal_set_reflections(cr, NULL); return 1; } @@ -890,7 +883,6 @@ int refine_prediction(struct image *image, Crystal *cr, } cffree(Minvs); - crystal_set_reflections(cr, NULL); reflist_free(reflist); n = pair_peaks(image, cr, NULL, rps); |