aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2024-01-18 15:16:52 +0100
committerThomas White <taw@physics.org>2024-02-06 16:59:34 +0100
commit335067449b3858a55442ffb355af56f55410d154 (patch)
treec947d1256d6ab06d81f4c58885567216e614c2fe /src
parent36b79bb6f65018fe74f63291857263c6a14d5697 (diff)
Crystals shouldn't own RefLists (part 5)
This fixes the entire partialator/scaling/rejection part.
Diffstat (limited to 'src')
-rw-r--r--src/merge.c34
-rw-r--r--src/merge.h8
-rw-r--r--src/partialator.c125
-rw-r--r--src/post-refinement.c98
-rw-r--r--src/post-refinement.h7
-rw-r--r--src/rejection.c43
-rw-r--r--src/rejection.h6
-rw-r--r--src/scaling.c25
-rw-r--r--src/scaling.h7
9 files changed, 178 insertions, 175 deletions
diff --git a/src/merge.c b/src/merge.c
index 0a5c5f14..4a2dae66 100644
--- a/src/merge.c
+++ b/src/merge.c
@@ -55,7 +55,7 @@ struct merge_queue_args
{
RefList *full;
pthread_rwlock_t full_lock;
- Crystal **crystals;
+ struct crystal_refls *crystals;
int n_started;
double push_res;
int use_weak;
@@ -68,6 +68,7 @@ struct merge_worker_args
{
struct merge_queue_args *qargs;
Crystal *crystal;
+ RefList *refls;
int crystal_number;
int n_reflections;
};
@@ -81,7 +82,9 @@ static void *create_merge_job(void *vqargs)
wargs = malloc(sizeof(struct merge_worker_args));
wargs->qargs = qargs;
wargs->crystal_number = qargs->n_started;
- wargs->crystal = qargs->crystals[qargs->n_started++];
+ wargs->crystal = qargs->crystals[qargs->n_started].cr;
+ wargs->refls = qargs->crystals[qargs->n_started].refls;
+ qargs->n_started++;
return wargs;
}
@@ -180,7 +183,7 @@ static void run_merge_job(void *vwargs, int cookie)
G = crystal_get_osf(cr);
B = crystal_get_Bfac(cr);
- for ( refl = first_refl(crystal_get_reflections(cr), &iter);
+ for ( refl = first_refl(wargs->refls, &iter);
refl != NULL;
refl = next_refl(refl, iter) )
{
@@ -262,8 +265,8 @@ static void finalise_merge_job(void *vqargs, void *vwargs)
}
-RefList *merge_intensities(Crystal **crystals, int n, int n_threads,
- int min_meas,
+RefList *merge_intensities(struct crystal_refls *crystals, int n,
+ int n_threads, int min_meas,
double push_res, int use_weak, int ln_merge)
{
RefList *full;
@@ -364,7 +367,7 @@ double correct_reflection(double val, Reflection *refl, double osf, double Bfac,
}
-double residual(Crystal *cr, const RefList *full, int free,
+double residual(RefList *list, Crystal *cr, const RefList *full, int free,
int *pn_used, const char *filename)
{
Reflection *refl;
@@ -376,7 +379,7 @@ double residual(Crystal *cr, const RefList *full, int free,
double B = crystal_get_Bfac(cr);
UnitCell *cell = crystal_get_cell(cr);
- for ( refl = first_refl(crystal_get_reflections(cr), &iter);
+ for ( refl = first_refl(list, &iter);
refl != NULL;
refl = next_refl(refl, iter) )
{
@@ -420,7 +423,8 @@ double residual(Crystal *cr, const RefList *full, int free,
}
-double log_residual(Crystal *cr, const RefList *full, int free,
+double log_residual(RefList *list, Crystal *cr,
+ const RefList *full, int free,
int *pn_used, const char *filename)
{
double dev = 0.0;
@@ -439,7 +443,7 @@ double log_residual(Crystal *cr, const RefList *full, int free,
}
}
- for ( refl = first_refl(crystal_get_reflections(cr), &iter);
+ for ( refl = first_refl(list, &iter);
refl != NULL;
refl = next_refl(refl, iter) )
{
@@ -487,7 +491,7 @@ double log_residual(Crystal *cr, const RefList *full, int free,
/* Has to match run_merge_job to be useful */
-void write_unmerged(const char *fn, Crystal **crystals, int n_crystals)
+void write_unmerged(const char *fn, struct crystal_refls *crystals, int n_crystals)
{
FILE *fh;
int i;
@@ -506,17 +510,17 @@ void write_unmerged(const char *fn, Crystal **crystals, int n_crystals)
UnitCell *cell;
fprintf(fh, "Crystal %i\n", i);
- if ( crystal_get_user_flag(crystals[i]) ) {
+ if ( crystal_get_user_flag(crystals[i].cr) ) {
fprintf(fh, "Flagged: yes\n");
} else {
fprintf(fh, "Flagged: no\n");
}
- G = crystal_get_osf(crystals[i]);
- B = crystal_get_Bfac(crystals[i]);
- cell = crystal_get_cell(crystals[i]);
+ G = crystal_get_osf(crystals[i].cr);
+ B = crystal_get_Bfac(crystals[i].cr);
+ cell = crystal_get_cell(crystals[i].cr);
- for ( refl = first_refl(crystal_get_reflections(crystals[i]), &iter);
+ for ( refl = first_refl(crystals[i].refls, &iter);
refl != NULL;
refl = next_refl(refl, iter) )
{
diff --git a/src/merge.h b/src/merge.h
index 5f7e0e64..e304db78 100644
--- a/src/merge.h
+++ b/src/merge.h
@@ -43,7 +43,7 @@
#define MIN_PART_MERGE (0.3)
-extern RefList *merge_intensities(Crystal **crystals, int n, int n_threads,
+extern RefList *merge_intensities(struct crystal_refls *crystals, int n, int n_threads,
int min_meas, double push_res, int use_weak,
int ln_merge);
@@ -53,12 +53,12 @@ extern double correct_reflection_nopart(double val, Reflection *refl,
extern double correct_reflection(double val, Reflection *refl, double osf,
double Bfac, double res);
-extern double residual(Crystal *cr, const RefList *full, int free,
+extern double residual(RefList *list, Crystal *cr, const RefList *full, int free,
int *pn_used, const char *filename);
-extern double log_residual(Crystal *cr, const RefList *full, int free,
+extern double log_residual(RefList *list, Crystal *cr, const RefList *full, int free,
int *pn_used, const char *filename);
-extern void write_unmerged(const char *fn, Crystal **crystals, int n_crystals);
+extern void write_unmerged(const char *fn, struct crystal_refls *crystals, int n_crystals);
#endif /* MERGE */
diff --git a/src/partialator.c b/src/partialator.c
index 6d362a01..659a12c5 100644
--- a/src/partialator.c
+++ b/src/partialator.c
@@ -169,14 +169,14 @@ static void add_to_csplit(struct custom_split *csplit, const char *id,
/* Write two-way split results (i.e. for CC1/2 etc) for this list of crystals */
-static void write_split(Crystal **crystals, int n_crystals, const char *outfile,
- int nthreads, PartialityModel pmodel,
+static void write_split(struct crystal_refls *crystals, int n_crystals,
+ const char *outfile, int nthreads, PartialityModel pmodel,
int min_measurements, SymOpList *sym, double push_res)
{
char tmp[1024];
RefList *split;
- Crystal **crystals1;
- Crystal **crystals2;
+ struct crystal_refls *crystals1;
+ struct crystal_refls *crystals2;
int n_crystals1 = 0;
int n_crystals2 = 0;
int i;
@@ -186,13 +186,12 @@ static void write_split(Crystal **crystals, int n_crystals, const char *outfile,
return;
}
- crystals1 = malloc(n_crystals * sizeof(Crystal *));
+ crystals1 = malloc(n_crystals * sizeof(struct crystal_refls));
if ( crystals1 == NULL ) return;
- crystals2 = malloc(n_crystals * sizeof(Crystal *));
+ crystals2 = malloc(n_crystals * sizeof(struct crystal_refls));
if ( crystals2 == NULL ) return;
-
for ( i=0; i<n_crystals; i++ ) {
if ( i % 2 ) {
crystals1[n_crystals1] = crystals[i];
@@ -259,14 +258,15 @@ static char *insert_into_filename(const char *fn, const char *add)
/* Write custom split results (including a two-way split) */
static void write_custom_split(struct custom_split *csplit, int dsn,
- Crystal **crystals, struct image **images, int n_crystals,
+ struct crystal_refls *crystals,
+ struct image **images, int n_crystals,
PartialityModel pmodel, int min_measurements,
double push_res, SymOpList *sym, int nthreads,
const char *outfile)
{
char *tmp;
RefList *split;
- Crystal *crystalsn[n_crystals];
+ struct crystal_refls crystalsn[n_crystals];
int n_crystalsn = 0;
int i;
@@ -362,7 +362,7 @@ static void show_help(const char *s)
}
-static signed int find_first_crystal(Crystal **crystals, struct image **images, int n_crystals,
+static signed int find_first_crystal(struct image **images, int n_crystals,
struct custom_split *csplit, int dsn)
{
int i;
@@ -394,8 +394,8 @@ static signed int find_first_crystal(Crystal **crystals, struct image **images,
}
-static void check_csplit(Crystal **crystals, struct image **images, int n_crystals,
- struct custom_split *csplit)
+static void check_csplit(struct crystal_refls *crystals, struct image **images,
+ int n_crystals, struct custom_split *csplit)
{
int i;
int n_nosplit = 0;
@@ -437,7 +437,7 @@ static void check_csplit(Crystal **crystals, struct image **images, int n_crysta
for ( i=0; i<csplit->n_datasets; i++ ) {
/* Try to find a crystal with dsn = i */
- if ( find_first_crystal(crystals, images, n_crystals, csplit, i) != -1 )
+ if ( find_first_crystal(images, n_crystals, csplit, i) != -1 )
{
n_cry++;
} else {
@@ -735,7 +735,7 @@ static void write_to_pgraph(FILE *fh, RefList *list, RefList *full, Crystal *cr,
}
-static void write_pgraph(RefList *full, Crystal **crystals, int n_crystals,
+static void write_pgraph(RefList *full, struct crystal_refls *crystals, int n_crystals,
signed int iter, const char *suff,
const char *log_folder)
{
@@ -761,16 +761,16 @@ static void write_pgraph(RefList *full, Crystal **crystals, int n_crystals,
}
for ( i=0; i<n_crystals; i++ ) {
- if ( crystal_get_user_flag(crystals[i]) != 0 ) continue;
- write_to_pgraph(fh, crystal_get_reflections(crystals[i]), full,
- crystals[i], i, iter);
+ if ( crystal_get_user_flag(crystals[i].cr) != 0 ) continue;
+ write_to_pgraph(fh, crystals[i].refls, full,
+ crystals[i].cr, i, iter);
}
fclose(fh);
}
-static void all_residuals(Crystal **crystals, int n_crystals, RefList *full,
+static void all_residuals(struct crystal_refls *crystals, int n_crystals, RefList *full,
int no_free,
double *presidual, double *pfree_residual,
double *plog_residual, double *pfree_log_residual,
@@ -797,28 +797,28 @@ static void all_residuals(Crystal **crystals, int n_crystals, RefList *full,
double r, free_r, log_r, free_log_r;
int n;
- if ( crystal_get_user_flag(crystals[i]) ) continue;
+ if ( crystal_get_user_flag(crystals[i].cr) ) continue;
/* Scaling should have been done right before calling this */
- r = residual(crystals[i], full, 0, &n, NULL);
+ r = residual(crystals[i].refls, crystals[i].cr, full, 0, &n, NULL);
if ( n == 0 ) {
n_non_linear++;
} else if ( isnan(r) ) {
n_nan_linear++;
}
- free_r = residual(crystals[i], full, 1, &n, NULL);
+ free_r = residual(crystals[i].refls, crystals[i].cr, full, 1, &n, NULL);
if ( n == 0 ) {
n_non_linear_free++;
} else if ( isnan(free_r) ) {
n_nan_linear_free++;
}
- log_r = log_residual(crystals[i], full, 0, &n, NULL);
+ log_r = log_residual(crystals[i].refls, crystals[i].cr, full, 0, &n, NULL);
if ( n == 0 ) {
n_non_log++;
} else if ( isnan(log_r) ) {
n_nan_log++;
}
- free_log_r = log_residual(crystals[i], full, 1, &n, NULL);
+ free_log_r = log_residual(crystals[i].refls, crystals[i].cr, full, 1, &n, NULL);
if ( n == 0 ) {
n_non_log_free++;
} else if ( isnan(free_log_r) ) {
@@ -875,7 +875,7 @@ static void all_residuals(Crystal **crystals, int n_crystals, RefList *full,
}
-static void show_all_residuals(Crystal **crystals, int n_crystals,
+static void show_all_residuals(struct crystal_refls *crystals, int n_crystals,
RefList *full, int no_free)
{
double dev, free_dev, log_dev, free_log_dev;
@@ -895,7 +895,7 @@ struct log_qargs
{
int iter;
int next;
- Crystal **crystals;
+ struct crystal_refls *crystals;
struct image **images;
int n_crystals;
RefList *full;
@@ -909,6 +909,7 @@ struct log_qargs
struct log_args
{
Crystal *cr;
+ RefList *refls;
struct image *image;
RefList *full;
int scaleflags;
@@ -929,7 +930,8 @@ static void *get_log_task(void *vp)
task = malloc(sizeof(struct log_args));
if ( task == NULL ) return NULL;
- task->cr = qargs->crystals[qargs->next];
+ task->cr = qargs->crystals[qargs->next].cr;
+ task->refls = qargs->crystals[qargs->next].refls;
task->image = qargs->images[qargs->next];
task->full = qargs->full;
task->iter = qargs->iter;
@@ -946,12 +948,13 @@ static void *get_log_task(void *vp)
static void write_logs(void *vp, int cookie)
{
struct log_args *args = vp;
- write_specgraph(args->cr, args->image, args->full, args->iter, args->cnum,
- args->log_folder);
- write_gridscan(args->cr, args->image, args->full, args->iter, args->cnum,
- args->scaleflags, args->pmodel, args->log_folder);
- write_test_logs(args->cr, args->image, args->full, args->iter, args->cnum,
- args->log_folder);
+ write_specgraph(args->refls, args->cr, args->image, args->full,
+ args->iter, args->cnum, args->log_folder);
+ write_gridscan(args->refls, args->cr, args->image, args->full,
+ args->iter, args->cnum, args->scaleflags, args->pmodel,
+ args->log_folder);
+ write_test_logs(args->cr, args->image, args->full, args->iter,
+ args->cnum, args->log_folder);
}
@@ -965,7 +968,7 @@ static void done_log(void *vqargs, void *vp)
}
-static void write_logs_parallel(Crystal **crystals, struct image **images,
+static void write_logs_parallel(struct crystal_refls *crystals, struct image **images,
int n_crystals,
RefList *full, int iter, int n_threads,
int scaleflags, PartialityModel pmodel,
@@ -1088,7 +1091,7 @@ int main(int argc, char *argv[])
int no_scale = 0;
int no_Bscale = 0;
int no_pr = 0;
- Crystal **crystals;
+ struct crystal_refls *crystals;
struct image **images;
char *pmodel_str = NULL;
PartialityModel pmodel = PMODEL_XSPHERE;
@@ -1566,7 +1569,6 @@ int main(int argc, char *argv[])
do {
struct image *image;
- RefList *as;
int i;
image = stream_read_chunk(st, STREAM_REFLECTIONS);
@@ -1580,41 +1582,39 @@ int main(int argc, char *argv[])
for ( i=0; i<image->n_crystals; i++ ) {
Crystal *cr;
- Crystal **crystals_new;
+ struct crystal_refls *crystals_new;
struct image **images_new;
RefList *cr_refl;
- RefList *cr_refl_raw;
struct image *image_for_crystal;
double lowest_r;
n_crystals_seen++;
if ( n_crystals_seen <= start_after ) continue;
- if ( crystal_get_resolution_limit(image->crystals[i]) < min_res ) continue;
+ if ( crystal_get_resolution_limit(image->crystals[i].cr) < min_res ) continue;
- lowest_r = lowest_reflection(crystal_get_cell(image->crystals[i]));
- if ( crystal_get_profile_radius(image->crystals[i]) > 0.5*lowest_r ) {
+ lowest_r = lowest_reflection(crystal_get_cell(image->crystals[i].cr));
+ if ( crystal_get_profile_radius(image->crystals[i].cr) > 0.5*lowest_r ) {
ERROR("Rejecting %s %s crystal %i because "
"profile radius is obviously too big (%e %e).\n",
image->filename, image->ev, i,
- crystal_get_profile_radius(image->crystals[i]),
+ crystal_get_profile_radius(image->crystals[i].cr),
lowest_r);
continue;
}
crystals_new = realloc(crystals,
- (n_crystals+1)*sizeof(Crystal *));
+ (n_crystals+1)*sizeof(struct crystal_refls));
if ( crystals_new == NULL ) {
ERROR("Failed to allocate memory for crystal "
"list.\n");
return 1;
}
crystals = crystals_new;
- crystals[n_crystals] = crystal_copy_deep(image->crystals[i]);
- cr = crystals[n_crystals];
+ cr = crystal_copy_deep(image->crystals[i].cr);
+ crystals[n_crystals].cr = cr;
- images_new = realloc(images,
- (n_crystals+1)*sizeof(struct image *));
+ images_new = realloc(images, (n_crystals+1)*sizeof(struct image *));
if ( images_new == NULL ) {
ERROR("Failed to allocate memory for image list\n");
return 1;
@@ -1631,9 +1631,8 @@ int main(int argc, char *argv[])
*image_for_crystal = *image;
images[n_crystals] = image_for_crystal;
- image_for_crystal->n_crystals = 1;
- image_for_crystal->crystals = malloc(sizeof(Crystal *));
- image_for_crystal->crystals[0] = cr;
+ image_for_crystal->n_crystals = 0;
+ image_for_crystal->crystals = NULL;
image_for_crystal->filename = strdup(image->filename);
image_for_crystal->ev = safe_strdup(image->ev);
image_for_crystal->detgeom = NULL;
@@ -1644,19 +1643,16 @@ int main(int argc, char *argv[])
image_for_crystal->bad = NULL;
image_for_crystal->sat = NULL;
- /* This is the raw list of reflections */
- cr_refl_raw = crystal_get_reflections(cr);
-
- cr_refl = apply_max_adu(cr_refl_raw, max_adu);
- reflist_free(cr_refl_raw);
-
+ cr_refl = apply_max_adu(image->crystals[i].refls, max_adu);
if ( !no_free ) select_free_reflections(cr_refl, rng);
-
- as = asymmetric_indices(cr_refl, sym);
- crystal_set_reflections(cr, as);
- crystal_set_user_flag(cr, PRFLAG_OK);
+ image_add_crystal_refls(image_for_crystal, cr,
+ asymmetric_indices(cr_refl, sym));
reflist_free(cr_refl);
+ crystals[n_crystals].cr = image_for_crystal->crystals[0].cr;
+ crystals[n_crystals].refls = image_for_crystal->crystals[0].refls;
+
+ crystal_set_user_flag(cr, PRFLAG_OK);
if ( set_initial_params(cr, image_for_crystal,
sparams_fh, force_bandwidth,
force_radius, force_lambda) )
@@ -1697,14 +1693,13 @@ int main(int argc, char *argv[])
STATUS("Initial partiality calculation...\n");
for ( icryst=0; icryst<n_crystals; icryst++ ) {
- Crystal *cr = crystals[icryst];
- update_predictions(cr, images[icryst]);
+ Crystal *cr = crystals[icryst].cr;
+ RefList *refls = crystals[icryst].refls;
+ update_predictions(refls, cr, images[icryst]);
/* Polarisation correction requires kpred values */
- polarisation_correction(crystal_get_reflections(cr),
- crystal_get_cell(cr), polarisation);
-
- calculate_partialities(cr, images[icryst], pmodel);
+ polarisation_correction(refls, crystal_get_cell(cr), polarisation);
+ calculate_partialities(refls, cr, images[icryst], pmodel);
}
if (csplit != NULL) check_csplit(crystals, images, n_crystals, csplit);
diff --git a/src/post-refinement.c b/src/post-refinement.c
index 1bad55ea..c67c0348 100644
--- a/src/post-refinement.c
+++ b/src/post-refinement.c
@@ -64,7 +64,8 @@ struct rf_priv
PartialityModel pmodel;
Crystal *cr_tgt; /**< Crystal to use for testing modifications */
- struct image image_tgt; /**< Image structure to go with cr_tgt */
+ struct image image_tgt; /**< Image structure to go with cr_tgt */
+ RefList *refls; /**< The reflections to use */
};
@@ -193,11 +194,11 @@ static double calc_residual(struct rf_priv *pv, struct rf_alteration alter,
return NAN;
}
- update_predictions(pv->cr_tgt, &pv->image_tgt);
- calculate_partialities(pv->cr_tgt, &pv->image_tgt, pv->pmodel);
+ update_predictions(pv->refls, pv->cr_tgt, &pv->image_tgt);
+ calculate_partialities(pv->refls, pv->cr_tgt, &pv->image_tgt, pv->pmodel);
- return residual(pv->cr_tgt, pv->full, free, NULL, NULL);
+ return residual(pv->refls, pv->cr_tgt, pv->full, free, NULL, NULL);
}
@@ -263,9 +264,9 @@ static void reindex_cell(UnitCell *cell, SymOpList *amb, int idx)
}
-static void try_reindex(Crystal *crin, struct image *image, const RefList *full,
- SymOpList *sym, SymOpList *amb, int scaleflags,
- PartialityModel pmodel)
+static void try_reindex(RefList **prefls, Crystal *crin, struct image *image,
+ const RefList *full, SymOpList *sym, SymOpList *amb,
+ int scaleflags, PartialityModel pmodel)
{
Crystal *cr;
double residual_original;
@@ -273,8 +274,8 @@ static void try_reindex(Crystal *crin, struct image *image, const RefList *full,
if ( sym == NULL || amb == NULL ) return;
- if ( scale_one_crystal(crin, full, scaleflags) ) return;
- residual_original = residual(crin, full, 0, NULL, NULL);
+ if ( scale_one_crystal(*prefls, crin, full, scaleflags) ) return;
+ residual_original = residual(*prefls, crin, full, 0, NULL, NULL);
cr = crystal_copy(crin);
@@ -291,23 +292,20 @@ static void try_reindex(Crystal *crin, struct image *image, const RefList *full,
reindex_cell(cell, amb, idx);
crystal_set_cell(cr, cell);
- list = reindex_reflections(crystal_get_reflections(crin),
- amb, sym, idx);
- crystal_set_reflections(cr, list);
-
- update_predictions(cr, image);
- calculate_partialities(cr, image, pmodel);
-
- if ( scale_one_crystal(cr, full, scaleflags) ) return;
- residual_flipped = residual(cr, full, 0, NULL, NULL);
+ list = reindex_reflections(*prefls, amb, sym, idx);
+ update_predictions(list, cr, image);
+ calculate_partialities(list, cr, image, pmodel);
+ if ( scale_one_crystal(list, cr, full, scaleflags) ) return;
+ residual_flipped = residual(list, cr, full, 0, NULL, NULL);
if ( residual_flipped < residual_original ) {
crystal_set_cell(crin, cell);
- crystal_set_reflections(crin, list);
+ reflist_free(*prefls);
+ *prefls = list;
residual_original = residual_flipped;
} else {
cell_free(crystal_get_cell(cr));
- reflist_free(crystal_get_reflections(cr));
+ reflist_free(list);
}
}
@@ -365,7 +363,7 @@ void write_test_logs(Crystal *crystal, struct image *image, const RefList *full,
}
-void write_specgraph(Crystal *crystal, struct image *image, const RefList *full,
+void write_specgraph(RefList *list, Crystal *crystal, struct image *image, const RefList *full,
signed int cycle, int serial,
const char *log_folder)
{
@@ -405,7 +403,7 @@ void write_specgraph(Crystal *crystal, struct image *image, const RefList *full,
ins[1] = '\0';
}
- for ( refl = first_refl(crystal_get_reflections(crystal), &iter);
+ for ( refl = first_refl(list, &iter);
refl != NULL;
refl = next_refl(refl, iter) )
{
@@ -440,7 +438,8 @@ void write_specgraph(Crystal *crystal, struct image *image, const RefList *full,
}
-static void write_angle_grid(Crystal *cr, struct image *image, const RefList *full,
+static void write_angle_grid(RefList *list_in, Crystal *cr, struct image *image,
+ const RefList *full,
signed int cycle, int serial, int scaleflags,
PartialityModel pmodel,
const char *log_folder)
@@ -449,7 +448,6 @@ static void write_angle_grid(Crystal *cr, struct image *image, const RefList *fu
char fn[64];
char ins[16];
struct rf_priv priv;
- RefList *list;
UnitCell *cell;
Spectrum *spectrum;
@@ -463,8 +461,7 @@ static void write_angle_grid(Crystal *cr, struct image *image, const RefList *fu
priv.image_tgt = *image;
spectrum = spectrum_new();
priv.image_tgt.spectrum = spectrum;
- list = copy_reflist(crystal_get_reflections(cr));
- crystal_set_reflections(priv.cr_tgt, list);
+ priv.refls = copy_reflist(list_in);
cell = cell_new_from_cell(crystal_get_cell(cr));
crystal_set_cell(priv.cr_tgt, cell);
@@ -501,13 +498,14 @@ static void write_angle_grid(Crystal *cr, struct image *image, const RefList *fu
fclose(fh);
}
- reflist_free(crystal_get_reflections(priv.cr_tgt));
+ reflist_free(priv.refls);
crystal_free(priv.cr_tgt);
spectrum_free(spectrum);
}
-static void write_radius_grid(Crystal *cr, struct image *image, const RefList *full,
+static void write_radius_grid(RefList *list_in, Crystal *cr, struct image *image,
+ const RefList *full,
signed int cycle, int serial, int scaleflags,
PartialityModel pmodel,
const char *log_folder)
@@ -516,7 +514,6 @@ static void write_radius_grid(Crystal *cr, struct image *image, const RefList *f
char fn[64];
char ins[16];
struct rf_priv priv;
- RefList *list;
UnitCell *cell;
Spectrum *spectrum;
@@ -530,8 +527,7 @@ static void write_radius_grid(Crystal *cr, struct image *image, const RefList *f
priv.image_tgt = *image;
spectrum = spectrum_new();
priv.image_tgt.spectrum = spectrum;
- list = copy_reflist(crystal_get_reflections(cr));
- crystal_set_reflections(priv.cr_tgt, list);
+ priv.refls = copy_reflist(list_in);
cell = cell_new_from_cell(crystal_get_cell(cr));
crystal_set_cell(priv.cr_tgt, cell);
@@ -568,19 +564,20 @@ static void write_radius_grid(Crystal *cr, struct image *image, const RefList *f
fclose(fh);
}
- reflist_free(crystal_get_reflections(priv.cr_tgt));
+ reflist_free(priv.refls);
crystal_free(priv.cr_tgt);
spectrum_free(spectrum);
}
-void write_gridscan(Crystal *cr, struct image *image, const RefList *full,
+void write_gridscan(RefList *list,
+ Crystal *cr, struct image *image, const RefList *full,
signed int cycle, int serial, int scaleflags,
PartialityModel pmodel,
const char *log_folder)
{
- write_angle_grid(cr, image, full, cycle, serial, scaleflags, pmodel, log_folder);
- write_radius_grid(cr, image, full, cycle, serial, scaleflags, pmodel, log_folder);
+ write_angle_grid(list, cr, image, full, cycle, serial, scaleflags, pmodel, log_folder);
+ write_radius_grid(list, cr, image, full, cycle, serial, scaleflags, pmodel, log_folder);
}
@@ -646,7 +643,8 @@ static void zero_alter(struct rf_alteration *alter)
}
-static void do_pr_refine(Crystal *cr, struct image *image, const RefList *full,
+static void do_pr_refine(RefList **plist_in, Crystal *cr, struct image *image,
+ const RefList *full,
PartialityModel pmodel, int serial,
int cycle, int write_logs,
SymOpList *sym, SymOpList *amb, int scaleflags,
@@ -656,12 +654,11 @@ static void do_pr_refine(Crystal *cr, struct image *image, const RefList *full,
struct rf_alteration alter;
int n_iter = 0;
double fom, freefom;
- RefList *list;
FILE *fh = NULL;
UnitCell *cell;
Spectrum *spectrum;
- try_reindex(cr, image, full, sym, amb, scaleflags, pmodel);
+ try_reindex(plist_in, cr, image, full, sym, amb, scaleflags, pmodel);
zero_alter(&alter);
@@ -675,8 +672,7 @@ static void do_pr_refine(Crystal *cr, struct image *image, const RefList *full,
priv.image_tgt = *image;
spectrum = spectrum_new();
priv.image_tgt.spectrum = spectrum;
- list = copy_reflist(crystal_get_reflections(cr));
- crystal_set_reflections(priv.cr_tgt, list);
+ priv.refls = copy_reflist(*plist_in);
cell = cell_new_from_cell(crystal_get_cell(cr));
crystal_set_cell(priv.cr_tgt, cell);
@@ -722,13 +718,13 @@ static void do_pr_refine(Crystal *cr, struct image *image, const RefList *full,
/* Apply the final shifts */
apply_parameters(cr, cr, image, image, alter);
- update_predictions(cr, image);
- calculate_partialities(cr, image, pmodel);
+ update_predictions(*plist_in, cr, image);
+ calculate_partialities(*plist_in, cr, image, pmodel);
if ( write_logs ) {
- write_gridscan(cr, image, full, cycle, serial, scaleflags,
+ write_gridscan(*plist_in, cr, image, full, cycle, serial, scaleflags,
pmodel, log_folder);
- write_specgraph(cr, image, full, cycle, serial, log_folder);
+ write_specgraph(*plist_in, cr, image, full, cycle, serial, log_folder);
write_test_logs(cr, image, full, cycle, serial, log_folder);
}
@@ -740,7 +736,7 @@ static void do_pr_refine(Crystal *cr, struct image *image, const RefList *full,
fclose(fh);
}
- reflist_free(crystal_get_reflections(priv.cr_tgt));
+ reflist_free(priv.refls);
crystal_free(priv.cr_tgt);
spectrum_free(spectrum);
}
@@ -750,6 +746,7 @@ struct refine_args
{
RefList *full;
Crystal *crystal;
+ RefList **prefls;
struct image *image;
PartialityModel pmodel;
int serial;
@@ -766,7 +763,7 @@ struct pr_queue_args
{
int n_started;
int n_done;
- Crystal **crystals;
+ struct crystal_refls *crystals;
struct image **images;
int n_crystals;
struct refine_args task_defaults;
@@ -780,7 +777,8 @@ static void refine_image(void *task, int id)
write_logs = !pargs->no_logs && (pargs->serial % 20 == 0);
- do_pr_refine(pargs->crystal, pargs->image, pargs->full, pargs->pmodel,
+ do_pr_refine(pargs->prefls, pargs->crystal, pargs->image,
+ pargs->full, pargs->pmodel,
pargs->serial, pargs->cycle, write_logs,
pargs->sym, pargs->amb, pargs->scaleflags,
pargs->log_folder);
@@ -795,7 +793,8 @@ static void *get_image(void *vqargs)
task = malloc(sizeof(struct refine_args));
memcpy(task, &qargs->task_defaults, sizeof(struct refine_args));
- task->crystal = qargs->crystals[qargs->n_started];
+ task->crystal = qargs->crystals[qargs->n_started].cr;
+ task->prefls = &qargs->crystals[qargs->n_started].refls;
task->image = qargs->images[qargs->n_started];
task->serial = qargs->n_started;
@@ -816,7 +815,7 @@ static void done_image(void *vqargs, void *task)
}
-void refine_all(Crystal **crystals, struct image **images, int n_crystals,
+void refine_all(struct crystal_refls *crystals, struct image **images, int n_crystals,
RefList *full, int nthreads, PartialityModel pmodel,
int cycle, int no_logs,
SymOpList *sym, SymOpList *amb, int scaleflags,
@@ -827,6 +826,7 @@ void refine_all(Crystal **crystals, struct image **images, int n_crystals,
task_defaults.full = full;
task_defaults.crystal = NULL;
+ task_defaults.prefls = NULL;
task_defaults.image = NULL;
task_defaults.pmodel = pmodel;
task_defaults.cycle = cycle;
diff --git a/src/post-refinement.h b/src/post-refinement.h
index 7eb1fd0b..91c0f4f8 100644
--- a/src/post-refinement.h
+++ b/src/post-refinement.h
@@ -58,19 +58,20 @@ enum prflag
extern const char *str_prflag(enum prflag flag);
-extern void refine_all(Crystal **crystals, struct image **images, int n_crystals,
+extern void refine_all(struct crystal_refls *crystals, struct image **images,
+ int n_crystals,
RefList *full, int nthreads, PartialityModel pmodel,
int cycle, int no_logs,
SymOpList *sym, SymOpList *amb, int scaleflags,
const char *log_folder);
-extern void write_gridscan(Crystal *cr, struct image *image,
+extern void write_gridscan(RefList *list, Crystal *cr, struct image *image,
const RefList *full,
int cycle, int serial, int scaleflags,
PartialityModel model,
const char *log_folder);
-extern void write_specgraph(Crystal *crystal, struct image *image,
+extern void write_specgraph(RefList *list, Crystal *crystal, struct image *image,
const RefList *full,
signed int cycle, int serial,
const char *log_folder);
diff --git a/src/rejection.c b/src/rejection.c
index 4e3ff6ba..d3aa9b1f 100644
--- a/src/rejection.c
+++ b/src/rejection.c
@@ -63,7 +63,7 @@ static double mean_intensity(RefList *list)
/* Reject really obvious outliers */
-void early_rejection(Crystal **crystals, int n)
+void early_rejection(struct crystal_refls *crystals, int n)
{
int i;
double m = 0.0;
@@ -73,18 +73,16 @@ void early_rejection(Crystal **crystals, int n)
for ( i=0; i<n; i++ ) {
double u;
- RefList *list = crystal_get_reflections(crystals[i]);
- u = mean_intensity(list);
+ u = mean_intensity(crystals[i].refls);
m += u;
fprintf(fh, "%i %f\n", i, u);
}
mean_m = m/n;
for ( i=0; i<n; i++ ) {
double u;
- RefList *list = crystal_get_reflections(crystals[i]);
- u = mean_intensity(list);
+ u = mean_intensity(crystals[i].refls);
if ( u/mean_m < 0.2 ) {
- crystal_set_user_flag(crystals[i], 5);
+ crystal_set_user_flag(crystals[i].cr, 5);
n_flag++;
}
}
@@ -219,7 +217,7 @@ static double calculate_cchalf(RefList *template, RefList *full,
* If the crystal is marked as bad, we should not remove it
* because it did not contribute in the first place. */
if ( exclude != NULL && !crystal_get_user_flag(exclude) ) {
- exrefl = find_refl(crystal_get_reflections(exclude), h, k, l);
+ exrefl = find_refl(template, h, k, l);
} else {
exrefl = NULL;
}
@@ -275,7 +273,7 @@ static double calculate_cchalf(RefList *template, RefList *full,
struct deltacchalf_queue_args
{
RefList *full;
- Crystal **crystals;
+ struct crystal_refls *crystals;
int n_crystals;
int n_done;
int n_started;
@@ -289,6 +287,7 @@ struct deltacchalf_worker_args
{
RefList *full;
Crystal *crystal;
+ RefList *refls;
int crystal_number;
int non;
int nan;
@@ -304,7 +303,8 @@ static void *create_deltacchalf_job(void *vqargs)
wargs = malloc(sizeof(struct deltacchalf_worker_args));
wargs->full = qargs->full;
- wargs->crystal = qargs->crystals[qargs->n_started];
+ wargs->crystal = qargs->crystals[qargs->n_started].cr;
+ wargs->refls = qargs->crystals[qargs->n_started].refls;
wargs->crystal_number = qargs->n_started;
wargs->non = 0;
wargs->nan = 0;
@@ -320,9 +320,8 @@ static void run_deltacchalf_job(void *vwargs, int cookie)
double cchalf, cchalfi;
struct deltacchalf_worker_args *wargs = vwargs;
int nref = 0;
- RefList *template = crystal_get_reflections(wargs->crystal);
- cchalf = calculate_cchalf(template, wargs->full, NULL, &nref);
- cchalfi = calculate_cchalf(template, wargs->full, wargs->crystal, &nref);
+ cchalf = calculate_cchalf(wargs->refls, wargs->full, NULL, &nref);
+ cchalfi = calculate_cchalf(wargs->refls, wargs->full, wargs->crystal, &nref);
//STATUS("Frame %i:", i);
//STATUS(" With = %f ", cchalf*100.0);
//STATUS("Without = %f", cchalfi*100.0);
@@ -355,8 +354,8 @@ static void finalise_deltacchalf_job(void *vqargs, void *vwargs)
}
-static void check_deltacchalf(Crystal **crystals, int n, RefList *full,
- int n_threads)
+static void check_deltacchalf(struct crystal_refls *crystals, int n,
+ RefList *full, int n_threads)
{
double cchalf;
int i;
@@ -409,7 +408,7 @@ static void check_deltacchalf(Crystal **crystals, int n, RefList *full,
if ( isnan(vals[i]) || isinf(vals[i])
|| ((vals[i]<0.0) && (vals[i] < mean-2.0*sd)) )
{
- crystal_set_user_flag(crystals[i], PRFLAG_DELTACCHALF);
+ crystal_set_user_flag(crystals[i].cr, PRFLAG_DELTACCHALF);
}
}
@@ -417,7 +416,7 @@ static void check_deltacchalf(Crystal **crystals, int n, RefList *full,
}
-static void show_duds(Crystal **crystals, int n_crystals)
+static void show_duds(struct crystal_refls *crystals, int n_crystals)
{
int j;
int bads[32];
@@ -427,7 +426,7 @@ static void show_duds(Crystal **crystals, int n_crystals)
for ( j=0; j<n_crystals; j++ ) {
int flag;
- flag = crystal_get_user_flag(crystals[j]);
+ flag = crystal_get_user_flag(crystals[j].cr);
assert(flag < 32);
bads[flag]++;
if ( flag != PRFLAG_OK ) any_bad++;
@@ -444,8 +443,8 @@ static void show_duds(Crystal **crystals, int n_crystals)
}
-void check_rejection(Crystal **crystals, int n, RefList *full, double max_B,
- int no_deltacchalf, int n_threads)
+void check_rejection(struct crystal_refls *crystals, int n, RefList *full,
+ double max_B, int no_deltacchalf, int n_threads)
{
int i;
int n_acc = 0;
@@ -456,10 +455,10 @@ void check_rejection(Crystal **crystals, int n, RefList *full, double max_B,
}
for ( i=0; i<n; i++ ) {
- if ( fabs(crystal_get_Bfac(crystals[i])) > max_B ) {
- crystal_set_user_flag(crystals[i], PRFLAG_BIGB);
+ if ( fabs(crystal_get_Bfac(crystals[i].cr)) > max_B ) {
+ crystal_set_user_flag(crystals[i].cr, PRFLAG_BIGB);
}
- if ( crystal_get_user_flag(crystals[i]) == 0 ) n_acc++;
+ if ( crystal_get_user_flag(crystals[i].cr) == 0 ) n_acc++;
}
show_duds(crystals, n);
diff --git a/src/rejection.h b/src/rejection.h
index 7dc2c92b..152c004e 100644
--- a/src/rejection.h
+++ b/src/rejection.h
@@ -35,10 +35,10 @@
#endif
-#include "crystal.h"
+#include "image.h"
-extern void early_rejection(Crystal **crystals, int n);
-extern void check_rejection(Crystal **crystals, int n, RefList *full,
+extern void early_rejection(struct crystal_refls *crystals, int n);
+extern void check_rejection(struct crystal_refls *crystals, int n, RefList *full,
double max_B, int no_deltacchalf, int n_threads);
#endif /* REJECTION_H */
diff --git a/src/scaling.c b/src/scaling.c
index f007b757..52954f9a 100644
--- a/src/scaling.c
+++ b/src/scaling.c
@@ -53,6 +53,7 @@ struct scale_args
{
RefList *full;
Crystal *crystal;
+ RefList *refls;
int flags;
};
@@ -61,7 +62,7 @@ struct scale_queue_args
{
int n_started;
int n_done;
- Crystal **crystals;
+ struct crystal_refls *crystals;
int n_crystals;
struct scale_args task_defaults;
};
@@ -70,7 +71,7 @@ struct scale_queue_args
static void scale_crystal(void *task, int id)
{
struct scale_args *pargs = task;
- scale_one_crystal(pargs->crystal, pargs->full, pargs->flags);
+ scale_one_crystal(pargs->refls, pargs->crystal, pargs->full, pargs->flags);
}
@@ -82,7 +83,8 @@ static void *get_crystal(void *vqargs)
task = malloc(sizeof(struct scale_args));
memcpy(task, &qargs->task_defaults, sizeof(struct scale_args));
- task->crystal = qargs->crystals[qargs->n_started];
+ task->crystal = qargs->crystals[qargs->n_started].cr;
+ task->refls = qargs->crystals[qargs->n_started].refls;
qargs->n_started++;
@@ -99,8 +101,8 @@ static void done_crystal(void *vqargs, void *task)
}
-static double total_log_r(Crystal **crystals, int n_crystals, RefList *full,
- int *ninc)
+static double total_log_r(struct crystal_refls *crystals, int n_crystals,
+ RefList *full, int *ninc)
{
int i;
double total = 0.0;
@@ -108,8 +110,9 @@ static double total_log_r(Crystal **crystals, int n_crystals, RefList *full,
for ( i=0; i<n_crystals; i++ ) {
double r;
- if ( crystal_get_user_flag(crystals[i]) ) continue;
- r = log_residual(crystals[i], full, 0, NULL, NULL);
+ if ( crystal_get_user_flag(crystals[i].cr) ) continue;
+ r = log_residual(crystals[i].refls, crystals[i].cr,
+ full, 0, NULL, NULL);
if ( isnan(r) ) continue;
total += r;
n++;
@@ -121,7 +124,7 @@ static double total_log_r(Crystal **crystals, int n_crystals, RefList *full,
/* Perform iterative scaling, all the way to convergence */
-void scale_all(Crystal **crystals, int n_crystals, int nthreads, int scaleflags)
+void scale_all(struct crystal_refls *crystals, int n_crystals, int nthreads, int scaleflags)
{
struct scale_args task_defaults;
struct scale_queue_args qargs;
@@ -163,7 +166,7 @@ void scale_all(Crystal **crystals, int n_crystals, int nthreads, int scaleflags)
int i;
double meanB = 0.0;
for ( i=0; i<n_crystals; i++ ) {
- meanB += crystal_get_Bfac(crystals[i]);
+ meanB += crystal_get_Bfac(crystals[i].cr);
}
meanB /= n_crystals;
STATUS("Mean B = %e\n", meanB);
@@ -181,7 +184,8 @@ void scale_all(Crystal **crystals, int n_crystals, int nthreads, int scaleflags)
/* Calculates G and B, by which cr's reflections should be multiplied to fit reference */
-int scale_one_crystal(Crystal *cr, const RefList *listR, int flags)
+int scale_one_crystal(const RefList *listS, Crystal *cr,
+ const RefList *listR, int flags)
{
const Reflection *reflS;
RefListIterator *iter;
@@ -202,7 +206,6 @@ int scale_one_crystal(Crystal *cr, const RefList *listR, int flags)
int n_part = 0;
int n_nom = 0;
int n_red = 0;
- RefList *listS = crystal_get_reflections(cr);
UnitCell *cell = crystal_get_cell(cr);
double G, B;
diff --git a/src/scaling.h b/src/scaling.h
index e47a845d..27ace6b7 100644
--- a/src/scaling.h
+++ b/src/scaling.h
@@ -45,9 +45,10 @@ enum ScaleFlags
SCALE_VERBOSE_ERRORS = 1<<1,
};
-extern int scale_one_crystal(Crystal *cr, const RefList *reference, int flags);
+extern int scale_one_crystal(const RefList *listS, Crystal *cr,
+ const RefList *reference, int flags);
-extern void scale_all(Crystal **crystals, int n_crystals, int nthreads,
- int flags);
+extern void scale_all(struct crystal_refls *crystals, int n_crystals,
+ int nthreads, int flags);
#endif /* SCALING_H */