| Bsoft 2.0.5 Bernard's software package

bbild.cpp
Go to the documentation of this file.
1
9 #include "rwmodel.h"
10 #include "rwmodel_bild.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
22 /* Usage assistance */
23 const char* use[] = {
24 " ",
25 "Usage: bbild [options] in1.star [in2.star ...]",
26 "----------------------------------------------",
27 "Generates BILD output from a model.",
28 " ",
29 "Actions:",
30 "-all Reset selection to all models before other selections.",
31 "-type poly Type of BILD output: views, polygons or neighbors.",
32 "-linklength 56.3 Generate links with this maximum length.",
33 "-color spectrum Color selection or polygons: spectrum=red->blue, density, fom.",
34 " ",
35 "Parameters:",
36 "-verbose 7 Verbose output.",
37 "-componentradius 8.4 Set display radius for all components.",
38 "-linkradius 5.1 Set display radius for all links.",
39 " ",
40 "Output:",
41 "-output file.bild Output model file.",
42 " ",
43 NULL
44 };
45
46 int main(int argc, char **argv)
47 {
48 /* Initialize variables */
49 int reset(0); // Keep selection as read from file
50 Bstring bild_type; // Default BILD output is views
51 double linklength(0); // Link length for generating links
52 int color_type(0); // Color scheme type: 1=spectrum, 2=fom
53 double comprad(0); // Component display radius
54 double linkrad(0); // Link display radius
55 Bstring outfile; // Output parameter file name
56
57 int optind;
58 Boption* option = get_option_list(use, argc, argv, optind);
59 Boption* curropt;
60 for ( curropt = option; curropt; curropt = curropt->next ) {
61 if ( curropt->tag == "all" ) reset = 1;
62 if ( curropt->tag == "type" ) bild_type = curropt->value.lower();
63 if ( curropt->tag == "linklength" )
64 if ( ( linklength = curropt->value.real() ) < 0.1 )
65 cerr << "-linklength: A link length must be specified!" << endl;
66 if ( curropt->tag == "color" ) {
67 if ( curropt->value.contains( "spe") ) color_type = 1;
68 if ( curropt->value.contains( "den") ) color_type = 2;
69 if ( curropt->value.contains( "fom") ) color_type = 3;
70 }
71 if ( curropt->tag == "componentradius" )
72 if ( ( comprad = curropt->value.real() ) < 0.001 )
73 cerr << "-componentradius: A display radius must be specified!" << endl;
74 if ( curropt->tag == "linkradius" )
75 if ( ( linkrad = curropt->value.real() ) < 0.001 )
76 cerr << "-linkradius: A radius must be specified!" << endl;
77 if ( curropt->tag == "output" )
78 outfile = curropt->filename();
79 }
80 option_kill(option);
81
82 double ti = timer_start();
83
84 // Read all the model parameter files
85 Bstring* file_list = NULL;
86 while ( optind < argc ) string_add(&file_list, argv[optind++]);
87 if ( !file_list ) {
88 cerr << "Error: No parameter or image files specified!" << endl;
89 bexit(-1);
90 }
91
92 Bmodel* model = read_model(file_list);
93 string_kill(file_list);
94
95 if ( !model ) {
96 cerr << "Error: Input file not read!" << endl;
97 bexit(-1);
98 }
99
100 if ( reset ) models_process(model, model_reset_selection);
101
102 if ( linklength > 0 ) model_link_list_generate(model, linklength);
103
104 if ( comprad > 0 ) models_process(model, comprad, model_set_component_radius);
105
106 if ( linkrad > 0 ) models_process(model, linkrad, model_set_link_radius);
107
108 model_selection_stats(model);
109
110 // Write an output parameter format file if a name is given
111 Bstring ext;
112 int order(6);
113
114 if ( outfile.length() ) {
115 ext = outfile.extension();
116 if ( ext.contains("bild") || ext.contains("bld") ) {
117 if ( bild_type[0] == 'v' ) // Views
118 model_to_bild_orientations(outfile, model, 1, color_type);
119 else if ( bild_type[0] == 'f' ) // Force vectors
120 model_to_bild_orientations(outfile, model, 2, color_type);
121 else if ( bild_type[0] == 's' ) // Velocity vectors
122 model_to_bild_orientations(outfile, model, 3, color_type);
123 else if ( bild_type[0] == 'b' ) // View sphere
124 model_to_bild_view_sphere(outfile, model, color_type);
125 else if ( bild_type[0] == 'c' )
126 model_to_bild_view_polygons(outfile, model, order, color_type);
127 else if ( bild_type[0] == 'p' ) // Polygons
128 model_to_bild_polygons(outfile, model, color_type);
129 else if ( bild_type[0] == 'n' ) // Neighbor planes
130 model_to_bild_neighbor_planes(outfile, model, color_type);
131 else
132 write_model_bild(outfile, model);
133 } else {
134 model_update_comment(model, argc, argv);
135 write_model(outfile, model);
136 }
137 }
138
139 model_kill(model);
140
141 if ( verbose & VERB_TIME )
142 timer_report(ti);
143
144 bexit(0);
145 }
146
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
model_to_bild_view_polygons
int model_to_bild_view_polygons(Bstring &filename, Bmodel *model, int order, int color_type)
Converts a model into a representation with view polygons.
Definition: rwmodel_bild.cpp:444
string_add
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
Definition: Bstring.cpp:705
write_model_bild
int write_model_bild(Bstring &filename, Bmodel *model)
Writes Chimera BILD model parameters.
Definition: rwmodel_bild.cpp:232
utilities.h
Header file for general utilities.
model_to_bild_view_sphere
int model_to_bild_view_sphere(Bstring &filename, Bmodel *model, int color_type)
Converts a model into a representation with views.
Definition: rwmodel_bild.cpp:362
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
Bstring::length
long length() const
Definition: Bstring.cpp:263
verbose
int verbose
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.
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
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
model_to_bild_neighbor_planes
int model_to_bild_neighbor_planes(Bstring &filename, Bmodel *model, int color_type)
Converts a model into a bild neighbor plane representation.
Definition: rwmodel_bild.cpp:593
Boption
A class for a command line input option.
Definition: options.h:26
VERB_TIME
#define VERB_TIME
Definition: utilities.h:110
Bstring::extension
Bstring extension()
Definition: Bstring.cpp:515
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
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
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.
model_link_list_generate
long model_link_list_generate(Bmodel *model, double maxlength)
Generates a link list for a model based on vertex separation.
Definition: model_links.cpp:70
timer_report
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:67
Bstring::lower
Bstring lower()
Definition: Bstring.cpp:308
option_kill
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:109
Bmodel
Definition: rwmodel.h:119
use
const char * use[]
Definition: bbild.cpp:23
options.h
Header file for option handlers.
model_to_bild_orientations
int model_to_bild_orientations(Bstring &filename, Bmodel *model, int vec_type, int color_type)
Converts a model into a representation with views.
Definition: rwmodel_bild.cpp:275
model_to_bild_polygons
int model_to_bild_polygons(Bstring &filename, Bmodel *model, int color_type)
Converts a model into a bild polygon representation.
Definition: rwmodel_bild.cpp:523
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.h
Header file for reading and writing atomic model files.
main
int main(int argc, char **argv)
Definition: bbild.cpp:46
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
rwmodel_bild.h
Header file for reading and writing Chimera BILD files.
string_kill
int string_kill(Bstring *list)
Kills a string linked list.
Definition: Bstring.cpp:760