source: src/builder.cpp@ c54da3

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since c54da3 was c54da3, checked in by Frederik Heber <heber@…>, 16 years ago

BUGFIX: RemoveAtom() would remove the iterator, molecule::RemoveAtom() did not decrease AtomCount

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