Bsoft  2.1.0
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 
98 
99  if ( cutoff ) models_process(model, cutoff, model_link_list_generate);
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 
112 
113  // Write an output parameter format file if a name is given
114  if ( outfile.length() && model ) {
115  write_model(outfile, model);
116  }
117 
118  model_kill(model);
119 
120  if ( verbose & VERB_TIME )
121  timer_report(ti);
122 
123  bexit(0);
124 }
125 
126 
Boption
A class for a command line input option.
Definition: options.h:26
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
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
model_path.h
Library routines used for model processing.
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:553
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_selection_stats
long model_selection_stats(Bmodel *model)
Calculates selection statistics.
Definition: model_select.cpp:870
Boption::tag
Bstring tag
Definition: options.h:29
main
int main(int argc, char **argv)
Definition: bpath.cpp:47
verbose
int verbose
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
model_select.h
Header file for reading and writing atomic model files.
timer.h
Utilities for timing functions.
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
utilities.h
Header file for general utilities.
write_model
int write_model(Bstring &filename, Bmodel *model)
Writes model parameters.
Definition: rwmodel.cpp:92
use
const char * use[]
Definition: bpath.cpp:23
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
Bmodel * model
Definition: bshow.cpp:34
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.
read_model
Bmodel * read_model(Bstring &filename)
Definition: rwmodel.cpp:29
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:1247
string_add
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
Definition: Bstring.cpp:713