/* * reflist-utils.c * * Utilities to complement the core reflist.c * * Copyright © 2012 Deutsches Elektronen-Synchrotron DESY, * a research centre of the Helmholtz Association. * * Authors: * 2011-2012 Thomas White * * This file is part of CrystFEL. * * CrystFEL is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * CrystFEL is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with CrystFEL. If not, see . * */ #define _ISOC99_SOURCE #define _GNU_SOURCE #include #include #include #include "reflist.h" #include "cell.h" #include "cell-utils.h" #include "utils.h" #include "reflist-utils.h" #include "symmetry.h" /** * SECTION:reflist-utils * @short_description: Reflection list utilities * @title: RefList utilities * @section_id: * @see_also: * @include: "reflist-utils.h" * @Image: * * There are some utility functions associated with the core %RefList. **/ int check_list_symmetry(RefList *list, const SymOpList *sym) { Reflection *refl; RefListIterator *iter; SymOpMask *mask; mask = new_symopmask(sym); if ( mask == NULL ) { ERROR("Couldn't create mask for list symmetry check.\n"); return 1; } for ( refl = first_refl(list, &iter); refl != NULL; refl = next_refl(refl, iter) ) { int j; int found = 0; signed int h, k, l; int n; get_indices(refl, &h, &k, &l); special_position(sym, mask, h, k, l); n = num_equivs(sym, mask); for ( j=0; j 1 ) { STATUS("Found %i %i %i: %i times:\n", h, k, l, found); for ( j=0; j *rmax ) *rmax = r; if ( r < *rmin ) *rmin = r; } } /** * max_intensity: * @list: A %RefList * * Returns: The maximum intensity in @list. **/ double max_intensity(RefList *list) { Reflection *refl; RefListIterator *iter; double max; max = -INFINITY; for ( refl = first_refl(list, &iter); refl != NULL; refl = next_refl(refl, iter) ) { double val = get_intensity(refl); if ( val > max ) max = val; } return max; } /** * res_cutoff: * @list: A %RefList * @cell: A %UnitCell with which to calculate 1/d values for @list * @min: Minimum acceptable value of 1/d * @max: Maximum acceptable value of 1/d * * Applies a resolution cutoff to @list, returning the new version and freeing * the old version. * * Returns: A new %RefList with resolution cutoff applied **/ RefList *res_cutoff(RefList *list, UnitCell *cell, double min, double max) { Reflection *refl; RefListIterator *iter; RefList *new; new = reflist_new(); for ( refl = first_refl(list, &iter); refl != NULL; refl = next_refl(refl, iter) ) { double one_over_d; signed int h, k, l; Reflection *n; get_indices(refl, &h, &k, &l); one_over_d = 2.0 * resolution(cell, h, k, l); if ( one_over_d < min ) continue; if ( one_over_d > max ) continue; n = add_refl(new, h, k, l); copy_data(n, refl); } reflist_free(list); return new; } /** * copy_reflist: * @list: A %RefList * * Returns: A copy of %RefList. **/ RefList *copy_reflist(RefList *list) { Reflection *refl; RefListIterator *iter; RefList *new; new = reflist_new(); for ( refl = first_refl(list, &iter); refl != NULL; refl = next_refl(refl, iter) ) { signed int h, k, l; Reflection *n; get_indices(refl, &h, &k, &l); n = add_refl(new, h, k, l); copy_data(n, refl); } return new; }