| Bsoft 2.0.5 Bernard's software package

bmodcol.cpp
Go to the documentation of this file.
1
9 #include "rwmodel.h"
10 #include "model_color.h"
11 #include "model_select.h"
12 #include "model_links.h"
13 #include "model_util.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: bmodcol [options] in.star",
25 "--------------------------------",
26 "Colors models based on selection.",
27 " ",
28 "Actions for preparation:",
29 "-all Reset selection to all components before other selections.",
30 " ",
31 "Selections:",
32 "-select #232@14 Select models and components.",
33 "-valence 3 Select components with the indicated valence.",
34 "-polygons 6 Select polygonal components with the indicated order.",
35 " ",
36 "Coloring actions:",
37 "-color 0.1,0.5,0.2,1 Color selected components and links.",
38 "-spectrum Color a model from red to blue by component order.",
39 "-density Color a model from red to blue by component density.",
40 "-fom Color a model from red to blue by component FOM.",
41 "-curvature Color a model from red to blue by curvature.",
42 "-chiral Color chiral vertices red (-) and blue (+).",
43 " ",
44 "Actions for finishing:",
45 "-reset Reset selection to all components before other selections.",
46 " ",
47 "Parameters:",
48 "-verbose 7 Verbosity of output.",
49 "-componentradius 0.5 Component display radius.",
50 "-linkradius 0.5 Link display radius.",
51 " ",
52 "Input:",
53 "-parameters param.star Input parameter file.",
54 " ",
55 "Output:",
56 "-output color.star Color model file.",
57 " ",
58 NULL
59 };
60
61 int main(int argc, char **argv)
62 {
63 /* Initialize variables */
64 int all(0); // Keep selection as read from file
65 int reset(0); // Keep selection as ouput
66 Bstring mod_select; // Model and component selection
67 int valence(0); // Valency selector
68 int poly_order(0); // Polygon selector
69 RGBA<float> color(-1,-1,-1,1); // Component color specification
70 int spectrum(0); // Flag to color models by component order
71 int density(0); // Flag to color models by component density
72 int fom(0); // Flag to color models by component FOM
73 int curvature(0); // Flag to color models by curvature
74 int chiral(0); // Flag to color chiral vertices
75 double compradius(0); // Component display radius
76 double linkradius(0); // Link display radius
77 Bstring paramfile; // Input parameter file name
78 Bstring outfile; // Output parameter file name
79
80 int optind;
81 Boption* option = get_option_list(use, argc, argv, optind);
82 Boption* curropt;
83 for ( curropt = option; curropt; curropt = curropt->next ) {
84 if ( curropt->tag == "all" ) all = 1;
85 if ( curropt->tag == "reset" ) reset = 1;
86 if ( curropt->tag == "select" )
87 mod_select = curropt->value;
88 if ( curropt->tag == "valence" )
89 if ( ( valence = curropt->value.integer() ) < 1 )
90 cerr << "-valence: A valency must be specified!" << endl;
91 if ( curropt->tag == "polygons" )
92 if ( ( poly_order = curropt->value.integer() ) < 1 )
93 cerr << "-polygons: A polygon order must be specified!" << endl;
94 if ( curropt->tag == "color" )
95 if ( curropt->values(color[0], color[1], color[2], color[3]) < 3 )
96 cerr << "-color: At least three color values must be specified!" << endl;
97 if ( curropt->tag == "spectrum" ) spectrum = 1;
98 if ( curropt->tag == "density" ) density = 1;
99 if ( curropt->tag == "fom" ) fom = 1;
100 if ( curropt->tag == "curvature" ) curvature = 1;
101 if ( curropt->tag == "chiral" ) chiral = 1;
102 if ( curropt->tag == "componentradius" )
103 if ( ( compradius = curropt->value.real() ) < 1 )
104 cerr << "-componentradius: The component display radius must be specified!" << endl;
105 if ( curropt->tag == "linkradius" )
106 if ( ( linkradius = curropt->value.real() ) < 1 )
107 cerr << "-linkradius: The link display radius must be specified!" << endl;
108 if ( curropt->tag == "parameters" )
109 paramfile = curropt->filename();
110 if ( curropt->tag == "output" )
111 outfile = curropt->filename();
112 }
113 option_kill(option);
114
115 double ti = timer_start();
116
117 // Read all the parameter files
118 Bstring* file_list = NULL;
119 while ( optind < argc ) string_add(&file_list, argv[optind++]);
120 if ( !file_list ) {
121 cerr << "Error: No model files specified!" << endl;
122 bexit(-1);
123 }
124
125 Bmodel* model = read_model(file_list, paramfile);
126 string_kill(file_list);
127
128 if ( !model ) {
129 cerr << "Error: Input file not read!" << endl;
130 bexit(-1);
131 }
132
133 if ( all ) models_process(model, model_reset_selection);
134
135 if ( mod_select.length() ) model_select(model, mod_select);
136
137 if ( valence > 0 ) model_select_valence(model, valence);
138
139 if ( poly_order > 0 ) model_select_polygons(model, poly_order);
140
141 if ( spectrum ) model_color_by_order(model);
142 else if ( curvature ) model_color_curvature(model);
143 else if ( chiral ) model_color_chiral_vertices(model);
144 else if ( density ) model_color_by_density(model);
145 else if ( fom ) model_color_by_fom(model);
146 else if ( color[0] >= 0 && color[1] >= 0 && color[2] >= 0 )
147 model_color_selected(model, color);
148
149 if ( reset ) models_process(model, model_reset_selection);
150
151 if ( compradius ) models_process(model, compradius, model_set_component_radius);
152
153 if ( linkradius ) models_process(model, linkradius, model_set_link_radius);
154
155 // Write an output parameter format file if a name is given
156 if ( outfile.length() && model ) {
157 model_update_comment(model, argc, argv);
158 write_model(outfile, model);
159 }
160
161 model_kill(model);
162
163 if ( verbose & VERB_TIME )
164 timer_report(ti);
165
166 bexit(0);
167 }
168
Bstring::real
double real()
Definition: Bstring.cpp:545
model_set_component_radius
long model_set_component_radius(Bmodel *model, double comprad)
Set the display radius for all components to a specific value.
Definition: rwmodel.cpp:1264
string_add
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
Definition: Bstring.cpp:705
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.
Boption::value
Bstring value
Definition: options.h:30
Boption::tag
Bstring tag
Definition: options.h:29
RGBA< float >
main
int main(int argc, char **argv)
Definition: bmodcol.cpp:61
model_select_polygons
long model_select_polygons(Bmodel *model, int order)
Selects model polygons with a given order.
Definition: model_select.cpp:535
use
const char * use[]
Definition: bmodcol.cpp:22
Bstring::length
long length() const
Definition: Bstring.cpp:263
model_color_chiral_vertices
int model_color_chiral_vertices(Bmodel *model)
Colors model vertices as a function of chirality.
Definition: model_color.cpp:259
model_links.h
Library routines used for model link processing.
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
Boption::filename
Bstring filename()
Definition: options.h:85
timer.h
Utilities for timing functions.
model_color_by_fom
int model_color_by_fom(Bmodel *model)
Colors model components by fom.
Definition: model_color.cpp:159
model_color.h
Functions to color models.
model_color_by_density
int model_color_by_density(Bmodel *model)
Colors model components by density.
Definition: model_color.cpp:118
model_kill
int model_kill(Bmodel *model)
Deallocates all memory in the list.
Definition: rwmodel.cpp:1124
model_color_by_order
int model_color_by_order(Bmodel *model)
Colors model components in order from red to blue.
Definition: model_color.cpp:82
model_set_link_radius
long model_set_link_radius(Bmodel *model, double linkrad)
Set the display radius for all links to a specific value.
Definition: model_links.cpp:139
Boption
A class for a command line input option.
Definition: options.h:26
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
verbose
int verbose
model_color_curvature
int model_color_curvature(Bmodel *model)
Colors model vertices and links as a function of curvature.
Definition: model_color.cpp:228
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
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
rwmodel.h
Header file for reading and writing atomic model files.
timer_report
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:67
model_color_selected
int model_color_selected(Bmodel *model, RGBA< float > color)
Colors selected model components.
Definition: model_color.cpp:55
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
Bmodel
Definition: rwmodel.h:119
options.h
Header file for option handlers.
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_select_valence
long model_select_valence(Bmodel *model, int valence)
Selects fullerene type models.
Definition: model_select.cpp:508
model_select.h
Header file for reading and writing atomic model files.
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