| Bsoft 2.0.5 Bernard's software package

bflat.cpp
Go to the documentation of this file.
1
12 #include "rwimg.h"
13 #include "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: bflat [options] input.img output.img",
25 "-------------------------------------------",
26 "Does phase extension by solvent flattening.",
27 "The amplitudes are defined in three possible mutually exclusive ways:",
28 "1. Derived from the input map (default).",
29 "2. Derived from a reference map.",
30 "3. Specified in an external amplitude map.",
31 " ",
32 "Actions:",
33 "-symmetrize C5 Apply point group symmetry.",
34 " ",
35 "Parameters:",
36 "-verbose 7 Verbosity of output.",
37 "-datatype u Force writing of a new data type.",
38 "-resolution 35,15.5,1.5 Resolution limit start, end and step (default 30,20,1).",
39 "-iterations 80 Iterations (default 1).",
40 "-exit 0.1 Exit condition based on amplitude RMSD (default 0.01).",
41 "-output 5 Number of iterations between writing output maps (default 100).",
42 " ",
43 "Input:",
44 "-Reference file.map File to generate amplitudes from (default amplitudes from input map).",
45 "-Amplitudes file.map File with amplitudes (default amplitudes from input map).",
46 "-Mask mask.tif Mask file.",
47 " ",
48 NULL
49 };
50
51 int main (int argc, char **argv)
52 {
53 // Initialize variables
54 Bsymmetry* sym = NULL; // Point group
55 DataType nudatatype(Unknown_Type); // Conversion to new type
56 int i; // loop variables
57 int imax(1); // largest iteration number
58 int iout(100); // iterations between writing output maps
59 double hi_res(20), lo_res(30); // High and low resolution limits
60 double step_res(1); // Resolution step size
61 double Rtarget(0.01); // Target for amplitude RMSD
62 Bstring maskfile; // Mask to use
63 Bstring reffile; // Reference file
64 Bstring ampfile; // Amplitude file
65
66 int optind;
67 Boption* option = get_option_list(use, argc, argv, optind);
68 Boption* curropt;
69 for ( curropt = option; curropt; curropt = curropt->next ) {
70 if ( curropt->tag == "symmetrize" )
71 sym = curropt->symmetry();
72 if ( curropt->tag == "datatype" )
73 nudatatype = curropt->datatype();
74 if ( curropt->tag == "resolution" )
75 if ( curropt->values(lo_res, hi_res, step_res) < 1 )
76 cerr << "-resolution: A high resolution limit must be specified!" << endl;
77 if ( curropt->tag == "iterations" )
78 if ( ( imax = curropt->value.integer() ) < 1 )
79 cerr << "-iterations: A number of iterations must be specified!" << endl;
80 if ( curropt->tag == "output" )
81 if ( ( iout = curropt->value.integer() ) < 1 )
82 cerr << "-output: A number of iterations must be specified!" << endl;
83 if ( curropt->tag == "exit" )
84 if ( ( Rtarget = curropt->value.real() ) < 1 )
85 cerr << "-exit: A target RMSD must be specified!" << endl;
86 if ( curropt->tag == "Reference" )
87 reffile = curropt->filename();
88 if ( curropt->tag == "Amplitude" )
89 ampfile = curropt->filename();
90 if ( curropt->tag == "Mask" )
91 maskfile = curropt->filename();
92 }
93 option_kill(option);
94
95 double ti = timer_start();
96
97 int dataflag(0);
98 if ( optind < argc - 1 ) dataflag = 1;
99 Bimage* p = read_img(argv[optind++], dataflag, 0);
100 if ( p == NULL ) {
101 cerr << "Error: No input file read!" << endl;
102 bexit(-1);
103 }
104
105 if ( optind >= argc ) {
106 cerr << "Error: No output file specified!" << endl;
107 bexit(-1);
108 }
109
110 p->label(get_cmd_line(argc, argv));
111
112 if ( nudatatype == Unknown_Type )
113 nudatatype = p->data_type();
114
115 p->change_type(Float);
116 p->rescale_to_avg_std(0, 1);
117
118 Bimage* pmask = NULL;
119 if ( maskfile.length() ) {
120 pmask = read_img(maskfile, dataflag, 0);
121 if ( pmask == NULL ) {
122 cerr << "Error: Mask file " << maskfile << " not read!" << endl;
123 bexit(-1);
124 }
125 }
126
127 Bimage* pamp = NULL;
128 Bimage* pref = NULL;
129
130 if ( reffile.length() ) {
131 pref = read_img(reffile, dataflag, 0);
132 } else if ( ampfile.length() ) {
133 pamp = read_img(ampfile, dataflag, 0);
134 } else {
135 pref = p->copy();
136 }
137
138 if ( pref ) pref->fft();
139
140 if ( hi_res ) p->fspace_bandpass(hi_res, 1e10, 0);
141
142 Bstring filename, outname(argv[optind]);
143 Bimage* pint = NULL;
144 double res = lo_res, R = 1e37;
145
146 if ( verbose )
147 cout << "Iter\tRes\tRMSD" << endl;
148 for ( i=0; i<imax && R>Rtarget; i++ ) {
149 if ( res > hi_res ) res -= step_res;
150
151 p->subtract_background();
152 p->multiply(pmask);
153
154 p->fft();
155
156 if ( pref ) {
157 R = p->merge_amplitudes_and_phases(pref, res, lo_res);
158 } else {
159 R = p->merge_amplitudes_and_phases(pamp);
160 p->fspace_bandpass(res, 1e10, 0);
161 }
162
163 if ( verbose )
164 cout << i+1 << tab << res << tab << R << endl;
165
166 p->fft_back();
167
168 if ( sym ) p->symmetrize(sym, 1);
169
170 p->statistics();
171
172 if ( (i+1)%iout == 0 && (i+1) != imax ) {
173 filename = outname.pre_rev('.') + Bstring(i+1, "_%04d.") + outname.post_rev('.');
174 pint = p->copy();
175 pint->change_type(nudatatype);
176 write_img(filename, pint, 0);
177 delete pint;
178 }
179 }
180
181 if ( optind < argc ) {
182 p->change_type(nudatatype);
183 write_img(argv[optind], p, 0);
184 }
185
186 delete p;
187 delete pamp;
188 delete pmask;
189 kill_symmetry(sym);
190
191 if ( verbose & VERB_TIME )
192 timer_report(ti);
193
194 bexit(0);
195 }
196
Bimage::change_type
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1743
Bstring::real
double real()
Definition: Bstring.cpp:545
DataType
DataType
Base data type specifier.
Definition: utilities.h:146
Bimage::fspace_bandpass
int fspace_bandpass(double res_hi, double res_lo=0, double width=0)
Applies a bandpass filter to an image.
Definition: Bimage_fspace.cpp:499
symmetry.h
Header file for general symmetry functions.
Bimage::fft
int fft()
Definition: Bimage.h:822
Bimage::fft_back
int fft_back()
Definition: Bimage.h:823
utilities.h
Header file for general utilities.
Boption::value
Bstring value
Definition: options.h:30
Boption::tag
Bstring tag
Definition: options.h:29
Bstring::length
long length() const
Definition: Bstring.cpp:263
Bimage::merge_amplitudes_and_phases
double merge_amplitudes_and_phases(Bimage *pamp)
Merges the amplitudes from one map with the phases of another.
Definition: Bimage_complex.cpp:1218
kill_symmetry
int kill_symmetry(Bsymmetry *sym)
Deallocates a symmetry structure.
Definition: symmetry.cpp:207
Bimage::multiply
void multiply(long j, Complex< double > cv)
Definition: Bimage.h:312
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
read_img
Bimage * read_img(char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
Definition: rwimg.cpp:76
get_cmd_line
string get_cmd_line(int argc, char **argv)
Returns the command line as a string.
Definition: utilities.cpp:36
Boption::filename
Bstring filename()
Definition: options.h:85
Bimage::subtract_background
int subtract_background()
Subtracts the background for each sub-image.
Definition: Bimage_background.cpp:337
timer.h
Utilities for timing functions.
Float
Definition: utilities.h:157
Bimage
General image parameter class.
Definition: Bimage.h:163
Bimage::statistics
long statistics()
Calculates the statistics for an image.
Definition: Bimage_stats.cpp:22
Boption
A class for a command line input option.
Definition: options.h:26
Bimage::label
void label(string s)
Definition: Bimage.h:235
VERB_TIME
#define VERB_TIME
Definition: utilities.h:110
Bimage::rescale_to_avg_std
int rescale_to_avg_std(double nuavg, double nustd)
Rescales the image data to a given average and standard deviation.
Definition: Bimage_rescale.cpp:163
main
int main(int argc, char **argv)
Definition: bflat.cpp:51
Boption::symmetry
Bsymmetry * symmetry()
Definition: options.h:252
Bimage::symmetrize
double symmetrize(Bstring &symmetry_string, int flag)
Definition: Bimage.h:1178
write_img
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Definition: rwimg.cpp:280
use
const char * use[]
Definition: bflat.cpp:22
Bstring::post_rev
Bstring post_rev(char c)
Definition: Bstring.cpp:428
Bsymmetry
Definition: symmetry.h:38
Boption::datatype
DataType datatype()
Definition: options.h:93
Boption::next
Boption * next
Definition: options.h:28
Bstring
Definition: Bstring.h:29
Bimage::copy
Bimage * copy()
Copies the header information and data of an image into a new image structure.
Definition: Bimage.cpp:2695
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:109
Bstring::integer
long integer()
Definition: Bstring.cpp:539
Unknown_Type
Definition: utilities.h:147
rwimg.h
Header file for 2D and 3D image I/O.
options.h
Header file for option handlers.
Bstring::pre_rev
Bstring pre_rev(char c)
Definition: Bstring.cpp:413
Bimage::data_type
DataType data_type()
Definition: Bimage.h:349
Boption::values
long values(T1 &v1, T2 &v2)
Definition: options.h:115
bexit
int bexit(int value)
Exit function for cleanup and debugging.
Definition: utilities.cpp:273
timer_start
double timer_start()
Starts timer and prints the time.
Definition: timer.cpp:52
tab
ostream & tab(ostream &out)
Definition: utilities.cpp:21
verbose
int verbose