| Bsoft 2.0.5 Bernard's software package

bpath.cpp
Go to the documentation of this file.
1
9 #include "rwmodel.h"
10 #include "model_path.h"
11 #include "model_select.h"
12 #include "model_links.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
22 /* Usage assistance */
23 const char* use[] = {
24 " ",
25 "Usage: bpath [options] in.star",
26 "------------------------------",
27 "Analyzes paths and cycles in a model.",
28 " ",
29 "Actions:",
30 "-all Reset selection to all components before other selections.",
31 "-cutoff 23.5 Assign links within this cutoff distance.",
32 " ",
33 "Parameters:",
34 "-verbose 7 Verbosity of output.",
35 "-componentradius 0.5 Component display radius.",
36 "-linkradius 0.5 Link display radius.",
37 " ",
38 "Input:",
39 "-parameters param.star Input parameter file.",
40 " ",
41 "Output:",
42 "-output path.star Output model file with components linked along paths.",
43 " ",
44 NULL
45 };
46
47 int main(int argc, char **argv)
48 {
49 /* Initialize variables */
50 int reset(0); // Keep selection as read from file
51 double cutoff(0); // Cutoff distance to assign links
52 int minval(2); // Minimum valency
53 double compradius(0); // Component display radius
54 double linkradius(0); // Link display radius
55 Bstring paramfile; // Input parameter file name
56 Bstring outfile; // Output parameter file name
57
58 int optind;
59 Boption* option = get_option_list(use, argc, argv, optind);
60 Boption* curropt;
61 for ( curropt = option; curropt; curropt = curropt->next ) {
62 if ( curropt->tag == "all" ) reset = 1;
63 if ( curropt->tag == "cutoff" )
64 if ( ( cutoff = curropt->value.real() ) < 1 )
65 cerr << "-cutoff: A cutoff distance must be specified!" << endl;
66 if ( curropt->tag == "componentradius" )
67 if ( ( compradius = curropt->value.real() ) < 0.001 )
68 cerr << "-componentradius: The component display radius must be specified!" << endl;
69 if ( curropt->tag == "linkradius" )
70 if ( ( linkradius = curropt->value.real() ) < 0.001 )
71 cerr << "-linkradius: The link display radius must be specified!" << endl;
72 if ( curropt->tag == "parameters" )
73 paramfile = curropt->filename();
74 if ( curropt->tag == "output" )
75 outfile = curropt->filename();
76 }
77 option_kill(option);
78
79 double ti = timer_start();
80
81 // Read all the parameter files
82 Bstring* file_list = NULL;
83 while ( optind < argc ) string_add(&file_list, argv[optind++]);
84 if ( !file_list ) {
85 cerr << "Error: No model files specified!" << endl;
86 bexit(-1);
87 }
88
89 Bmodel* model = read_model(file_list, paramfile);
90 string_kill(file_list);
91
92 if ( !model ) {
93 cerr << "Error: Input file not read!" << endl;
94 bexit(-1);
95 }
96
97 if ( reset ) models_process(model, model_reset_selection);
98
99 if ( cutoff ) models_process(model, cutoff, model_link_list_generate);
100 else models_process(model, minval, model_links_minimum_valency);
101
102 Bmodel* modpath = NULL;
103 modpath = model_hamiltonian_cycle(model);
104 model_kill(model);
105 model = modpath;
106
107 if ( compradius ) models_process(model, compradius, model_set_component_radius);
108
109 if ( linkradius ) models_process(model, linkradius, model_set_link_radius);
110
111 model_selection_stats(model);
112
113 // Write an output parameter format file if a name is given
114 if ( outfile.length() && model ) {
115 model_update_comment(model, argc, argv);
116 write_model(outfile, model);
117 }
118
119 model_kill(model);
120
121 if ( verbose & VERB_TIME )
122 timer_report(ti);
123
124 bexit(0);
125 }
126
127
model_hamiltonian_cycle
Bmodel * model_hamiltonian_cycle(Bmodel *model)
Calculates the Hamiltonian cycles in a model.
Definition: model_path.cpp:239
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
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
Bstring::length
long length() const
Definition: Bstring.cpp:263
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
timer.h
Utilities for timing functions.
main
int main(int argc, char **argv)
Definition: bpath.cpp:47
verbose
int verbose
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
Boption
A class for a command line input option.
Definition: options.h:26
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_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
Boption::next
Boption * next
Definition: options.h:28
use
const char * use[]
Definition: bpath.cpp:23
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_link_list_generate
long model_link_list_generate(Bmodel *model, double maxlength)
Generates a link list for a model based on vertex separation.
Definition: model_links.cpp:70
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
option_kill
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:109
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_links_minimum_valency
long model_links_minimum_valency(Bmodel *model, long valency)
Generates links such that each component has at least the given valency.
Definition: model_links.cpp:294
model_select.h
Header file for reading and writing atomic model files.
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
string_kill
int string_kill(Bstring *list)
Kills a string linked list.
Definition: Bstring.cpp:760