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