1 | /** \file builder.cpp
|
---|
2 | *
|
---|
3 | * By stating absolute positions or binding angles and distances atomic positions of a molecule can be constructed.
|
---|
4 | * The output is the complete configuration file for PCP for direct use.
|
---|
5 | * Features:
|
---|
6 | * -# Atomic data is retrieved from a file, if not found requested and stored there for later re-use
|
---|
7 | * -# step-by-step construction of the molecule beginning either at a centre of with a certain atom
|
---|
8 | *
|
---|
9 | */
|
---|
10 |
|
---|
11 | /*! \mainpage Molecuilder - a molecular set builder
|
---|
12 | *
|
---|
13 | * This introductory shall briefly make aquainted with the program, helping in installing and a first run.
|
---|
14 | *
|
---|
15 | * \section about About the Program
|
---|
16 | *
|
---|
17 | * Molecuilder is a short program, written in C++, that enables the construction of a coordinate set for the
|
---|
18 | * atoms making up an molecule by the successive statement of binding angles and distances and referencing to
|
---|
19 | * already constructed atoms.
|
---|
20 | *
|
---|
21 | * A configuration file may be written that is compatible to the format used by PCP - a parallel Car-Parrinello
|
---|
22 | * molecular dynamics implementation.
|
---|
23 | *
|
---|
24 | * \section install Installation
|
---|
25 | *
|
---|
26 | * Installation should without problems succeed as follows:
|
---|
27 | * -# ./configure (or: mkdir build;mkdir run;cd build; ../configure --bindir=../run)
|
---|
28 | * -# make
|
---|
29 | * -# make install
|
---|
30 | *
|
---|
31 | * Further useful commands are
|
---|
32 | * -# make clean uninstall: deletes .o-files and removes executable from the given binary directory\n
|
---|
33 | * -# make doxygen-doc: Creates these html pages out of the documented source
|
---|
34 | *
|
---|
35 | * \section run Running
|
---|
36 | *
|
---|
37 | * The program can be executed by running: ./molecuilder
|
---|
38 | *
|
---|
39 | * Note, that it uses a database, called "elements.db", in the executable's directory. If the file is not found,
|
---|
40 | * it is created and any given data on elements of the periodic table will be stored therein and re-used on
|
---|
41 | * later re-execution.
|
---|
42 | *
|
---|
43 | * \section ref References
|
---|
44 | *
|
---|
45 | * For the special configuration file format, see the documentation of pcp.
|
---|
46 | *
|
---|
47 | */
|
---|
48 |
|
---|
49 | #include "Helpers/MemDebug.hpp"
|
---|
50 |
|
---|
51 | #include <boost/bind.hpp>
|
---|
52 |
|
---|
53 | using namespace std;
|
---|
54 |
|
---|
55 | #include <cstring>
|
---|
56 | #include <cstdlib>
|
---|
57 |
|
---|
58 | #include "analysis_bonds.hpp"
|
---|
59 | #include "analysis_correlation.hpp"
|
---|
60 | #include "atom.hpp"
|
---|
61 | #include "bond.hpp"
|
---|
62 | #include "bondgraph.hpp"
|
---|
63 | #include "boundary.hpp"
|
---|
64 | #include "CommandLineParser.hpp"
|
---|
65 | #include "config.hpp"
|
---|
66 | #include "element.hpp"
|
---|
67 | #include "ellipsoid.hpp"
|
---|
68 | #include "helpers.hpp"
|
---|
69 | #include "leastsquaremin.hpp"
|
---|
70 | #include "linkedcell.hpp"
|
---|
71 | #include "log.hpp"
|
---|
72 | #include "memoryusageobserver.hpp"
|
---|
73 | #include "molecule.hpp"
|
---|
74 | #include "periodentafel.hpp"
|
---|
75 | #include "UIElements/UIFactory.hpp"
|
---|
76 | #include "UIElements/TextUI/TextUIFactory.hpp"
|
---|
77 | #include "UIElements/CommandLineUI/CommandLineUIFactory.hpp"
|
---|
78 | #ifdef USE_GUI_QT
|
---|
79 | #include "UIElements/QT4/QTUIFactory.hpp"
|
---|
80 | #endif
|
---|
81 | #include "UIElements/MainWindow.hpp"
|
---|
82 | #include "UIElements/Dialog.hpp"
|
---|
83 | #include "Menu/ActionMenuItem.hpp"
|
---|
84 | #include "Actions/ActionRegistry.hpp"
|
---|
85 | #include "Actions/ActionHistory.hpp"
|
---|
86 | #include "Actions/MapOfActions.hpp"
|
---|
87 | #include "Actions/MethodAction.hpp"
|
---|
88 | #include "Actions/MoleculeAction/ChangeNameAction.hpp"
|
---|
89 | #include "World.hpp"
|
---|
90 | #include "version.h"
|
---|
91 | #include "World.hpp"
|
---|
92 |
|
---|
93 |
|
---|
94 | /********************************************* Subsubmenu routine ************************************/
|
---|
95 | #if 0
|
---|
96 | /** Submenu for adding atoms to the molecule.
|
---|
97 | * \param *periode periodentafel
|
---|
98 | * \param *molecule molecules with atoms
|
---|
99 | */
|
---|
100 | static void AddAtoms(periodentafel *periode, molecule *mol)
|
---|
101 | {
|
---|
102 | atom *first, *second, *third, *fourth;
|
---|
103 | Vector **atoms;
|
---|
104 | Vector x,y,z,n; // coordinates for absolute point in cell volume
|
---|
105 | double a,b,c;
|
---|
106 | char choice; // menu choice char
|
---|
107 | bool valid;
|
---|
108 |
|
---|
109 | cout << Verbose(0) << "===========ADD ATOM============================" << endl;
|
---|
110 | cout << Verbose(0) << " a - state absolute coordinates of atom" << endl;
|
---|
111 | cout << Verbose(0) << " b - state relative coordinates of atom wrt to reference point" << endl;
|
---|
112 | cout << Verbose(0) << " c - state relative coordinates of atom wrt to already placed atom" << endl;
|
---|
113 | cout << Verbose(0) << " d - state two atoms, two angles and a distance" << endl;
|
---|
114 | cout << Verbose(0) << " e - least square distance position to a set of atoms" << endl;
|
---|
115 | cout << Verbose(0) << "all else - go back" << endl;
|
---|
116 | cout << Verbose(0) << "===============================================" << endl;
|
---|
117 | cout << Verbose(0) << "Note: Specifiy angles in degrees not multiples of Pi!" << endl;
|
---|
118 | cout << Verbose(0) << "INPUT: ";
|
---|
119 | cin >> choice;
|
---|
120 |
|
---|
121 | switch (choice) {
|
---|
122 | default:
|
---|
123 | DoeLog(2) && (eLog()<< Verbose(2) << "Not a valid choice." << endl);
|
---|
124 | break;
|
---|
125 | case 'a': // absolute coordinates of atom
|
---|
126 | cout << Verbose(0) << "Enter absolute coordinates." << endl;
|
---|
127 | first = new atom;
|
---|
128 | first->x.AskPosition(World::getInstance().getDomain(), false);
|
---|
129 | first->type = periode->AskElement(); // give type
|
---|
130 | mol->AddAtom(first); // add to molecule
|
---|
131 | break;
|
---|
132 |
|
---|
133 | case 'b': // relative coordinates of atom wrt to reference point
|
---|
134 | first = new atom;
|
---|
135 | valid = true;
|
---|
136 | do {
|
---|
137 | if (!valid) DoeLog(2) && (eLog()<< Verbose(2) << "Resulting position out of cell." << endl);
|
---|
138 | cout << Verbose(0) << "Enter reference coordinates." << endl;
|
---|
139 | x.AskPosition(World::getInstance().getDomain(), true);
|
---|
140 | cout << Verbose(0) << "Enter relative coordinates." << endl;
|
---|
141 | first->x.AskPosition(World::getInstance().getDomain(), false);
|
---|
142 | first->x.AddVector((const Vector *)&x);
|
---|
143 | cout << Verbose(0) << "\n";
|
---|
144 | } while (!(valid = mol->CheckBounds((const Vector *)&first->x)));
|
---|
145 | first->type = periode->AskElement(); // give type
|
---|
146 | mol->AddAtom(first); // add to molecule
|
---|
147 | break;
|
---|
148 |
|
---|
149 | case 'c': // relative coordinates of atom wrt to already placed atom
|
---|
150 | first = new atom;
|
---|
151 | valid = true;
|
---|
152 | do {
|
---|
153 | if (!valid) DoeLog(2) && (eLog()<< Verbose(2) << "Resulting position out of cell." << endl);
|
---|
154 | second = mol->AskAtom("Enter atom number: ");
|
---|
155 | DoLog(0) && (Log() << Verbose(0) << "Enter relative coordinates." << endl);
|
---|
156 | first->x.AskPosition(World::getInstance().getDomain(), false);
|
---|
157 | for (int i=NDIM;i--;) {
|
---|
158 | first->x.x[i] += second->x.x[i];
|
---|
159 | }
|
---|
160 | } while (!(valid = mol->CheckBounds((const Vector *)&first->x)));
|
---|
161 | first->type = periode->AskElement(); // give type
|
---|
162 | mol->AddAtom(first); // add to molecule
|
---|
163 | break;
|
---|
164 |
|
---|
165 | case 'd': // two atoms, two angles and a distance
|
---|
166 | first = new atom;
|
---|
167 | valid = true;
|
---|
168 | do {
|
---|
169 | if (!valid) {
|
---|
170 | DoeLog(2) && (eLog()<< Verbose(2) << "Resulting coordinates out of cell - " << first->x << endl);
|
---|
171 | }
|
---|
172 | cout << Verbose(0) << "First, we need two atoms, the first atom is the central, while the second is the outer one." << endl;
|
---|
173 | second = mol->AskAtom("Enter central atom: ");
|
---|
174 | third = mol->AskAtom("Enter second atom (specifying the axis for first angle): ");
|
---|
175 | fourth = mol->AskAtom("Enter third atom (specifying a plane for second angle): ");
|
---|
176 | a = ask_value("Enter distance between central (first) and new atom: ");
|
---|
177 | b = ask_value("Enter angle between new, first and second atom (degrees): ");
|
---|
178 | b *= M_PI/180.;
|
---|
179 | bound(&b, 0., 2.*M_PI);
|
---|
180 | c = ask_value("Enter second angle between new and normal vector of plane defined by first, second and third atom (degrees): ");
|
---|
181 | c *= M_PI/180.;
|
---|
182 | bound(&c, -M_PI, M_PI);
|
---|
183 | cout << Verbose(0) << "radius: " << a << "\t phi: " << b*180./M_PI << "\t theta: " << c*180./M_PI << endl;
|
---|
184 | /*
|
---|
185 | second->Output(1,1,(ofstream *)&cout);
|
---|
186 | third->Output(1,2,(ofstream *)&cout);
|
---|
187 | fourth->Output(1,3,(ofstream *)&cout);
|
---|
188 | n.MakeNormalvector((const vector *)&second->x, (const vector *)&third->x, (const vector *)&fourth->x);
|
---|
189 | x.Copyvector(&second->x);
|
---|
190 | x.SubtractVector(&third->x);
|
---|
191 | x.Copyvector(&fourth->x);
|
---|
192 | x.SubtractVector(&third->x);
|
---|
193 |
|
---|
194 | if (!z.SolveSystem(&x,&y,&n, b, c, a)) {
|
---|
195 | coutg() << Verbose(0) << "Failure solving self-dependent linear system!" << endl;
|
---|
196 | continue;
|
---|
197 | }
|
---|
198 | DoLog(0) && (Log() << Verbose(0) << "resulting relative coordinates: ");
|
---|
199 | z.Output();
|
---|
200 | DoLog(0) && (Log() << Verbose(0) << endl);
|
---|
201 | */
|
---|
202 | // calc axis vector
|
---|
203 | x.CopyVector(&second->x);
|
---|
204 | x.SubtractVector(&third->x);
|
---|
205 | x.Normalize();
|
---|
206 | Log() << Verbose(0) << "x: ",
|
---|
207 | x.Output();
|
---|
208 | DoLog(0) && (Log() << Verbose(0) << endl);
|
---|
209 | z.MakeNormalVector(&second->x,&third->x,&fourth->x);
|
---|
210 | Log() << Verbose(0) << "z: ",
|
---|
211 | z.Output();
|
---|
212 | DoLog(0) && (Log() << Verbose(0) << endl);
|
---|
213 | y.MakeNormalVector(&x,&z);
|
---|
214 | Log() << Verbose(0) << "y: ",
|
---|
215 | y.Output();
|
---|
216 | DoLog(0) && (Log() << Verbose(0) << endl);
|
---|
217 |
|
---|
218 | // rotate vector around first angle
|
---|
219 | first->x.CopyVector(&x);
|
---|
220 | first->x.RotateVector(&z,b - M_PI);
|
---|
221 | Log() << Verbose(0) << "Rotated vector: ",
|
---|
222 | first->x.Output();
|
---|
223 | DoLog(0) && (Log() << Verbose(0) << endl);
|
---|
224 | // remove the projection onto the rotation plane of the second angle
|
---|
225 | n.CopyVector(&y);
|
---|
226 | n.Scale(first->x.ScalarProduct(&y));
|
---|
227 | Log() << Verbose(0) << "N1: ",
|
---|
228 | n.Output();
|
---|
229 | DoLog(0) && (Log() << Verbose(0) << endl);
|
---|
230 | first->x.SubtractVector(&n);
|
---|
231 | Log() << Verbose(0) << "Subtracted vector: ",
|
---|
232 | first->x.Output();
|
---|
233 | DoLog(0) && (Log() << Verbose(0) << endl);
|
---|
234 | n.CopyVector(&z);
|
---|
235 | n.Scale(first->x.ScalarProduct(&z));
|
---|
236 | Log() << Verbose(0) << "N2: ",
|
---|
237 | n.Output();
|
---|
238 | DoLog(0) && (Log() << Verbose(0) << endl);
|
---|
239 | first->x.SubtractVector(&n);
|
---|
240 | Log() << Verbose(0) << "2nd subtracted vector: ",
|
---|
241 | first->x.Output();
|
---|
242 | DoLog(0) && (Log() << Verbose(0) << endl);
|
---|
243 |
|
---|
244 | // rotate another vector around second angle
|
---|
245 | n.CopyVector(&y);
|
---|
246 | n.RotateVector(&x,c - M_PI);
|
---|
247 | Log() << Verbose(0) << "2nd Rotated vector: ",
|
---|
248 | n.Output();
|
---|
249 | DoLog(0) && (Log() << Verbose(0) << endl);
|
---|
250 |
|
---|
251 | // add the two linear independent vectors
|
---|
252 | first->x.AddVector(&n);
|
---|
253 | first->x.Normalize();
|
---|
254 | first->x.Scale(a);
|
---|
255 | first->x.AddVector(&second->x);
|
---|
256 |
|
---|
257 | DoLog(0) && (Log() << Verbose(0) << "resulting coordinates: ");
|
---|
258 | first->x.Output();
|
---|
259 | DoLog(0) && (Log() << Verbose(0) << endl);
|
---|
260 | } while (!(valid = mol->CheckBounds((const Vector *)&first->x)));
|
---|
261 | first->type = periode->AskElement(); // give type
|
---|
262 | mol->AddAtom(first); // add to molecule
|
---|
263 | break;
|
---|
264 |
|
---|
265 | case 'e': // least square distance position to a set of atoms
|
---|
266 | first = new atom;
|
---|
267 | atoms = new (Vector*[128]);
|
---|
268 | valid = true;
|
---|
269 | for(int i=128;i--;)
|
---|
270 | atoms[i] = NULL;
|
---|
271 | int i=0, j=0;
|
---|
272 | cout << Verbose(0) << "Now we need at least three molecules.\n";
|
---|
273 | do {
|
---|
274 | cout << Verbose(0) << "Enter " << i+1 << "th atom: ";
|
---|
275 | cin >> j;
|
---|
276 | if (j != -1) {
|
---|
277 | second = mol->FindAtom(j);
|
---|
278 | atoms[i++] = &(second->x);
|
---|
279 | }
|
---|
280 | } while ((j != -1) && (i<128));
|
---|
281 | if (i >= 2) {
|
---|
282 | first->x.LSQdistance((const Vector **)atoms, i);
|
---|
283 | first->x.Output();
|
---|
284 | first->type = periode->AskElement(); // give type
|
---|
285 | mol->AddAtom(first); // add to molecule
|
---|
286 | } else {
|
---|
287 | delete first;
|
---|
288 | cout << Verbose(0) << "Please enter at least two vectors!\n";
|
---|
289 | }
|
---|
290 | break;
|
---|
291 | };
|
---|
292 | };
|
---|
293 |
|
---|
294 | /** Submenu for centering the atoms in the molecule.
|
---|
295 | * \param *mol molecule with all the atoms
|
---|
296 | */
|
---|
297 | static void CenterAtoms(molecule *mol)
|
---|
298 | {
|
---|
299 | Vector x, y, helper;
|
---|
300 | char choice; // menu choice char
|
---|
301 |
|
---|
302 | cout << Verbose(0) << "===========CENTER ATOMS=========================" << endl;
|
---|
303 | cout << Verbose(0) << " a - on origin" << endl;
|
---|
304 | cout << Verbose(0) << " b - on center of gravity" << endl;
|
---|
305 | cout << Verbose(0) << " c - within box with additional boundary" << endl;
|
---|
306 | cout << Verbose(0) << " d - within given simulation box" << endl;
|
---|
307 | cout << Verbose(0) << "all else - go back" << endl;
|
---|
308 | cout << Verbose(0) << "===============================================" << endl;
|
---|
309 | cout << Verbose(0) << "INPUT: ";
|
---|
310 | cin >> choice;
|
---|
311 |
|
---|
312 | switch (choice) {
|
---|
313 | default:
|
---|
314 | cout << Verbose(0) << "Not a valid choice." << endl;
|
---|
315 | break;
|
---|
316 | case 'a':
|
---|
317 | cout << Verbose(0) << "Centering atoms in config file on origin." << endl;
|
---|
318 | mol->CenterOrigin();
|
---|
319 | break;
|
---|
320 | case 'b':
|
---|
321 | cout << Verbose(0) << "Centering atoms in config file on center of gravity." << endl;
|
---|
322 | mol->CenterPeriodic();
|
---|
323 | break;
|
---|
324 | case 'c':
|
---|
325 | cout << Verbose(0) << "Centering atoms in config file within given additional boundary." << endl;
|
---|
326 | for (int i=0;i<NDIM;i++) {
|
---|
327 | cout << Verbose(0) << "Enter axis " << i << " boundary: ";
|
---|
328 | cin >> y.x[i];
|
---|
329 | }
|
---|
330 | mol->CenterEdge(&x); // make every coordinate positive
|
---|
331 | mol->Center.AddVector(&y); // translate by boundary
|
---|
332 | helper.CopyVector(&y);
|
---|
333 | helper.Scale(2.);
|
---|
334 | helper.AddVector(&x);
|
---|
335 | mol->SetBoxDimension(&helper); // update Box of atoms by boundary
|
---|
336 | break;
|
---|
337 | case 'd':
|
---|
338 | cout << Verbose(1) << "Centering atoms in config file within given simulation box." << endl;
|
---|
339 | for (int i=0;i<NDIM;i++) {
|
---|
340 | cout << Verbose(0) << "Enter axis " << i << " boundary: ";
|
---|
341 | cin >> x.x[i];
|
---|
342 | }
|
---|
343 | // update Box of atoms by boundary
|
---|
344 | mol->SetBoxDimension(&x);
|
---|
345 | // center
|
---|
346 | mol->CenterInBox();
|
---|
347 | break;
|
---|
348 | }
|
---|
349 | };
|
---|
350 |
|
---|
351 | /** Submenu for aligning the atoms in the molecule.
|
---|
352 | * \param *periode periodentafel
|
---|
353 | * \param *mol molecule with all the atoms
|
---|
354 | */
|
---|
355 | static void AlignAtoms(periodentafel *periode, molecule *mol)
|
---|
356 | {
|
---|
357 | atom *first, *second, *third;
|
---|
358 | Vector x,n;
|
---|
359 | char choice; // menu choice char
|
---|
360 |
|
---|
361 | cout << Verbose(0) << "===========ALIGN ATOMS=========================" << endl;
|
---|
362 | cout << Verbose(0) << " a - state three atoms defining align plane" << endl;
|
---|
363 | cout << Verbose(0) << " b - state alignment vector" << endl;
|
---|
364 | cout << Verbose(0) << " c - state two atoms in alignment direction" << endl;
|
---|
365 | cout << Verbose(0) << " d - align automatically by least square fit" << endl;
|
---|
366 | cout << Verbose(0) << "all else - go back" << endl;
|
---|
367 | cout << Verbose(0) << "===============================================" << endl;
|
---|
368 | cout << Verbose(0) << "INPUT: ";
|
---|
369 | cin >> choice;
|
---|
370 |
|
---|
371 | switch (choice) {
|
---|
372 | default:
|
---|
373 | case 'a': // three atoms defining mirror plane
|
---|
374 | first = mol->AskAtom("Enter first atom: ");
|
---|
375 | second = mol->AskAtom("Enter second atom: ");
|
---|
376 | third = mol->AskAtom("Enter third atom: ");
|
---|
377 |
|
---|
378 | n.MakeNormalVector((const Vector *)&first->x,(const Vector *)&second->x,(const Vector *)&third->x);
|
---|
379 | break;
|
---|
380 | case 'b': // normal vector of mirror plane
|
---|
381 | cout << Verbose(0) << "Enter normal vector of mirror plane." << endl;
|
---|
382 | n.AskPosition(World::getInstance().getDomain(),0);
|
---|
383 | n.Normalize();
|
---|
384 | break;
|
---|
385 | case 'c': // three atoms defining mirror plane
|
---|
386 | first = mol->AskAtom("Enter first atom: ");
|
---|
387 | second = mol->AskAtom("Enter second atom: ");
|
---|
388 |
|
---|
389 | n.CopyVector((const Vector *)&first->x);
|
---|
390 | n.SubtractVector((const Vector *)&second->x);
|
---|
391 | n.Normalize();
|
---|
392 | break;
|
---|
393 | case 'd':
|
---|
394 | char shorthand[4];
|
---|
395 | Vector a;
|
---|
396 | struct lsq_params param;
|
---|
397 | do {
|
---|
398 | fprintf(stdout, "Enter the element of atoms to be chosen: ");
|
---|
399 | fscanf(stdin, "%3s", shorthand);
|
---|
400 | } while ((param.type = periode->FindElement(shorthand)) == NULL);
|
---|
401 | cout << Verbose(0) << "Element is " << param.type->name << endl;
|
---|
402 | mol->GetAlignvector(¶m);
|
---|
403 | for (int i=NDIM;i--;) {
|
---|
404 | x.x[i] = gsl_vector_get(param.x,i);
|
---|
405 | n.x[i] = gsl_vector_get(param.x,i+NDIM);
|
---|
406 | }
|
---|
407 | gsl_vector_free(param.x);
|
---|
408 | cout << Verbose(0) << "Offset vector: ";
|
---|
409 | x.Output();
|
---|
410 | DoLog(0) && (Log() << Verbose(0) << endl);
|
---|
411 | n.Normalize();
|
---|
412 | break;
|
---|
413 | };
|
---|
414 | DoLog(0) && (Log() << Verbose(0) << "Alignment vector: ");
|
---|
415 | n.Output();
|
---|
416 | DoLog(0) && (Log() << Verbose(0) << endl);
|
---|
417 | mol->Align(&n);
|
---|
418 | };
|
---|
419 |
|
---|
420 | /** Submenu for mirroring the atoms in the molecule.
|
---|
421 | * \param *mol molecule with all the atoms
|
---|
422 | */
|
---|
423 | static void MirrorAtoms(molecule *mol)
|
---|
424 | {
|
---|
425 | atom *first, *second, *third;
|
---|
426 | Vector n;
|
---|
427 | char choice; // menu choice char
|
---|
428 |
|
---|
429 | DoLog(0) && (Log() << Verbose(0) << "===========MIRROR ATOMS=========================" << endl);
|
---|
430 | DoLog(0) && (Log() << Verbose(0) << " a - state three atoms defining mirror plane" << endl);
|
---|
431 | DoLog(0) && (Log() << Verbose(0) << " b - state normal vector of mirror plane" << endl);
|
---|
432 | DoLog(0) && (Log() << Verbose(0) << " c - state two atoms in normal direction" << endl);
|
---|
433 | DoLog(0) && (Log() << Verbose(0) << "all else - go back" << endl);
|
---|
434 | DoLog(0) && (Log() << Verbose(0) << "===============================================" << endl);
|
---|
435 | DoLog(0) && (Log() << Verbose(0) << "INPUT: ");
|
---|
436 | cin >> choice;
|
---|
437 |
|
---|
438 | switch (choice) {
|
---|
439 | default:
|
---|
440 | case 'a': // three atoms defining mirror plane
|
---|
441 | first = mol->AskAtom("Enter first atom: ");
|
---|
442 | second = mol->AskAtom("Enter second atom: ");
|
---|
443 | third = mol->AskAtom("Enter third atom: ");
|
---|
444 |
|
---|
445 | n.MakeNormalVector((const Vector *)&first->x,(const Vector *)&second->x,(const Vector *)&third->x);
|
---|
446 | break;
|
---|
447 | case 'b': // normal vector of mirror plane
|
---|
448 | DoLog(0) && (Log() << Verbose(0) << "Enter normal vector of mirror plane." << endl);
|
---|
449 | n.AskPosition(World::getInstance().getDomain(),0);
|
---|
450 | n.Normalize();
|
---|
451 | break;
|
---|
452 | case 'c': // three atoms defining mirror plane
|
---|
453 | first = mol->AskAtom("Enter first atom: ");
|
---|
454 | second = mol->AskAtom("Enter second atom: ");
|
---|
455 |
|
---|
456 | n.CopyVector((const Vector *)&first->x);
|
---|
457 | n.SubtractVector((const Vector *)&second->x);
|
---|
458 | n.Normalize();
|
---|
459 | break;
|
---|
460 | };
|
---|
461 | DoLog(0) && (Log() << Verbose(0) << "Normal vector: ");
|
---|
462 | n.Output();
|
---|
463 | DoLog(0) && (Log() << Verbose(0) << endl);
|
---|
464 | mol->Mirror((const Vector *)&n);
|
---|
465 | };
|
---|
466 |
|
---|
467 | /** Submenu for removing the atoms from the molecule.
|
---|
468 | * \param *mol molecule with all the atoms
|
---|
469 | */
|
---|
470 | static void RemoveAtoms(molecule *mol)
|
---|
471 | {
|
---|
472 | atom *first, *second;
|
---|
473 | int axis;
|
---|
474 | double tmp1, tmp2;
|
---|
475 | char choice; // menu choice char
|
---|
476 |
|
---|
477 | DoLog(0) && (Log() << Verbose(0) << "===========REMOVE ATOMS=========================" << endl);
|
---|
478 | DoLog(0) && (Log() << Verbose(0) << " a - state atom for removal by number" << endl);
|
---|
479 | DoLog(0) && (Log() << Verbose(0) << " b - keep only in radius around atom" << endl);
|
---|
480 | DoLog(0) && (Log() << Verbose(0) << " c - remove this with one axis greater value" << endl);
|
---|
481 | DoLog(0) && (Log() << Verbose(0) << "all else - go back" << endl);
|
---|
482 | DoLog(0) && (Log() << Verbose(0) << "===============================================" << endl);
|
---|
483 | DoLog(0) && (Log() << Verbose(0) << "INPUT: ");
|
---|
484 | cin >> choice;
|
---|
485 |
|
---|
486 | switch (choice) {
|
---|
487 | default:
|
---|
488 | case 'a':
|
---|
489 | if (mol->RemoveAtom(mol->AskAtom("Enter number of atom within molecule: ")))
|
---|
490 | DoLog(1) && (Log() << Verbose(1) << "Atom removed." << endl);
|
---|
491 | else
|
---|
492 | DoLog(1) && (Log() << Verbose(1) << "Atom not found." << endl);
|
---|
493 | break;
|
---|
494 | case 'b':
|
---|
495 | second = mol->AskAtom("Enter number of atom as reference point: ");
|
---|
496 | DoLog(0) && (Log() << Verbose(0) << "Enter radius: ");
|
---|
497 | cin >> tmp1;
|
---|
498 | first = mol->start;
|
---|
499 | second = first->next;
|
---|
500 | while(second != mol->end) {
|
---|
501 | first = second;
|
---|
502 | second = first->next;
|
---|
503 | if (first->x.DistanceSquared((const Vector *)&second->x) > tmp1*tmp1) // distance to first above radius ...
|
---|
504 | mol->RemoveAtom(first);
|
---|
505 | }
|
---|
506 | break;
|
---|
507 | case 'c':
|
---|
508 | DoLog(0) && (Log() << Verbose(0) << "Which axis is it: ");
|
---|
509 | cin >> axis;
|
---|
510 | DoLog(0) && (Log() << Verbose(0) << "Lower boundary: ");
|
---|
511 | cin >> tmp1;
|
---|
512 | DoLog(0) && (Log() << Verbose(0) << "Upper boundary: ");
|
---|
513 | cin >> tmp2;
|
---|
514 | first = mol->start;
|
---|
515 | second = first->next;
|
---|
516 | while(second != mol->end) {
|
---|
517 | first = second;
|
---|
518 | second = first->next;
|
---|
519 | if ((first->x.x[axis] < tmp1) || (first->x.x[axis] > tmp2)) {// out of boundary ...
|
---|
520 | //Log() << Verbose(0) << "Atom " << *first << " with " << first->x.x[axis] << " on axis " << axis << " is out of bounds [" << tmp1 << "," << tmp2 << "]." << endl;
|
---|
521 | mol->RemoveAtom(first);
|
---|
522 | }
|
---|
523 | }
|
---|
524 | break;
|
---|
525 | };
|
---|
526 | //mol->Output();
|
---|
527 | choice = 'r';
|
---|
528 | };
|
---|
529 |
|
---|
530 | /** Submenu for measuring out the atoms in the molecule.
|
---|
531 | * \param *periode periodentafel
|
---|
532 | * \param *mol molecule with all the atoms
|
---|
533 | */
|
---|
534 | static void MeasureAtoms(periodentafel *periode, molecule *mol, config *configuration)
|
---|
535 | {
|
---|
536 | atom *first, *second, *third;
|
---|
537 | Vector x,y;
|
---|
538 | double min[256], tmp1, tmp2, tmp3;
|
---|
539 | int Z;
|
---|
540 | char choice; // menu choice char
|
---|
541 |
|
---|
542 | DoLog(0) && (Log() << Verbose(0) << "===========MEASURE ATOMS=========================" << endl);
|
---|
543 | DoLog(0) && (Log() << Verbose(0) << " a - calculate bond length between one atom and all others" << endl);
|
---|
544 | DoLog(0) && (Log() << Verbose(0) << " b - calculate bond length between two atoms" << endl);
|
---|
545 | DoLog(0) && (Log() << Verbose(0) << " c - calculate bond angle" << endl);
|
---|
546 | DoLog(0) && (Log() << Verbose(0) << " d - calculate principal axis of the system" << endl);
|
---|
547 | DoLog(0) && (Log() << Verbose(0) << " e - calculate volume of the convex envelope" << endl);
|
---|
548 | DoLog(0) && (Log() << Verbose(0) << " f - calculate temperature from current velocity" << endl);
|
---|
549 | DoLog(0) && (Log() << Verbose(0) << " g - output all temperatures per step from velocities" << endl);
|
---|
550 | DoLog(0) && (Log() << Verbose(0) << "all else - go back" << endl);
|
---|
551 | DoLog(0) && (Log() << Verbose(0) << "===============================================" << endl);
|
---|
552 | DoLog(0) && (Log() << Verbose(0) << "INPUT: ");
|
---|
553 | cin >> choice;
|
---|
554 |
|
---|
555 | switch(choice) {
|
---|
556 | default:
|
---|
557 | DoLog(1) && (Log() << Verbose(1) << "Not a valid choice." << endl);
|
---|
558 | break;
|
---|
559 | case 'a':
|
---|
560 | first = mol->AskAtom("Enter first atom: ");
|
---|
561 | for (int i=MAX_ELEMENTS;i--;)
|
---|
562 | min[i] = 0.;
|
---|
563 |
|
---|
564 | second = mol->start;
|
---|
565 | while ((second->next != mol->end)) {
|
---|
566 | second = second->next; // advance
|
---|
567 | Z = second->type->Z;
|
---|
568 | tmp1 = 0.;
|
---|
569 | if (first != second) {
|
---|
570 | x.CopyVector((const Vector *)&first->x);
|
---|
571 | x.SubtractVector((const Vector *)&second->x);
|
---|
572 | tmp1 = x.Norm();
|
---|
573 | }
|
---|
574 | if ((tmp1 != 0.) && ((min[Z] == 0.) || (tmp1 < min[Z]))) min[Z] = tmp1;
|
---|
575 | //Log() << Verbose(0) << "Bond length between Atom " << first->nr << " and " << second->nr << ": " << tmp1 << " a.u." << endl;
|
---|
576 | }
|
---|
577 | for (int i=MAX_ELEMENTS;i--;)
|
---|
578 | if (min[i] != 0.) Log() << Verbose(0) << "Minimum Bond length between " << first->type->name << " Atom " << first->nr << " and next Ion of type " << (periode->FindElement(i))->name << ": " << min[i] << " a.u." << endl;
|
---|
579 | break;
|
---|
580 |
|
---|
581 | case 'b':
|
---|
582 | first = mol->AskAtom("Enter first atom: ");
|
---|
583 | second = mol->AskAtom("Enter second atom: ");
|
---|
584 | for (int i=NDIM;i--;)
|
---|
585 | min[i] = 0.;
|
---|
586 | x.CopyVector((const Vector *)&first->x);
|
---|
587 | x.SubtractVector((const Vector *)&second->x);
|
---|
588 | tmp1 = x.Norm();
|
---|
589 | DoLog(1) && (Log() << Verbose(1) << "Distance vector is ");
|
---|
590 | x.Output();
|
---|
591 | DoLog(0) && (Log() << Verbose(0) << "." << endl << "Norm of distance is " << tmp1 << "." << endl);
|
---|
592 | break;
|
---|
593 |
|
---|
594 | case 'c':
|
---|
595 | DoLog(0) && (Log() << Verbose(0) << "Evaluating bond angle between three - first, central, last - atoms." << endl);
|
---|
596 | first = mol->AskAtom("Enter first atom: ");
|
---|
597 | second = mol->AskAtom("Enter central atom: ");
|
---|
598 | third = mol->AskAtom("Enter last atom: ");
|
---|
599 | tmp1 = tmp2 = tmp3 = 0.;
|
---|
600 | x.CopyVector((const Vector *)&first->x);
|
---|
601 | x.SubtractVector((const Vector *)&second->x);
|
---|
602 | y.CopyVector((const Vector *)&third->x);
|
---|
603 | y.SubtractVector((const Vector *)&second->x);
|
---|
604 | DoLog(0) && (Log() << Verbose(0) << "Bond angle between first atom Nr." << first->nr << ", central atom Nr." << second->nr << " and last atom Nr." << third->nr << ": ");
|
---|
605 | DoLog(0) && (Log() << Verbose(0) << (acos(x.ScalarProduct((const Vector *)&y)/(y.Norm()*x.Norm()))/M_PI*180.) << " degrees" << endl);
|
---|
606 | break;
|
---|
607 | case 'd':
|
---|
608 | DoLog(0) && (Log() << Verbose(0) << "Evaluating prinicipal axis." << endl);
|
---|
609 | DoLog(0) && (Log() << Verbose(0) << "Shall we rotate? [0/1]: ");
|
---|
610 | cin >> Z;
|
---|
611 | if ((Z >=0) && (Z <=1))
|
---|
612 | mol->PrincipalAxisSystem((bool)Z);
|
---|
613 | else
|
---|
614 | mol->PrincipalAxisSystem(false);
|
---|
615 | break;
|
---|
616 | case 'e':
|
---|
617 | {
|
---|
618 | DoLog(0) && (Log() << Verbose(0) << "Evaluating volume of the convex envelope.");
|
---|
619 | class Tesselation *TesselStruct = NULL;
|
---|
620 | const LinkedCell *LCList = NULL;
|
---|
621 | LCList = new LinkedCell(mol, 10.);
|
---|
622 | FindConvexBorder(mol, TesselStruct, LCList, NULL);
|
---|
623 | double clustervolume = VolumeOfConvexEnvelope(TesselStruct, configuration);
|
---|
624 | DoLog(0) && (Log() << Verbose(0) << "The tesselated surface area is " << clustervolume << "." << endl);\
|
---|
625 | delete(LCList);
|
---|
626 | delete(TesselStruct);
|
---|
627 | }
|
---|
628 | break;
|
---|
629 | case 'f':
|
---|
630 | mol->OutputTemperatureFromTrajectories((ofstream *)&cout, mol->MDSteps-1, mol->MDSteps);
|
---|
631 | break;
|
---|
632 | case 'g':
|
---|
633 | {
|
---|
634 | char filename[255];
|
---|
635 | DoLog(0) && (Log() << Verbose(0) << "Please enter filename: " << endl);
|
---|
636 | cin >> filename;
|
---|
637 | DoLog(1) && (Log() << Verbose(1) << "Storing temperatures in " << filename << "." << endl);
|
---|
638 | ofstream *output = new ofstream(filename, ios::trunc);
|
---|
639 | if (!mol->OutputTemperatureFromTrajectories(output, 0, mol->MDSteps))
|
---|
640 | DoLog(2) && (Log() << Verbose(2) << "File could not be written." << endl);
|
---|
641 | else
|
---|
642 | DoLog(2) && (Log() << Verbose(2) << "File stored." << endl);
|
---|
643 | output->close();
|
---|
644 | delete(output);
|
---|
645 | }
|
---|
646 | break;
|
---|
647 | }
|
---|
648 | };
|
---|
649 |
|
---|
650 | /** Submenu for measuring out the atoms in the molecule.
|
---|
651 | * \param *mol molecule with all the atoms
|
---|
652 | * \param *configuration configuration structure for the to be written config files of all fragments
|
---|
653 | */
|
---|
654 | static void FragmentAtoms(molecule *mol, config *configuration)
|
---|
655 | {
|
---|
656 | int Order1;
|
---|
657 | clock_t start, end;
|
---|
658 |
|
---|
659 | DoLog(0) && (Log() << Verbose(0) << "Fragmenting molecule with current connection matrix ..." << endl);
|
---|
660 | DoLog(0) && (Log() << Verbose(0) << "What's the desired bond order: ");
|
---|
661 | cin >> Order1;
|
---|
662 | if (mol->first->next != mol->last) { // there are bonds
|
---|
663 | start = clock();
|
---|
664 | mol->FragmentMolecule(Order1, configuration);
|
---|
665 | end = clock();
|
---|
666 | DoLog(0) && (Log() << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl);
|
---|
667 | } else
|
---|
668 | DoLog(0) && (Log() << Verbose(0) << "Connection matrix has not yet been generated!" << endl);
|
---|
669 | };
|
---|
670 |
|
---|
671 | /********************************************** Submenu routine **************************************/
|
---|
672 |
|
---|
673 | /** Submenu for manipulating atoms.
|
---|
674 | * \param *periode periodentafel
|
---|
675 | * \param *molecules list of molecules whose atoms are to be manipulated
|
---|
676 | */
|
---|
677 | static void ManipulateAtoms(periodentafel *periode, MoleculeListClass *molecules, config *configuration)
|
---|
678 | {
|
---|
679 | atom *first, *second, *third;
|
---|
680 | molecule *mol = NULL;
|
---|
681 | Vector x,y,z,n; // coordinates for absolute point in cell volume
|
---|
682 | double *factor; // unit factor if desired
|
---|
683 | double bond, minBond;
|
---|
684 | char choice; // menu choice char
|
---|
685 | bool valid;
|
---|
686 |
|
---|
687 | DoLog(0) && (Log() << Verbose(0) << "=========MANIPULATE ATOMS======================" << endl);
|
---|
688 | DoLog(0) && (Log() << Verbose(0) << "a - add an atom" << endl);
|
---|
689 | DoLog(0) && (Log() << Verbose(0) << "r - remove an atom" << endl);
|
---|
690 | DoLog(0) && (Log() << Verbose(0) << "b - scale a bond between atoms" << endl);
|
---|
691 | DoLog(0) && (Log() << Verbose(0) << "t - turn an atom round another bond" << endl);
|
---|
692 | DoLog(0) && (Log() << Verbose(0) << "u - change an atoms element" << endl);
|
---|
693 | DoLog(0) && (Log() << Verbose(0) << "l - measure lengths, angles, ... for an atom" << endl);
|
---|
694 | DoLog(0) && (Log() << Verbose(0) << "all else - go back" << endl);
|
---|
695 | DoLog(0) && (Log() << Verbose(0) << "===============================================" << endl);
|
---|
696 | if (molecules->NumberOfActiveMolecules() > 1)
|
---|
697 | DoeLog(2) && (eLog()<< Verbose(2) << "There is more than one molecule active! Atoms will be added to each." << endl);
|
---|
698 | DoLog(0) && (Log() << Verbose(0) << "INPUT: ");
|
---|
699 | cin >> choice;
|
---|
700 |
|
---|
701 | switch (choice) {
|
---|
702 | default:
|
---|
703 | DoLog(0) && (Log() << Verbose(0) << "Not a valid choice." << endl);
|
---|
704 | break;
|
---|
705 |
|
---|
706 | case 'a': // add atom
|
---|
707 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
|
---|
708 | if ((*ListRunner)->ActiveFlag) {
|
---|
709 | mol = *ListRunner;
|
---|
710 | DoLog(0) && (Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl);
|
---|
711 | AddAtoms(periode, mol);
|
---|
712 | }
|
---|
713 | break;
|
---|
714 |
|
---|
715 | case 'b': // scale a bond
|
---|
716 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
|
---|
717 | if ((*ListRunner)->ActiveFlag) {
|
---|
718 | mol = *ListRunner;
|
---|
719 | DoLog(0) && (Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl);
|
---|
720 | DoLog(0) && (Log() << Verbose(0) << "Scaling bond length between two atoms." << endl);
|
---|
721 | first = mol->AskAtom("Enter first (fixed) atom: ");
|
---|
722 | second = mol->AskAtom("Enter second (shifting) atom: ");
|
---|
723 | minBond = 0.;
|
---|
724 | for (int i=NDIM;i--;)
|
---|
725 | minBond += (first->x.x[i]-second->x.x[i])*(first->x.x[i] - second->x.x[i]);
|
---|
726 | minBond = sqrt(minBond);
|
---|
727 | DoLog(0) && (Log() << Verbose(0) << "Current Bond length between " << first->type->name << " Atom " << first->nr << " and " << second->type->name << " Atom " << second->nr << ": " << minBond << " a.u." << endl);
|
---|
728 | DoLog(0) && (Log() << Verbose(0) << "Enter new bond length [a.u.]: ");
|
---|
729 | cin >> bond;
|
---|
730 | for (int i=NDIM;i--;) {
|
---|
731 | second->x.x[i] -= (second->x.x[i]-first->x.x[i])/minBond*(minBond-bond);
|
---|
732 | }
|
---|
733 | //Log() << Verbose(0) << "New coordinates of Atom " << second->nr << " are: ";
|
---|
734 | //second->Output(second->type->No, 1);
|
---|
735 | }
|
---|
736 | break;
|
---|
737 |
|
---|
738 | case 'c': // unit scaling of the metric
|
---|
739 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
|
---|
740 | if ((*ListRunner)->ActiveFlag) {
|
---|
741 | mol = *ListRunner;
|
---|
742 | DoLog(0) && (Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl);
|
---|
743 | DoLog(0) && (Log() << Verbose(0) << "Angstroem -> Bohrradius: 1.8897261\t\tBohrradius -> Angstroem: 0.52917721" << endl);
|
---|
744 | DoLog(0) && (Log() << Verbose(0) << "Enter three factors: ");
|
---|
745 | factor = new double[NDIM];
|
---|
746 | cin >> factor[0];
|
---|
747 | cin >> factor[1];
|
---|
748 | cin >> factor[2];
|
---|
749 | valid = true;
|
---|
750 | mol->Scale((const double ** const)&factor);
|
---|
751 | delete[](factor);
|
---|
752 | }
|
---|
753 | break;
|
---|
754 |
|
---|
755 | case 'l': // measure distances or angles
|
---|
756 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
|
---|
757 | if ((*ListRunner)->ActiveFlag) {
|
---|
758 | mol = *ListRunner;
|
---|
759 | DoLog(0) && (Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl);
|
---|
760 | MeasureAtoms(periode, mol, configuration);
|
---|
761 | }
|
---|
762 | break;
|
---|
763 |
|
---|
764 | case 'r': // remove atom
|
---|
765 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
|
---|
766 | if ((*ListRunner)->ActiveFlag) {
|
---|
767 | mol = *ListRunner;
|
---|
768 | DoLog(0) && (Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl);
|
---|
769 | RemoveAtoms(mol);
|
---|
770 | }
|
---|
771 | break;
|
---|
772 |
|
---|
773 | case 't': // turn/rotate atom
|
---|
774 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
|
---|
775 | if ((*ListRunner)->ActiveFlag) {
|
---|
776 | mol = *ListRunner;
|
---|
777 | DoLog(0) && (Log() << Verbose(0) << "Turning atom around another bond - first is atom to turn, second (central) and third specify bond" << endl);
|
---|
778 | first = mol->AskAtom("Enter turning atom: ");
|
---|
779 | second = mol->AskAtom("Enter central atom: ");
|
---|
780 | third = mol->AskAtom("Enter bond atom: ");
|
---|
781 | cout << Verbose(0) << "Enter new angle in degrees: ";
|
---|
782 | double tmp = 0.;
|
---|
783 | cin >> tmp;
|
---|
784 | // calculate old angle
|
---|
785 | x.CopyVector((const Vector *)&first->x);
|
---|
786 | x.SubtractVector((const Vector *)&second->x);
|
---|
787 | y.CopyVector((const Vector *)&third->x);
|
---|
788 | y.SubtractVector((const Vector *)&second->x);
|
---|
789 | double alpha = (acos(x.ScalarProduct((const Vector *)&y)/(y.Norm()*x.Norm()))/M_PI*180.);
|
---|
790 | cout << Verbose(0) << "Bond angle between first atom Nr." << first->nr << ", central atom Nr." << second->nr << " and last atom Nr." << third->nr << ": ";
|
---|
791 | cout << Verbose(0) << alpha << " degrees" << endl;
|
---|
792 | // rotate
|
---|
793 | z.MakeNormalVector(&x,&y);
|
---|
794 | x.RotateVector(&z,(alpha-tmp)*M_PI/180.);
|
---|
795 | x.AddVector(&second->x);
|
---|
796 | first->x.CopyVector(&x);
|
---|
797 | // check new angle
|
---|
798 | x.CopyVector((const Vector *)&first->x);
|
---|
799 | x.SubtractVector((const Vector *)&second->x);
|
---|
800 | alpha = (acos(x.ScalarProduct((const Vector *)&y)/(y.Norm()*x.Norm()))/M_PI*180.);
|
---|
801 | cout << Verbose(0) << "new Bond angle between first atom Nr." << first->nr << ", central atom Nr." << second->nr << " and last atom Nr." << third->nr << ": ";
|
---|
802 | cout << Verbose(0) << alpha << " degrees" << endl;
|
---|
803 | }
|
---|
804 | break;
|
---|
805 |
|
---|
806 | case 'u': // change an atom's element
|
---|
807 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
|
---|
808 | if ((*ListRunner)->ActiveFlag) {
|
---|
809 | int Z;
|
---|
810 | mol = *ListRunner;
|
---|
811 | DoLog(0) && (Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl);
|
---|
812 | first = NULL;
|
---|
813 | do {
|
---|
814 | DoLog(0) && (Log() << Verbose(0) << "Change the element of which atom: ");
|
---|
815 | cin >> Z;
|
---|
816 | } while ((first = mol->FindAtom(Z)) == NULL);
|
---|
817 | DoLog(0) && (Log() << Verbose(0) << "New element by atomic number Z: ");
|
---|
818 | cin >> Z;
|
---|
819 | first->type = periode->FindElement(Z);
|
---|
820 | DoLog(0) && (Log() << Verbose(0) << "Atom " << first->nr << "'s element is " << first->type->name << "." << endl);
|
---|
821 | }
|
---|
822 | break;
|
---|
823 | }
|
---|
824 | };
|
---|
825 |
|
---|
826 | /** Submenu for manipulating molecules.
|
---|
827 | * \param *periode periodentafel
|
---|
828 | * \param *molecules list of molecule to manipulate
|
---|
829 | */
|
---|
830 | static void ManipulateMolecules(periodentafel *periode, MoleculeListClass *molecules, config *configuration)
|
---|
831 | {
|
---|
832 | atom *first = NULL;
|
---|
833 | Vector x,y,z,n; // coordinates for absolute point in cell volume
|
---|
834 | int j, axis, count, faktor;
|
---|
835 | char choice; // menu choice char
|
---|
836 | molecule *mol = NULL;
|
---|
837 | element **Elements;
|
---|
838 | Vector **vectors;
|
---|
839 | MoleculeLeafClass *Subgraphs = NULL;
|
---|
840 |
|
---|
841 | DoLog(0) && (Log() << Verbose(0) << "=========MANIPULATE GLOBALLY===================" << endl);
|
---|
842 | DoLog(0) && (Log() << Verbose(0) << "c - scale by unit transformation" << endl);
|
---|
843 | DoLog(0) && (Log() << Verbose(0) << "d - duplicate molecule/periodic cell" << endl);
|
---|
844 | DoLog(0) && (Log() << Verbose(0) << "f - fragment molecule many-body bond order style" << endl);
|
---|
845 | DoLog(0) && (Log() << Verbose(0) << "g - center atoms in box" << endl);
|
---|
846 | DoLog(0) && (Log() << Verbose(0) << "i - realign molecule" << endl);
|
---|
847 | DoLog(0) && (Log() << Verbose(0) << "m - mirror all molecules" << endl);
|
---|
848 | DoLog(0) && (Log() << Verbose(0) << "o - create connection matrix" << endl);
|
---|
849 | DoLog(0) && (Log() << Verbose(0) << "t - translate molecule by vector" << endl);
|
---|
850 | DoLog(0) && (Log() << Verbose(0) << "all else - go back" << endl);
|
---|
851 | DoLog(0) && (Log() << Verbose(0) << "===============================================" << endl);
|
---|
852 | if (molecules->NumberOfActiveMolecules() > 1)
|
---|
853 | DoeLog(2) && (eLog()<< Verbose(2) << "There is more than one molecule active! Atoms will be added to each." << endl);
|
---|
854 | DoLog(0) && (Log() << Verbose(0) << "INPUT: ");
|
---|
855 | cin >> choice;
|
---|
856 |
|
---|
857 | switch (choice) {
|
---|
858 | default:
|
---|
859 | DoLog(0) && (Log() << Verbose(0) << "Not a valid choice." << endl);
|
---|
860 | break;
|
---|
861 |
|
---|
862 | case 'd': // duplicate the periodic cell along a given axis, given times
|
---|
863 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
|
---|
864 | if ((*ListRunner)->ActiveFlag) {
|
---|
865 | mol = *ListRunner;
|
---|
866 | DoLog(0) && (Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl);
|
---|
867 | DoLog(0) && (Log() << Verbose(0) << "State the axis [(+-)123]: ");
|
---|
868 | cin >> axis;
|
---|
869 | DoLog(0) && (Log() << Verbose(0) << "State the factor: ");
|
---|
870 | cin >> faktor;
|
---|
871 |
|
---|
872 | mol->CountAtoms(); // recount atoms
|
---|
873 | if (mol->getAtomCount() != 0) { // if there is more than none
|
---|
874 | count = mol->getAtomCount(); // is changed becausing of adding, thus has to be stored away beforehand
|
---|
875 | Elements = new element *[count];
|
---|
876 | vectors = new Vector *[count];
|
---|
877 | j = 0;
|
---|
878 | first = mol->start;
|
---|
879 | while (first->next != mol->end) { // make a list of all atoms with coordinates and element
|
---|
880 | first = first->next;
|
---|
881 | Elements[j] = first->type;
|
---|
882 | vectors[j] = &first->x;
|
---|
883 | j++;
|
---|
884 | }
|
---|
885 | if (count != j)
|
---|
886 | DoeLog(1) && (eLog()<< Verbose(1) << "AtomCount " << count << " is not equal to number of atoms in molecule " << j << "!" << endl);
|
---|
887 | x.Zero();
|
---|
888 | y.Zero();
|
---|
889 | y.x[abs(axis)-1] = World::getInstance().getDomain()[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] * abs(axis)/axis; // last term is for sign, first is for magnitude
|
---|
890 | for (int i=1;i<faktor;i++) { // then add this list with respective translation factor times
|
---|
891 | x.AddVector(&y); // per factor one cell width further
|
---|
892 | for (int k=count;k--;) { // go through every atom of the original cell
|
---|
893 | first = new atom(); // create a new body
|
---|
894 | first->x.CopyVector(vectors[k]); // use coordinate of original atom
|
---|
895 | first->x.AddVector(&x); // translate the coordinates
|
---|
896 | first->type = Elements[k]; // insert original element
|
---|
897 | mol->AddAtom(first); // and add to the molecule (which increments ElementsInMolecule, AtomCount, ...)
|
---|
898 | }
|
---|
899 | }
|
---|
900 | if (mol->first->next != mol->last) // if connect matrix is present already, redo it
|
---|
901 | mol->CreateAdjacencyList(mol->BondDistance, configuration->GetIsAngstroem(), &BondGraph::CovalentMinMaxDistance, NULL);
|
---|
902 | // free memory
|
---|
903 | delete[](Elements);
|
---|
904 | delete[](vectors);
|
---|
905 | // correct cell size
|
---|
906 | if (axis < 0) { // if sign was negative, we have to translate everything
|
---|
907 | x.Zero();
|
---|
908 | x.AddVector(&y);
|
---|
909 | x.Scale(-(faktor-1));
|
---|
910 | mol->Translate(&x);
|
---|
911 | }
|
---|
912 | World::getInstance().getDomain()[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] *= faktor;
|
---|
913 | }
|
---|
914 | }
|
---|
915 | break;
|
---|
916 |
|
---|
917 | case 'f':
|
---|
918 | FragmentAtoms(mol, configuration);
|
---|
919 | break;
|
---|
920 |
|
---|
921 | case 'g': // center the atoms
|
---|
922 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
|
---|
923 | if ((*ListRunner)->ActiveFlag) {
|
---|
924 | mol = *ListRunner;
|
---|
925 | DoLog(0) && (Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl);
|
---|
926 | CenterAtoms(mol);
|
---|
927 | }
|
---|
928 | break;
|
---|
929 |
|
---|
930 | case 'i': // align all atoms
|
---|
931 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
|
---|
932 | if ((*ListRunner)->ActiveFlag) {
|
---|
933 | mol = *ListRunner;
|
---|
934 | DoLog(0) && (Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl);
|
---|
935 | AlignAtoms(periode, mol);
|
---|
936 | }
|
---|
937 | break;
|
---|
938 |
|
---|
939 | case 'm': // mirror atoms along a given axis
|
---|
940 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
|
---|
941 | if ((*ListRunner)->ActiveFlag) {
|
---|
942 | mol = *ListRunner;
|
---|
943 | DoLog(0) && (Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl);
|
---|
944 | MirrorAtoms(mol);
|
---|
945 | }
|
---|
946 | break;
|
---|
947 |
|
---|
948 | case 'o': // create the connection matrix
|
---|
949 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
|
---|
950 | if ((*ListRunner)->ActiveFlag) {
|
---|
951 | mol = *ListRunner;
|
---|
952 | double bonddistance;
|
---|
953 | clock_t start,end;
|
---|
954 | DoLog(0) && (Log() << Verbose(0) << "What's the maximum bond distance: ");
|
---|
955 | cin >> bonddistance;
|
---|
956 | start = clock();
|
---|
957 | mol->CreateAdjacencyList(bonddistance, configuration->GetIsAngstroem(), &BondGraph::CovalentMinMaxDistance, NULL);
|
---|
958 | end = clock();
|
---|
959 | DoLog(0) && (Log() << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl);
|
---|
960 | }
|
---|
961 | break;
|
---|
962 |
|
---|
963 | case 't': // translate all atoms
|
---|
964 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
|
---|
965 | if ((*ListRunner)->ActiveFlag) {
|
---|
966 | mol = *ListRunner;
|
---|
967 | DoLog(0) && (Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl);
|
---|
968 | DoLog(0) && (Log() << Verbose(0) << "Enter translation vector." << endl);
|
---|
969 | x.AskPosition(World::getInstance().getDomain(),0);
|
---|
970 | mol->Center.AddVector((const Vector *)&x);
|
---|
971 | }
|
---|
972 | break;
|
---|
973 | }
|
---|
974 | // Free all
|
---|
975 | if (Subgraphs != NULL) { // free disconnected subgraph list of DFS analysis was performed
|
---|
976 | while (Subgraphs->next != NULL) {
|
---|
977 | Subgraphs = Subgraphs->next;
|
---|
978 | delete(Subgraphs->previous);
|
---|
979 | }
|
---|
980 | delete(Subgraphs);
|
---|
981 | }
|
---|
982 | };
|
---|
983 |
|
---|
984 |
|
---|
985 | /** Submenu for creating new molecules.
|
---|
986 | * \param *periode periodentafel
|
---|
987 | * \param *molecules list of molecules to add to
|
---|
988 | */
|
---|
989 | static void EditMolecules(periodentafel *periode, MoleculeListClass *molecules)
|
---|
990 | {
|
---|
991 | char choice; // menu choice char
|
---|
992 | Vector center;
|
---|
993 | int nr, count;
|
---|
994 | molecule *mol = NULL;
|
---|
995 |
|
---|
996 | DoLog(0) && (Log() << Verbose(0) << "==========EDIT MOLECULES=====================" << endl);
|
---|
997 | DoLog(0) && (Log() << Verbose(0) << "c - create new molecule" << endl);
|
---|
998 | DoLog(0) && (Log() << Verbose(0) << "l - load molecule from xyz file" << endl);
|
---|
999 | DoLog(0) && (Log() << Verbose(0) << "n - change molecule's name" << endl);
|
---|
1000 | DoLog(0) && (Log() << Verbose(0) << "N - give molecules filename" << endl);
|
---|
1001 | DoLog(0) && (Log() << Verbose(0) << "p - parse atoms in xyz file into molecule" << endl);
|
---|
1002 | DoLog(0) && (Log() << Verbose(0) << "r - remove a molecule" << endl);
|
---|
1003 | DoLog(0) && (Log() << Verbose(0) << "all else - go back" << endl);
|
---|
1004 | DoLog(0) && (Log() << Verbose(0) << "===============================================" << endl);
|
---|
1005 | DoLog(0) && (Log() << Verbose(0) << "INPUT: ");
|
---|
1006 | cin >> choice;
|
---|
1007 |
|
---|
1008 | switch (choice) {
|
---|
1009 | default:
|
---|
1010 | DoLog(0) && (Log() << Verbose(0) << "Not a valid choice." << endl);
|
---|
1011 | break;
|
---|
1012 | case 'c':
|
---|
1013 | mol = World::getInstance().createMolecule();
|
---|
1014 | molecules->insert(mol);
|
---|
1015 | break;
|
---|
1016 |
|
---|
1017 | case 'l': // load from XYZ file
|
---|
1018 | {
|
---|
1019 | char filename[MAXSTRINGSIZE];
|
---|
1020 | DoLog(0) && (Log() << Verbose(0) << "Format should be XYZ with: ShorthandOfElement\tX\tY\tZ" << endl);
|
---|
1021 | mol = World::getInstance().createMolecule();
|
---|
1022 | do {
|
---|
1023 | DoLog(0) && (Log() << Verbose(0) << "Enter file name: ");
|
---|
1024 | cin >> filename;
|
---|
1025 | } while (!mol->AddXYZFile(filename));
|
---|
1026 | mol->SetNameFromFilename(filename);
|
---|
1027 | // center at set box dimensions
|
---|
1028 | mol->CenterEdge(¢er);
|
---|
1029 | double * const cell_size = World::getInstance().getDomain();
|
---|
1030 | cell_size[0] = center.x[0];
|
---|
1031 | cell_size[1] = 0;
|
---|
1032 | cell_size[2] = center.x[1];
|
---|
1033 | cell_size[3] = 0;
|
---|
1034 | cell_size[4] = 0;
|
---|
1035 | cell_size[5] = center.x[2];
|
---|
1036 | molecules->insert(mol);
|
---|
1037 | }
|
---|
1038 | break;
|
---|
1039 |
|
---|
1040 | case 'n':
|
---|
1041 | {
|
---|
1042 | char filename[MAXSTRINGSIZE];
|
---|
1043 | do {
|
---|
1044 | DoLog(0) && (Log() << Verbose(0) << "Enter index of molecule: ");
|
---|
1045 | cin >> nr;
|
---|
1046 | mol = molecules->ReturnIndex(nr);
|
---|
1047 | } while (mol == NULL);
|
---|
1048 | DoLog(0) && (Log() << Verbose(0) << "Enter name: ");
|
---|
1049 | cin >> filename;
|
---|
1050 | strcpy(mol->name, filename);
|
---|
1051 | }
|
---|
1052 | break;
|
---|
1053 |
|
---|
1054 | case 'N':
|
---|
1055 | {
|
---|
1056 | char filename[MAXSTRINGSIZE];
|
---|
1057 | do {
|
---|
1058 | DoLog(0) && (Log() << Verbose(0) << "Enter index of molecule: ");
|
---|
1059 | cin >> nr;
|
---|
1060 | mol = molecules->ReturnIndex(nr);
|
---|
1061 | } while (mol == NULL);
|
---|
1062 | DoLog(0) && (Log() << Verbose(0) << "Enter name: ");
|
---|
1063 | cin >> filename;
|
---|
1064 | mol->SetNameFromFilename(filename);
|
---|
1065 | }
|
---|
1066 | break;
|
---|
1067 |
|
---|
1068 | case 'p': // parse XYZ file
|
---|
1069 | {
|
---|
1070 | char filename[MAXSTRINGSIZE];
|
---|
1071 | mol = NULL;
|
---|
1072 | do {
|
---|
1073 | DoLog(0) && (Log() << Verbose(0) << "Enter index of molecule: ");
|
---|
1074 | cin >> nr;
|
---|
1075 | mol = molecules->ReturnIndex(nr);
|
---|
1076 | } while (mol == NULL);
|
---|
1077 | DoLog(0) && (Log() << Verbose(0) << "Format should be XYZ with: ShorthandOfElement\tX\tY\tZ" << endl);
|
---|
1078 | do {
|
---|
1079 | DoLog(0) && (Log() << Verbose(0) << "Enter file name: ");
|
---|
1080 | cin >> filename;
|
---|
1081 | } while (!mol->AddXYZFile(filename));
|
---|
1082 | mol->SetNameFromFilename(filename);
|
---|
1083 | }
|
---|
1084 | break;
|
---|
1085 |
|
---|
1086 | case 'r':
|
---|
1087 | DoLog(0) && (Log() << Verbose(0) << "Enter index of molecule: ");
|
---|
1088 | cin >> nr;
|
---|
1089 | count = 1;
|
---|
1090 | for(MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
|
---|
1091 | if (nr == (*ListRunner)->IndexNr) {
|
---|
1092 | mol = *ListRunner;
|
---|
1093 | molecules->ListOfMolecules.erase(ListRunner);
|
---|
1094 | delete(mol);
|
---|
1095 | break;
|
---|
1096 | }
|
---|
1097 | break;
|
---|
1098 | }
|
---|
1099 | };
|
---|
1100 |
|
---|
1101 |
|
---|
1102 | /** Submenu for merging molecules.
|
---|
1103 | * \param *periode periodentafel
|
---|
1104 | * \param *molecules list of molecules to add to
|
---|
1105 | */
|
---|
1106 | static void MergeMolecules(periodentafel *periode, MoleculeListClass *molecules)
|
---|
1107 | {
|
---|
1108 | char choice; // menu choice char
|
---|
1109 |
|
---|
1110 | DoLog(0) && (Log() << Verbose(0) << "===========MERGE MOLECULES=====================" << endl);
|
---|
1111 | DoLog(0) && (Log() << Verbose(0) << "a - simple add of one molecule to another" << endl);
|
---|
1112 | DoLog(0) && (Log() << Verbose(0) << "b - count the number of bonds of two elements" << endl);
|
---|
1113 | DoLog(0) && (Log() << Verbose(0) << "B - count the number of bonds of three elements " << endl);
|
---|
1114 | DoLog(0) && (Log() << Verbose(0) << "e - embedding merge of two molecules" << endl);
|
---|
1115 | DoLog(0) && (Log() << Verbose(0) << "h - count the number of hydrogen bonds" << endl);
|
---|
1116 | DoLog(0) && (Log() << Verbose(0) << "b - count the number of hydrogen bonds" << endl);
|
---|
1117 | DoLog(0) && (Log() << Verbose(0) << "m - multi-merge of all molecules" << endl);
|
---|
1118 | DoLog(0) && (Log() << Verbose(0) << "s - scatter merge of two molecules" << endl);
|
---|
1119 | DoLog(0) && (Log() << Verbose(0) << "t - simple merge of two molecules" << endl);
|
---|
1120 | DoLog(0) && (Log() << Verbose(0) << "all else - go back" << endl);
|
---|
1121 | DoLog(0) && (Log() << Verbose(0) << "===============================================" << endl);
|
---|
1122 | DoLog(0) && (Log() << Verbose(0) << "INPUT: ");
|
---|
1123 | cin >> choice;
|
---|
1124 |
|
---|
1125 | switch (choice) {
|
---|
1126 | default:
|
---|
1127 | DoLog(0) && (Log() << Verbose(0) << "Not a valid choice." << endl);
|
---|
1128 | break;
|
---|
1129 |
|
---|
1130 | case 'a':
|
---|
1131 | {
|
---|
1132 | int src, dest;
|
---|
1133 | molecule *srcmol = NULL, *destmol = NULL;
|
---|
1134 | {
|
---|
1135 | do {
|
---|
1136 | DoLog(0) && (Log() << Verbose(0) << "Enter index of destination molecule: ");
|
---|
1137 | cin >> dest;
|
---|
1138 | destmol = molecules->ReturnIndex(dest);
|
---|
1139 | } while ((destmol == NULL) && (dest != -1));
|
---|
1140 | do {
|
---|
1141 | DoLog(0) && (Log() << Verbose(0) << "Enter index of source molecule to add from: ");
|
---|
1142 | cin >> src;
|
---|
1143 | srcmol = molecules->ReturnIndex(src);
|
---|
1144 | } while ((srcmol == NULL) && (src != -1));
|
---|
1145 | if ((src != -1) && (dest != -1))
|
---|
1146 | molecules->SimpleAdd(srcmol, destmol);
|
---|
1147 | }
|
---|
1148 | }
|
---|
1149 | break;
|
---|
1150 |
|
---|
1151 | case 'b':
|
---|
1152 | {
|
---|
1153 | const int nr = 2;
|
---|
1154 | char *names[nr] = {"first", "second"};
|
---|
1155 | int Z[nr];
|
---|
1156 | element *elements[nr];
|
---|
1157 | for (int i=0;i<nr;i++) {
|
---|
1158 | Z[i] = 0;
|
---|
1159 | do {
|
---|
1160 | cout << "Enter " << names[i] << " element: ";
|
---|
1161 | cin >> Z[i];
|
---|
1162 | } while ((Z[i] <= 0) && (Z[i] > MAX_ELEMENTS));
|
---|
1163 | elements[i] = periode->FindElement(Z[i]);
|
---|
1164 | }
|
---|
1165 | const int count = CountBondsOfTwo(molecules, elements[0], elements[1]);
|
---|
1166 | cout << endl << "There are " << count << " ";
|
---|
1167 | for (int i=0;i<nr;i++) {
|
---|
1168 | if (i==0)
|
---|
1169 | cout << elements[i]->symbol;
|
---|
1170 | else
|
---|
1171 | cout << "-" << elements[i]->symbol;
|
---|
1172 | }
|
---|
1173 | cout << " bonds." << endl;
|
---|
1174 | }
|
---|
1175 | break;
|
---|
1176 |
|
---|
1177 | case 'B':
|
---|
1178 | {
|
---|
1179 | const int nr = 3;
|
---|
1180 | char *names[nr] = {"first", "second", "third"};
|
---|
1181 | int Z[nr];
|
---|
1182 | element *elements[nr];
|
---|
1183 | for (int i=0;i<nr;i++) {
|
---|
1184 | Z[i] = 0;
|
---|
1185 | do {
|
---|
1186 | cout << "Enter " << names[i] << " element: ";
|
---|
1187 | cin >> Z[i];
|
---|
1188 | } while ((Z[i] <= 0) && (Z[i] > MAX_ELEMENTS));
|
---|
1189 | elements[i] = periode->FindElement(Z[i]);
|
---|
1190 | }
|
---|
1191 | const int count = CountBondsOfThree(molecules, elements[0], elements[1], elements[2]);
|
---|
1192 | cout << endl << "There are " << count << " ";
|
---|
1193 | for (int i=0;i<nr;i++) {
|
---|
1194 | if (i==0)
|
---|
1195 | cout << elements[i]->symbol;
|
---|
1196 | else
|
---|
1197 | cout << "-" << elements[i]->symbol;
|
---|
1198 | }
|
---|
1199 | cout << " bonds." << endl;
|
---|
1200 | }
|
---|
1201 | break;
|
---|
1202 |
|
---|
1203 | case 'e':
|
---|
1204 | {
|
---|
1205 | int src, dest;
|
---|
1206 | molecule *srcmol = NULL, *destmol = NULL;
|
---|
1207 | do {
|
---|
1208 | DoLog(0) && (Log() << Verbose(0) << "Enter index of matrix molecule (the variable one): ");
|
---|
1209 | cin >> src;
|
---|
1210 | srcmol = molecules->ReturnIndex(src);
|
---|
1211 | } while ((srcmol == NULL) && (src != -1));
|
---|
1212 | do {
|
---|
1213 | DoLog(0) && (Log() << Verbose(0) << "Enter index of molecule to merge into (the fixed one): ");
|
---|
1214 | cin >> dest;
|
---|
1215 | destmol = molecules->ReturnIndex(dest);
|
---|
1216 | } while ((destmol == NULL) && (dest != -1));
|
---|
1217 | if ((src != -1) && (dest != -1))
|
---|
1218 | molecules->EmbedMerge(destmol, srcmol);
|
---|
1219 | }
|
---|
1220 | break;
|
---|
1221 |
|
---|
1222 | case 'h':
|
---|
1223 | {
|
---|
1224 | int Z;
|
---|
1225 | cout << "Please enter interface element: ";
|
---|
1226 | cin >> Z;
|
---|
1227 | element * const InterfaceElement = periode->FindElement(Z);
|
---|
1228 | cout << endl << "There are " << CountHydrogenBridgeBonds(molecules, InterfaceElement) << " hydrogen bridges with connections to " << (InterfaceElement != 0 ? InterfaceElement->name : "None") << "." << endl;
|
---|
1229 | }
|
---|
1230 | break;
|
---|
1231 |
|
---|
1232 | case 'm':
|
---|
1233 | {
|
---|
1234 | int nr;
|
---|
1235 | molecule *mol = NULL;
|
---|
1236 | do {
|
---|
1237 | DoLog(0) && (Log() << Verbose(0) << "Enter index of molecule to merge into: ");
|
---|
1238 | cin >> nr;
|
---|
1239 | mol = molecules->ReturnIndex(nr);
|
---|
1240 | } while ((mol == NULL) && (nr != -1));
|
---|
1241 | if (nr != -1) {
|
---|
1242 | int N = molecules->ListOfMolecules.size()-1;
|
---|
1243 | int *src = new int(N);
|
---|
1244 | for(MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
|
---|
1245 | if ((*ListRunner)->IndexNr != nr)
|
---|
1246 | src[N++] = (*ListRunner)->IndexNr;
|
---|
1247 | molecules->SimpleMultiMerge(mol, src, N);
|
---|
1248 | delete[](src);
|
---|
1249 | }
|
---|
1250 | }
|
---|
1251 | break;
|
---|
1252 |
|
---|
1253 | case 's':
|
---|
1254 | DoLog(0) && (Log() << Verbose(0) << "Not implemented yet." << endl);
|
---|
1255 | break;
|
---|
1256 |
|
---|
1257 | case 't':
|
---|
1258 | {
|
---|
1259 | int src, dest;
|
---|
1260 | molecule *srcmol = NULL, *destmol = NULL;
|
---|
1261 | {
|
---|
1262 | do {
|
---|
1263 | DoLog(0) && (Log() << Verbose(0) << "Enter index of destination molecule: ");
|
---|
1264 | cin >> dest;
|
---|
1265 | destmol = molecules->ReturnIndex(dest);
|
---|
1266 | } while ((destmol == NULL) && (dest != -1));
|
---|
1267 | do {
|
---|
1268 | DoLog(0) && (Log() << Verbose(0) << "Enter index of source molecule to merge into: ");
|
---|
1269 | cin >> src;
|
---|
1270 | srcmol = molecules->ReturnIndex(src);
|
---|
1271 | } while ((srcmol == NULL) && (src != -1));
|
---|
1272 | if ((src != -1) && (dest != -1))
|
---|
1273 | molecules->SimpleMerge(srcmol, destmol);
|
---|
1274 | }
|
---|
1275 | }
|
---|
1276 | break;
|
---|
1277 | }
|
---|
1278 | };
|
---|
1279 |
|
---|
1280 | /********************************************** Test routine **************************************/
|
---|
1281 |
|
---|
1282 | /** Is called always as option 'T' in the menu.
|
---|
1283 | * \param *molecules list of molecules
|
---|
1284 | */
|
---|
1285 | static void testroutine(MoleculeListClass *molecules)
|
---|
1286 | {
|
---|
1287 | // the current test routine checks the functionality of the KeySet&Graph concept:
|
---|
1288 | // We want to have a multiindex (the KeySet) describing a unique subgraph
|
---|
1289 | int i, comp, counter=0;
|
---|
1290 |
|
---|
1291 | // create a clone
|
---|
1292 | molecule *mol = NULL;
|
---|
1293 | if (molecules->ListOfMolecules.size() != 0) // clone
|
---|
1294 | mol = (molecules->ListOfMolecules.front())->CopyMolecule();
|
---|
1295 | else {
|
---|
1296 | DoeLog(0) && (eLog()<< Verbose(0) << "I don't have anything to test on ... ");
|
---|
1297 | performCriticalExit();
|
---|
1298 | return;
|
---|
1299 | }
|
---|
1300 | atom *Walker = mol->start;
|
---|
1301 |
|
---|
1302 | // generate some KeySets
|
---|
1303 | DoLog(0) && (Log() << Verbose(0) << "Generating KeySets." << endl);
|
---|
1304 | KeySet TestSets[mol->getAtomCount()+1];
|
---|
1305 | i=1;
|
---|
1306 | while (Walker->next != mol->end) {
|
---|
1307 | Walker = Walker->next;
|
---|
1308 | for (int j=0;j<i;j++) {
|
---|
1309 | TestSets[j].insert(Walker->nr);
|
---|
1310 | }
|
---|
1311 | i++;
|
---|
1312 | }
|
---|
1313 | DoLog(0) && (Log() << Verbose(0) << "Testing insertion of already present item in KeySets." << endl);
|
---|
1314 | KeySetTestPair test;
|
---|
1315 | test = TestSets[mol->getAtomCount()-1].insert(Walker->nr);
|
---|
1316 | if (test.second) {
|
---|
1317 | DoLog(1) && (Log() << Verbose(1) << "Insertion worked?!" << endl);
|
---|
1318 | } else {
|
---|
1319 | DoLog(1) && (Log() << Verbose(1) << "Insertion rejected: Present object is " << (*test.first) << "." << endl);
|
---|
1320 | }
|
---|
1321 | TestSets[mol->getAtomCount()].insert(mol->end->previous->nr);
|
---|
1322 | TestSets[mol->getAtomCount()].insert(mol->end->previous->previous->previous->nr);
|
---|
1323 |
|
---|
1324 | // constructing Graph structure
|
---|
1325 | DoLog(0) && (Log() << Verbose(0) << "Generating Subgraph class." << endl);
|
---|
1326 | Graph Subgraphs;
|
---|
1327 |
|
---|
1328 | // insert KeySets into Subgraphs
|
---|
1329 | DoLog(0) && (Log() << Verbose(0) << "Inserting KeySets into Subgraph class." << endl);
|
---|
1330 | for (int j=0;j<mol->getAtomCount();j++) {
|
---|
1331 | Subgraphs.insert(GraphPair (TestSets[j],pair<int, double>(counter++, 1.)));
|
---|
1332 | }
|
---|
1333 | DoLog(0) && (Log() << Verbose(0) << "Testing insertion of already present item in Subgraph." << endl);
|
---|
1334 | GraphTestPair test2;
|
---|
1335 | test2 = Subgraphs.insert(GraphPair (TestSets[mol->getAtomCount()],pair<int, double>(counter++, 1.)));
|
---|
1336 | if (test2.second) {
|
---|
1337 | DoLog(1) && (Log() << Verbose(1) << "Insertion worked?!" << endl);
|
---|
1338 | } else {
|
---|
1339 | DoLog(1) && (Log() << Verbose(1) << "Insertion rejected: Present object is " << (*(test2.first)).second.first << "." << endl);
|
---|
1340 | }
|
---|
1341 |
|
---|
1342 | // show graphs
|
---|
1343 | DoLog(0) && (Log() << Verbose(0) << "Showing Subgraph's contents, checking that it's sorted." << endl);
|
---|
1344 | Graph::iterator A = Subgraphs.begin();
|
---|
1345 | while (A != Subgraphs.end()) {
|
---|
1346 | DoLog(0) && (Log() << Verbose(0) << (*A).second.first << ": ");
|
---|
1347 | KeySet::iterator key = (*A).first.begin();
|
---|
1348 | comp = -1;
|
---|
1349 | while (key != (*A).first.end()) {
|
---|
1350 | if ((*key) > comp)
|
---|
1351 | DoLog(0) && (Log() << Verbose(0) << (*key) << " ");
|
---|
1352 | else
|
---|
1353 | DoLog(0) && (Log() << Verbose(0) << (*key) << "! ");
|
---|
1354 | comp = (*key);
|
---|
1355 | key++;
|
---|
1356 | }
|
---|
1357 | DoLog(0) && (Log() << Verbose(0) << endl);
|
---|
1358 | A++;
|
---|
1359 | }
|
---|
1360 | delete(mol);
|
---|
1361 | };
|
---|
1362 |
|
---|
1363 | #endif
|
---|
1364 |
|
---|
1365 | /** Tries given filename or standard on saving the config file.
|
---|
1366 | * \param *ConfigFileName name of file
|
---|
1367 | * \param *configuration pointer to configuration structure with all the values
|
---|
1368 | * \param *periode pointer to periodentafel structure with all the elements
|
---|
1369 | * \param *molecules list of molecules structure with all the atoms and coordinates
|
---|
1370 | */
|
---|
1371 | static void SaveConfig(char *ConfigFileName, config *configuration, periodentafel *periode, MoleculeListClass *molecules)
|
---|
1372 | {
|
---|
1373 | char filename[MAXSTRINGSIZE];
|
---|
1374 | ofstream output;
|
---|
1375 | molecule *mol = World::getInstance().createMolecule();
|
---|
1376 | mol->SetNameFromFilename(ConfigFileName);
|
---|
1377 |
|
---|
1378 | if (!strcmp(configuration->configpath, configuration->GetDefaultPath())) {
|
---|
1379 | DoeLog(2) && (eLog()<< Verbose(2) << "config is found under different path then stated in config file::defaultpath!" << endl);
|
---|
1380 | }
|
---|
1381 |
|
---|
1382 |
|
---|
1383 | // first save as PDB data
|
---|
1384 | if (ConfigFileName != NULL)
|
---|
1385 | strcpy(filename, ConfigFileName);
|
---|
1386 | if (output == NULL)
|
---|
1387 | strcpy(filename,"main_pcp_linux");
|
---|
1388 | DoLog(0) && (Log() << Verbose(0) << "Saving as pdb input ");
|
---|
1389 | if (configuration->SavePDB(filename, molecules))
|
---|
1390 | DoLog(0) && (Log() << Verbose(0) << "done." << endl);
|
---|
1391 | else
|
---|
1392 | DoLog(0) && (Log() << Verbose(0) << "failed." << endl);
|
---|
1393 |
|
---|
1394 | // then save as tremolo data file
|
---|
1395 | if (ConfigFileName != NULL)
|
---|
1396 | strcpy(filename, ConfigFileName);
|
---|
1397 | if (output == NULL)
|
---|
1398 | strcpy(filename,"main_pcp_linux");
|
---|
1399 | DoLog(0) && (Log() << Verbose(0) << "Saving as tremolo data input ");
|
---|
1400 | if (configuration->SaveTREMOLO(filename, molecules))
|
---|
1401 | DoLog(0) && (Log() << Verbose(0) << "done." << endl);
|
---|
1402 | else
|
---|
1403 | DoLog(0) && (Log() << Verbose(0) << "failed." << endl);
|
---|
1404 |
|
---|
1405 | // translate each to its center and merge all molecules in MoleculeListClass into this molecule
|
---|
1406 | int N = molecules->ListOfMolecules.size();
|
---|
1407 | int *src = new int[N];
|
---|
1408 | N=0;
|
---|
1409 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) {
|
---|
1410 | src[N++] = (*ListRunner)->IndexNr;
|
---|
1411 | (*ListRunner)->Translate(&(*ListRunner)->Center);
|
---|
1412 | }
|
---|
1413 | molecules->SimpleMultiAdd(mol, src, N);
|
---|
1414 | delete[](src);
|
---|
1415 |
|
---|
1416 | // ... and translate back
|
---|
1417 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) {
|
---|
1418 | (*ListRunner)->Center.Scale(-1.);
|
---|
1419 | (*ListRunner)->Translate(&(*ListRunner)->Center);
|
---|
1420 | (*ListRunner)->Center.Scale(-1.);
|
---|
1421 | }
|
---|
1422 |
|
---|
1423 | DoLog(0) && (Log() << Verbose(0) << "Storing configuration ... " << endl);
|
---|
1424 | // get correct valence orbitals
|
---|
1425 | mol->CalculateOrbitals(*configuration);
|
---|
1426 | configuration->InitMaxMinStopStep = configuration->MaxMinStopStep = configuration->MaxPsiDouble;
|
---|
1427 | if (ConfigFileName != NULL) { // test the file name
|
---|
1428 | strcpy(filename, ConfigFileName);
|
---|
1429 | output.open(filename, ios::trunc);
|
---|
1430 | } else if (strlen(configuration->configname) != 0) {
|
---|
1431 | strcpy(filename, configuration->configname);
|
---|
1432 | output.open(configuration->configname, ios::trunc);
|
---|
1433 | } else {
|
---|
1434 | strcpy(filename, DEFAULTCONFIG);
|
---|
1435 | output.open(DEFAULTCONFIG, ios::trunc);
|
---|
1436 | }
|
---|
1437 | output.close();
|
---|
1438 | output.clear();
|
---|
1439 | DoLog(0) && (Log() << Verbose(0) << "Saving of config file ");
|
---|
1440 | if (configuration->Save(filename, periode, mol))
|
---|
1441 | DoLog(0) && (Log() << Verbose(0) << "successful." << endl);
|
---|
1442 | else
|
---|
1443 | DoLog(0) && (Log() << Verbose(0) << "failed." << endl);
|
---|
1444 |
|
---|
1445 | // and save to xyz file
|
---|
1446 | if (ConfigFileName != NULL) {
|
---|
1447 | strcpy(filename, ConfigFileName);
|
---|
1448 | strcat(filename, ".xyz");
|
---|
1449 | output.open(filename, ios::trunc);
|
---|
1450 | }
|
---|
1451 | if (output == NULL) {
|
---|
1452 | strcpy(filename,"main_pcp_linux");
|
---|
1453 | strcat(filename, ".xyz");
|
---|
1454 | output.open(filename, ios::trunc);
|
---|
1455 | }
|
---|
1456 | DoLog(0) && (Log() << Verbose(0) << "Saving of XYZ file ");
|
---|
1457 | if (mol->MDSteps <= 1) {
|
---|
1458 | if (mol->OutputXYZ(&output))
|
---|
1459 | DoLog(0) && (Log() << Verbose(0) << "successful." << endl);
|
---|
1460 | else
|
---|
1461 | DoLog(0) && (Log() << Verbose(0) << "failed." << endl);
|
---|
1462 | } else {
|
---|
1463 | if (mol->OutputTrajectoriesXYZ(&output))
|
---|
1464 | DoLog(0) && (Log() << Verbose(0) << "successful." << endl);
|
---|
1465 | else
|
---|
1466 | DoLog(0) && (Log() << Verbose(0) << "failed." << endl);
|
---|
1467 | }
|
---|
1468 | output.close();
|
---|
1469 | output.clear();
|
---|
1470 |
|
---|
1471 | // and save as MPQC configuration
|
---|
1472 | if (ConfigFileName != NULL)
|
---|
1473 | strcpy(filename, ConfigFileName);
|
---|
1474 | if (output == NULL)
|
---|
1475 | strcpy(filename,"main_pcp_linux");
|
---|
1476 | DoLog(0) && (Log() << Verbose(0) << "Saving as mpqc input ");
|
---|
1477 | if (configuration->SaveMPQC(filename, mol))
|
---|
1478 | DoLog(0) && (Log() << Verbose(0) << "done." << endl);
|
---|
1479 | else
|
---|
1480 | DoLog(0) && (Log() << Verbose(0) << "failed." << endl);
|
---|
1481 |
|
---|
1482 | if (!strcmp(configuration->configpath, configuration->GetDefaultPath())) {
|
---|
1483 | DoeLog(2) && (eLog()<< Verbose(2) << "config is found under different path then stated in config file::defaultpath!" << endl);
|
---|
1484 | }
|
---|
1485 |
|
---|
1486 | World::getInstance().destroyMolecule(mol);
|
---|
1487 | };
|
---|
1488 |
|
---|
1489 | /** Parses the command line options.
|
---|
1490 | * Note that this function is from now on transitional. All commands that are not passed
|
---|
1491 | * here are handled by CommandLineParser and the actions of CommandLineUIFactory.
|
---|
1492 | * \param argc argument count
|
---|
1493 | * \param **argv arguments array
|
---|
1494 | * \param *molecules list of molecules structure
|
---|
1495 | * \param *periode elements structure
|
---|
1496 | * \param configuration config file structure
|
---|
1497 | * \param *ConfigFileName pointer to config file name in **argv
|
---|
1498 | * \param *PathToDatabases pointer to db's path in **argv
|
---|
1499 | * \param &ArgcList list of arguments that we do not parse here
|
---|
1500 | * \return exit code (0 - successful, all else - something's wrong)
|
---|
1501 | */
|
---|
1502 | static int ParseCommandLineOptions(int argc, char **argv, MoleculeListClass *&molecules, periodentafel *&periode,
|
---|
1503 | config& configuration, char **ConfigFileName, set<int> &ArgcList)
|
---|
1504 | {
|
---|
1505 | Vector x,y,z,n; // coordinates for absolute point in cell volume
|
---|
1506 | double *factor; // unit factor if desired
|
---|
1507 | ifstream test;
|
---|
1508 | ofstream output;
|
---|
1509 | string line;
|
---|
1510 | atom *first;
|
---|
1511 | bool SaveFlag = false;
|
---|
1512 | int ExitFlag = 0;
|
---|
1513 | int j;
|
---|
1514 | double volume = 0.;
|
---|
1515 | enum ConfigStatus configPresent = absent;
|
---|
1516 | clock_t start,end;
|
---|
1517 | double MaxDistance = -1;
|
---|
1518 | int argptr;
|
---|
1519 | molecule *mol = NULL;
|
---|
1520 | string BondGraphFileName("\n");
|
---|
1521 | bool DatabasePathGiven = false;
|
---|
1522 |
|
---|
1523 | if (argc > 1) { // config file specified as option
|
---|
1524 | // 1. : Parse options that just set variables or print help
|
---|
1525 | argptr = 1;
|
---|
1526 | do {
|
---|
1527 | if (argv[argptr][0] == '-') {
|
---|
1528 | DoLog(0) && (Log() << Verbose(0) << "Recognized command line argument: " << argv[argptr][1] << ".\n");
|
---|
1529 | argptr++;
|
---|
1530 | switch(argv[argptr-1][1]) {
|
---|
1531 | case 'h':
|
---|
1532 | case 'H':
|
---|
1533 | case '?':
|
---|
1534 | ArgcList.insert(argptr-1);
|
---|
1535 | return(1);
|
---|
1536 | break;
|
---|
1537 | case 'v':
|
---|
1538 | if ((argptr >= argc) || (argv[argptr][0] == '-')) {
|
---|
1539 | DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments for specifying verbosity: -v <level>" << endl);
|
---|
1540 | performCriticalExit();
|
---|
1541 | } else {
|
---|
1542 | setVerbosity(atoi(argv[argptr]));
|
---|
1543 | ArgcList.insert(argptr-1);
|
---|
1544 | ArgcList.insert(argptr);
|
---|
1545 | argptr++;
|
---|
1546 | }
|
---|
1547 | break;
|
---|
1548 | case 'V':
|
---|
1549 | ArgcList.insert(argptr-1);
|
---|
1550 | return(1);
|
---|
1551 | break;
|
---|
1552 | case 'B':
|
---|
1553 | if (ExitFlag == 0) ExitFlag = 1;
|
---|
1554 | if ((argptr+5 >= argc)) {
|
---|
1555 | DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments for setting Box: -B <xx> <<xy> <<xz> <yy> <yz> <zz>" << endl);
|
---|
1556 | performCriticalExit();
|
---|
1557 | } else {
|
---|
1558 | ArgcList.insert(argptr-1);
|
---|
1559 | ArgcList.insert(argptr);
|
---|
1560 | ArgcList.insert(argptr+1);
|
---|
1561 | ArgcList.insert(argptr+2);
|
---|
1562 | ArgcList.insert(argptr+3);
|
---|
1563 | ArgcList.insert(argptr+4);
|
---|
1564 | ArgcList.insert(argptr+5);
|
---|
1565 | argptr+=6;
|
---|
1566 | }
|
---|
1567 | break;
|
---|
1568 | case 'e':
|
---|
1569 | if ((argptr >= argc) || (argv[argptr][0] == '-')) {
|
---|
1570 | DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments for specifying element db: -e <db file>" << endl);
|
---|
1571 | performCriticalExit();
|
---|
1572 | } else {
|
---|
1573 | ArgcList.insert(argptr-1);
|
---|
1574 | ArgcList.insert(argptr);
|
---|
1575 | argptr+=1;
|
---|
1576 | }
|
---|
1577 | break;
|
---|
1578 | case 'g':
|
---|
1579 | if ((argptr >= argc) || (argv[argptr][0] == '-')) {
|
---|
1580 | DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments for specifying bond length table: -g <table file>" << endl);
|
---|
1581 | performCriticalExit();
|
---|
1582 | } else {
|
---|
1583 | ArgcList.insert(argptr-1);
|
---|
1584 | ArgcList.insert(argptr);
|
---|
1585 | argptr+=1;
|
---|
1586 | }
|
---|
1587 | break;
|
---|
1588 | case 'M':
|
---|
1589 | if ((argptr >= argc) || (argv[argptr][0] == '-')) {
|
---|
1590 | ExitFlag = 255;
|
---|
1591 | DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for setting MPQC basis: -M <basis name>" << endl);
|
---|
1592 | performCriticalExit();
|
---|
1593 | } else {
|
---|
1594 | ArgcList.insert(argptr-1);
|
---|
1595 | ArgcList.insert(argptr);
|
---|
1596 | argptr+=1;
|
---|
1597 | }
|
---|
1598 | break;
|
---|
1599 | case 'n':
|
---|
1600 | if ((argptr >= argc) || (argv[argptr][0] == '-')) {
|
---|
1601 | ExitFlag = 255;
|
---|
1602 | DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for setting fast-parsing: -n <0/1>" << endl);
|
---|
1603 | performCriticalExit();
|
---|
1604 | } else {
|
---|
1605 | ArgcList.insert(argptr-1);
|
---|
1606 | ArgcList.insert(argptr);
|
---|
1607 | argptr+=1;
|
---|
1608 | }
|
---|
1609 | break;
|
---|
1610 | case 'X':
|
---|
1611 | if ((argptr >= argc) || (argv[argptr][0] == '-')) {
|
---|
1612 | ExitFlag = 255;
|
---|
1613 | DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for setting default molecule name: -X <name>" << endl);
|
---|
1614 | performCriticalExit();
|
---|
1615 | } else {
|
---|
1616 | ArgcList.insert(argptr-1);
|
---|
1617 | ArgcList.insert(argptr);
|
---|
1618 | argptr+=1;
|
---|
1619 | }
|
---|
1620 | break;
|
---|
1621 | default: // no match? Step on
|
---|
1622 | argptr++;
|
---|
1623 | break;
|
---|
1624 | }
|
---|
1625 | } else
|
---|
1626 | argptr++;
|
---|
1627 | } while (argptr < argc);
|
---|
1628 |
|
---|
1629 | // 3b. Find config file name and parse if possible, also BondGraphFileName
|
---|
1630 | if (argv[1][0] != '-') {
|
---|
1631 | // simply create a new molecule, wherein the config file is loaded and the manipulation takes place
|
---|
1632 | DoLog(0) && (Log() << Verbose(0) << "Config file given." << endl);
|
---|
1633 | test.open(argv[1], ios::in);
|
---|
1634 | if (test == NULL) {
|
---|
1635 | //return (1);
|
---|
1636 | output.open(argv[1], ios::out);
|
---|
1637 | if (output == NULL) {
|
---|
1638 | DoLog(1) && (Log() << Verbose(1) << "Specified config file " << argv[1] << " not found." << endl);
|
---|
1639 | configPresent = absent;
|
---|
1640 | } else {
|
---|
1641 | DoLog(0) && (Log() << Verbose(0) << "Empty configuration file." << endl);
|
---|
1642 | strcpy(*ConfigFileName, argv[1]);
|
---|
1643 | configPresent = empty;
|
---|
1644 | output.close();
|
---|
1645 | }
|
---|
1646 | } else {
|
---|
1647 | test.close();
|
---|
1648 | strcpy(*ConfigFileName, argv[1]);
|
---|
1649 | DoLog(1) && (Log() << Verbose(1) << "Specified config file found, parsing ... ");
|
---|
1650 | switch (configuration.TestSyntax(*ConfigFileName, periode)) {
|
---|
1651 | case 1:
|
---|
1652 | DoLog(0) && (Log() << Verbose(0) << "new syntax." << endl);
|
---|
1653 | configuration.Load(*ConfigFileName, BondGraphFileName, periode, molecules);
|
---|
1654 | configPresent = present;
|
---|
1655 | break;
|
---|
1656 | case 0:
|
---|
1657 | DoLog(0) && (Log() << Verbose(0) << "old syntax." << endl);
|
---|
1658 | configuration.LoadOld(*ConfigFileName, BondGraphFileName, periode, molecules);
|
---|
1659 | configPresent = present;
|
---|
1660 | break;
|
---|
1661 | default:
|
---|
1662 | DoLog(0) && (Log() << Verbose(0) << "Unknown syntax or empty, yet present file." << endl);
|
---|
1663 | configPresent = empty;
|
---|
1664 | }
|
---|
1665 | }
|
---|
1666 | } else
|
---|
1667 | configPresent = absent;
|
---|
1668 | // set mol to first active molecule
|
---|
1669 | if (molecules->ListOfMolecules.size() != 0) {
|
---|
1670 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
|
---|
1671 | if ((*ListRunner)->ActiveFlag) {
|
---|
1672 | mol = *ListRunner;
|
---|
1673 | break;
|
---|
1674 | }
|
---|
1675 | }
|
---|
1676 | if (mol == NULL) {
|
---|
1677 | mol = World::getInstance().createMolecule();
|
---|
1678 | mol->ActiveFlag = true;
|
---|
1679 | if (*ConfigFileName != NULL)
|
---|
1680 | mol->SetNameFromFilename(*ConfigFileName);
|
---|
1681 | molecules->insert(mol);
|
---|
1682 | }
|
---|
1683 |
|
---|
1684 | // 4. parse again through options, now for those depending on elements db and config presence
|
---|
1685 | argptr = 1;
|
---|
1686 | do {
|
---|
1687 | DoLog(0) && (Log() << Verbose(0) << "Current Command line argument: " << argv[argptr] << "." << endl);
|
---|
1688 | if (argv[argptr][0] == '-') {
|
---|
1689 | argptr++;
|
---|
1690 | if ((configPresent == present) || (configPresent == empty)) {
|
---|
1691 | switch(argv[argptr-1][1]) {
|
---|
1692 | case 'p':
|
---|
1693 | if (ExitFlag == 0) ExitFlag = 1;
|
---|
1694 | if ((argptr >= argc) || (argv[argptr][0] == '-')) {
|
---|
1695 | ExitFlag = 255;
|
---|
1696 | DoeLog(0) && (eLog()<< Verbose(0) << "Not enough arguments for parsing: -p <xyz file>" << endl);
|
---|
1697 | performCriticalExit();
|
---|
1698 | } else {
|
---|
1699 | SaveFlag = true;
|
---|
1700 | DoLog(1) && (Log() << Verbose(1) << "Parsing xyz file for new atoms." << endl);
|
---|
1701 | if (!mol->AddXYZFile(argv[argptr]))
|
---|
1702 | DoLog(2) && (Log() << Verbose(2) << "File not found." << endl);
|
---|
1703 | else {
|
---|
1704 | DoLog(2) && (Log() << Verbose(2) << "File found and parsed." << endl);
|
---|
1705 | configPresent = present;
|
---|
1706 | }
|
---|
1707 | }
|
---|
1708 | break;
|
---|
1709 | case 'a':
|
---|
1710 | if (ExitFlag == 0) ExitFlag = 1;
|
---|
1711 | if ((argptr+4 >= argc) || (argv[argptr][0] == '-')) {
|
---|
1712 | ExitFlag = 255;
|
---|
1713 | DoeLog(0) && (eLog()<< Verbose(0) << "Not enough arguments for adding atom: -a <Z> --position <x> <y> <z>" << endl);
|
---|
1714 | performCriticalExit();
|
---|
1715 | } else {
|
---|
1716 | ArgcList.insert(argptr-1);
|
---|
1717 | ArgcList.insert(argptr);
|
---|
1718 | ArgcList.insert(argptr+1);
|
---|
1719 | ArgcList.insert(argptr+2);
|
---|
1720 | ArgcList.insert(argptr+3);
|
---|
1721 | ArgcList.insert(argptr+4);
|
---|
1722 | argptr+=5;
|
---|
1723 | }
|
---|
1724 | break;
|
---|
1725 | default: // no match? Don't step on (this is done in next switch's default)
|
---|
1726 | break;
|
---|
1727 | }
|
---|
1728 | }
|
---|
1729 | if (configPresent == present) {
|
---|
1730 | switch(argv[argptr-1][1]) {
|
---|
1731 | case 'D':
|
---|
1732 | if (ExitFlag == 0) ExitFlag = 1;
|
---|
1733 | if ((argptr >= argc) || (argv[argptr][0] == '-')) {
|
---|
1734 | ExitFlag = 255;
|
---|
1735 | DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for depth-first-search analysis: -D <max. bond distance>" << endl);
|
---|
1736 | performCriticalExit();
|
---|
1737 | } else {
|
---|
1738 | ArgcList.insert(argptr-1);
|
---|
1739 | ArgcList.insert(argptr);
|
---|
1740 | argptr+=1;
|
---|
1741 | }
|
---|
1742 | break;
|
---|
1743 | case 'I':
|
---|
1744 | DoLog(1) && (Log() << Verbose(1) << "Dissecting molecular system into a set of disconnected subgraphs ... " << endl);
|
---|
1745 | ArgcList.insert(argptr-1);
|
---|
1746 | argptr+=0;
|
---|
1747 | break;
|
---|
1748 | case 'C':
|
---|
1749 | {
|
---|
1750 | if (ExitFlag == 0) ExitFlag = 1;
|
---|
1751 | if ((argptr+11 >= argc)) {
|
---|
1752 | ExitFlag = 255;
|
---|
1753 | DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for pair correlation analysis: -C[p] <type: E/P/S> [more params] <output> <bin output> <BinStart> <BinEnd>" << endl);
|
---|
1754 | performCriticalExit();
|
---|
1755 | } else {
|
---|
1756 | switch(argv[argptr][0]) {
|
---|
1757 | case 'E':
|
---|
1758 | ArgcList.insert(argptr-1);
|
---|
1759 | ArgcList.insert(argptr);
|
---|
1760 | ArgcList.insert(argptr+1);
|
---|
1761 | ArgcList.insert(argptr+2);
|
---|
1762 | ArgcList.insert(argptr+3);
|
---|
1763 | ArgcList.insert(argptr+4);
|
---|
1764 | ArgcList.insert(argptr+5);
|
---|
1765 | ArgcList.insert(argptr+6);
|
---|
1766 | ArgcList.insert(argptr+7);
|
---|
1767 | ArgcList.insert(argptr+8);
|
---|
1768 | ArgcList.insert(argptr+9);
|
---|
1769 | ArgcList.insert(argptr+10);
|
---|
1770 | ArgcList.insert(argptr+11);
|
---|
1771 | argptr+=12;
|
---|
1772 | break;
|
---|
1773 |
|
---|
1774 | case 'P':
|
---|
1775 | ArgcList.insert(argptr-1);
|
---|
1776 | ArgcList.insert(argptr);
|
---|
1777 | ArgcList.insert(argptr+1);
|
---|
1778 | ArgcList.insert(argptr+2);
|
---|
1779 | ArgcList.insert(argptr+3);
|
---|
1780 | ArgcList.insert(argptr+4);
|
---|
1781 | ArgcList.insert(argptr+5);
|
---|
1782 | ArgcList.insert(argptr+6);
|
---|
1783 | ArgcList.insert(argptr+7);
|
---|
1784 | ArgcList.insert(argptr+8);
|
---|
1785 | ArgcList.insert(argptr+9);
|
---|
1786 | ArgcList.insert(argptr+10);
|
---|
1787 | ArgcList.insert(argptr+11);
|
---|
1788 | ArgcList.insert(argptr+12);
|
---|
1789 | ArgcList.insert(argptr+13);
|
---|
1790 | ArgcList.insert(argptr+14);
|
---|
1791 | argptr+=15;
|
---|
1792 | break;
|
---|
1793 |
|
---|
1794 | case 'S':
|
---|
1795 | ArgcList.insert(argptr-1);
|
---|
1796 | ArgcList.insert(argptr);
|
---|
1797 | ArgcList.insert(argptr+1);
|
---|
1798 | ArgcList.insert(argptr+2);
|
---|
1799 | ArgcList.insert(argptr+3);
|
---|
1800 | ArgcList.insert(argptr+4);
|
---|
1801 | ArgcList.insert(argptr+5);
|
---|
1802 | ArgcList.insert(argptr+6);
|
---|
1803 | ArgcList.insert(argptr+7);
|
---|
1804 | ArgcList.insert(argptr+8);
|
---|
1805 | ArgcList.insert(argptr+9);
|
---|
1806 | ArgcList.insert(argptr+10);
|
---|
1807 | ArgcList.insert(argptr+11);
|
---|
1808 | ArgcList.insert(argptr+12);
|
---|
1809 | ArgcList.insert(argptr+13);
|
---|
1810 | ArgcList.insert(argptr+14);
|
---|
1811 | argptr+=15;
|
---|
1812 | break;
|
---|
1813 |
|
---|
1814 | default:
|
---|
1815 | ExitFlag = 255;
|
---|
1816 | DoeLog(0) && (eLog()<< Verbose(0) << "Invalid type given for pair correlation analysis: -C <type: E/P/S> [more params] <output> <bin output>" << endl);
|
---|
1817 | performCriticalExit();
|
---|
1818 | break;
|
---|
1819 | }
|
---|
1820 | }
|
---|
1821 | break;
|
---|
1822 | }
|
---|
1823 | case 'E':
|
---|
1824 | if (ExitFlag == 0) ExitFlag = 1;
|
---|
1825 | if ((argptr+2 >= argc) || (!IsValidNumber(argv[argptr]))) {
|
---|
1826 | ExitFlag = 255;
|
---|
1827 | DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for changing element: -E <atom nr.> --element <Z>" << endl);
|
---|
1828 | performCriticalExit();
|
---|
1829 | } else {
|
---|
1830 | ArgcList.insert(argptr-1);
|
---|
1831 | ArgcList.insert(argptr);
|
---|
1832 | ArgcList.insert(argptr+1);
|
---|
1833 | ArgcList.insert(argptr+2);
|
---|
1834 | argptr+=3;
|
---|
1835 | }
|
---|
1836 | break;
|
---|
1837 | case 'F':
|
---|
1838 | if (ExitFlag == 0) ExitFlag = 1;
|
---|
1839 | if ((argptr+12 >= argc) || (argv[argptr][0] == '-')) {
|
---|
1840 | ExitFlag = 255;
|
---|
1841 | DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for filling with molecule: -F <filler xyz file> --MaxDistance <distance or -1> --distances <x> <y> <z> --lengths <surface> <randatm> <randmol> --DoRotate <0/1>" << endl);
|
---|
1842 | performCriticalExit();
|
---|
1843 | } else {
|
---|
1844 | ArgcList.insert(argptr-1);
|
---|
1845 | ArgcList.insert(argptr);
|
---|
1846 | ArgcList.insert(argptr+1);
|
---|
1847 | ArgcList.insert(argptr+2);
|
---|
1848 | ArgcList.insert(argptr+3);
|
---|
1849 | ArgcList.insert(argptr+4);
|
---|
1850 | ArgcList.insert(argptr+5);
|
---|
1851 | ArgcList.insert(argptr+6);
|
---|
1852 | ArgcList.insert(argptr+7);
|
---|
1853 | ArgcList.insert(argptr+8);
|
---|
1854 | ArgcList.insert(argptr+9);
|
---|
1855 | ArgcList.insert(argptr+10);
|
---|
1856 | ArgcList.insert(argptr+11);
|
---|
1857 | ArgcList.insert(argptr+12);
|
---|
1858 | argptr+=13;
|
---|
1859 | }
|
---|
1860 | break;
|
---|
1861 | case 'A':
|
---|
1862 | if (ExitFlag == 0) ExitFlag = 1;
|
---|
1863 | if ((argptr+2 >= argc) || (argv[argptr][0] == '-')) {
|
---|
1864 | ExitFlag =255;
|
---|
1865 | DoeLog(0) && (eLog()<< Verbose(0) << "Missing source file for bonds in molecule: -A <bond sourcefile> --molecule-by-id <molecule_id>" << endl);
|
---|
1866 | performCriticalExit();
|
---|
1867 | } else {
|
---|
1868 | ArgcList.insert(argptr-1);
|
---|
1869 | ArgcList.insert(argptr);
|
---|
1870 | ArgcList.insert(argptr+1);
|
---|
1871 | ArgcList.insert(argptr+2);
|
---|
1872 | argptr+=3;
|
---|
1873 | }
|
---|
1874 | break;
|
---|
1875 |
|
---|
1876 | case 'J':
|
---|
1877 | if (ExitFlag == 0) ExitFlag = 1;
|
---|
1878 | if ((argptr+2 >= argc) || (argv[argptr][0] == '-')) {
|
---|
1879 | ExitFlag =255;
|
---|
1880 | DoeLog(0) && (eLog()<< Verbose(0) << "Missing path of adjacency file: -J <path> --molecule-by-id <molecule_id>" << endl);
|
---|
1881 | performCriticalExit();
|
---|
1882 | } else {
|
---|
1883 | ArgcList.insert(argptr-1);
|
---|
1884 | ArgcList.insert(argptr);
|
---|
1885 | ArgcList.insert(argptr+1);
|
---|
1886 | ArgcList.insert(argptr+2);
|
---|
1887 | argptr+=3;
|
---|
1888 | }
|
---|
1889 | break;
|
---|
1890 |
|
---|
1891 | case 'j':
|
---|
1892 | if (ExitFlag == 0) ExitFlag = 1;
|
---|
1893 | if ((argptr >= argc) || (argv[argptr][0] == '-')) {
|
---|
1894 | ExitFlag =255;
|
---|
1895 | DoeLog(0) && (eLog()<< Verbose(0) << "Missing path of bonds file: -j <path> --molecule-by-id <molecule_id>" << endl);
|
---|
1896 | performCriticalExit();
|
---|
1897 | } else {
|
---|
1898 | ArgcList.insert(argptr-1);
|
---|
1899 | ArgcList.insert(argptr);
|
---|
1900 | ArgcList.insert(argptr+1);
|
---|
1901 | ArgcList.insert(argptr+2);
|
---|
1902 | argptr+=3;
|
---|
1903 | }
|
---|
1904 | break;
|
---|
1905 |
|
---|
1906 | case 'N':
|
---|
1907 | if (ExitFlag == 0) ExitFlag = 1;
|
---|
1908 | if ((argptr+4 >= argc) || (argv[argptr][0] == '-')){
|
---|
1909 | ExitFlag = 255;
|
---|
1910 | DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for non-convex envelope: -N <molecule_id> --sphere-radius <radius> --nonconvex-file <output prefix>" << endl);
|
---|
1911 | performCriticalExit();
|
---|
1912 | } else {
|
---|
1913 | ArgcList.insert(argptr-1);
|
---|
1914 | ArgcList.insert(argptr);
|
---|
1915 | ArgcList.insert(argptr+1);
|
---|
1916 | ArgcList.insert(argptr+2);
|
---|
1917 | ArgcList.insert(argptr+3);
|
---|
1918 | ArgcList.insert(argptr+4);
|
---|
1919 | argptr+=5;
|
---|
1920 | }
|
---|
1921 | break;
|
---|
1922 | case 'S':
|
---|
1923 | if (ExitFlag == 0) ExitFlag = 1;
|
---|
1924 | if ((argptr+2 >= argc) || (argv[argptr][0] == '-')) {
|
---|
1925 | ExitFlag = 255;
|
---|
1926 | DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for storing tempature: -S <temperature file> --molecule-by-id 0" << endl);
|
---|
1927 | performCriticalExit();
|
---|
1928 | } else {
|
---|
1929 | ArgcList.insert(argptr-1);
|
---|
1930 | ArgcList.insert(argptr);
|
---|
1931 | ArgcList.insert(argptr+1);
|
---|
1932 | ArgcList.insert(argptr+2);
|
---|
1933 | argptr+=3;
|
---|
1934 | }
|
---|
1935 | break;
|
---|
1936 | case 'L':
|
---|
1937 | if (ExitFlag == 0) ExitFlag = 1;
|
---|
1938 | if ((argptr+8 >= argc) || (argv[argptr][0] == '-')) {
|
---|
1939 | ExitFlag = 255;
|
---|
1940 | DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for linear interpolation: -L <prefix> --start-step <step0> --end-step <step1> --molecule-by-id 0 --id-mapping <0/1>" << endl);
|
---|
1941 | performCriticalExit();
|
---|
1942 | } else {
|
---|
1943 | ArgcList.insert(argptr-1);
|
---|
1944 | ArgcList.insert(argptr);
|
---|
1945 | ArgcList.insert(argptr+1);
|
---|
1946 | ArgcList.insert(argptr+2);
|
---|
1947 | ArgcList.insert(argptr+3);
|
---|
1948 | ArgcList.insert(argptr+4);
|
---|
1949 | ArgcList.insert(argptr+5);
|
---|
1950 | ArgcList.insert(argptr+6);
|
---|
1951 | ArgcList.insert(argptr+7);
|
---|
1952 | ArgcList.insert(argptr+8);
|
---|
1953 | argptr+=9;
|
---|
1954 | }
|
---|
1955 | break;
|
---|
1956 | case 'P':
|
---|
1957 | if (ExitFlag == 0) ExitFlag = 1;
|
---|
1958 | if ((argptr+2 >= argc) || (argv[argptr][0] == '-')) {
|
---|
1959 | ExitFlag = 255;
|
---|
1960 | DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for parsing and integrating forces: -P <forces file> --molecule-by-id <molecule_id>" << endl);
|
---|
1961 | performCriticalExit();
|
---|
1962 | } else {
|
---|
1963 | ArgcList.insert(argptr-1);
|
---|
1964 | ArgcList.insert(argptr);
|
---|
1965 | ArgcList.insert(argptr+1);
|
---|
1966 | ArgcList.insert(argptr+2);
|
---|
1967 | argptr+=3;
|
---|
1968 | }
|
---|
1969 | break;
|
---|
1970 | case 'R':
|
---|
1971 | if (ExitFlag == 0) ExitFlag = 1;
|
---|
1972 | if ((argptr+4 >= argc) || (argv[argptr][0] == '-')) {
|
---|
1973 | ExitFlag = 255;
|
---|
1974 | DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for removing atoms: -R <distance> --position <x> <y> <z>" << endl);
|
---|
1975 | performCriticalExit();
|
---|
1976 | } else {
|
---|
1977 | ArgcList.insert(argptr-1);
|
---|
1978 | ArgcList.insert(argptr);
|
---|
1979 | ArgcList.insert(argptr+1);
|
---|
1980 | ArgcList.insert(argptr+2);
|
---|
1981 | ArgcList.insert(argptr+3);
|
---|
1982 | ArgcList.insert(argptr+4);
|
---|
1983 | argptr+=5;
|
---|
1984 | }
|
---|
1985 | break;
|
---|
1986 | case 't':
|
---|
1987 | if (ExitFlag == 0) ExitFlag = 1;
|
---|
1988 | if ((argptr+4 >= argc) || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) {
|
---|
1989 | ExitFlag = 255;
|
---|
1990 | DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for translation: -t <x> <y> <z> --molecule-by-id <molecule_id> --periodic <0/1>" << endl);
|
---|
1991 | performCriticalExit();
|
---|
1992 | } else {
|
---|
1993 | ArgcList.insert(argptr-1);
|
---|
1994 | ArgcList.insert(argptr);
|
---|
1995 | ArgcList.insert(argptr+1);
|
---|
1996 | ArgcList.insert(argptr+2);
|
---|
1997 | ArgcList.insert(argptr+3);
|
---|
1998 | ArgcList.insert(argptr+4);
|
---|
1999 | ArgcList.insert(argptr+5);
|
---|
2000 | ArgcList.insert(argptr+6);
|
---|
2001 | argptr+=7;
|
---|
2002 | }
|
---|
2003 | break;
|
---|
2004 | case 's':
|
---|
2005 | if (ExitFlag == 0) ExitFlag = 1;
|
---|
2006 | if ((argptr+2 >= argc) || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) {
|
---|
2007 | ExitFlag = 255;
|
---|
2008 | DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for scaling: -s <factor_x> [factor_y] [factor_z]" << endl);
|
---|
2009 | performCriticalExit();
|
---|
2010 | } else {
|
---|
2011 | ArgcList.insert(argptr-1);
|
---|
2012 | ArgcList.insert(argptr);
|
---|
2013 | ArgcList.insert(argptr+1);
|
---|
2014 | ArgcList.insert(argptr+2);
|
---|
2015 | argptr+=3;
|
---|
2016 | }
|
---|
2017 | break;
|
---|
2018 | case 'b':
|
---|
2019 | if (ExitFlag == 0) ExitFlag = 1;
|
---|
2020 | if ((argptr+5 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) || (!IsValidNumber(argv[argptr+3])) || (!IsValidNumber(argv[argptr+4])) || (!IsValidNumber(argv[argptr+5])) ) {
|
---|
2021 | ExitFlag = 255;
|
---|
2022 | DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for centering in box: -b <xx> <xy> <xz> <yy> <yz> <zz>" << endl);
|
---|
2023 | performCriticalExit();
|
---|
2024 | } else {
|
---|
2025 | ArgcList.insert(argptr-1);
|
---|
2026 | ArgcList.insert(argptr);
|
---|
2027 | ArgcList.insert(argptr+1);
|
---|
2028 | ArgcList.insert(argptr+2);
|
---|
2029 | ArgcList.insert(argptr+3);
|
---|
2030 | ArgcList.insert(argptr+4);
|
---|
2031 | ArgcList.insert(argptr+5);
|
---|
2032 | argptr+=6;
|
---|
2033 | }
|
---|
2034 | break;
|
---|
2035 | case 'B':
|
---|
2036 | if (ExitFlag == 0) ExitFlag = 1;
|
---|
2037 | if ((argptr+5 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) || (!IsValidNumber(argv[argptr+3])) || (!IsValidNumber(argv[argptr+4])) || (!IsValidNumber(argv[argptr+5])) ) {
|
---|
2038 | ExitFlag = 255;
|
---|
2039 | DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for bounding in box: -B <xx> <xy> <xz> <yy> <yz> <zz>" << endl);
|
---|
2040 | performCriticalExit();
|
---|
2041 | } else {
|
---|
2042 | ArgcList.insert(argptr-1);
|
---|
2043 | ArgcList.insert(argptr);
|
---|
2044 | ArgcList.insert(argptr+1);
|
---|
2045 | ArgcList.insert(argptr+2);
|
---|
2046 | ArgcList.insert(argptr+3);
|
---|
2047 | ArgcList.insert(argptr+4);
|
---|
2048 | ArgcList.insert(argptr+5);
|
---|
2049 | argptr+=6;
|
---|
2050 | }
|
---|
2051 | break;
|
---|
2052 | case 'c':
|
---|
2053 | if (ExitFlag == 0) ExitFlag = 1;
|
---|
2054 | if ((argptr+2 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) {
|
---|
2055 | ExitFlag = 255;
|
---|
2056 | DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for centering with boundary: -c <boundary_x> <boundary_y> <boundary_z>" << endl);
|
---|
2057 | performCriticalExit();
|
---|
2058 | } else {
|
---|
2059 | ArgcList.insert(argptr-1);
|
---|
2060 | ArgcList.insert(argptr);
|
---|
2061 | ArgcList.insert(argptr+1);
|
---|
2062 | ArgcList.insert(argptr+2);
|
---|
2063 | argptr+=3;
|
---|
2064 | }
|
---|
2065 | break;
|
---|
2066 | case 'O':
|
---|
2067 | if (ExitFlag == 0) ExitFlag = 1;
|
---|
2068 | ArgcList.insert(argptr-1);
|
---|
2069 | argptr+=0;
|
---|
2070 | break;
|
---|
2071 | case 'r':
|
---|
2072 | if (ExitFlag == 0) ExitFlag = 1;
|
---|
2073 | if ((argptr >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr]))) {
|
---|
2074 | ExitFlag = 255;
|
---|
2075 | DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for removing atoms: -r <id>" << endl);
|
---|
2076 | performCriticalExit();
|
---|
2077 | } else {
|
---|
2078 | ArgcList.insert(argptr-1);
|
---|
2079 | ArgcList.insert(argptr);
|
---|
2080 | argptr+=1;
|
---|
2081 | }
|
---|
2082 | break;
|
---|
2083 | case 'f':
|
---|
2084 | if (ExitFlag == 0) ExitFlag = 1;
|
---|
2085 | if ((argptr+1 >= argc) || (argv[argptr][0] == '-')) {
|
---|
2086 | ExitFlag = 255;
|
---|
2087 | DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments for fragmentation: -f <max. bond distance> <bond order>" << endl);
|
---|
2088 | performCriticalExit();
|
---|
2089 | } else {
|
---|
2090 | ArgcList.insert(argptr-1);
|
---|
2091 | ArgcList.insert(argptr);
|
---|
2092 | ArgcList.insert(argptr+1);
|
---|
2093 | ArgcList.insert(argptr+2);
|
---|
2094 | ArgcList.insert(argptr+3);
|
---|
2095 | ArgcList.insert(argptr+4);
|
---|
2096 | argptr+=5;
|
---|
2097 | }
|
---|
2098 | break;
|
---|
2099 | case 'm':
|
---|
2100 | if (ExitFlag == 0) ExitFlag = 1;
|
---|
2101 | j = atoi(argv[argptr++]);
|
---|
2102 | if ((j<0) || (j>1)) {
|
---|
2103 | DoeLog(1) && (eLog()<< Verbose(1) << "Argument of '-m' should be either 0 for no-rotate or 1 for rotate." << endl);
|
---|
2104 | j = 0;
|
---|
2105 | }
|
---|
2106 | if (j) {
|
---|
2107 | SaveFlag = true;
|
---|
2108 | DoLog(0) && (Log() << Verbose(0) << "Converting to prinicipal axis system." << endl);
|
---|
2109 | mol->PrincipalAxisSystem((bool)j);
|
---|
2110 | } else
|
---|
2111 | ArgcList.insert(argptr-1);
|
---|
2112 | argptr+=0;
|
---|
2113 | break;
|
---|
2114 | case 'o':
|
---|
2115 | if (ExitFlag == 0) ExitFlag = 1;
|
---|
2116 | if ((argptr+4 >= argc) || (argv[argptr][0] == '-')){
|
---|
2117 | ExitFlag = 255;
|
---|
2118 | DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for convex envelope: -o <molecule_id> --output-file <output file> --output-file <binned output file>" << endl);
|
---|
2119 | performCriticalExit();
|
---|
2120 | } else {
|
---|
2121 | ArgcList.insert(argptr-1);
|
---|
2122 | ArgcList.insert(argptr);
|
---|
2123 | ArgcList.insert(argptr+1);
|
---|
2124 | ArgcList.insert(argptr+2);
|
---|
2125 | ArgcList.insert(argptr+3);
|
---|
2126 | ArgcList.insert(argptr+4);
|
---|
2127 | argptr+=5;
|
---|
2128 | }
|
---|
2129 | break;
|
---|
2130 | case 'U':
|
---|
2131 | if (ExitFlag == 0) ExitFlag = 1;
|
---|
2132 | if ((argptr+1 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) ) {
|
---|
2133 | ExitFlag = 255;
|
---|
2134 | DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for suspension with specified volume: -U <volume> <density>" << endl);
|
---|
2135 | performCriticalExit();
|
---|
2136 | } else {
|
---|
2137 | volume = atof(argv[argptr++]);
|
---|
2138 | DoLog(0) && (Log() << Verbose(0) << "Using " << volume << " angstrom^3 as the volume instead of convex envelope one's." << endl);
|
---|
2139 | }
|
---|
2140 | case 'u':
|
---|
2141 | if (ExitFlag == 0) ExitFlag = 1;
|
---|
2142 | if ((argptr >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) ) {
|
---|
2143 | if (volume != -1)
|
---|
2144 | ExitFlag = 255;
|
---|
2145 | DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for suspension: -u <density>" << endl);
|
---|
2146 | performCriticalExit();
|
---|
2147 | } else {
|
---|
2148 | ArgcList.insert(argptr-1);
|
---|
2149 | ArgcList.insert(argptr);
|
---|
2150 | argptr+=1;
|
---|
2151 | }
|
---|
2152 | break;
|
---|
2153 | case 'd':
|
---|
2154 | if (ExitFlag == 0) ExitFlag = 1;
|
---|
2155 | if ((argptr+2 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) {
|
---|
2156 | ExitFlag = 255;
|
---|
2157 | DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for repeating cells: -d <repeat_x> <repeat_y> <repeat_z>" << endl);
|
---|
2158 | performCriticalExit();
|
---|
2159 | } else {
|
---|
2160 | ArgcList.insert(argptr-1);
|
---|
2161 | ArgcList.insert(argptr);
|
---|
2162 | ArgcList.insert(argptr+1);
|
---|
2163 | ArgcList.insert(argptr+2);
|
---|
2164 | argptr+=3;
|
---|
2165 | }
|
---|
2166 | break;
|
---|
2167 | default: // no match? Step on
|
---|
2168 | if ((argptr < argc) && (argv[argptr][0] != '-')) // if it started with a '-' we've already made a step!
|
---|
2169 | argptr++;
|
---|
2170 | break;
|
---|
2171 | }
|
---|
2172 | }
|
---|
2173 | } else argptr++;
|
---|
2174 | } while (argptr < argc);
|
---|
2175 | if (SaveFlag)
|
---|
2176 | configuration.SaveAll(*ConfigFileName, periode, molecules);
|
---|
2177 | } else { // no arguments, hence scan the elements db
|
---|
2178 | if (periode->LoadPeriodentafel(configuration.databasepath))
|
---|
2179 | DoLog(0) && (Log() << Verbose(0) << "Element list loaded successfully." << endl);
|
---|
2180 | else
|
---|
2181 | DoLog(0) && (Log() << Verbose(0) << "Element list loading failed." << endl);
|
---|
2182 | configuration.RetrieveConfigPathAndName("main_pcp_linux");
|
---|
2183 | }
|
---|
2184 | return(ExitFlag);
|
---|
2185 | };
|
---|
2186 |
|
---|
2187 | /********************************************** Main routine **************************************/
|
---|
2188 |
|
---|
2189 | void cleanUp(){
|
---|
2190 | World::purgeInstance();
|
---|
2191 | logger::purgeInstance();
|
---|
2192 | errorLogger::purgeInstance();
|
---|
2193 | UIFactory::purgeInstance();
|
---|
2194 | MapOfActions::purgeInstance();
|
---|
2195 | CommandLineParser::purgeInstance();
|
---|
2196 | ActionRegistry::purgeInstance();
|
---|
2197 | ActionHistory::purgeInstance();
|
---|
2198 | #ifdef LOG_OBSERVER
|
---|
2199 | cout << observerLog().getLog();
|
---|
2200 | #endif
|
---|
2201 | Memory::getState();
|
---|
2202 | }
|
---|
2203 |
|
---|
2204 | int main(int argc, char **argv)
|
---|
2205 | {
|
---|
2206 | config *configuration = World::getInstance().getConfig();
|
---|
2207 | // while we are non interactive, we want to abort from asserts
|
---|
2208 | //ASSERT_DO(Assert::Abort);
|
---|
2209 | molecule *mol = NULL;
|
---|
2210 | Vector x, y, z, n;
|
---|
2211 | ifstream test;
|
---|
2212 | ofstream output;
|
---|
2213 | string line;
|
---|
2214 | char **Arguments = NULL;
|
---|
2215 | int ArgcSize = 0;
|
---|
2216 | int ExitFlag = 0;
|
---|
2217 | bool ArgumentsCopied = false;
|
---|
2218 | char *ConfigFileName = new char[MAXSTRINGSIZE];
|
---|
2219 |
|
---|
2220 | // print version check whether arguments are present at all
|
---|
2221 | cout << ESPACKVersion << endl;
|
---|
2222 | if (argc < 2) {
|
---|
2223 | cout << "Obtain help with " << argv[0] << " -h." << endl;
|
---|
2224 | cleanUp();
|
---|
2225 | Memory::getState();
|
---|
2226 | return(1);
|
---|
2227 | }
|
---|
2228 |
|
---|
2229 |
|
---|
2230 | setVerbosity(0);
|
---|
2231 | // need to init the history before any action is created
|
---|
2232 | ActionHistory::init();
|
---|
2233 |
|
---|
2234 | // In the interactive mode, we can leave the user the choice in case of error
|
---|
2235 | ASSERT_DO(Assert::Ask);
|
---|
2236 |
|
---|
2237 | // from this moment on, we need to be sure to deeinitialize in the correct order
|
---|
2238 | // this is handled by the cleanup function
|
---|
2239 | atexit(cleanUp);
|
---|
2240 |
|
---|
2241 | // Parse command line options and if present create respective UI
|
---|
2242 | {
|
---|
2243 | set<int> ArgcList;
|
---|
2244 | ArgcList.insert(0); // push back program!
|
---|
2245 | ArgcList.insert(1); // push back config file name
|
---|
2246 | // handle arguments by ParseCommandLineOptions()
|
---|
2247 | ExitFlag = ParseCommandLineOptions(argc,argv,World::getInstance().getMolecules(),World::getInstance().getPeriode(),*World::getInstance().getConfig(), &ConfigFileName, ArgcList);
|
---|
2248 | World::getInstance().setExitFlag(ExitFlag);
|
---|
2249 | // copy all remaining arguments to a new argv
|
---|
2250 | Arguments = new char *[ArgcList.size()];
|
---|
2251 | cout << "The following arguments are handled by CommandLineParser: ";
|
---|
2252 | for (set<int>::iterator ArgcRunner = ArgcList.begin(); ArgcRunner != ArgcList.end(); ++ArgcRunner) {
|
---|
2253 | Arguments[ArgcSize] = new char[strlen(argv[*ArgcRunner])+2];
|
---|
2254 | strcpy(Arguments[ArgcSize], argv[*ArgcRunner]);
|
---|
2255 | cout << " " << argv[*ArgcRunner];
|
---|
2256 | ArgcSize++;
|
---|
2257 | }
|
---|
2258 | cout << endl;
|
---|
2259 | ArgumentsCopied = true;
|
---|
2260 | // handle remaining arguments by CommandLineParser
|
---|
2261 | MapOfActions::getInstance().AddOptionsToParser();
|
---|
2262 | map <std::string, std::string> ShortFormToActionMap = MapOfActions::getInstance().getShortFormToActionMap();
|
---|
2263 | CommandLineParser::getInstance().Run(ArgcSize,Arguments, ShortFormToActionMap);
|
---|
2264 | if (!CommandLineParser::getInstance().isEmpty()) {
|
---|
2265 | DoLog(0) && (Log() << Verbose(0) << "Setting UI to CommandLine." << endl);
|
---|
2266 | UIFactory::registerFactory(new CommandLineUIFactory::description());
|
---|
2267 | UIFactory::makeUserInterface("CommandLine");
|
---|
2268 | } else {
|
---|
2269 | #ifdef USE_GUI_QT
|
---|
2270 | DoLog(0) && (Log() << Verbose(0) << "Setting UI to QT4." << endl);
|
---|
2271 | UIFactory::registerFactory(new QTUIFactory::description());
|
---|
2272 | UIFactory::makeUserInterface("QT4");
|
---|
2273 | #else
|
---|
2274 | DoLog(0) && (Log() << Verbose(0) << "Setting UI to Text." << endl);
|
---|
2275 | cout << ESPACKVersion << endl;
|
---|
2276 | UIFactory::registerFactory(new TextUIFactory::description());
|
---|
2277 | UIFactory::makeUserInterface("Text");
|
---|
2278 | #endif
|
---|
2279 | }
|
---|
2280 | }
|
---|
2281 |
|
---|
2282 | {
|
---|
2283 | MainWindow *mainWindow = UIFactory::getInstance().makeMainWindow();
|
---|
2284 | mainWindow->display();
|
---|
2285 | delete mainWindow;
|
---|
2286 | }
|
---|
2287 |
|
---|
2288 | Log() << Verbose(0) << "Saving to " << ConfigFileName << "." << endl;
|
---|
2289 | World::getInstance().getConfig()->SaveAll(ConfigFileName, World::getInstance().getPeriode(), World::getInstance().getMolecules());
|
---|
2290 |
|
---|
2291 | // free the new argv
|
---|
2292 | if (ArgumentsCopied) {
|
---|
2293 | for (int i=0; i<ArgcSize;i++)
|
---|
2294 | delete[](Arguments[i]);
|
---|
2295 | delete[](Arguments);
|
---|
2296 | }
|
---|
2297 | delete[](ConfigFileName);
|
---|
2298 |
|
---|
2299 | ExitFlag = World::getInstance().getExitFlag();
|
---|
2300 | return (ExitFlag == 1 ? 0 : ExitFlag);
|
---|
2301 | }
|
---|
2302 |
|
---|
2303 | /********************************************** E N D **************************************************/
|
---|