Bsoft  1.9
Bernard's software package
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
breflect.cpp
Go to the documentation of this file.
1 
9 #include "rwimg.h"
10 #include "img_fourier.h"
11 #include "img_reflections.h"
12 #include "img_ampweigh.h"
13 #include "img_symmetry.h"
14 #include "utilities.h"
15 #include "options.h"
16 #include "timer.h"
17 
18 // Declaration of global variables
19 extern int verbose; // Level of output to the screen
20 
21 /* Usage assistance */
22 const char* use[] = {
23 " ",
24 "Usage: breflect [options] file.hkl file.hkl",
25 "-------------------------------------------",
26 "Edits and analyzes structure factor files.",
27 " ",
28 "Actions:",
29 "-fom 0,1.0,0.0 Rescale FOM to min and max and apply cutoff.",
30 "-weigh Weigh the amplitudes with the FOM.",
31 "-translate 1.5,-5.2,3 Translation in pixel coordinates.",
32 "-analyze Analyze structure factors.",
33 "-mirror Mirror = invert Friedel symmetry.",
34 "-normalize Normalize to average amplitude.",
35 "-scale file.hkl Scale SF with profile from input SF.",
36 "-combine file.hkl Combine SF with profile scaling with input SF.",
37 "-symmetry 1 Check symmetry for this space group.",
38 "-Symmetry 1 Apply symmetry for this space group.",
39 " ",
40 "Parameters:",
41 "-verbose 7 Verbosity of output.",
42 "-datatype u Force writing of a new data type.",
43 "-sampling 2,3.5,1 Sampling (angstrom/voxel, a single value sets all three).",
44 "-resolution 6.5,150 High and low resolution in A (default maximum in data).",
45 "-unitcell 96,96,100,90,90,90 Unit cell parameters.",
46 "-free 15 % flagged for R-free calculations (default 10%).",
47 " ",
48 NULL
49 };
50 
51 int main(int argc, char **argv)
52 {
53  // Initialize variables
54  DataType newdatatype = Unknown_Type; // Conversion to new type
55  int setanalyze(0);
56  int setmirror(0);
57  int setnormal(0);
58  float hires(0), lores(0); // Resolution limits
59 // float tol = 0.001; // Tolerance
60  Vector3<float> sampling; // Units for the three axes (A/pixel)
61  Vector3<float> shift; // Shift in fractional coordinates
62  int space(0);
63  int apply(0);
64  UnitCell uc(0,0,0,M_PI_2,M_PI_2,M_PI_2);
65  float fommin(0), fommax(0); // Keep old FOM's
66  float fomcut(0); // All reflections
67  int weigh(0); // Don't weigh amplitudes
68  float pfree(10); // % Rfree flags
69  Bstring scalefile;
70  Bstring combinefile;
71 
72  int optind;
73  Boption* option = get_option_list(use, argc, argv, optind);
74  Boption* curropt;
75  for ( curropt = option; curropt; curropt = curropt->next ) {
76  if ( curropt->tag == "datatype" )
77  newdatatype = curropt->datatype();
78  if ( curropt->tag == "sampling" )
79  sampling = curropt->sampling();
80  if ( curropt->tag == "translate" ) {
81  shift = curropt->vector3();
82  if ( shift.length() < 0.1 )
83  cerr << "-translate: Three values must be specified!" << endl;
84  }
85  if ( curropt->tag == "analyze" )
86  setanalyze = 1;
87  if ( curropt->tag == "resolution" )
88  if ( curropt->values(hires, lores) < 1 )
89  cerr << "-resolution: A resolution limit must be specified!" << endl;
90  if ( curropt->tag == "fom" )
91  if ( curropt->values(fommin, fommax, fomcut) > 0 )
92  if ( fommax <= 0 ) fommax = -1;
93  if ( curropt->tag == "symmetry" )
94  if ( ( space = curropt->value.integer() ) < 1 )
95  cerr << "-symmetry: A space group must be specified!" << endl;
96  if ( curropt->tag == "Symmetry" ) {
97  if ( ( space = curropt->value.integer() ) < 1 )
98  cerr << "-Symmetry: A space group must be specified!" << endl;
99  else apply = 1;
100  }
101  if ( curropt->tag == "unitcell" )
102  uc = curropt->unit_cell();
103  if ( curropt->tag == "mirror" )
104  setmirror = 1;
105  if ( curropt->tag == "normalize" )
106  setnormal = 1;
107  if ( curropt->tag == "weigh" )
108  weigh = 1;
109  if ( curropt->tag == "free" )
110  if ( ( pfree = curropt->value.real() ) < 0.0001 )
111  cerr << "-free: %% reflections flagged must be specified" << endl;
112  if ( curropt->tag == "scale" )
113  scalefile = curropt->filename();
114  if ( curropt->tag == "combine" )
115  combinefile = curropt->filename();
116  }
117  option_kill(option);
118 
119  double ti;
120  if ( verbose & VERB_TIME )
121  ti = timer_start();
122 
123  Bimage* p = read_img(argv[optind++], 1, -1);
124  if ( !p ) {
125  cerr << "Error: File not read!" << endl;
126  exit(-1);
127  }
128 
129  if ( newdatatype == Unknown_Type )
130  newdatatype = p->data_type();
131 
132  if ( sampling.volume() > 0 ) p->sampling(sampling);
133 
134  if ( space > 0 ) p->space_group(space);
135  if ( uc.check() ) p->unit_cell(uc);
136 
137  if ( verbose & VERB_PROCESS ) {
138  cout << "Resolution: " << hires << endl;
139  cout << "Sampling: " << p->sampling() << endl;
140  cout << "Space group: " << p->space_group() << endl;
141  cout << "Unit cell dimensions: " <<
142  uc.a() << " " << uc.b() << " " << uc.c() << endl;
143  cout << "Unit cell angles: " <<
144  uc.alpha()*180/M_PI << " " << uc.beta()*180/M_PI << " " << uc.gamma()*180/M_PI << endl << endl;
145  }
146 
147  if ( p->compound_type() == TSimple )
148  img_fft(FFTW_FORWARD, p);
149 
150  if ( hires ) img_select_reflections(p, hires, lores, M_PI_2, 0, 0);
151 
152  if ( fommax > 0 ) p->FOM_adjust(fommin, fommax, fomcut);
153 
154  if ( shift.length() )
155  p->phase_shift(shift);
156 
157  if ( weigh )
159 
160  if ( setmirror )
162 
163  if ( setnormal )
165 
166  if ( setanalyze )
167  img_sfanalyze(p);
168 
169  double* dx = NULL; // Shift vector
170  if ( p->space_group() > 1 ) {
171  if ( apply ) {
172  dx = img_apply_space_group(p, hires); // Apply symmetry, estimate shift
173  } else {
174  dx = img_check_space_group(p, hires); // Check symmetry, estimate shift
175  }
176  if ( verbose & VERB_LABEL )
177  cout << "Origin at: " << dx[0] << " " << dx[1] << " " << dx[2] << endl;
178  }
179 
180  if ( scalefile.length() )
181  img_sfscale(p, scalefile);
182 
183  if ( combinefile.length() )
184  img_sfmerge(p, combinefile);
185 
186  // Write an output file if a file name is given
187  if ( optind < argc ) {
188  p->change_type(newdatatype);
189  p->label(get_cmd_line(argc, argv));
190  p->FOM_maximum(pfree);
191  write_img(argv[optind], p);
192  }
193 
194  delete p;
195 
196  if ( verbose & VERB_TIME )
197  timer_report(ti);
198 
199  bexit(0);
200 }
201 
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1440
UnitCell unit_cell()
Definition: options.h:280
int phase_shift(Vector3< double > shift)
Phase shifts a set of reflections.
#define M_PI_2
Definition: utilities.h:54
double real()
Definition: Bstring.cpp:584
unsigned long values(T1 &v1, T2 &v2)
Definition: options.h:114
double length()
Definition: Vector3.h:198
double * img_check_space_group(Bimage *p, double resolution)
Checks the crystal space group symmetry and the shift to a symmetry axis.
void gamma(double d)
Definition: UnitCell.h:41
Header file for general utilities.
Vector3< double > sampling()
Definition: options.h:201
Bstring value
Definition: options.h:31
Bstring tag
Definition: options.h:30
CompoundType compound_type()
Definition: Bimage.h:294
void beta(double d)
Definition: UnitCell.h:40
void unit_cell(UnitCell u)
Definition: Bimage.h:507
double * img_apply_space_group(Bimage *p, double resolution)
Applies the necessary shift to superimpose the origin on a symmetry axis.
#define VERB_PROCESS
Definition: utilities.h:99
Bstring get_cmd_line(int argc, char **argv)
Returns the command line as a string.
Definition: utilities.cpp:36
void a(double d)
Definition: UnitCell.h:36
int main(int argc, char **argv)
Definition: breflect.cpp:51
int verbose
Boption * get_option_list(const char *use[], int argc, char *argv[], int &optind)
Parses command line arguments based on a template.
Definition: options.cpp:40
int img_sfscale(Bimage *p, Bstring &hklname)
Scales the input reflections with a second set.
Header file for image utilities.
Bstring filename()
Definition: options.h:85
Definition: Bimage.h:68
Utilities for timing functions.
General image parameter class.
Definition: Bimage.h:150
int img_mirror_reflections(Bimage *p)
Mirrors a set of reflections by negating the phases.
#define M_PI
Definition: utilities.h:51
Bimage * read_img(const char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
Definition: rwimg.cpp:75
A class for a command line input option.
Definition: options.h:27
void sampling(double s)
Definition: Bimage.h:462
unsigned long img_select_reflections(Bimage *p, double hires, double lores, double cone, int weigh, double fomcut)
Selects reflections for output.
#define VERB_TIME
Definition: utilities.h:102
General FFT for n-dimensional data.
void b(double d)
Definition: UnitCell.h:37
unsigned int space_group()
Definition: Bimage.h:502
int img_fft(Bimage *p)
Fast Fourier transforms an image.
Definition: img_fourier.cpp:42
int img_multiply_by_fom(Bimage *p)
Weighs a set of reflections by its figure-of-merit.
DataType
Base data type specifier.
Definition: Bimage.h:46
int img_normalize_reflections(Bimage *p)
Normalizes a set of reflections encoded as a complex image.
double FOM_maximum()
Definition: Bimage.h:238
int write_img(const char *filename, Bimage *p)
General driver function to write multiple image formats This is the only image writing function that ...
Definition: rwimg.cpp:251
DataType datatype()
Definition: options.h:92
Boption * next
Definition: options.h:29
void alpha(double d)
Definition: UnitCell.h:39
const char * use[]
Definition: breflect.cpp:22
Vector3< double > vector3()
Definition: options.h:153
Header file for symmetry functions.
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:67
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:108
long integer()
Definition: Bstring.cpp:578
Header file for 2D and 3D image I/O.
Header file for option handlers.
bool check()
Definition: UnitCell.h:34
int img_sfmerge(Bimage *p, Bstring &hklname)
Merges the input reflections with a second set.
long length() const
Definition: Bstring.cpp:317
void label(Bstring s)
Definition: Bimage.h:216
#define VERB_LABEL
Definition: utilities.h:98
DataType data_type()
Definition: Bimage.h:292
double volume()
Definition: Vector3.h:207
int bexit(int value)
Exit function for cleanup and debugging.
Definition: utilities.cpp:285
Routines to manipulate reflection files.
double timer_start()
Starts timer and prints the time.
Definition: timer.cpp:52
void c(double d)
Definition: UnitCell.h:38
int FOM_adjust(double fommin, double fommax, double fomcut)
Adjust the figure-of-merit values to a new range.
Definition: Bimage.cpp:668
int img_sfanalyze(Bimage *p)
Analyzes the FOM's of a set of reflections encoded as a complex image.