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