| Bsoft 2.0.5 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 "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: bmodcomp [options] in.star",
25 "---------------------------------",
26 "Compares models internally or to reference models.",
27 " ",
28 "Actions:",
29 "-all Select all models for comparison.",
30 "-distance Calculate a distance matrix.",
31 "-unknown Select unknown models for comparison.",
32 "-closed order,3 Select based on valency (valency,<n>) or polygon order (order,<n>).",
33 "-consensus 12.5 Calculate a consensus model: components are considered the same if within the given distance.",
34 " ",
35 "Parameters:",
36 "-verbose 7 Verbosity of output.",
37 " ",
38 "Input:",
39 "-parameters parm.star Molecular parameter file (default atom_prop.star).",
40 "-reference ref.star File with reference models.",
41 " ",
42 "Output:",
43 "-output new.star Output model file.",
44 "-writereference ref.star Reference output model file.",
45 " ",
46 NULL
47 };
48
49 int main(int argc, char **argv)
50 {
51 /* Initialize variables */
52 int all(0); // Flag to select all models
53 int calc_dist(0); // Flag to calculate a distance matrix
54 int unknown(0); // Flag to select unknown models
55 int closure_rule(0); // Closure rule: 1=valency, 2=order
56 int val_order(0); // Valency or order - depending on rule
57 double distance(0); // Cutoff distance for consensus model
58 Bstring atom_select("ALL");
59 Bstring paramfile; // Use default parameter file
60 Bstring reffile; // Reference model file
61 Bstring outfile; // Output model file
62 Bstring refoutfile; // Reference output model file
63
64 int optind;
65 Boption* option = get_option_list(use, argc, argv, optind);
66 Boption* curropt;
67 for ( curropt = option; curropt; curropt = curropt->next ) {
68 if ( curropt->tag == "all" ) all = 1;
69 if ( curropt->tag == "distance" ) calc_dist = 1;
70 if ( curropt->tag == "unknown" ) unknown = 1;
71 if ( curropt->tag == "closed" ) {
72 if ( curropt->value[0] == 'v' ) closure_rule = 1;
73 if ( curropt->value[0] == 'o' ) closure_rule = 2;
74 if ( curropt->value.contains(",") )
75 val_order = curropt->value.post(',').integer();
76 }
77 if ( curropt->tag == "consensus" )
78 if ( ( distance = curropt->real() ) < 1 )
79 cerr << "-consensus: A cutoff distance must be specified!" << endl;
80 if ( curropt->tag == "parameters" )
81 paramfile = curropt->filename();
82 if ( curropt->tag == "reference" )
83 reffile = curropt->filename();
84 if ( curropt->tag == "output" )
85 outfile = curropt->filename();
86 if ( curropt->tag == "writereference" )
87 refoutfile = curropt->filename();
88 }
89 option_kill(option);
90
91 double ti = timer_start();
92
93 // Read all the parameter files
94 Bstring* file_list = NULL;
95 while ( optind < argc ) string_add(&file_list, argv[optind++]);
96 if ( !file_list ) {
97 cerr << "Error: No model files specified!" << endl;
98 bexit(-1);
99 }
100
101 Bmodel* model = read_model(file_list, paramfile);
102 string_kill(file_list);
103
104 if ( all ) models_process(model, model_reset_selection);
105
106 Bmodel* refmodel = NULL;
107 if ( reffile.length() )
108 refmodel = read_model(reffile, paramfile);
109
110 if ( !model->poly ) model_poly_generate(model);
111
112 if ( calc_dist ) {
113 Bmodel* mp;
114 Matrix mat;
115 for ( mp = model; mp; mp = mp->next ) {
116 mat = model_distance_matrix(mp, 0);
117 // cout << mp->id << endl << mat << endl;
118 cout << mp->id << tab << mp->fmap << tab << mat[0][1] << endl;
119 }
120 }
121
122 if ( unknown ) {
123 model_select_unknowns(model);
124 refmodel = model;
125 }
126
127 if ( closure_rule ) model_select_closed(model, closure_rule, val_order);
128
129 if ( refmodel ) {
130 if ( model->poly )
131 model_poly_compare(model, refmodel);
132 else
133 model_compare(model, refmodel);
134 }
135
136 Bmodel* numod = NULL;
137 if ( distance > 0 ) {
138 numod = models_consensus(model, distance);
139 model_kill(model);
140 model = numod;
141 }
142
143 if ( outfile.length() ) {
144 model_update_comment(model, argc, argv);
145 write_model(outfile, model);
146 }
147
148 if ( refoutfile.length() ) {
149 model_update_comment(refmodel, argc, argv);
150 write_model(refoutfile, refmodel);
151 }
152
153 if ( model != refmodel ) model_kill(model);
154 model_kill(refmodel);
155
156 if ( verbose & VERB_TIME )
157 timer_report(ti);
158
159 bexit(0);
160 }
161
distance
double distance(vector< T1 > &v1, vector< T2 > &v2)
Definition: Vector3.h:536
string_add
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
Definition: Bstring.cpp:705
model_select_unknowns
long model_select_unknowns(Bmodel *model)
Resets the selection to all unknown models.
Definition: model_select.cpp:208
Bstring::post
Bstring post(char c)
Definition: Bstring.cpp:394
Bmodel::id
Bstring id
Definition: rwmodel.h:121
Bmodel::poly
Bpolygon * poly
Definition: rwmodel.h:134
main
int main(int argc, char **argv)
Definition: bmodcomp.cpp:49
utilities.h
Header file for general utilities.
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
Boption::real
double real()
Definition: options.h:107
use
const char * use[]
Definition: bmodcomp.cpp:22
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
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
Boption
A class for a command line input option.
Definition: options.h:26
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
models_consensus
Bmodel * models_consensus(Bmodel *model, double distance)
Determines a consensus between models in a list.
Definition: model_compare.cpp:324
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
model_poly_generate
int model_poly_generate(Bmodel *model)
Generates polygons based on a vertex network.
Definition: model_poly.cpp:145
model_compare
double model_compare(Bmodel *model1, Bmodel *model2)
Compares two models.
Definition: model_compare.cpp:66
model_poly.h
Functions to manipulate polyhedral coordinate files.
verbose
int verbose
Bmodel::next
Bmodel * next
Definition: rwmodel.h:120
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
Matrix
Definition: Matrix.h:21
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
Bmodel::fmap
Bstring fmap
Definition: rwmodel.h:125
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
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
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
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.h
Header file for reading and writing atomic model files.
model_compare.h
Functions to compare models and components.
model_distance_matrix
Matrix model_distance_matrix(Bmodel *model, int view_flag)
Calculates the distance matrix for a model.
Definition: model_compare.cpp:189
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
tab
ostream & tab(ostream &out)
Definition: utilities.cpp:21
string_kill
int string_kill(Bstring *list)
Kills a string linked list.
Definition: Bstring.cpp:760