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