| Bsoft 2.0.5 Bernard's software package

bmodsel.cpp
Go to the documentation of this file.
1
9 #include "rwmolecule.h"
10 #include "rwmodel.h"
11 #include "rwimg.h"
12 #include "model_select.h"
13 #include "model_util.h"
14 #include "ps_model.h"
15 #include "utilities.h"
16 #include "options.h"
17 #include "timer.h"
18
19 // Declaration of global variables
20 extern int verbose; // Level of output to the screen
21
22
23 /* Usage assistance */
24 const char* use[] = {
25 " ",
26 "Usage: bmodsel [options] in1.star [in2.star...]",
27 "-----------------------------------------------",
28 "Selects and manipulates models and components.",
29 "Selection syntax:",
30 " #model_id",
31 " ^model_type_id",
32 " @component_id",
33 " %component_type_id",
34 " #model_id@component_id",
35 " #model_id%component_type_id",
36 " ^model_type_id@component_id",
37 " ^model_type_id%component_type_id",
38 " wild cards allowed: .",
39 " ",
40 "Actions for preparation:",
41 "-all Reset selection to all components before other selections.",
42 "-merge Merge models in different files rather than concatenate.",
43 "-invert Inverts selection.",
44 " ",
45 "Selections:",
46 "-select #Mod1@14 Select models and components.",
47 "-group 3 Select components with this selection flag number.",
48 "-number 24,36 Select models based on the number of components.",
49 "-sets 20,1 Generate sets of this size of selected components, ",
50 " with a flag not to select across model boundaries.",
51 "-closed order,3 Select models based on valency (valency,<n>) or polygon order (order,<n>).",
52 "-fullerene Select fullerene type models.",
53 "-nonfullerene Select non-fullerene type models.",
54 "-fom 0.25 Select: FOM cutoff.",
55 "-fraction 0.6 Select: FOM/FOMmax ratio cutoff.",
56 "-rank 5 Select: Rank components into a number of groups.",
57 "-prune fom Type of pruning: simple, fom, similar, large.",
58 "-minradius 70 Distance criterion for minimal allowed distance from the origin.",
59 "-maxradius 180 Distance criterion for maximal allowed distance from the origin.",
60 //"-average 5.9 Average components within this distance from each other.",
61 "-delete Delete non-selected models and components.",
62 " ",
63 "Actions for finishing:",
64 "-reset Reset selection to all components after other operations.",
65 " ",
66 "Parameters:",
67 "-verbose 7 Verbose output.",
68 "-distance 12.8 Distance criterion for pruning or overlap (default 10 angstrom).",
69 " ",
70 "Input:",
71 "-parameters param.star Input parameter file.",
72 "-overlap file.star Deselect components that overlap with this model (use with -distance).",
73 "-mask mask.pif Select components only within the mask.",
74 " ",
75 "Output:",
76 "-output file.star Output model parameter file.",
77 "-FOM histogram.ps Postscript output with component FOM distributions.",
78 " ",
79 NULL
80 };
81
82 int main(int argc, char **argv)
83 {
84 /* Initialize variables */
85 int all(0); // Keep selection as read from file
86 int reset(0); // Keep selection as ouput
87 int merge(0); // Flag to merge models rather than concatenate
88 int invert(0); // Flag to invert selection
89 Bstring mod_select; // Model and component selection
90 long group(0); // Group selection
91 long ncomp_min(0), ncomp_max(0); // Minimum and maximum number of components to select for
92 long set_size(0); // Size of sets
93 int set_flag(0); // Flag to keep set within model
94 int closure_rule(0); // Closure rule: 1=valency, 2=order
95 int val_order(0); // Valency or order - depending on rule
96 int fullerene(0); // Flag to select fullerenes
97 int nonfullerene(0); // Flag to select non-fullerenes
98 double fom_cutoff(0); // No selection based on FOM
99 double fom_fraction(0); // No selection based on FOM/FOMmax fraction
100 int rank(0); // Ranking selection into a number of groups
101 int prune_type(0); // Prune type: 1=simple, 2=fom, 3=fit, 4=large
102 Bstring prune_type_string("none"); // Prune type string
103 double distance(10); // Prune distance between components criterion
104 double minrad(0); // Prune distance criterion from the origin
105 double maxrad(0); // Prune distance criterion from the origin
106 int mod_comp_del(0); // Flag to delete non-selected models and components
107 Bstring atom_select("all");
108 Bstring paramfile; // Input parameter file name
109 Bstring ovlapfile; // Reference file name for deselecting overlaps
110 Bstring maskfile; // Mask for selection
111 Bstring outfile; // Output parameter file name
112 Bstring FOMps = NULL; // Output postscript file name for FOM histogram
113
114 int optind;
115 Boption* option = get_option_list(use, argc, argv, optind);
116 Boption* curropt;
117 for ( curropt = option; curropt; curropt = curropt->next ) {
118 if ( curropt->tag == "merge" ) merge = 1;
119 if ( curropt->tag == "all" ) all = 1;
120 if ( curropt->tag == "reset" ) reset = 1;
121 if ( curropt->tag == "invert" ) invert = 1;
122 if ( curropt->tag == "select" )
123 mod_select = curropt->value;
124 if ( curropt->tag == "group" )
125 if ( ( group = curropt->integer() ) < 1 )
126 cerr << "-group: A selection number must be specified!" << endl;
127 if ( curropt->tag == "number" )
128 if ( curropt->values(ncomp_min, ncomp_max) < 1 )
129 cerr << "-number: A number of components must be specified!" << endl;
130 if ( curropt->tag == "delete" ) mod_comp_del = 1;
131 if ( curropt->tag == "sets" )
132 if ( curropt->values(set_size, set_flag) < 1 )
133 cerr << "-sets: A set size must be specified!" << endl;
134 if ( curropt->tag == "closed" ) {
135 if ( curropt->value[0] == 'v' ) closure_rule = 1;
136 if ( curropt->value[0] == 'o' ) closure_rule = 2;
137 if ( curropt->value.contains(",") )
138 val_order = curropt->value.post(',').integer();
139 }
140 if ( curropt->tag == "fullerene" ) fullerene = 1;
141 if ( curropt->tag == "nonfullerene" ) nonfullerene = 1;
142 if ( curropt->tag == "fom" )
143 if ( ( fom_cutoff = curropt->value.real() ) < 0.0001 )
144 cerr << "-fom: A FOM cutoff must be specified!" << endl;
145 if ( curropt->tag == "fraction" )
146 if ( ( fom_fraction = curropt->value.real() ) < 0.0001 )
147 cerr << "-fraction: A fraction must be specified!" << endl;
148 if ( curropt->tag == "rank" )
149 if ( ( rank = curropt->value.integer() ) < 1 )
150 cerr << "-rank: A number must be specified!" << endl;
151 if ( curropt->tag == "prune" ) {
152 prune_type_string = curropt->value;
153 if ( prune_type_string.length() < 1 )
154 cerr << "-prune: A prune type must be specified!" << endl;
155 else {
156 if ( prune_type_string.contains("simp") ) prune_type = 1;
157 if ( prune_type_string.contains("fom") ) prune_type = 2;
158 if ( prune_type_string.contains("fit") ) prune_type = 3;
159 if ( prune_type_string.contains("simi") ) prune_type = 4;
160 if ( prune_type_string.contains("larg") ) prune_type = 5;
161 }
162 }
163 if ( curropt->tag == "distance" )
164 if ( ( distance = curropt->value.real() ) < 1 )
165 cerr << "-distance: The overlap distance must be specified!" << endl;
166 if ( curropt->tag == "minradius" )
167 if ( ( minrad = curropt->value.real() ) < 1 )
168 cerr << "-minradius: The minimum allowed distance from the origin must be specified!" << endl;
169 if ( curropt->tag == "maxradius" )
170 if ( ( maxrad = curropt->value.real() ) < 1 )
171 cerr << "-maxradius: The maximum allowed distance from the origin must be specified!" << endl;
172 if ( curropt->tag == "parameters" )
173 paramfile = curropt->filename();
174 if ( curropt->tag == "overlap" )
175 ovlapfile = curropt->filename();
176 if ( curropt->tag == "mask" )
177 maskfile = curropt->filename();
178 if ( curropt->tag == "output" )
179 outfile = curropt->filename();
180 if ( curropt->tag == "FOM" )
181 FOMps = curropt->filename();
182 }
183 option_kill(option);
184
185 double ti = timer_start();
186
187 // Read all the parameter files
188 Bstring* file_list = NULL;
189 while ( optind < argc ) string_add(&file_list, argv[optind++]);
190 if ( !file_list ) {
191 cerr << "Error: No parameter or image files specified!" << endl;
192 bexit(-1);
193 }
194
195 Bmodel* model = read_model(file_list);
196 string_kill(file_list);
197
198 if ( !model ) {
199 cerr << "Error: Input file not read!" << endl;
200 bexit(-1);
201 }
202
203 if ( all ) models_process(model, model_reset_selection);
204
205 if ( merge ) model_merge(model);
206
207 if ( mod_select.length() ) model_select(model, mod_select);
208
209 if ( group ) model_select(model, group);
210
211 if ( ncomp_min ) model_select_number_of_components(model, ncomp_min, ncomp_max);
212
213 if ( closure_rule ) model_select_closed(model, closure_rule, val_order);
214
215 if ( fullerene ) model_select_fullerene(model);
216
217 if ( nonfullerene ) model_select_non_fullerene(model);
218
219 if ( set_size ) model_select_sets(model, set_size, set_flag);
220
221 if ( fom_cutoff > 0 ) model_fom_deselect(model, fom_cutoff);
222
223 if ( fom_fraction > 0 ) model_fom_max_fraction_deselect(model, fom_fraction);
224
225 if ( rank > 1 ) model_fom_ranking(model, rank);
226
227 if ( minrad || maxrad ) models_radius_deselect(model, minrad, maxrad);
228
229 if ( prune_type > 4 ) models_process(model, distance, model_prune_large);
230 else if ( prune_type == 4 ) models_process(model, model_prune_similar);
231 else if ( prune_type == 3 ) models_process(model, distance, model_prune_fit);
232 else if ( prune_type == 2 ) models_process(model, distance, model_prune_fom);
233 else if ( prune_type == 1 ) models_process(model, distance, model_prune_simple);
234
235 if ( ovlapfile.length() )
236 model_find_overlap(model, ovlapfile, distance);
237
238 if ( maskfile.length() ) {
239 Bimage* pmask = read_img(maskfile, 1, 0);
240 model_select_in_mask(model, pmask);
241 delete pmask;
242 }
243
244 if ( invert )
245 models_process(model, model_invert_selection);
246
247 if ( FOMps.length() )
248 ps_model_fom_histogram(FOMps, model);
249
250 if ( mod_comp_del ) model_delete_non_selected(&model);
251
252 if ( reset ) models_process(model, model_reset_selection);
253
254 model_selection_stats(model);
255
256 // Write an output parameter format file if a name is given
257 if ( outfile.length() && model ) {
258 model_update_comment(model, argc, argv);
259 write_model(outfile, model);
260 }
261
262 model_kill(model);
263
264 if ( verbose & VERB_TIME )
265 timer_report(ti);
266
267 bexit(0);
268 }
269
distance
double distance(vector< T1 > &v1, vector< T2 > &v2)
Definition: Vector3.h:536
Bstring::real
double real()
Definition: Bstring.cpp:545
string_add
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
Definition: Bstring.cpp:705
model_prune_fit
long model_prune_fit(Bmodel *model, double distance)
Deselects components based on overlap distance and the FOM.
Definition: model_select.cpp:1805
Bstring::post
Bstring post(char c)
Definition: Bstring.cpp:394
use
const char * use[]
Definition: bmodsel.cpp:24
ps_model_fom_histogram
int ps_model_fom_histogram(Bstring &filename, Bmodel *model)
Postscript plot of the model component FOM histogram.
Definition: ps_model.cpp:141
model_select_fullerene
long model_select_fullerene(Bmodel *model)
Selects fullerene type models.
Definition: model_select.cpp:448
utilities.h
Header file for general utilities.
model_select
long model_select(Bmodel *model, Bstring &comptype)
Selects models, components and component types.
Definition: model_select.cpp:36
model_util.h
Library routines used for model processing.
model_prune_simple
long model_prune_simple(Bmodel *model, double mindist)
Prunes overlapping components based on a distance criterion.
Definition: model_select.cpp:1468
Boption::value
Bstring value
Definition: options.h:30
model_find_overlap
long model_find_overlap(Bmodel *model, Bstring &reffile, double distance)
Finds the components that overlap with the reference.
Definition: model_select.cpp:2056
Boption::tag
Bstring tag
Definition: options.h:29
Bstring::length
long length() const
Definition: Bstring.cpp:263
model_prune_large
long model_prune_large(Bmodel *model, double sampling)
Deselects components based on overlap distance and the FOM.
Definition: model_select.cpp:1936
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
Boption::filename
Bstring filename()
Definition: options.h:85
timer.h
Utilities for timing functions.
Bimage
General image parameter class.
Definition: Bimage.h:163
main
int main(int argc, char **argv)
Definition: bmodsel.cpp:82
Bstring::contains
bool contains(const Bstring &s)
Definition: Bstring.cpp:584
model_kill
int model_kill(Bmodel *model)
Deallocates all memory in the list.
Definition: rwmodel.cpp:1124
rwmolecule.h
Header file for reading reflection files.
Boption::integer
long integer()
Definition: options.h:100
model_prune_similar
long model_prune_similar(Bmodel *model)
Averages similar components and reduces redundancy.
Definition: model_select.cpp:1610
verbose
int verbose
Boption
A class for a command line input option.
Definition: options.h:26
model_select_closed
long model_select_closed(Bmodel *model, int closure_rule, int val_order)
Determines if a polyhedron is closed given a rule.
Definition: model_select.cpp:397
VERB_TIME
#define VERB_TIME
Definition: utilities.h:110
model_update_comment
int model_update_comment(Bmodel *model, int n, char **strings)
Puts a set of strings and time in the comment of a model.
Definition: rwmodel.cpp:1158
merge
int merge(Bimage *p, int padd)
Pads an image and shifts it to the middle.
Definition: sin_gal.cpp:270
model_fom_deselect
long model_fom_deselect(Bmodel *model, double fom_cutoff)
Deselects components based on the FOM.
Definition: model_select.cpp:1154
model_selection_stats
long model_selection_stats(Bmodel *model)
Calculates selection statistics.
Definition: model_select.cpp:870
model
Bmodel * model
Definition: bshow.cpp:32
read_model
Bmodel * read_model(Bstring &filename)
Definition: rwmodel.cpp:28
write_model
int write_model(Bstring &filename, Bmodel *model)
Writes model parameters.
Definition: rwmodel.cpp:91
Boption::next
Boption * next
Definition: options.h:28
model_invert_selection
long model_invert_selection(Bmodel *model)
Inverts the selection of all components.
Definition: model_select.cpp:286
Bstring
Definition: Bstring.h:29
model_reset_selection
long model_reset_selection(Bmodel *model)
Resets the selection to all components.
Definition: model_select.cpp:232
model_delete_non_selected
long model_delete_non_selected(Bmodel **model)
Deletes selected components and associated links from the model.
Definition: model_select.cpp:781
model_fom_ranking
long model_fom_ranking(Bmodel *model, int nrank)
Ranks components based on the FOM.
Definition: model_select.cpp:1307
model_fom_max_fraction_deselect
long model_fom_max_fraction_deselect(Bmodel *model, double fom_fraction)
Deselects components based on the FOM relative to the maximum FOM.
Definition: model_select.cpp:1180
rwmodel.h
Header file for reading and writing atomic model files.
models_radius_deselect
long models_radius_deselect(Bmodel *model, double minrad, double maxrad)
Deselects components based on the distance from the origin.
Definition: model_select.cpp:1215
timer_report
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:67
ps_model.h
Header file for postscript tools dealing with models.
model_select_sets
long model_select_sets(Bmodel *model, int size, int flag)
Selects sets of components, each set with the same size.
Definition: model_select.cpp:312
model_select_non_fullerene
long model_select_non_fullerene(Bmodel *model)
Selects non-fullerene type models.
Definition: model_select.cpp:477
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
model_select_in_mask
long model_select_in_mask(Bmodel *model, Bimage *pmask)
Selects components within a mask.
Definition: model_select.cpp:590
Bmodel
Definition: rwmodel.h:119
rwimg.h
Header file for 2D and 3D image I/O.
options.h
Header file for option handlers.
model_merge
long model_merge(Bmodel *model)
Merges components from all models into one.
Definition: model_util.cpp:299
models_process
long models_process(Bmodel *model, long(modfunc)(Bmodel *))
Process a list of models using the specified function.
Definition: model_util.cpp:36
model_prune_fom
long model_prune_fom(Bmodel *model, double distance)
Deselects components based on overlap distance and the FOM.
Definition: model_select.cpp:1518
model_select.h
Header file for reading and writing atomic model files.
model_select_number_of_components
long model_select_number_of_components(Bmodel *model, int ncomp_min, int ncomp_max)
Selects models within a range of the number of components.
Definition: model_select.cpp:359
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
string_kill
int string_kill(Bstring *list)
Kills a string linked list.
Definition: Bstring.cpp:760