| Bsoft 2.0.5 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
144 models_process(model, 0.1*linklength, model_set_component_radius);
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 model_update_comment(model, argc, argv);
154 write_model(filename, model);
155 }
156
157 model_kill(model);
158
159 if ( verbose & VERB_TIME )
160 timer_report(ti);
161
162 bexit(i);
163 }
164
main
int main(int argc, char **argv)
Definition: bspiral.cpp:53
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
Bmodel::id
Bstring id
Definition: rwmodel.h:121
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
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
count_list
long count_list(char *list)
Counts the number of items in a linked list.
Definition: linked_list.cpp:235
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
verbose
int verbose
Boption::filename
Bstring filename()
Definition: options.h:85
timer.h
Utilities for timing functions.
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
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
linked_list.h
Header file for generalized linked list functions.
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
Bmodel::symmetry
Bstring symmetry
Definition: rwmodel.h:124
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.
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
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
model
Bmodel * model
Definition: bshow.cpp:32
write_model
int write_model(Bstring &filename, Bmodel *model)
Writes model parameters.
Definition: rwmodel.cpp:91
Boption::next
Boption * next
Definition: options.h:28
Bstring
Definition: Bstring.h:29
rwmodel.h
Header file for reading and writing atomic model files.
Vector3< double >
timer_report
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:67
model_scale
long model_scale(Bmodel *model, Vector3< double > scale, Vector3< double > origin)
Scales a model.
Definition: model_transform.cpp:87
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
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
use
const char * use[]
Definition: bspiral.cpp:27
model_poly_spiral.h
Functions to generate polyhedra using the spiral algorithm.
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