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