source: molecuilder/src/builder.cpp@ 41c2f1

Last change on this file since 41c2f1 was 7fcea6, checked in by Frederik Heber <heber@…>, 17 years ago

Smaller fixes

CreateClustersinWater is now PrepareClustersinWater (as actual suspension is done in VMD still)
BoundaryPoints can be returned or not in VolumeOfConvexEnvelope

  • Property mode set to 100644
File size: 50.5 KB
RevLine 
[a0bcf1]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
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;
65 vector **atoms;
66 vector x,y,z,n; // coordinates for absolute point in cell volume
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;
82
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;
91
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);
101 first->x.AddVector((const vector *)&x);
102 cout << Verbose(0) << "\n";
103 } while (!(valid = mol->CheckBounds((const vector *)&first->x)));
104 first->type = periode->AskElement(); // give type
105 mol->AddAtom(first); // add to molecule
106 break;
107
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;
113 second = mol->AskAtom("Enter atom number: ");
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 }
119 } while (!(valid = mol->CheckBounds((const vector *)&first->x)));
120 first->type = periode->AskElement(); // give type
121 mol->AddAtom(first); // add to molecule
122 break;
123
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);
149 n.MakeNormalVector((const vector *)&second->x, (const vector *)&third->x, (const vector *)&fourth->x);
150 x.CopyVector(&second->x);
151 x.SubtractVector(&third->x);
152 x.CopyVector(&fourth->x);
153 x.SubtractVector(&third->x);
154
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);
169 cout << endl;
170 z.MakeNormalVector(&second->x,&third->x,&fourth->x);
171 cout << "z: ",
172 z.Output((ofstream *)&cout);
173 cout << endl;
174 y.MakeNormalVector(&x,&z);
175 cout << "y: ",
176 y.Output((ofstream *)&cout);
177 cout << endl;
178
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);
184 cout << endl;
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);
190 cout << endl;
191 first->x.SubtractVector(&n);
192 cout << "Subtracted vector: ",
193 first->x.Output((ofstream *)&cout);
194 cout << endl;
195 n.CopyVector(&z);
196 n.Scale(first->x.Projection(&z));
197 cout << "N2: ",
198 n.Output((ofstream *)&cout);
199 cout << endl;
200 first->x.SubtractVector(&n);
201 cout << "2nd subtracted vector: ",
202 first->x.Output((ofstream *)&cout);
203 cout << endl;
204
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);
210 cout << endl;
211
212 // add the two linear independent vectors
213 first->x.AddVector(&n);
214 first->x.Normalize();
215 first->x.Scale(a);
216 first->x.AddVector(&second->x);
217
218 cout << Verbose(0) << "resulting coordinates: ";
219 first->x.Output((ofstream *)&cout);
220 cout << Verbose(0) << endl;
221 } while (!(valid = mol->CheckBounds((const vector *)&first->x)));
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;
228 atoms = new (vector*[128]);
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) {
243 first->x.LSQdistance(atoms, i);
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{
[3ce105]261 vector x, y;
[a0bcf1]262 char choice; // menu choice char
263
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;
273
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;
317 vector x,n;
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;
329
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
337 n.MakeNormalVector((const vector *)&first->x,(const vector *)&second->x,(const vector *)&third->x);
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
348 n.CopyVector((const vector *)&first->x);
349 n.SubtractVector((const vector *)&second->x);
350 n.Normalize();
351 break;
352 case 'd':
353 char shorthand[4];
354 vector a;
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;
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);
[a0bcf1]365 }
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();
371 break;
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;
385 vector n;
386 char choice; // menu choice char
387
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;
396
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
404 n.MakeNormalVector((const vector *)&first->x,(const vector *)&second->x,(const vector *)&third->x);
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
415 n.CopyVector((const vector *)&first->x);
416 n.SubtractVector((const vector *)&second->x);
417 n.Normalize();
418 break;
419 };
420 cout << Verbose(0) << "Normal vector: ";
421 n.Output((ofstream *)&cout);
422 cout << Verbose(0) << endl;
423 mol->Mirror((const vector *)&n);
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
435
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;
444
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;
460 if (first->x.Distance((const vector *)&second->x) > tmp1*tmp1) // distance to first above radius ...
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 }
477 break;
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;
490 vector x,y;
491 double min[256], tmp1, tmp2, tmp3;
492 int Z;
493 char choice; // menu choice char
494
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;
[a0bcf1]501 cout << Verbose(0) << "all else - go back" << endl;
502 cout << Verbose(0) << "===============================================" << endl;
503 cout << Verbose(0) << "INPUT: ";
504 cin >> choice;
505
506 switch(choice) {
507 default:
508 cout << Verbose(1) << "Not a valid choice." << endl;
509 break;
510 case 'a':
511 first = mol->AskAtom("Enter first atom: ");
[f75030]512 for (int i=MAX_ELEMENTS;i--;)
[a0bcf1]513 min[i] = 0.;
514
515 second = mol->start;
516 while ((second->next != mol->end)) {
517 second = second->next; // advance
518 Z = second->type->Z;
519 tmp1 = 0.;
520 if (first != second) {
521 x.CopyVector((const vector *)&first->x);
522 x.SubtractVector((const vector *)&second->x);
523 tmp1 = x.Norm();
524 }
525 if ((tmp1 != 0.) && ((min[Z] == 0.) || (tmp1 < min[Z]))) min[Z] = tmp1;
526 //cout << Verbose(0) << "Bond length between Atom " << first->nr << " and " << second->nr << ": " << tmp1 << " a.u." << endl;
527 }
[f75030]528 for (int i=MAX_ELEMENTS;i--;)
[a0bcf1]529 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;
530 break;
531
532 case 'b':
533 first = mol->AskAtom("Enter first atom: ");
534 second = mol->AskAtom("Enter second atom: ");
[f75030]535 for (int i=NDIM;i--;)
[a0bcf1]536 min[i] = 0.;
537 x.CopyVector((const vector *)&first->x);
538 x.SubtractVector((const vector *)&second->x);
539 tmp1 = x.Norm();
540 cout << Verbose(1) << "Distance vector is ";
541 x.Output((ofstream *)&cout);
542 cout << "." << endl << "Norm of distance is " << tmp1 << "." << endl;
543 break;
544
545 case 'c':
546 cout << Verbose(0) << "Evaluating bond angle between three - first, central, last - atoms." << endl;
547 first = mol->AskAtom("Enter first atom: ");
548 second = mol->AskAtom("Enter central atom: ");
549 third = mol->AskAtom("Enter last atom: ");
550 tmp1 = tmp2 = tmp3 = 0.;
551 x.CopyVector((const vector *)&first->x);
552 x.SubtractVector((const vector *)&second->x);
553 y.CopyVector((const vector *)&third->x);
554 y.SubtractVector((const vector *)&second->x);
555 cout << Verbose(0) << "Bond angle between first atom Nr." << first->nr << ", central atom Nr." << second->nr << " and last atom Nr." << third->nr << ": ";
556 cout << Verbose(0) << (acos(x.ScalarProduct((const vector *)&y)/(y.Norm()*x.Norm()))/M_PI*180.) << " degrees" << endl;
557 break;
[32b6dc]558 case 'd':
559 cout << Verbose(0) << "Evaluating prinicipal axis." << endl;
560 cout << Verbose(0) << "Shall we rotate? [0/1]: ";
561 cin >> Z;
562 if ((Z >=0) && (Z <=1))
563 mol->PrincipalAxisSystem((ofstream *)&cout, (bool)Z);
564 else
565 mol->PrincipalAxisSystem((ofstream *)&cout, false);
566 break;
567 case 'e':
568 cout << Verbose(0) << "Evaluating volume of the convex envelope.";
[7fcea6]569 VolumeOfConvexEnvelope((ofstream *)&cout, configuration, NULL, mol);
[32b6dc]570 break;
[a0bcf1]571 }
572};
573
574/** Submenu for measuring out the atoms in the molecule.
575 * \param *mol the molecule with all the atoms
576 * \param *configuration configuration structure for the to be written config files of all fragments
577 */
[f75030]578static void FragmentAtoms(molecule *mol, config *configuration)
[a0bcf1]579{
[c75363]580 int Order1;
[a0bcf1]581 clock_t start, end;
582
583 cout << Verbose(0) << "Fragmenting molecule with current connection matrix ..." << endl;
584 cout << Verbose(0) << "What's the desired bond order: ";
585 cin >> Order1;
586 if (mol->first->next != mol->last) { // there are bonds
587 start = clock();
[c75363]588 mol->FragmentMolecule((ofstream *)&cout, Order1, configuration);
[a0bcf1]589 end = clock();
590 cout << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl;
591 } else
592 cout << Verbose(0) << "Connection matrix has not yet been generated!" << endl;
593};
594
595/********************************************** Test routine **************************************/
596
597/** Is called always as option 'T' in the menu.
598 */
[f75030]599static void testroutine(molecule *mol)
[a0bcf1]600{
601 // the current test routine checks the functionality of the KeySet&Graph concept:
602 // We want to have a multiindex (the KeySet) describing a unique subgraph
603 atom *Walker = mol->start;
604 int i, comp, counter=0;
605
606 // generate some KeySets
607 cout << "Generating KeySets." << endl;
608 KeySet TestSets[mol->AtomCount+1];
609 i=1;
610 while (Walker->next != mol->end) {
611 Walker = Walker->next;
612 for (int j=0;j<i;j++) {
613 TestSets[j].insert(Walker->nr);
614 }
615 i++;
616 }
617 cout << "Testing insertion of already present item in KeySets." << endl;
618 KeySetTestPair test;
619 test = TestSets[mol->AtomCount-1].insert(Walker->nr);
620 if (test.second) {
621 cout << Verbose(1) << "Insertion worked?!" << endl;
622 } else {
623 cout << Verbose(1) << "Insertion rejected: Present object is " << (*test.first) << "." << endl;
624 }
625 TestSets[mol->AtomCount].insert(mol->end->previous->nr);
626 TestSets[mol->AtomCount].insert(mol->end->previous->previous->previous->nr);
627
628 // constructing Graph structure
629 cout << "Generating Subgraph class." << endl;
630 Graph Subgraphs;
631
632 // insert KeySets into Subgraphs
633 cout << "Inserting KeySets into Subgraph class." << endl;
634 for (int j=0;j<mol->AtomCount;j++) {
635 Subgraphs.insert(GraphPair (TestSets[j],pair<int, double>(counter++, 1.)));
636 }
637 cout << "Testing insertion of already present item in Subgraph." << endl;
638 GraphTestPair test2;
639 test2 = Subgraphs.insert(GraphPair (TestSets[mol->AtomCount],pair<int, double>(counter++, 1.)));
640 if (test2.second) {
641 cout << Verbose(1) << "Insertion worked?!" << endl;
642 } else {
643 cout << Verbose(1) << "Insertion rejected: Present object is " << (*(test2.first)).second.first << "." << endl;
644 }
645
646 // show graphs
647 cout << "Showing Subgraph's contents, checking that it's sorted." << endl;
648 Graph::iterator A = Subgraphs.begin();
649 while (A != Subgraphs.end()) {
650 cout << (*A).second.first << ": ";
651 KeySet::iterator key = (*A).first.begin();
652 comp = -1;
653 while (key != (*A).first.end()) {
654 if ((*key) > comp)
655 cout << (*key) << " ";
656 else
657 cout << (*key) << "! ";
658 comp = (*key);
659 key++;
660 }
661 cout << endl;
662 A++;
663 }
664};
665
[8129de]666/** Tries given filename or standard on saving the config file.
667 * \param *ConfigFileName name of file
668 * \param *configuration pointer to configuration structure with all the values
669 * \param *periode pointer to periodentafel structure with all the elements
670 * \param *mol pointer to molecule structure with all the atoms and coordinates
671 */
[f75030]672static void SaveConfig(char *ConfigFileName, config *configuration, periodentafel *periode, molecule *mol)
[8129de]673{
[c510a7]674 char filename[MAXSTRINGSIZE];
[8129de]675 ofstream output;
676
[a829d1]677 cout << Verbose(0) << "Storing configuration ... " << endl;
[8129de]678 // get correct valence orbitals
679 mol->CalculateOrbitals(*configuration);
680 configuration->InitMaxMinStopStep = configuration->MaxMinStopStep = configuration->MaxPsiDouble;
[584691]681 if (ConfigFileName != NULL) {
[8129de]682 output.open(ConfigFileName, ios::trunc);
[9bd230]683 } else if (strlen(configuration->configname) != 0) {
[584691]684 output.open(configuration->configname, ios::trunc);
[9bd230]685 } else {
686 output.open(DEFAULTCONFIG, ios::trunc);
687 }
[8129de]688 if (configuration->Save(&output, periode, mol))
689 cout << Verbose(0) << "Saving of config file successful." << endl;
690 else
691 cout << Verbose(0) << "Saving of config file failed." << endl;
692 output.close();
693 output.clear();
694 // and save to xyz file
695 if (ConfigFileName != NULL) {
696 strcpy(filename, ConfigFileName);
697 strcat(filename, ".xyz");
698 output.open(filename, ios::trunc);
699 }
700 if (output == NULL) {
701 strcpy(filename,"main_pcp_linux");
702 strcat(filename, ".xyz");
703 output.open(filename, ios::trunc);
704 }
705 if (mol->OutputXYZ(&output))
706 cout << Verbose(0) << "Saving of XYZ file successful." << endl;
707 else
708 cout << Verbose(0) << "Saving of XYZ file failed." << endl;
709 output.close();
710 output.clear();
[584691]711
[36b128]712 if (!strcmp(configuration->configpath, configuration->GetDefaultPath())) {
713 cerr << "WARNING: config is found under different path then stated in config file::defaultpath!" << endl;
714 }
[8129de]715};
716
[3ce105]717/** Parses the command line options.
718 * \param argc argument count
719 * \param **argv arguments array
720 * \param *mol molecule structure
721 * \param *periode elements structure
722 * \param configuration config file structure
723 * \param *ConfigFileName pointer to config file name in **argv
[8b486e]724 * \param *PathToDatabases pointer to db's path in **argv
[3ce105]725 * \return exit code (0 - successful, all else - something's wrong)
726 */
[8b486e]727static int ParseCommandLineOptions(int argc, char **argv, molecule *&mol, periodentafel *&periode, config& configuration, char *&ConfigFileName, char *&PathToDatabases)
[a0bcf1]728{
729 element *finder;
730 vector x,y,z,n; // coordinates for absolute point in cell volume
[3ce105]731 double *factor; // unit factor if desired
[a0bcf1]732 ifstream test;
733 ofstream output;
734 string line;
[3ce105]735 atom *first;
[0e348e]736 int ExitFlag = 0;
[3ce105]737 int j;
[8129de]738 enum ConfigStatus config_present = absent;
[a0bcf1]739 clock_t start,end;
[a829d1]740 int argptr;
[8b486e]741 PathToDatabases = LocalPath;
[3ce105]742
[584691]743 if (argc > 1) { // config file specified as option
[a829d1]744 // 1. : Parse options that just set variables or print help
[3ce105]745 argptr = 1;
746 do {
747 if (argv[argptr][0] == '-') {
[a829d1]748 cout << Verbose(0) << "Recognized command line argument: " << argv[argptr][1] << ".\n";
749 argptr++;
750 switch(argv[argptr-1][1]) {
751 case 'h':
752 case 'H':
753 case '?':
754 cout << "MoleCuilder suite" << endl << "==================" << endl << endl;
[c75363]755 cout << "Usage: " << argv[0] << "[config file] [-{acefpsthH?vfrp}] [further arguments]" << endl;
[a829d1]756 cout << "or simply " << argv[0] << " without arguments for interactive session." << endl;
757 cout << "\t-a Z x1 x2 x3\tAdd new atom of element Z at coordinates (x1,x2,x3)." << endl;
[3ce105]758 cout << "\t-b x1 x2 x3\tCenter atoms in domain with given edge lengths of (x1,x2,x3)." << endl;
[a829d1]759 cout << "\t-c x1 x2 x3\tCenter atoms in domain with a minimum distance to boundary of (x1,x2,x3)." << endl;
[8b486e]760 cout << "\t-e <file>\tSets the databases path to be parsed (default: ./)." << endl;
[0e348e]761 cout << "\t-f <dist> <order>\tFragments the molecule in BOSSANOVA manner and stores config files in same dir as config." << endl;
[a829d1]762 cout << "\t-h/-H/-?\tGive this help screen." << endl;
[32b6dc]763 cout << "\t-m\tAlign in PAS with greatest EV along z axis." << endl;
[ffcf49]764 cout << "\t-n\tFast parsing (i.e. no trajectories are looked for)." << endl;
[e292c10]765 cout << "\t-o\tGet volume of the convex envelope (and store to tecplot file)." << endl;
[a829d1]766 cout << "\t-p <file>\tParse given xyz file and create raw config file from it." << endl;
767 cout << "\t-r\t\tConvert file from an old pcp syntax." << endl;
768 cout << "\t-t x1 x2 x3\tTranslate all atoms by this vector (x1,x2,x3)." << endl;
769 cout << "\t-s x1 x2 x3\tScale all atom coordinates by this vector (x1,x2,x3)." << endl;
770 cout << "\t-v/-V\t\tGives version information." << endl;
[f5306f]771 cout << "Note: config files must not begin with '-' !" << endl;
[36b128]772 delete(mol);
773 delete(periode);
[3ce105]774 return (1);
[a829d1]775 break;
776 case 'v':
777 case 'V':
778 cout << argv[0] << " " << VERSIONSTRING << endl;
779 cout << "Build your own molecule position set." << endl;
[36b128]780 delete(mol);
781 delete(periode);
[3ce105]782 return (1);
[a829d1]783 break;
784 case 'e':
785 cout << "Using " << argv[argptr] << " as elements database." << endl;
[8b486e]786 PathToDatabases = argv[argptr];
[a829d1]787 argptr+=1;
788 break;
[ffcf49]789 case 'n':
790 cout << "I won't parse trajectories." << endl;
791 configuration.FastParsing = true;
[a829d1]792 default: // no match? Step on
793 argptr++;
794 break;
795 }
[3ce105]796 } else
797 argptr++;
[9bd230]798 } while (argptr < argc);
[3ce105]799
800 // 2. Parse the element database
[8b486e]801 if (periode->LoadPeriodentafel(PathToDatabases)) {
[a829d1]802 cout << Verbose(0) << "Element list loaded successfully." << endl;
[8b486e]803 periode->Output((ofstream *)&cout);
804 } else
[a829d1]805 cout << Verbose(0) << "Element list loading failed." << endl;
[9bd230]806
[3ce105]807 // 3. Find config file name and parse if possible
[9bd230]808 if (argv[1][0] != '-') {
[8129de]809 cout << Verbose(0) << "Config file given." << endl;
[9bd230]810 test.open(argv[1], ios::in);
[8129de]811 if (test == NULL) {
812 //return (1);
[9bd230]813 output.open(argv[1], ios::out);
[8129de]814 if (output == NULL) {
[9bd230]815 cout << Verbose(1) << "Specified config file " << argv[1] << " not found." << endl;
[8129de]816 config_present = absent;
817 } else {
818 cout << "Empty configuration file." << endl;
[9bd230]819 ConfigFileName = argv[1];
[8129de]820 config_present = empty;
821 output.close();
822 }
823 } else {
[f5306f]824 test.close();
[9bd230]825 ConfigFileName = argv[1];
[9e831e]826 cout << Verbose(1) << "Specified config file found, parsing ... ";
[f5306f]827 switch (configuration.TestSyntax(ConfigFileName, periode, mol)) {
[8129de]828 case 1:
829 cout << "new syntax." << endl;
[f5306f]830 configuration.Load(ConfigFileName, periode, mol);
[8129de]831 config_present = present;
832 break;
833 case 0:
834 cout << "old syntax." << endl;
[f5306f]835 configuration.LoadOld(ConfigFileName, periode, mol);
[8129de]836 config_present = present;
837 break;
838 default:
839 cout << "Unknown syntax or empty, yet present file." << endl;
840 config_present = empty;
841 }
[a0bcf1]842 }
[a829d1]843 } else
844 config_present = absent;
[9bd230]845
[a829d1]846 // 4. parse again through options, now for those depending on elements db and config presence
847 argptr = 1;
848 do {
[3ce105]849 cout << "Current Command line argument: " << argv[argptr] << "." << endl;
[a829d1]850 if (argv[argptr][0] == '-') {
[8129de]851 argptr++;
852 if ((config_present == present) || (config_present == empty)) {
853 switch(argv[argptr-1][1]) {
854 case 'p':
[0e348e]855 ExitFlag = 1;
[8129de]856 cout << Verbose(1) << "Parsing xyz file for new atoms." << endl;
[3ce105]857 if (!mol->AddXYZFile(argv[argptr]))
[8129de]858 cout << Verbose(2) << "File not found." << endl;
859 else
860 cout << Verbose(2) << "File found and parsed." << endl;
[a829d1]861 config_present = present;
[a0bcf1]862 break;
[a829d1]863 default: // no match? Don't step on (this is done in next switch's default)
[a0bcf1]864 break;
[8129de]865 }
866 }
[3ce105]867 if (config_present == present) {
868 switch(argv[argptr-1][1]) {
869 case 't':
870 ExitFlag = 1;
871 cout << Verbose(1) << "Translating all ions to new origin." << endl;
[f75030]872 for (int i=NDIM;i--;)
[3ce105]873 x.x[i] = atof(argv[argptr+i]);
874 mol->Translate((const vector *)&x);
875 argptr+=3;
876 break;
877 case 'a':
878 ExitFlag = 1;
879 cout << Verbose(1) << "Adding new atom." << endl;
880 first = new atom;
[f75030]881 for (int i=NDIM;i--;)
[3ce105]882 first->x.x[i] = atof(argv[argptr+1+i]);
883 finder = periode->start;
884 while (finder != periode->end) {
885 finder = finder->next;
886 if (strncmp(finder->symbol,argv[argptr+1],3) == 0) {
887 first->type = finder;
888 break;
[a0bcf1]889 }
[3ce105]890 }
891 mol->AddAtom(first); // add to molecule
892 argptr+=4;
893 break;
894 case 's':
895 ExitFlag = 1;
896 j = -1;
897 cout << Verbose(1) << "Scaling all ion positions by factor." << endl;
[f75030]898 factor = new double[NDIM];
[3ce105]899 factor[0] = atof(argv[argptr]);
900 if (argc > argptr+1)
901 argptr++;
902 factor[1] = atof(argv[argptr]);
903 if (argc > argptr+1)
904 argptr++;
905 factor[2] = atof(argv[argptr]);
906 mol->Scale(&factor);
[f75030]907 for (int i=0;i<NDIM;i++) {
[3ce105]908 j += i+1;
[f75030]909 x.x[i] = atof(argv[NDIM+i]);
[3ce105]910 mol->cell_size[j]*=factor[i];
911 }
[f75030]912 delete[](factor);
[3ce105]913 argptr+=1;
914 break;
915 case 'b':
916 ExitFlag = 1;
917 j = -1;
918 cout << Verbose(1) << "Centering atoms in config file within given simulation box." << endl;
919 j=-1;
[f75030]920 for (int i=0;i<NDIM;i++) {
[3ce105]921 j += i+1;
922 x.x[i] = atof(argv[argptr++]);
923 mol->cell_size[j] += x.x[i]*2.;
924 }
925 // center
926 mol->CenterInBox((ofstream *)&cout, &x);
927 // update Box of atoms by boundary
928 mol->SetBoxDimension(&x);
929 break;
930 case 'c':
931 ExitFlag = 1;
932 j = -1;
933 cout << Verbose(1) << "Centering atoms in config file within given additional boundary." << endl;
934 // make every coordinate positive
935 mol->CenterEdge((ofstream *)&cout, &x);
936 // update Box of atoms by boundary
937 mol->SetBoxDimension(&x);
938 // translate each coordinate by boundary
939 j=-1;
[f75030]940 for (int i=0;i<NDIM;i++) {
[3ce105]941 j += i+1;
942 x.x[i] = atof(argv[argptr++]);
943 mol->cell_size[j] += x.x[i]*2.;
944 }
945 mol->Translate((const vector *)&x);
946 break;
947 case 'r':
948 ExitFlag = 1;
949 cout << Verbose(1) << "Converting config file from supposed old to new syntax." << endl;
950 break;
951 case 'f':
952 if (ExitFlag ==0) ExitFlag = 2; // only set if not already by other command line switch
953 cout << "Fragmenting molecule with bond distance " << argv[argptr] << " angstroem, order of " << argv[argptr+1] << "." << endl;
954 if (argc >= argptr+2) {
955 cout << Verbose(0) << "Creating connection matrix..." << endl;
956 start = clock();
[5eb05a]957 mol->CreateAdjacencyList((ofstream *)&cout, atof(argv[argptr++]), configuration.GetIsAngstroem());
[3ce105]958 cout << Verbose(0) << "Fragmenting molecule with current connection matrix ..." << endl;
959 if (mol->first->next != mol->last) {
960 mol->FragmentMolecule((ofstream *)&cout, atoi(argv[argptr]), &configuration);
[8129de]961 }
[3ce105]962 end = clock();
963 cout << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl;
[8129de]964 argptr+=1;
[3ce105]965 } else {
966 cerr << "Not enough arguments for fragmentation: -f <max. bond distance> <bond order>" << endl;
967 }
968 break;
[32b6dc]969 case 'm':
970 ExitFlag = 1;
[e292c10]971 j = atoi(argv[argptr++]);
972 if ((j<0) || (j>1)) {
973 cerr << Verbose(1) << "ERROR: Argument of '-m' should be either 0 for no-rotate or 1 for rotate." << endl;
974 j = 0;
975 }
976 if (j)
977 cout << Verbose(0) << "Converting to prinicipal axis system." << endl;
978 else
979 cout << Verbose(0) << "Evaluating prinicipal axis." << endl;
980 mol->PrincipalAxisSystem((ofstream *)&cout, (bool)j);
981 break;
982 case 'o':
983 ExitFlag = 1;
984 cout << Verbose(0) << "Evaluating volume of the convex envelope.";
985// tmp = atof(argv[argptr++]);
986// if (tmp < 1.0) {
987// cerr << Verbose(0) << "Density must be greater than 1.0g/cm^3 !" << endl;
988// tmp = 1.3;
989// }
[7fcea6]990 VolumeOfConvexEnvelope((ofstream *)&cout, &configuration, NULL, mol);
[32b6dc]991 break;
[3ce105]992 default: // no match? Step on
[e292c10]993 if (argv[argptr][0] != '-') // if it started with a '-' we've already made a step!
994 argptr++;
[3ce105]995 break;
[a0bcf1]996 }
997 }
[3ce105]998 } else argptr++;
999 } while (argptr < argc);
[0e348e]1000 if (ExitFlag == 1) // 1 means save and exit
[8129de]1001 SaveConfig(ConfigFileName, &configuration, periode, mol);
[0e348e]1002 if (ExitFlag >= 1) { // 2 means just exit
[f5306f]1003 delete(mol);
1004 delete(periode);
[8b486e]1005 return (1);
[f5306f]1006 }
[584691]1007 } else { // no arguments, hence scan the elements db
[8b486e]1008 if (periode->LoadPeriodentafel(PathToDatabases))
[584691]1009 cout << Verbose(0) << "Element list loaded successfully." << endl;
1010 else
1011 cout << Verbose(0) << "Element list loading failed." << endl;
1012 configuration.RetrieveConfigPathAndName("main_pcp_linux");
[a0bcf1]1013 }
[3ce105]1014 return(0);
1015};
1016
1017/********************************************** Main routine **************************************/
[a0bcf1]1018
[3ce105]1019int main(int argc, char **argv)
1020{
1021 periodentafel *periode = new periodentafel; // and a period table of all elements
1022 molecule *mol = new molecule(periode); // first we need an empty molecule
1023 config configuration;
1024 double tmp1;
1025 double bond, min_bond;
1026 atom *first, *second;
1027 char choice; // menu choice char
1028 vector x,y,z,n; // coordinates for absolute point in cell volume
1029 double *factor; // unit factor if desired
1030 bool valid; // flag if input was valid or not
1031 ifstream test;
1032 ofstream output;
1033 string line;
1034 char filename[MAXSTRINGSIZE];
1035 char *ConfigFileName = NULL;
1036 char *ElementsFileName = NULL;
1037 int Z;
1038 int j, axis, count, faktor;
1039 int *MinimumRingSize = NULL;
1040 MoleculeLeafClass *Subgraphs = NULL;
1041 clock_t start,end;
1042 element **Elements;
1043 vector **Vectors;
1044
1045 // =========================== PARSE COMMAND LINE OPTIONS ====================================
1046 j = ParseCommandLineOptions(argc, argv, mol, periode, configuration, ConfigFileName, ElementsFileName);
[8b486e]1047 if (j == 1) return 0; // just for -v and -h options
[3ce105]1048 if (j) return j; // something went wrong
[a0bcf1]1049
1050 // General stuff
1051 if (mol->cell_size[0] == 0.) {
1052 cout << Verbose(0) << "enter lower triadiagonal form of basis matrix" << endl << endl;
1053 for (int i=0;i<6;i++) {
1054 cout << Verbose(1) << "Cell size" << i << ": ";
1055 cin >> mol->cell_size[i];
1056 }
1057 }
1058
[a829d1]1059 // =========================== START INTERACTIVE SESSION ====================================
1060
[a0bcf1]1061 // now the main construction loop
1062 cout << Verbose(0) << endl << "Now comes the real construction..." << endl;
1063 do {
1064 cout << Verbose(0) << endl << endl;
1065 cout << Verbose(0) << "============Element list=======================" << endl;
1066 mol->Checkout((ofstream *)&cout);
1067 cout << Verbose(0) << "============Atom list==========================" << endl;
1068 mol->Output((ofstream *)&cout);
1069 cout << Verbose(0) << "============Menu===============================" << endl;
1070 cout << Verbose(0) << "a - add an atom" << endl;
1071 cout << Verbose(0) << "r - remove an atom" << endl;
1072 cout << Verbose(0) << "b - scale a bond between atoms" << endl;
1073 cout << Verbose(0) << "u - change an atoms element" << endl;
1074 cout << Verbose(0) << "l - measure lengths, angles, ... for an atom" << endl;
1075 cout << Verbose(0) << "-----------------------------------------------" << endl;
1076 cout << Verbose(0) << "p - Parse xyz file" << endl;
1077 cout << Verbose(0) << "e - edit the current configuration" << endl;
1078 cout << Verbose(0) << "o - create connection matrix" << endl;
1079 cout << Verbose(0) << "f - fragment molecule many-body bond order style" << endl;
1080 cout << Verbose(0) << "-----------------------------------------------" << endl;
1081 cout << Verbose(0) << "d - duplicate molecule/periodic cell" << endl;
1082 cout << Verbose(0) << "i - realign molecule" << endl;
1083 cout << Verbose(0) << "m - mirror all molecules" << endl;
1084 cout << Verbose(0) << "t - translate molecule by vector" << endl;
1085 cout << Verbose(0) << "c - scale by unit transformation" << endl;
1086 cout << Verbose(0) << "g - center atoms in box" << endl;
1087 cout << Verbose(0) << "-----------------------------------------------" << endl;
1088 cout << Verbose(0) << "s - save current setup to config file" << endl;
1089 cout << Verbose(0) << "T - call the current test routine" << endl;
1090 cout << Verbose(0) << "q - quit" << endl;
1091 cout << Verbose(0) << "===============================================" << endl;
1092 cout << Verbose(0) << "Input: ";
1093 cin >> choice;
1094
1095 switch (choice) {
1096 default:
1097 case 'a': // add atom
1098 AddAtoms(periode, mol);
1099 choice = 'a';
1100 break;
1101
[3ce105]1102 case 'b': // scale a bond
1103 cout << Verbose(0) << "Scaling bond length between two atoms." << endl;
1104 first = mol->AskAtom("Enter first (fixed) atom: ");
1105 second = mol->AskAtom("Enter second (shifting) atom: ");
1106 min_bond = 0.;
[f75030]1107 for (int i=NDIM;i--;)
[3ce105]1108 min_bond += (first->x.x[i]-second->x.x[i])*(first->x.x[i] - second->x.x[i]);
1109 min_bond = sqrt(min_bond);
1110 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;
1111 cout << Verbose(0) << "Enter new bond length [a.u.]: ";
1112 cin >> bond;
[f75030]1113 for (int i=NDIM;i--;) {
[3ce105]1114 second->x.x[i] -= (second->x.x[i]-first->x.x[i])/min_bond*(min_bond-bond);
1115 }
1116 //cout << Verbose(0) << "New coordinates of Atom " << second->nr << " are: ";
1117 //second->Output(second->type->No, 1, (ofstream *)&cout);
1118 break;
1119
1120 case 'c': // unit scaling of the metric
1121 cout << Verbose(0) << "Angstroem -> Bohrradius: 1.8897261\t\tBohrradius -> Angstroem: 0.52917721" << endl;
1122 cout << Verbose(0) << "Enter three factors: ";
1123 factor = new double[NDIM];
1124 cin >> factor[0];
1125 cin >> factor[1];
1126 cin >> factor[2];
1127 valid = true;
1128 mol->Scale(&factor);
1129 delete[](factor);
1130 break;
1131
[a0bcf1]1132 case 'd': // duplicate the periodic cell along a given axis, given times
1133 cout << Verbose(0) << "State the axis [(+-)123]: ";
1134 cin >> axis;
1135 cout << Verbose(0) << "State the factor: ";
1136 cin >> faktor;
1137
1138 mol->CountAtoms((ofstream *)&cout); // recount atoms
1139 if (mol->AtomCount != 0) { // if there is more than none
1140 count = mol->AtomCount; // is changed becausing of adding, thus has to be stored away beforehand
[3ce105]1141 Elements = new element *[count];
1142 Vectors = new vector *[count];
[a0bcf1]1143 j = 0;
1144 first = mol->start;
1145 while (first->next != mol->end) { // make a list of all atoms with coordinates and element
1146 first = first->next;
1147 Elements[j] = first->type;
1148 Vectors[j] = &first->x;
1149 j++;
1150 }
1151 if (count != j)
1152 cout << Verbose(0) << "ERROR: AtomCount " << count << " is not equal to number of atoms in molecule " << j << "!" << endl;
1153 x.Zero();
1154 y.Zero();
1155 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
1156 for (int i=1;i<faktor;i++) { // then add this list with respective translation factor times
1157 x.AddVector(&y); // per factor one cell width further
[f75030]1158 for (int k=count;k--;) { // go through every atom of the original cell
[a0bcf1]1159 first = new atom(); // create a new body
1160 first->x.CopyVector(Vectors[k]); // use coordinate of original atom
1161 first->x.AddVector(&x); // translate the coordinates
1162 first->type = Elements[k]; // insert original element
1163 mol->AddAtom(first); // and add to the molecule (which increments ElementsInMolecule, AtomCount, ...)
1164 }
1165 }
1166 if (mol->first->next != mol->last) // if connect matrix is present already, redo it
[5eb05a]1167 mol->CreateAdjacencyList((ofstream *)&cout, mol->BondDistance, configuration.GetIsAngstroem());
[a0bcf1]1168 // free memory
[3ce105]1169 delete[](Elements);
1170 delete[](Vectors);
[a0bcf1]1171 // correct cell size
1172 if (axis < 0) { // if sign was negative, we have to translate everything
1173 x.Zero();
1174 x.AddVector(&y);
1175 x.Scale(-(faktor-1));
1176 mol->Translate(&x);
1177 }
1178 mol->cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] *= faktor;
1179 }
1180 break;
1181
[3ce105]1182 case 'e': // edit each field of the configuration
1183 configuration.Edit(mol);
1184 break;
1185
1186 case 'f':
1187 FragmentAtoms(mol, &configuration);
1188 break;
1189
[a0bcf1]1190 case 'g': // center the atoms
1191 CenterAtoms(mol);
1192 break;
1193
1194 case 'i': // align all atoms
1195 AlignAtoms(periode, mol);
1196 break;
1197
1198 case 'l': // measure distances or angles
[32b6dc]1199 MeasureAtoms(periode, mol, &configuration);
[a0bcf1]1200 break;
1201
[3ce105]1202 case 'm': // mirror atoms along a given axis
1203 MirrorAtoms(mol);
[a0bcf1]1204 break;
[3ce105]1205
[a0bcf1]1206 case 'o': // create the connection matrix
1207 cout << Verbose(0) << "What's the maximum bond distance: ";
1208 cin >> tmp1;
1209 start = clock();
[5eb05a]1210 mol->CreateAdjacencyList((ofstream *)&cout, tmp1, configuration.GetIsAngstroem());
[a0bcf1]1211 //mol->CreateListOfBondsPerAtom((ofstream *)&cout);
[32b6dc]1212 Subgraphs = mol->DepthFirstSearchAnalysis((ofstream *)&cout, MinimumRingSize);
[a0bcf1]1213 while (Subgraphs->next != NULL) {
1214 Subgraphs = Subgraphs->next;
1215 delete(Subgraphs->previous);
1216 }
1217 delete(Subgraphs); // we don't need the list here, so free everything
[0716ff4]1218 delete[](MinimumRingSize);
[a0bcf1]1219 Subgraphs = NULL;
1220 end = clock();
1221 cout << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl;
1222 break;
1223
[3ce105]1224 case 'p': // parse and XYZ file
1225 cout << Verbose(0) << "Format should be XYZ with: ShorthandOfElement\tX\tY\tZ" << endl;
1226 do {
1227 cout << Verbose(0) << "Enter file name: ";
1228 cin >> filename;
1229 } while (!mol->AddXYZFile(filename));
1230 break;
1231
1232 case 'q': // quit
1233 break;
[a0bcf1]1234
[3ce105]1235 case 'r': // remove atom
1236 RemoveAtoms(mol);
1237 break;
1238
1239 case 's': // save to config file
1240 SaveConfig(ConfigFileName, &configuration, periode, mol);
1241 break;
1242
1243 case 't': // translate all atoms
1244 cout << Verbose(0) << "Enter translation vector." << endl;
1245 x.AskPosition(mol->cell_size,0);
1246 mol->Translate((const vector *)&x);
1247 break;
1248
1249 case 'T':
1250 testroutine(mol);
1251 break;
1252
[a0bcf1]1253 case 'u': // change an atom's element
1254 first = NULL;
1255 do {
1256 cout << Verbose(0) << "Change the element of which atom: ";
1257 cin >> Z;
1258 } while ((first = mol->FindAtom(Z)) == NULL);
1259 cout << Verbose(0) << "New element by atomic number Z: ";
1260 cin >> Z;
1261 first->type = periode->FindElement(Z);
1262 cout << Verbose(0) << "Atom " << first->nr << "'s element is " << first->type->name << "." << endl;
1263 break;
1264 };
1265 } while (choice != 'q');
1266
1267 // save element data base
[e292c10]1268 if (periode->StorePeriodentafel(ElementsFileName)) //ElementsFileName
[a0bcf1]1269 cout << Verbose(0) << "Saving of elements.db successful." << endl;
1270 else
1271 cout << Verbose(0) << "Saving of elements.db failed." << endl;
1272
1273 // Free all
1274 if (Subgraphs != NULL) { // free disconnected subgraph list of DFS analysis was performed
1275 while (Subgraphs->next != NULL) {
1276 Subgraphs = Subgraphs->next;
1277 delete(Subgraphs->previous);
1278 }
1279 delete(Subgraphs);
1280 }
1281 delete(mol);
1282 delete(periode);
1283 return (0);
1284}
1285
1286/********************************************** E N D **************************************************/
Note: See TracBrowser for help on using the repository browser.