Bsoft  2.1.0
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->scale();
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 
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  write_img(mapfile, map, 0);
122  delete map;
123  }
124 
125  // Write an output parameter format file if a name is given
126  if ( outfile.length() && model ) {
127  write_model(outfile, model);
128  }
129 
130  model_kill(model);
131 
132  if ( verbose & VERB_TIME )
133  timer_report(ti);
134 
135  bexit(0);
136 }
137 
Boption
A class for a command line input option.
Definition: options.h:26
use
const char * use[]
Definition: bmodmap.cpp:22
Boption::scale
Vector3< double > scale()
Definition: options.h:190
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:768
rwmodel.h
Header file for reading and writing atomic model files.
Bstring
Definition: Bstring.h:29
Boption::next
Boption * next
Definition: options.h:28
Vector3< double >
bexit
int bexit(int value)
Exit function for cleanup and debugging.
Definition: utilities.cpp:280
model_map.h
Header file for model to map conversions.
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
Bstring::real
double real()
Definition: Bstring.cpp:553
options.h
Header file for option handlers.
Boption::origin
Vector3< double > origin()
Definition: options.h:180
models_process
long models_process(Bmodel *model, long(modfunc)(Bmodel *))
Process a list of models using the specified function.
Definition: model_util.cpp:36
Boption::tag
Bstring tag
Definition: options.h:29
main
int main(int argc, char **argv)
Definition: bmodmap.cpp:49
write_img
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Definition: rwimg.cpp:281
Boption::value
Bstring value
Definition: options.h:30
model_kill
int model_kill(Bmodel *model)
Deallocates all memory in the list.
Definition: rwmodel.cpp:1127
Bimage
General image parameter class.
Definition: Bimage.h:177
model_select.h
Header file for reading and writing atomic model files.
timer.h
Utilities for timing functions.
Unknown_Type
@ Unknown_Type
Definition: utilities.h:151
model_reset_selection
long model_reset_selection(Bmodel *model)
Resets the selection to all components.
Definition: model_select.cpp:232
VERB_TIME
#define VERB_TIME
Definition: utilities.h:114
Bmodel
Definition: rwmodel.h:119
timer_start
double timer_start()
Starts timer and prints the time.
Definition: timer.cpp:61
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:398
Bimage::data_type
DataType data_type()
Definition: Bimage.h:362
utilities.h
Header file for general utilities.
write_model
int write_model(Bstring &filename, Bmodel *model)
Writes model parameters.
Definition: rwmodel.cpp:92
Boption::size
Vector3< long > size()
Definition: options.h:163
Bstring::length
long length() const
Definition: Bstring.cpp:263
timer_report
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:76
Bimage::change_type
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1765
model
Bmodel * model
Definition: bshow.cpp:34
Vector3::volume
double volume()
Definition: Vector3.h:237
rwimg.h
Header file for 2D and 3D image I/O.
Boption::filename
Bstring filename()
Definition: options.h:85
option_kill
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:111
model_util.h
Library routines used for model processing.
verbose
int verbose
read_model
Bmodel * read_model(Bstring &filename)
Definition: rwmodel.cpp:29
DataType
DataType
Base data type specifier.
Definition: utilities.h:150
string_add
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
Definition: Bstring.cpp:713