aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/partialator.c4
-rw-r--r--src/post-refinement.c18
-rw-r--r--src/post-refinement.h2
-rw-r--r--src/scaling.c46
-rw-r--r--src/scaling.h3
-rw-r--r--tests/linear_scale_check.c2
6 files changed, 42 insertions, 33 deletions
diff --git a/src/partialator.c b/src/partialator.c
index 7c3a481c..ced67edb 100644
--- a/src/partialator.c
+++ b/src/partialator.c
@@ -749,8 +749,8 @@ static void all_residuals(Crystal **crystals, int n_crystals, RefList *full,
if ( crystal_get_user_flag(crystals[i]) ) continue;
- r = residual(crystals[i], full, 0, NULL, NULL);
- free_r = residual(crystals[i], full, 1, NULL, NULL);
+ r = residual(crystals[i], full, 0, NULL, NULL, 1);
+ free_r = residual(crystals[i], full, 1, NULL, NULL, 1);
log_r = log_residual(crystals[i], full, 0, NULL, NULL);
free_log_r = log_residual(crystals[i], full, 1, NULL, NULL);
diff --git a/src/post-refinement.c b/src/post-refinement.c
index 7402b91c..ccaee00d 100644
--- a/src/post-refinement.c
+++ b/src/post-refinement.c
@@ -81,7 +81,7 @@ const char *str_prflag(enum prflag flag)
double residual(Crystal *cr, const RefList *full, int free,
- int *pn_used, const char *filename)
+ int *pn_used, const char *filename, int complain)
{
Reflection *refl;
RefListIterator *iter;
@@ -92,7 +92,7 @@ double residual(Crystal *cr, const RefList *full, int free,
double B = crystal_get_Bfac(cr);
UnitCell *cell = crystal_get_cell(cr);
- if ( linear_scale(full, crystal_get_reflections(cr), &G) ) {
+ if ( linear_scale(full, crystal_get_reflections(cr), &G, complain) ) {
return INFINITY;
}
@@ -308,12 +308,12 @@ static double residual_f(const gsl_vector *v, void *pp)
update_predictions(cr);
calculate_partialities(cr, PMODEL_XSPHERE);
- res = residual(cr, pv->full, 0, NULL, NULL);
+ res = residual(cr, pv->full, 0, NULL, NULL, 0);
if ( isnan(res) ) {
ERROR("NaN residual\n");
ERROR("G=%e, B=%e\n", crystal_get_osf(cr), crystal_get_Bfac(cr));
- residual(cr, pv->full, 0, NULL, "nan-residual.dat");
+ residual(cr, pv->full, 0, NULL, "nan-residual.dat", 1);
abort();
}
@@ -385,8 +385,8 @@ static void do_pr_refine(Crystal *cr, const RefList *full,
double G;
double residual_start, residual_free_start;
- residual_start = residual(cr, full, 0, NULL, NULL);
- residual_free_start = residual(cr, full, 1, NULL, NULL);
+ residual_start = residual(cr, full, 0, NULL, NULL, 1);
+ residual_free_start = residual(cr, full, 1, NULL, NULL, 1);
if ( verbose ) {
STATUS("\nPR initial: dev = %10.5e, free dev = %10.5e\n",
@@ -458,7 +458,7 @@ static void do_pr_refine(Crystal *cr, const RefList *full,
apply_parameters(min->x, initial, rv, cr);
update_predictions(cr);
calculate_partialities(cr, PMODEL_XSPHERE);
- r = linear_scale(full, crystal_get_reflections(cr), &G);
+ r = linear_scale(full, crystal_get_reflections(cr), &G, 1);
if ( r == 0 ) {
crystal_set_osf(cr, G);
} else {
@@ -467,8 +467,8 @@ static void do_pr_refine(Crystal *cr, const RefList *full,
if ( verbose ) {
STATUS("PR final: dev = %10.5e, free dev = %10.5e\n",
- residual(cr, full, 0, NULL, NULL),
- residual(cr, full, 1, NULL, NULL));
+ residual(cr, full, 0, NULL, NULL, 1),
+ residual(cr, full, 1, NULL, NULL, 1));
}
gsl_multimin_fminimizer_free(min);
diff --git a/src/post-refinement.h b/src/post-refinement.h
index 7f395013..3487ebac 100644
--- a/src/post-refinement.h
+++ b/src/post-refinement.h
@@ -64,6 +64,6 @@ extern double gradient(Crystal *cr, int k, Reflection *refl,
PartialityModel pmodel);
extern double residual(Crystal *cr, const RefList *full, int free,
- int *pn_used, const char *filename);
+ int *pn_used, const char *filename, int complain);
#endif /* POST_REFINEMENT_H */
diff --git a/src/scaling.c b/src/scaling.c
index 168531e8..9eec8a99 100644
--- a/src/scaling.c
+++ b/src/scaling.c
@@ -141,7 +141,7 @@ static void scale_crystal(void *task, int id)
double G;
/* Simple iterative algorithm */
- r = linear_scale(pargs->full, crystal_get_reflections(pargs->crystal), &G);
+ r = linear_scale(pargs->full, crystal_get_reflections(pargs->crystal), &G, 1);
if ( r == 0 ) {
crystal_set_osf(pargs->crystal, G);
} /* else don't change it */
@@ -178,7 +178,8 @@ static void done_crystal(void *vqargs, void *task)
/* Calculates G, by which list2 should be multiplied to fit list1 */
-int linear_scale(const RefList *list1, const RefList *list2, double *G)
+int linear_scale(const RefList *list1, const RefList *list2, double *G,
+ int complain_loudly)
{
const Reflection *refl1;
const Reflection *refl2;
@@ -263,17 +264,20 @@ int linear_scale(const RefList *list1, const RefList *list2, double *G)
}
if ( n < 2 ) {
- ERROR("Not enough reflections for scaling (had %i, but %i remain)\n", nb, n);
- if ( n_esd1 ) ERROR("%i reference reflection esd\n", n_esd1);
- if ( n_esd2 ) ERROR("%i subject reflection esd\n", n_esd2);
- if ( n_ih1 ) ERROR("%i reference reflection intensity\n", n_ih1);
- if ( n_ih2 ) ERROR("%i subject reflection intensity\n", n_ih2);
- if ( n_nan1 ) ERROR("%i reference reflection nan\n", n_nan1);
- if ( n_nan2 ) ERROR("%i subject reflection nan\n", n_nan2);
- if ( n_inf1 ) ERROR("%i reference reflection inf\n", n_inf1);
- if ( n_inf2 ) ERROR("%i subject reflection inf\n", n_inf2);
- if ( n_part ) ERROR("%i subject reflection partiality\n", n_part);
- if ( n_nom ) ERROR("%i no match in reference list\n", n_nom);
+ if ( complain_loudly ) {
+ ERROR("Not enough reflections for scaling (had %i, but %i remain)\n", nb, n);
+ if ( n_esd1 ) ERROR("%i reference reflection esd\n", n_esd1);
+ if ( n_esd2 ) ERROR("%i subject reflection esd\n", n_esd2);
+ if ( n_ih1 ) ERROR("%i reference reflection intensity\n", n_ih1);
+ if ( n_ih2 ) ERROR("%i subject reflection intensity\n", n_ih2);
+ if ( n_nan1 ) ERROR("%i reference reflection nan\n", n_nan1);
+ if ( n_nan2 ) ERROR("%i subject reflection nan\n", n_nan2);
+ if ( n_inf1 ) ERROR("%i reference reflection inf\n", n_inf1);
+ if ( n_inf2 ) ERROR("%i subject reflection inf\n", n_inf2);
+ if ( n_part ) ERROR("%i subject reflection partiality\n", n_part);
+ if ( n_nom ) ERROR("%i no match in reference list\n", n_nom);
+ }
+ *G = 1.0;
return 1;
}
@@ -285,14 +289,18 @@ int linear_scale(const RefList *list1, const RefList *list2, double *G)
}
if ( isnan(*G) ) {
- ERROR("Scaling gave NaN (%i pairs)\n", n);
- *G = 1.0;
- if ( n < 10 ) {
- int i;
- for ( i=0; i<n; i++ ) {
- STATUS("%i %e %e %e\n", i, x[i], y[i], w[n]);
+
+ if ( complain_loudly ) {
+ ERROR("Scaling gave NaN (%i pairs)\n", n);
+ if ( n < 10 ) {
+ int i;
+ for ( i=0; i<n; i++ ) {
+ STATUS("%i %e %e %e\n", i, x[i], y[i], w[n]);
+ }
}
}
+
+ *G = 1.0;
return 1;
}
diff --git a/src/scaling.h b/src/scaling.h
index 6ff0a337..b345029a 100644
--- a/src/scaling.h
+++ b/src/scaling.h
@@ -41,7 +41,8 @@
extern double log_residual(Crystal *cr, const RefList *full, int free,
int *pn_used, const char *filename);
-extern int linear_scale(const RefList *list1, const RefList *list2, double *G);
+extern int linear_scale(const RefList *list1, const RefList *list2, double *G,
+ int complain_loudly);
extern void scale_all_to_reference(Crystal **crystals, int n_crystals,
RefList *reference, int nthreads);
diff --git a/tests/linear_scale_check.c b/tests/linear_scale_check.c
index 21e21945..4cb6a1ba 100644
--- a/tests/linear_scale_check.c
+++ b/tests/linear_scale_check.c
@@ -70,7 +70,7 @@ int main(int argc, char *argv[])
set_partiality(refl2, 1.0);
}
- r = linear_scale(list1, list2, &G);
+ r = linear_scale(list1, list2, &G, 1);
STATUS("Scaling result: %i, G = %f\n", r, G);
return fail;