Bsoft  2.1.0
Bernard's software package
bmodcomp.cpp
Go to the documentation of this file.
1 
9 #include "rwmodel.h"
10 #include "model_select.h"
11 #include "model_poly.h"
12 #include "model_compare.h"
13 #include "model_util.h"
14 #include "rwimg.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 /* Usage assistance */
23 const char* use[] = {
24 " ",
25 "Usage: bmodcomp [options] in.star",
26 "---------------------------------",
27 "Compares models internally or to reference models.",
28 " ",
29 "Actions:",
30 "-all Select all models for comparison.",
31 "-distance Calculate a distance matrix.",
32 "-unknown Select unknown models for comparison.",
33 "-closed order,3 Select based on valency (valency,<n>) or polygon order (order,<n>).",
34 "-consensus 12.5 Calculate a consensus model: components are considered the same if within the given distance.",
35 " ",
36 "Parameters:",
37 "-verbose 7 Verbosity of output.",
38 " ",
39 "Input:",
40 "-parameters parm.star Molecular parameter file (default atom_prop.star).",
41 "-reference ref.star File with reference models.",
42 " ",
43 "Output:",
44 "-output new.star Output model file.",
45 "-writereference ref.star Reference output model file.",
46 "-matrix file.mat Distance matrix.",
47 "-image file.map Distance matrix as an image.",
48 " ",
49 NULL
50 };
51 
52 int main(int argc, char **argv)
53 {
54  /* Initialize variables */
55  int all(0); // Flag to select all models
56  int calc_dist(0); // Flag to calculate a distance matrix
57  int unknown(0); // Flag to select unknown models
58  int closure_rule(0); // Closure rule: 1=valency, 2=order
59  int val_order(0); // Valency or order - depending on rule
60  double distance(0); // Cutoff distance for consensus model
61  Bstring atom_select("ALL");
62  Bstring paramfile; // Use default parameter file
63  Bstring reffile; // Reference model file
64  Bstring outfile; // Output model file
65  Bstring refoutfile; // Reference output model file
66  Bstring matfile; // Output matrix file
67  Bstring imgfile; // Output image file
68 
69  int optind;
70  Boption* option = get_option_list(use, argc, argv, optind);
71  Boption* curropt;
72  for ( curropt = option; curropt; curropt = curropt->next ) {
73  if ( curropt->tag == "all" ) all = 1;
74  if ( curropt->tag == "distance" ) calc_dist = 1;
75  if ( curropt->tag == "unknown" ) unknown = 1;
76  if ( curropt->tag == "closed" ) {
77  if ( curropt->value[0] == 'v' ) closure_rule = 1;
78  if ( curropt->value[0] == 'o' ) closure_rule = 2;
79  if ( curropt->value.contains(",") )
80  val_order = curropt->value.post(',').integer();
81  }
82  if ( curropt->tag == "consensus" )
83  if ( ( distance = curropt->real() ) < 1 )
84  cerr << "-consensus: A cutoff distance must be specified!" << endl;
85  if ( curropt->tag == "parameters" )
86  paramfile = curropt->filename();
87  if ( curropt->tag == "reference" )
88  reffile = curropt->filename();
89  if ( curropt->tag == "output" )
90  outfile = curropt->filename();
91  if ( curropt->tag == "writereference" )
92  refoutfile = curropt->filename();
93  if ( curropt->tag == "matrix" )
94  matfile = curropt->filename();
95  if ( curropt->tag == "image" )
96  imgfile = curropt->filename();
97  }
98  option_kill(option);
99 
100  double ti = timer_start();
101 
102  // Read all the parameter files
103  Bstring* file_list = NULL;
104  while ( optind < argc ) string_add(&file_list, argv[optind++]);
105  if ( !file_list ) {
106  cerr << "Error: No model files specified!" << endl;
107  bexit(-1);
108  }
109 
110  Bmodel* model = read_model(file_list, paramfile);
111  string_kill(file_list);
112 
114 
115  Bmodel* refmodel = NULL;
116  if ( reffile.length() )
117  refmodel = read_model(reffile, paramfile);
118 
120 
121  if ( calc_dist ) {
122  Matrix mat;
123  if ( refmodel )
124  mat = model_distance_matrix(model, refmodel);
125  else
127 // for ( mp = model; mp; mp = mp->next ) {
128 // mat = model_distance_matrix(mp, 0);
129 // cout << mp->id << endl << mat << endl;
130 // cout << mp->id << tab << mp->fmap << tab << mat[0][1] << endl;
131 // }
132  if ( imgfile.length() && mat.rows() ) {
133  Bimage* pimg = new Bimage(mat, 1);
134 // pimg->change_type(nudatatype);
135  write_img(imgfile, pimg, 0);
136  delete pimg;
137  }
138  }
139 
140  if ( unknown ) {
142  refmodel = model;
143  }
144 
145  if ( closure_rule ) model_select_closed(model, closure_rule, val_order);
146 
147  if ( refmodel ) {
148  if ( model->poly )
149  model_poly_compare(model, refmodel);
150  else
151  model_compare(model, refmodel);
152  }
153 
154  Bmodel* numod = NULL;
155  if ( distance > 0 ) {
156  numod = models_consensus(model, distance);
157  model_kill(model);
158  model = numod;
159  }
160 
161  if ( outfile.length() ) {
162  write_model(outfile, model);
163  }
164 
165  if ( refoutfile.length() ) {
166  write_model(refoutfile, refmodel);
167  }
168 
169  if ( model != refmodel ) model_kill(model);
170  model_kill(refmodel);
171 
172  if ( verbose & VERB_TIME )
173  timer_report(ti);
174 
175  bexit(0);
176 }
177 
Boption
A class for a command line input option.
Definition: options.h:26
main
int main(int argc, char **argv)
Definition: bmodcomp.cpp:52
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
Bstring::integer
long integer()
Definition: Bstring.cpp:547
Boption::next
Boption * next
Definition: options.h:28
bexit
int bexit(int value)
Exit function for cleanup and debugging.
Definition: utilities.cpp:280
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
verbose
int verbose
options.h
Header file for option handlers.
Bstring::post
Bstring post(char c)
Definition: Bstring.cpp:402
model_select_unknowns
long model_select_unknowns(Bmodel *model)
Resets the selection to all unknown models.
Definition: model_select.cpp:208
model_compare.h
Functions to compare models and components.
model_compare
double model_compare(Bmodel *model1, Bmodel *model2)
Compares two models.
Definition: model_compare.cpp:66
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
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::real
double real()
Definition: options.h:107
Matrix::rows
long rows()
Definition: Matrix.h:153
models_consensus
Bmodel * models_consensus(Bmodel *model, double distance)
Determines a consensus between models in a list.
Definition: model_compare.cpp:322
use
const char * use[]
Definition: bmodcomp.cpp:23
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.
distance
double distance(vector< T1 > &v1, vector< T2 > &v2)
Definition: Vector3.h:538
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
Bmodel::poly
Bpolygon * poly
Definition: rwmodel.h:134
timer_start
double timer_start()
Starts timer and prints the time.
Definition: timer.cpp:61
utilities.h
Header file for general utilities.
write_model
int write_model(Bstring &filename, Bmodel *model)
Writes model parameters.
Definition: rwmodel.cpp:92
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
model_distance_matrix
Matrix model_distance_matrix(Bmodel *model, int view_flag)
Calculates the distance matrix for a model.
Definition: model_compare.cpp:189
model
Bmodel * model
Definition: bshow.cpp:34
rwimg.h
Header file for 2D and 3D image I/O.
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
Boption::filename
Bstring filename()
Definition: options.h:85
model_poly.h
Functions to manipulate polyhedral coordinate files.
option_kill
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:111
model_poly_compare
int model_poly_compare(Bmodel *model, Bmodel *refmodel)
Compares a model with reference models based on the eigenvalues of the adjacency matrix.
Definition: model_poly.cpp:1495
model_poly_generate
int model_poly_generate(Bmodel *model)
Generates polygons based on a vertex network.
Definition: model_poly.cpp:145
model_util.h
Library routines used for model processing.
read_model
Bmodel * read_model(Bstring &filename)
Definition: rwmodel.cpp:29
Bstring::contains
bool contains(const Bstring &s)
Definition: Bstring.cpp:592
Matrix
Definition: Matrix.h:22
string_add
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
Definition: Bstring.cpp:713