| Bsoft 2.0.5 Bernard's software package

bpoly.cpp
Go to the documentation of this file.
1
9 #include "rwmodel.h"
10 #include "model_poly.h"
11 #include "model_mechanics.h"
12 #include "model_transform.h"
13 #include "model_shell.h"
14 #include "model_path.h"
15 #include "model_select.h"
16 #include "model_views.h"
17 #include "model_links.h"
18 #include "model_util.h"
19 #include "utilities.h"
20 #include "options.h"
21 #include "timer.h"
22
23 // Declaration of global variables
24 extern int verbose; // Level of output to the screen
25
26 /* Usage assistance */
27 const char* use[] = {
28 " ",
29 "Usage: bpoly [options] in1.star [in2.star...]",
30 "---------------------------------------------",
31 "Manipulate model polyhedral coordinate files.",
32 " ",
33 "Actions:",
34 "-center Center before all other operations.",
35 "-rename Rename components based on the number of links.",
36 "-vertextypes 1 Determine vertex types from adjacent polygons (1=3-digit, 2=6-digit).",
37 "-views local Calculate views for components. Modes: origin: current origin,",
38 " com: center-of-mass origin, map: map origin, local: neigbor plane.",
39 "-analyze Analyze the polyhedrons.",
40 "-angles Analyze the angles in polyhedrons.",
41 "-energy 112.4 Calculate the energy components of models using the given reference angle.",
42 " If the angle is 0, the inner polygon angle will be used as reference.",
43 "-pentagon Calculate the pentagon adjacency.",
44 "-sphericity Estimate the spherical nature of the polyhedron.",
45 "-ellipsoidicity Estimate the ellipsoid nature of the polyhedron.",
46 "-wiener Calculate the Wiener index for each polyhedron.",
47 "-eigen Do an eigenanalysis for each polyhedron.",
48 "-coordinates Generate new coordinates based on spherical harmonics.",
49 "-dual Calculate the dual of a polyhedron.",
50 "-faces 5 Generate a dual using only the faces of the given order.",
51 "-find 34.7 Find symmetry axes with an RMSD below the given value.",
52 "-regularize 150 Number of iterations for regularizing a polyhedron.",
53 " ",
54 "Selections:",
55 "-all Reset selection to all components before other selections.",
56 "-closed order,3 Select based on valency (valency,<n>) or polygon order (order,<n>).",
57 "-select #232@14 Select models and components.",
58 " ",
59 "Parameters:",
60 "-verbose 7 Verbosity of output.",
61 "-componentradius 0.5 Component display radius.",
62 "-linkradius 0.5 Link display radius.",
63 " ",
64 "Regularization parameters:",
65 "-distance 212 Interaction reference distance.",
66 "-linklength 150 Vertex link reference length.",
67 "-Kdistance 0.1 Distance force constant (default 0).",
68 "-Klink 0.01 Link force constant (default 0.1).",
69 "-Kpolyangle 0.1 Angle force constant (default 0.01).",
70 "-Kpolygon 0.001 Polygon regularity force constant (default 0).",
71 "-Kpolyplane 0.1 Polygon planarity force constant (default 0).",
72 "-Kpoint 0.1,0.02 Point force constant and decay (default 0,0.01).",
73 " ",
74 "Input:",
75 "-parameters parm.star Molecular parameter file (default atom_prop.star).",
76 " ",
77 "Output:",
78 "-output file.star Output model parameter file.",
79 " ",
80 NULL
81 };
82
83 int main(int argc, char **argv)
84 {
85 /* Initialize variables */
86 int reset(0); // Keep selection as read from file
87 int closure_rule(0); // Closure rule: 1=valency, 2=order
88 int val_order(0); // Valency or order - depending on rule
89 Bstring mod_select; // Model and component selection
90 int center(0); // Flag to center the structure
91 int rename(0); // Flag to rename components
92 int vertextypes(0); // Flag to determine vertex types
93 Bstring calc_views; // Mode to calculate component views
94 int angles(0); // Flag to analyze the polygon angles
95 int analyze(0); // Flag to analyze the structure
96 double angle_ref(0); // Reference angle and flag to calculate the energy components of models
97 int pentagon(0); // Flag to calculate the pentagon adjacency
98 int sphere(0); // Flag to estimate the sphericity
99 int ellips(0); // Flag to estimate the ellipsoidicity
100 int wiener(0); // Flag to calculate the Wiener index
101 int eigen(0); // Flag to do an eigenanalysis
102 int coor(0); // Flag to generate new coordinates
103 int dual(0); // Flag to calculate dual of polyhedron
104 int faces(0); // Flag to calculate dual of polyhedron restricted to specific faces
105 double find(0); // RMSD cutoff to find symmetry axes
106 long reg_iter(0); // Number of iterations/cycles for regularization
107 double distance(0); // Unit length separating vertices
108 double compradius(0); // Component display radius
109 double linkradius(0); // Link display radius
110 double linklength(0); // Unit length linking vertices
111 double Kdistance(0); // Distance interaction strength
112 double Klink(0.1); // Link strength
113 double Kpolyangle(0.01); // Angle strength
114 double Kpolygon(0); // Polygon regularity strength
115 double Kpolyplane(0); // Polygon planarity strength
116 double Kpoint(0); // Point force strength
117 double decay(0.01); // Point force decay with distance
118 Bstring map_path; // Path to density map
119 Bstring atom_select("ALL");
120 Bstring paramfile; // Use default parameter file
121 Bstring outfile; // Output parameter file name
122
123 int optind;
124 Boption* option = get_option_list(use, argc, argv, optind);
125 Boption* curropt;
126 for ( curropt = option; curropt; curropt = curropt->next ) {
127 if ( curropt->tag == "all" ) reset = 1;
128 if ( curropt->tag == "closed" ) {
129 if ( curropt->value[0] == 'v' ) closure_rule = 1;
130 if ( curropt->value[0] == 'o' ) closure_rule = 2;
131 if ( curropt->value.contains(",") )
132 val_order = curropt->value.post(',').integer();
133 }
134 if ( curropt->tag == "select" )
135 mod_select = curropt->value;
136 if ( curropt->tag == "center" ) center = 1;
137 if ( curropt->tag == "rename" ) rename = 1;
138 if ( curropt->tag == "vertextypes" )
139 if ( ( vertextypes = curropt->value.integer() ) < 1 )
140 cerr << "-vertextypes: A selection number must be specified!" << endl;
141 if ( curropt->tag == "views" ) calc_views = curropt->value.lower();
142 if ( curropt->tag == "analyze" ) analyze = 1;
143 if ( curropt->tag == "angles" ) angles = 1;
144 if ( curropt->tag == "energy" ) {
145 if ( ( angle_ref = curropt->value.real() ) < 1e-30 )
146 cerr << "-energy: A reference angle must be specified!" << endl;
147 else {
148 angle_ref *= M_PI/180.0;
149 if ( angle_ref <= 0 ) angle_ref = -1;
150 }
151 }
152 if ( curropt->tag == "pentagon" ) pentagon = 1;
153 if ( curropt->tag == "sphericity" ) sphere = 1;
154 if ( curropt->tag == "ellipsoidicity" ) ellips = 1;
155 if ( curropt->tag == "wiener" ) wiener = 1;
156 if ( curropt->tag == "eigen" ) eigen = 1;
157 if ( curropt->tag == "coordinates" ) coor = 1;
158 if ( curropt->tag == "dual" ) dual = 1;
159 if ( curropt->tag == "faces" )
160 if ( ( faces = curropt->value.integer() ) < 1 )
161 cerr << "-faces: A polygon order must be specified!" << endl;
162 if ( curropt->tag == "find" )
163 if ( ( find = curropt->value.real() ) < 1e-30 )
164 cerr << "-find: A RMSD cutoff must be specified!" << endl;
165 if ( curropt->tag == "regularize" )
166 if ( ( reg_iter = curropt->value.integer() ) < 1 )
167 cerr << "-regularize: The number of iterations must be specified!" << endl;
168 if ( curropt->tag == "distance" )
169 if ( ( distance = curropt->value.real() ) < 1e-30 )
170 cerr << "-distance: The reference distance separating vertices must be specified!" << endl;
171 if ( curropt->tag == "componentradius" )
172 if ( ( compradius = curropt->value.real() ) < 1e-30 )
173 cerr << "-componentradius: The component display radius must be specified!" << endl;
174 if ( curropt->tag == "linkradius" )
175 if ( ( linkradius = curropt->value.real() ) < 1e-30 )
176 cerr << "-linkradius: The link display radius must be specified!" << endl;
177 if ( curropt->tag == "linklength" )
178 if ( ( linklength = curropt->value.real() ) < 1e-30 )
179 cerr << "-linklength: The link length must be specified!" << endl;
180 if ( curropt->tag == "Kdistance" )
181 if ( ( Kdistance = curropt->value.real() ) < 1e-30 )
182 cerr << "-Kdistance: The distance interaction strength must be specified!" << endl;
183 if ( curropt->tag == "Klink" )
184 if ( ( Klink = curropt->value.real() ) < 1e-30 )
185 cerr << "-Klink: The link strength must be specified!" << endl;
186 if ( curropt->tag == "Kpolyangle" )
187 if ( ( Kpolyangle = curropt->value.real() ) < 1e-30 )
188 cerr << "-Kpolyangle: The angle strength must be specified!" << endl;
189 if ( curropt->tag == "Kpolygon" )
190 if ( ( Kpolygon = curropt->value.real() ) < 1e-30 )
191 cerr << "-Kpolygon: The polygon regularity strength must be specified!" << endl;
192 if ( curropt->tag == "Kpolyplane" )
193 if ( ( Kpolyplane = curropt->value.real() ) < 1e-30 )
194 cerr << "-Kpolyplane: The polygon planarity strength must be specified!" << endl;
195 if ( curropt->tag == "Kpoint" )
196 if ( curropt->values(Kpoint, decay) < 1 )
197 cerr << "-Kpoint: The point force strength must be specified!" << endl;
198 if ( curropt->tag == "parameters" )
199 paramfile = curropt->filename();
200 if ( curropt->tag == "output" )
201 outfile = curropt->filename();
202 }
203 option_kill(option);
204
205 double ti = timer_start();
206
207 // Read all the parameter files
208 Bstring* file_list = NULL;
209 while ( optind < argc ) string_add(&file_list, argv[optind++]);
210 if ( !file_list ) {
211 cerr << "Error: No model files specified!" << endl;
212 bexit(-1);
213 }
214
215 Bmodel* model = read_model(file_list, paramfile);
216 string_kill(file_list);
217
218 if ( !model ) {
219 cerr << "Error: Input file not read!" << endl;
220 bexit(-1);
221 }
222
223 if ( reset ) models_process(model, model_reset_selection);
224
225 if ( !model->poly ) model_poly_generate(model);
226
227 if ( closure_rule ) model_select_closed(model, closure_rule, val_order);
228
229 if ( mod_select.length() ) model_select(model, mod_select);
230
231 if ( rename ) models_process(model, model_rename_components);
232
233 if ( coor ) model_poly_sphere_coor(model); // Pointer to eigenvalue array not freed! Single model
234
235 if ( linklength > 0 ) models_process(model, linklength, model_set_link_length);
236
237 if ( center ) models_process(model, model_center);
238
239 if ( vertextypes == 1 ) model_vertex_types(model);
240 else if ( vertextypes == 2 ) model_extended_vertex_types(model);
241
242 if ( calc_views.length() ) model_calculate_views(model, calc_views);
243
244 if ( analyze ) model_poly_analyze(model);
245
246 if ( angles ) model_poly_angles(model);
247
248 if ( angle_ref ) model_poly_energy(model, angle_ref);
249
250 if ( pentagon ) model_poly_pentagon_adjacency(model);
251
252 Bmodel* mp;
253 double sph, ell;
254 if ( sphere && ellips ) {
255 cout << "Model\tSphericity\tEllipsoidicity" << endl;
256 for ( mp = model; mp; mp = mp->next ) if ( mp->sel ) {
257 sph = model_sphericity(mp);
258 ell = model_ellipsoidicity(mp);
259 cout << mp->id << tab << sph << tab << ell << endl;
260 }
261 } else if ( sphere ) {
262 cout << "Model\tSphericity" << endl;
263 for ( mp = model; mp; mp = mp->next ) if ( mp->sel ) {
264 sph = model_sphericity(mp);
265 cout << mp->id << tab << sph << endl;
266 }
267 } else if ( ellips ) {
268 cout << "Model\tEllipsoidicity" << endl;
269 for ( mp = model; mp; mp = mp->next ) if ( mp->sel ) {
270 ell = model_ellipsoidicity(mp);
271 cout << mp->id << tab << ell << endl;
272 }
273 }
274
275 if ( wiener ) model_wiener_index(model);
276
277 if ( eigen ) model_poly_eigenvalues(model, 1);
278
279 if ( dual || faces ) {
280 Bmodel* new_model = model_poly_dual(model, faces);
281 if ( new_model ) {
282 model_kill(model);
283 model = new_model;
284 }
285 }
286
287 model_check(model, map_path);
288
289 model_selection_stats(model);
290
291 if ( find ) {
292 if ( verbose )
293 cout << "Model\tPgroup" << endl;
294 for ( mp = model; mp; mp = mp->next ) {
295 model_poly_find_symmetry(mp, find);
296 if ( verbose )
297 cout << mp->id << tab << mp->symmetry << endl;
298 }
299 if ( verbose )
300 cout << endl;
301 }
302
303 if ( reg_iter )
304 model_regularize(model, reg_iter, distance, Kdistance,
305 Klink, Kpolyangle, Kpolygon, Kpolyplane, Kpoint, decay);
306
307 if ( compradius > 0 ) models_process(model, compradius, model_set_component_radius);
308
309 if ( linkradius > 0 ) models_process(model, linkradius, model_set_link_radius);
310
311 if ( outfile.length() ) {
312 model_update_comment(model, argc, argv);
313 write_model(outfile, model);
314 }
315
316 model_kill(model);
317
318 if ( verbose & VERB_TIME )
319 timer_report(ti);
320
321 bexit(0);
322 }
323
324
distance
double distance(vector< T1 > &v1, vector< T2 > &v2)
Definition: Vector3.h:536
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
string_add
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
Definition: Bstring.cpp:705
model_wiener_index
double model_wiener_index(Bmodel *model)
Calculates the Wiener index.
Definition: model_path.cpp:82
Bstring::post
Bstring post(char c)
Definition: Bstring.cpp:394
Bmodel::id
Bstring id
Definition: rwmodel.h:121
model_views.h
Library routines used for analysing model component views.
Bmodel::poly
Bpolygon * poly
Definition: rwmodel.h:134
model_sphericity
double model_sphericity(Bmodel *model)
Calculates how close the model is to a spherical shape.
Definition: model_shell.cpp:194
model_regularize
int model_regularize(Bmodel *model, int reg_iter, double distance, double Kdistance, double Klink, double Kangle, double Kpoly, double Kpolyplane, double Kpoint, double decay)
Regularizes a model.
Definition: model_mechanics.cpp:1411
utilities.h
Header file for general utilities.
model_select
long model_select(Bmodel *model, Bstring &comptype)
Selects models, components and component types.
Definition: model_select.cpp:36
model_poly_pentagon_adjacency
int model_poly_pentagon_adjacency(Bmodel *model)
Calculates the number of edges shared by pentagons.
Definition: model_poly.cpp:1041
model_util.h
Library routines used for model processing.
Boption::value
Bstring value
Definition: options.h:30
model_shell.h
Library routines used for shell model processing.
verbose
int verbose
Boption::tag
Bstring tag
Definition: options.h:29
Bstring::length
long length() const
Definition: Bstring.cpp:263
model_extended_vertex_types
int model_extended_vertex_types(Bmodel *model)
Determines the vertex type based on adjacent and opposed polygons.
Definition: model_poly.cpp:396
Bmodel::sel
int sel
Definition: rwmodel.h:129
sphere
int sphere(Bimage *p)
Definition: radon_util.cpp:114
model_poly_energy
double model_poly_energy(Bmodel *model, double angle_ref)
Calculates the different energy terms for all models.
Definition: model_poly.cpp:915
model_mechanics.h
Functions to do molecular mechanics.
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
model_poly_dual
Bmodel * model_poly_dual(Bmodel *model, int order)
Calculates the dual of a polyhedral network.
Definition: model_poly.cpp:454
timer.h
Utilities for timing functions.
Bstring::contains
bool contains(const Bstring &s)
Definition: Bstring.cpp:584
M_PI
#define M_PI
Definition: utilities.h:59
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_rename_components
long model_rename_components(Bmodel *model)
Rename components.
Definition: model_util.cpp:378
model_poly_angles
int model_poly_angles(Bmodel *model)
Calculates all the polygon angles.
Definition: model_poly.cpp:646
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
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
Bmodel::symmetry
Bstring symmetry
Definition: rwmodel.h:124
model_poly_generate
int model_poly_generate(Bmodel *model)
Generates polygons based on a vertex network.
Definition: model_poly.cpp:145
model_poly_analyze
int model_poly_analyze(Bmodel *model)
Analyzes a model for polygon regularity and planarity.
Definition: model_poly.cpp:538
model_vertex_types
int model_vertex_types(Bmodel *model)
Determines the vertex type based on adjacent polygons.
Definition: model_poly.cpp:313
model_poly.h
Functions to manipulate polyhedral coordinate files.
Bmodel::next
Bmodel * next
Definition: rwmodel.h:120
model_poly_find_symmetry
Bstring model_poly_find_symmetry(Bmodel *model, double find)
Finds the symmetry axes associated with polyhedral elements.
Definition: model_poly.cpp:1095
model_poly_eigenvalues
vector< double > model_poly_eigenvalues(Bmodel *model, int show)
Generates the eigenvalues of the adjacency matrix for a model.
Definition: model_poly.cpp:1580
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
use
const char * use[]
Definition: bpoly.cpp:27
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_path.h
Library routines used for model processing.
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
model_center
long model_center(Bmodel *model)
Shifts one models to its center of mass.
Definition: model_transform.cpp:27
model_set_link_length
long model_set_link_length(Bmodel *model, double linklength)
Sets the reference link lengths.
Definition: model_links.cpp:112
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
Bmodel
Definition: rwmodel.h:119
model_poly_sphere_coor
vector< double > model_poly_sphere_coor(Bmodel *model)
Generates coordinates for components based on the eigenvectors of the adjacency matrix.
Definition: model_poly.cpp:1659
options.h
Header file for option handlers.
model_ellipsoidicity
double model_ellipsoidicity(Bmodel *model)
Calculates how close the model is to an ellipsoid shape.
Definition: model_shell.cpp:234
models_process
long models_process(Bmodel *model, long(modfunc)(Bmodel *))
Process a list of models using the specified function.
Definition: model_util.cpp:36
main
int main(int argc, char **argv)
Definition: bpoly.cpp:83
model_calculate_views
long model_calculate_views(Bmodel *model, Bstring &mode)
Calculates the views associated with each component.
Definition: model_views.cpp:263
model_select.h
Header file for reading and writing atomic model files.
model_transform.h
Library routines used for model transformation.
Boption::values
long values(T1 &v1, T2 &v2)
Definition: options.h:115
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
model_check
int model_check(Bmodel *model, Bstring path)
Checks model properties.
Definition: rwmodel.cpp:592