| Bsoft 1.9 Bernard's software package

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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 )
158 img_multiply_by_fom(p);
159
160 if ( setmirror )
161 img_mirror_reflections(p);
162
163 if ( setnormal )
164 img_normalize_reflections(p);
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
Bimage::change_type
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1440
Boption::unit_cell
UnitCell unit_cell()
Definition: options.h:280
Bimage::phase_shift
int phase_shift(Vector3< double > shift)
Phase shifts a set of reflections.
Definition: Bimage_complex.cpp:233
M_PI_2
#define M_PI_2
Definition: utilities.h:54
UnitCell
Definition: UnitCell.h:22
Bstring::real
double real()
Definition: Bstring.cpp:584
Boption::values
unsigned long values(T1 &v1, T2 &v2)
Definition: options.h:114
Vector3::length
double length()
Definition: Vector3.h:198
img_check_space_group
double * img_check_space_group(Bimage *p, double resolution)
Checks the crystal space group symmetry and the shift to a symmetry axis.
Definition: img_symmetry.cpp:1247
UnitCell::gamma
void gamma(double d)
Definition: UnitCell.h:41
utilities.h
Header file for general utilities.
Boption::sampling
Vector3< double > sampling()
Definition: options.h:201
Boption::value
Bstring value
Definition: options.h:31
Boption::tag
Bstring tag
Definition: options.h:30
Bimage::compound_type
CompoundType compound_type()
Definition: Bimage.h:294
UnitCell::beta
void beta(double d)
Definition: UnitCell.h:40
Bimage::unit_cell
void unit_cell(UnitCell u)
Definition: Bimage.h:507
img_apply_space_group
double * img_apply_space_group(Bimage *p, double resolution)
Applies the necessary shift to superimpose the origin on a symmetry axis.
Definition: img_symmetry.cpp:1397
Vector3< float >
VERB_PROCESS
#define VERB_PROCESS
Definition: utilities.h:99
get_cmd_line
Bstring get_cmd_line(int argc, char **argv)
Returns the command line as a string.
Definition: utilities.cpp:36
UnitCell::a
void a(double d)
Definition: UnitCell.h:36
main
int main(int argc, char **argv)
Definition: breflect.cpp:51
verbose
int verbose
get_option_list
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
img_sfscale
int img_sfscale(Bimage *p, Bstring &hklname)
Scales the input reflections with a second set.
Definition: img_reflections.cpp:418
img_ampweigh.h
Header file for image utilities.
Boption::filename
Bstring filename()
Definition: options.h:85
TSimple
Definition: Bimage.h:68
timer.h
Utilities for timing functions.
Bimage
General image parameter class.
Definition: Bimage.h:150
img_mirror_reflections
int img_mirror_reflections(Bimage *p)
Mirrors a set of reflections by negating the phases.
Definition: img_reflections.cpp:64
M_PI
#define M_PI
Definition: utilities.h:51
read_img
Bimage * read_img(const char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
Definition: rwimg.cpp:75
Boption
A class for a command line input option.
Definition: options.h:27
Bimage::sampling
void sampling(double s)
Definition: Bimage.h:462
img_select_reflections
unsigned long img_select_reflections(Bimage *p, double hires, double lores, double cone, int weigh, double fomcut)
Selects reflections for output.
Definition: img_reflections.cpp:94
VERB_TIME
#define VERB_TIME
Definition: utilities.h:102
img_fourier.h
General FFT for n-dimensional data.
UnitCell::b
void b(double d)
Definition: UnitCell.h:37
Bimage::space_group
unsigned int space_group()
Definition: Bimage.h:502
img_fft
int img_fft(Bimage *p)
Fast Fourier transforms an image.
Definition: img_fourier.cpp:42
img_multiply_by_fom
int img_multiply_by_fom(Bimage *p)
Weighs a set of reflections by its figure-of-merit.
Definition: img_ampweigh.cpp:25
DataType
DataType
Base data type specifier.
Definition: Bimage.h:46
img_normalize_reflections
int img_normalize_reflections(Bimage *p)
Normalizes a set of reflections encoded as a complex image.
Definition: img_reflections.cpp:29
Bimage::FOM_maximum
double FOM_maximum()
Definition: Bimage.h:238
write_img
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
Boption::datatype
DataType datatype()
Definition: options.h:92
Boption::next
Boption * next
Definition: options.h:29
Unknown_Type
Definition: Bimage.h:47
UnitCell::alpha
void alpha(double d)
Definition: UnitCell.h:39
Bstring
Definition: Bstring.h:25
use
const char * use[]
Definition: breflect.cpp:22
Boption::vector3
Vector3< double > vector3()
Definition: options.h:153
img_symmetry.h
Header file for symmetry functions.
timer_report
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:67
option_kill
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:108
Bstring::integer
long integer()
Definition: Bstring.cpp:578
rwimg.h
Header file for 2D and 3D image I/O.
options.h
Header file for option handlers.
UnitCell::check
bool check()
Definition: UnitCell.h:34
img_sfmerge
int img_sfmerge(Bimage *p, Bstring &hklname)
Merges the input reflections with a second set.
Definition: img_reflections.cpp:477
Bstring::length
long length() const
Definition: Bstring.cpp:317
FFTW_FORWARD
Definition: fftw.h:64
Bimage::label
void label(Bstring s)
Definition: Bimage.h:216
VERB_LABEL
#define VERB_LABEL
Definition: utilities.h:98
Bimage::data_type
DataType data_type()
Definition: Bimage.h:292
Vector3::volume
double volume()
Definition: Vector3.h:207
bexit
int bexit(int value)
Exit function for cleanup and debugging.
Definition: utilities.cpp:285
img_reflections.h
Routines to manipulate reflection files.
timer_start
double timer_start()
Starts timer and prints the time.
Definition: timer.cpp:52
UnitCell::c
void c(double d)
Definition: UnitCell.h:38
Bimage::FOM_adjust
int FOM_adjust(double fommin, double fommax, double fomcut)
Adjust the figure-of-merit values to a new range.
Definition: Bimage.cpp:668
img_sfanalyze
int img_sfanalyze(Bimage *p)
Analyzes the FOM's of a set of reflections encoded as a complex image.
Definition: img_reflections.cpp:300