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