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