Bsoft  2.1.0
Bernard's software package
bspiral.cpp
Go to the documentation of this file.
1 
9 #include "rwmodel.h"
10 #include "model_poly.h"
11 #include "model_poly_spiral.h"
12 #include "model_transform.h"
13 #include "model_links.h"
14 #include "model_util.h"
15 #include "linked_list.h"
16 #include "utilities.h"
17 #include "options.h"
18 #include "timer.h"
19 
20 #include <sys/stat.h>
21 #include <fcntl.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: bspiral [options] out.star",
30 "---------------------------------",
31 "Generates a polyhedron using the spiral algorithm.",
32 " ",
33 "Actions:",
34 "-analyze Analyze the polyhedron.",
35 "-enantiomorph Generate the enantiomorph of the polyhedron.",
36 "-sequence 5566665566565 Sequence of polygons to use in stead of permutations.",
37 "-cone 14,30,25 Polygons to generate for the tip, body and base of a cone.",
38 "-lozenge 2,7 Unit lengths for the top and body of a lozenge.",
39 "-coffin 3,5,2 Unit lengths for the top, body and base of a coffin.",
40 " ",
41 "Parameters:",
42 "-verbose 7 Verbosity of output.",
43 "-vertices 36 Number of vertices (default 20).",
44 "-linklength 150 Vertex separation (default 10 A).",
45 "-requirements 0 Polyhedron acceptance requirements (default 1 = strict).",
46 " ",
47 "Input:",
48 "-parameters parm.star Molecular parameter file (default atom_prop.star).",
49 " ",
50 NULL
51 };
52 
53 int main(int argc, char **argv)
54 {
55  /* Initialize variables */
56  int analyze(0); // Flag to analyze the structure
57  int enantiomorph(0); // Flag to generate enantiomorphs
58  int vertices(20); // Number of vertices
59  int valence(3); // Vertex valence
60  double linklength(1); // Unit length separating vertices/triskelions
61  int use_one(0); // Flag to indicate using only one sequence
62  int conetip(0);
63  int conebody(0);
64  int conebase(0);
65  int loztop(0);
66  int lozbody(0);
67  int coftop(0);
68  int cofbody(0);
69  int cofbase(0);
70  int requirements(1); // Polyhedron acceptance requirements
71  Bstring seq("555555555555"); // Initial sequence
72  Bstring paramfile; // Use default parameter file
73 
74  int i, optind;
75  Boption* option = get_option_list(use, argc, argv, optind);
76  Boption* curropt;
77  for ( curropt = option; curropt; curropt = curropt->next ) {
78  if ( curropt->tag == "analyze" ) analyze = 1;
79  if ( curropt->tag == "enantiomorph" ) enantiomorph = 1;
80  if ( curropt->tag == "vertices" ) {
81  if ( ( vertices = curropt->value.integer() ) < 1 )
82  cerr << "-vertices: The number of vertices must be specified!" << endl;
83  else {
84  use_one = 0;
85  }
86  }
87  if ( curropt->tag == "sequence" ) {
88  seq = curropt->value;
89  vertices = 20 + 2*(seq.length() - 12);
90  use_one = 1;
91  }
92  if ( curropt->tag == "cone" )
93  if ( curropt->values(conetip, conebody, conebase) < 3 )
94  cerr << "-cone: Three integers must be specified!" << endl;
95  if ( curropt->tag == "lozenge" )
96  if ( curropt->values(loztop, lozbody) < 2 )
97  cerr << "-lozenge: Two integers must be specified!" << endl;
98  if ( curropt->tag == "coffin" )
99  if ( curropt->values(coftop, cofbody, cofbase) < 3 )
100  cerr << "-coffin: Three integers must be specified!" << endl;
101  if ( curropt->tag == "linklength" )
102  if ( ( linklength = curropt->value.real() ) < 1 )
103  cerr << "-linklength: The link length separating vertices must be specified!" << endl;
104  if ( curropt->tag == "requirements" )
105  if ( ( requirements = curropt->value.integer() ) < 1 )
106  cerr << "-requirements: An integer must be specified!" << endl;
107  if ( curropt->tag == "parameters" )
108  paramfile = curropt->filename();
109  }
110  option_kill(option);
111 
112  double ti = timer_start();
113 
114  mkdir("temp", O_CREAT );
115  chmod("temp", 0755);
116 
117  Bmodel* model = NULL;
118 
119  if ( use_one ) {
120  model = model_poly_gen_sequence(seq, valence, enantiomorph, requirements, 0);
121  if ( model )
122  cout << model->id << ": " << seq << ": " << model->symmetry << endl;
123  } else if ( conetip > 0 && conebody > 0 && conebase > 0 ) {
124  model = model_poly_gen_cone(conetip, conebody, conebase, valence, enantiomorph, requirements);
125  } else if ( loztop > 0 ) {
126  model = model_poly_gen_lozenge(loztop, lozbody, valence, enantiomorph, requirements);
127  } else if ( coftop > 0 && cofbody > 0 && cofbase > 0 ) {
128 // model = model_poly_gen_coffin(coftop, cofbody, cofbase, valence, enantiomorph, requirements);
129 // model = model_poly_gen_coffin_loose(coftop, cofbody, cofbase, valence, enantiomorph, requirements);
130  model = model_poly_gen_coffin_jiggle(coftop, cofbody, cofbase, valence, enantiomorph, requirements);
131  } else {
132  model = model_poly_gen_permutations(vertices, valence, enantiomorph);
133  }
134 
135  i = count_list((char *)model);
136 
137  if ( !i )
138  if ( verbose ) cout << "No model generated!" << endl;
139 
140  Vector3<double> scale(linklength,linklength,linklength);
141  Vector3<double> origin;
142  model_scale(model, scale, origin);
143 
145 
146  models_process(model, 0.1*linklength, model_set_link_radius);
147 
148  if ( analyze ) model_poly_analyze(model);
149 
150  Bstring filename;
151  if ( optind < argc ) {
152  filename = argv[optind];
153  write_model(filename, model);
154  }
155 
156  model_kill(model);
157 
158  if ( verbose & VERB_TIME )
159  timer_report(ti);
160 
161  bexit(i);
162 }
163 
Boption
A class for a command line input option.
Definition: options.h:26
rwmodel.h
Header file for reading and writing atomic model files.
Bstring
Definition: Bstring.h:29
use
const char * use[]
Definition: bspiral.cpp:27
Bstring::integer
long integer()
Definition: Bstring.cpp:547
Boption::next
Boption * next
Definition: options.h:28
model_poly_gen_lozenge
Bmodel * model_poly_gen_lozenge(int ttop, int tbody, int valence, int enantiomorph, int requirements)
Two icosahedral tips are set up and polyhedra generated by rotating the 2 tips.
Definition: model_poly_spiral.cpp:598
Vector3< double >
bexit
int bexit(int value)
Exit function for cleanup and debugging.
Definition: utilities.cpp:280
model_poly_gen_permutations
Bmodel * model_poly_gen_permutations(int vertices, int valence, int enantiomorph)
All polyhedra are generated for a given number of vertices.
Definition: model_poly_spiral.cpp:494
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.
count_list
long count_list(char *list)
Counts the number of items in a linked list.
Definition: linked_list.cpp:235
models_process
long models_process(Bmodel *model, long(modfunc)(Bmodel *))
Process a list of models using the specified function.
Definition: model_util.cpp:36
verbose
int verbose
model_poly_gen_sequence
Bmodel * model_poly_gen_sequence(Bstring &seq, int valence, int enantiomorph, int requirements, int nm)
Generates a polyhedron using a given sequence.
Definition: model_poly_spiral.cpp:399
Boption::tag
Bstring tag
Definition: options.h:29
Boption::values
long values(T1 &v1, T2 &v2)
Definition: options.h:115
main
int main(int argc, char **argv)
Definition: bspiral.cpp:53
Bmodel::id
Bstring id
Definition: rwmodel.h:121
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.
model_poly_gen_cone
Bmodel * model_poly_gen_cone(int tip, int body, int base, int valence, int enantiomorph, int requirements)
A cone tip with 5 pentagons and a base with 7 pentagons are use to generate polyhedra.
Definition: model_poly_spiral.cpp:557
model_poly_spiral.h
Functions to generate polyhedra using the spiral algorithm.
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
linked_list.h
Header file for generalized linked list functions.
Boption::filename
Bstring filename()
Definition: options.h:85
model_poly_analyze
int model_poly_analyze(Bmodel *model)
Analyzes a model for polygon regularity and planarity.
Definition: model_poly.cpp:538
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_util.h
Library routines used for model processing.
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
model_poly_gen_coffin_jiggle
Bmodel * model_poly_gen_coffin_jiggle(int ttop, int tbody, int tbase, int valence, int enantiomorph, int requirements)
An icosahedral tip and a 6-fold base is set up and polyhedra generated by moving pentagons around.
Definition: model_poly_spiral.cpp:770
Bmodel::symmetry
Bstring symmetry
Definition: rwmodel.h:124