source: molecuilder/src/builder.cpp@ 2ac928

Last change on this file since 2ac928 was 735468, checked in by Christian Neuen <neuen@…>, 17 years ago

Another update w.r.t. the Tesselation.
Some signs switched, but atom indices might be misused.

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