| Bsoft 2.0.5 Bernard's software package

bmodmap.cpp
Go to the documentation of this file.
1
9 #include "rwmodel.h"
10 #include "model_map.h"
11 #include "rwimg.h"
12 #include "model_select.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: bmodmap [options] in.star",
25 "--------------------------------",
26 "Generates a map from a model.",
27 " ",
28 "Actions:",
29 "-all Reset selection to all components before other selections.",
30 " ",
31 "Parameters:",
32 "-verbose 7 Verbosity of output.",
33 "-datatype u Force writing of a new image data type.",
34 "-origin 0,0,0 Origin placement within image (default 0,0,0).",
35 "-size 10,10,10 Map size, input map size otherwise (voxels).",
36 "-sampling 1 Sampling (default 1 angstrom/voxel).",
37 "-sigma 3.5 Density decay around a component (default 10).",
38 " ",
39 "Input:",
40 "-parameters param.star Input parameter file.",
41 " ",
42 "Output:",
43 "-output model.star New model file.",
44 "-map density.map New map file.",
45 " ",
46 NULL
47 };
48
49 int main(int argc, char **argv)
50 {
51 /* Initialize variables */
52 int reset(0); // Keep selection as read from file
53 DataType nudatatype(Unknown_Type); // Conversion to new type
54 Vector3<double> origin; // Coordinate origin placement
55 int set_origin(0); // Flag to set origin
56 Vector3<long> size; // New map size
57 Vector3<double> sam; // Sampling in angstrom/voxel side
58 double sigma(0); // Component density decay radius
59 Bstring paramfile; // Input parameter file name
60 Bstring outfile; // Output parameter file name
61 Bstring mapfile; // Output map file name
62
63 int optind;
64 Boption* option = get_option_list(use, argc, argv, optind);
65 Boption* curropt;
66 for ( curropt = option; curropt; curropt = curropt->next ) {
67 if ( curropt->tag == "all" ) reset = 1;
68 if ( curropt->tag == "origin" ) {
69 if ( curropt->value[0] == 'c' ) {
70 set_origin = 2;
71 } else {
72 origin = curropt->origin();
73 set_origin = 1;
74 }
75 }
76 if ( curropt->tag == "size" )
77 size = curropt->size();
78 if ( curropt->tag == "sampling" )
79 sam = curropt->sampling();
80 if ( curropt->tag == "sigma" )
81 if ( ( sigma = curropt->value.real() ) < 1 )
82 cerr << "-sigma: The component density decay radius must be specified!" << endl;
83 if ( curropt->tag == "parameters" )
84 paramfile = curropt->filename();
85 if ( curropt->tag == "output" )
86 outfile = curropt->filename();
87 if ( curropt->tag == "map" )
88 mapfile = curropt->filename();
89 }
90 option_kill(option);
91
92 double ti = timer_start();
93
94 // Read all the parameter files
95 Bstring* file_list = NULL;
96 while ( optind < argc ) string_add(&file_list, argv[optind++]);
97 if ( !file_list ) {
98 cerr << "Error: No model files specified!" << endl;
99 bexit(-1);
100 }
101
102 Bmodel* model = read_model(file_list, paramfile);
103 string_kill(file_list);
104
105 if ( !model ) {
106 cerr << "Error: Input file not read!" << endl;
107 bexit(-1);
108 }
109
110 if ( reset ) models_process(model, model_reset_selection);
111
112 if ( set_origin == 2 ) origin = {double(size[0]/2), double(size[1]/2), double(size[2]/2)};
113
114 Bimage* map = NULL;
115
116 if ( mapfile.length() && size.volume() ) {
117 model_set_map_filenames(model, mapfile);
118 map = img_from_model(model, origin, size, sam, sigma);
119 if ( nudatatype == Unknown_Type ) nudatatype = map->data_type();
120 map->change_type(nudatatype);
121 map->label(get_cmd_line(argc, argv));
122 write_img(mapfile, map, 0);
123 delete map;
124 }
125
126 // Write an output parameter format file if a name is given
127 if ( outfile.length() && model ) {
128 model_update_comment(model, argc, argv);
129 write_model(outfile, model);
130 }
131
132 model_kill(model);
133
134 if ( verbose & VERB_TIME )
135 timer_report(ti);
136
137 bexit(0);
138 }
139
Bimage::change_type
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1743
model_map.h
Header file for model to map conversions.
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
DataType
DataType
Base data type specifier.
Definition: utilities.h:146
main
int main(int argc, char **argv)
Definition: bmodmap.cpp:49
utilities.h
Header file for general utilities.
Boption::sampling
Vector3< double > sampling()
Definition: options.h:202
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
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
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
timer.h
Utilities for timing functions.
Bimage
General image parameter class.
Definition: Bimage.h:163
Boption::size
Vector3< long > size()
Definition: options.h:163
model_kill
int model_kill(Bmodel *model)
Deallocates all memory in the list.
Definition: rwmodel.cpp:1124
model_set_map_filenames
int model_set_map_filenames(Bmodel *model, Bstring &mapfile)
Sets all the map file names of selected models.
Definition: rwmodel.cpp:395
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
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
write_img
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Definition: rwimg.cpp:280
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.
verbose
int verbose
Vector3< double >
Boption::origin
Vector3< double > origin()
Definition: options.h:180
timer_report
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:67
use
const char * use[]
Definition: bmodmap.cpp:22
option_kill
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:109
Bmodel
Definition: rwmodel.h:119
Unknown_Type
Definition: utilities.h:147
rwimg.h
Header file for 2D and 3D image I/O.
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
Vector3::volume
double volume()
Definition: Vector3.h:235
model_select.h
Header file for reading and writing atomic model files.
Bimage::data_type
DataType data_type()
Definition: Bimage.h:349
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
img_from_model
Bimage * img_from_model(Bmodel *model, Vector3< double > ori, Vector3< long > size, Vector3< double > sam, double sigma)
Calculates a map from model component coordinates.
Definition: model_map.cpp:59
string_kill
int string_kill(Bstring *list)
Kills a string linked list.
Definition: Bstring.cpp:760