Bsoft  2.1.0
Bernard's software package
bdelta.cpp
Go to the documentation of this file.
1 
9 #include "rwmodel.h"
10 #include "model_poly.h"
11 #include "model_poly_delta.h"
12 #include "model_transform.h"
13 #include "model_links.h"
14 #include "model_util.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: bdelta [options] in.star [in2.star ...]",
26 "----------------------------------------------",
27 "Generates and analyzes deltagraphs.",
28 "The creation options are mutually exclusive.",
29 " ",
30 "Actions:",
31 "-pentagonal Create a pentagonal deltagraph.",
32 "-hexagonal Create a hexagonal deltagraph.",
33 "-tube 8,3 Create a tubular deltagraph with the given lattice parameters.",
34 "-caps 2 Add 1 or 2 caps.",
35 "-dual Calculate the dual of a polyhedron.",
36 " ",
37 "Parameters:",
38 "-verbose 7 Verbosity of output.",
39 "-componentradius 0.5 Component display radius.",
40 "-linkradius 0.5 Link display radius.",
41 "-linklength 150 Link length (default 1).",
42 "-radius 3 Radius in integer units (default 1).",
43 "-height 5 Height in integer units (default 1).",
44 " ",
45 "Input:",
46 "-parameters param.star Input parameter file.",
47 " ",
48 "Output:",
49 "-output file.star Output model parameter file.",
50 " ",
51 NULL
52 };
53 
54 int main(int argc, char **argv)
55 {
56  /* Initialize variables */
57  int type(0); // Type of deltagraph
58  int h(0), k(0); // Tube lattice
59  int radius(0); // Cylinder radius
60  int height(0); // Cylinder height
61  int dual(0); // Flag to calculate dual of polyhedron
62  double compradius(0); // Component display radius
63  double linkradius(0); // Link display radius
64  double linklength(1); // Link length
65  Bstring comp_select("all");
66  Bstring paramfile; // Input parameter file
67  Bstring outfile; // Output model parameter 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 == "pentagonal" ) type = 2;
74  if ( curropt->tag == "hexagonal" ) type = 1;
75  if ( curropt->tag == "caps" ) type |= 8 * curropt->value.integer() - 4;
76  if ( curropt->tag == "tube" )
77  if ( curropt->values(h, k) < 1 )
78  cerr << "-tube: At least one integer must be specified!" << endl;
79  if ( curropt->tag == "dual" ) dual = 1;
80  if ( curropt->tag == "radius" )
81  if ( ( radius = curropt->value.integer() ) < 1 )
82  cerr << "-radius: A radius must be specified!" << endl;
83  if ( curropt->tag == "height" )
84  if ( ( height = curropt->value.integer() ) < 1 )
85  cerr << "-height: A height must be specified!" << endl;
86  if ( curropt->tag == "componentradius" )
87  if ( ( compradius = curropt->value.real() ) < 0.001 )
88  cerr << "-componentradius: The component display radius must be specified!" << endl;
89  if ( curropt->tag == "linkradius" )
90  if ( ( linkradius = curropt->value.real() ) < 0.001 )
91  cerr << "-linkradius: The link display radius must be specified!" << endl;
92  if ( curropt->tag == "linklength" )
93  if ( ( linklength = curropt->value.real() ) < 0.001 )
94  cerr << "-linklength: The link length between vertices must be specified!" << endl;
95  if ( curropt->tag == "parameters" )
96  paramfile = curropt->filename();
97  if ( curropt->tag == "output" )
98  outfile = curropt->filename();
99  }
100  option_kill(option);
101 
102  double ti = timer_start();
103 
104  Bmodel* model = NULL;
105  Vector3<double> scale(linklength, linklength, linklength), origin;
106 
107  // Read all the parameter files
108  Bstring* file_list = NULL;
109  while ( optind < argc ) string_add(&file_list, argv[optind++]);
110  if ( !file_list ) {
111  if ( radius > 0 && height > 0 && ( type & 3 ) ) {
112  model = model_delta_create_cylinder(type, radius, height);
113  } else if ( h ) {
114  model = model_delta_create_tube(h, k, height);
115  }
116  if ( model ) {
117  if ( linklength != 1 )
118  model_scale(model, scale, origin);
119  models_process(model, 0.1*linklength, model_set_link_radius);
120  } else {
121  cerr << "Error: No model files specified or generated!" << endl;
122  bexit(-1);
123  }
124  } else {
125  model = read_model(file_list, paramfile);
126  string_kill(file_list);
127  }
128 
129  if ( !model ) {
130  cerr << "Error: No model read or generated!" << endl;
131  bexit(-1);
132  }
133 
134  if ( compradius ) models_process(model, compradius, model_set_component_radius);
135 
136  if ( linkradius ) models_process(model, linkradius, model_set_link_radius);
137 
139 
140  if ( dual ) {
141  Bmodel* new_model = model_poly_dual(model, 0);
142  if ( new_model ) {
143  model_kill(model);
144  model = new_model;
145  }
146  }
147 
148  if ( outfile.length() ) {
149  write_model(outfile, model);
150  }
151 
152  model_kill(model);
153 
154  if ( verbose & VERB_TIME )
155  timer_report(ti);
156 
157  bexit(0);
158 }
159 
Boption
A class for a command line input option.
Definition: options.h:26
model_delta_create_cylinder
Bmodel * model_delta_create_cylinder(int type, int radius, int height)
Generates a new deltagraph based on the type.
Definition: model_poly_delta.cpp:152
string_kill
int string_kill(Bstring *list)
Kills a string linked list.
Definition: Bstring.cpp:768
model_poly_delta.h
Functions to generate deltagraph polyhedra.
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
Vector3< double >
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
Bstring::real
double real()
Definition: Bstring.cpp:553
options.h
Header file for option handlers.
model_delta_create_tube
Bmodel * model_delta_create_tube(int h, int k, int height)
Generates a new tubular deltagraph.
Definition: model_poly_delta.cpp:78
verbose
int verbose
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
Boption::values
long values(T1 &v1, T2 &v2)
Definition: options.h:115
model_poly_dual
Bmodel * model_poly_dual(Bmodel *model, int order)
Calculates the dual of a polyhedral network.
Definition: model_poly.cpp:454
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
timer.h
Utilities for timing functions.
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
Bstring::length
long length() const
Definition: Bstring.cpp:263
model_scale
long model_scale(Bmodel *model, Vector3< double > scale, Vector3< double > origin)
Scales a model.
Definition: model_transform.cpp:87
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
use
const char * use[]
Definition: bdelta.cpp:23
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_transform.h
Library routines used for model transformation.
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
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
main
int main(int argc, char **argv)
Definition: bdelta.cpp:54
string_add
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
Definition: Bstring.cpp:713