source: src/builder.cpp@ 63f06e

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 63f06e was 63f06e, checked in by Frederik Heber <heber@…>, 16 years ago

fixes due to changes in molecule structure (Center...()) and merge submenu is done.

  • Property mode set to 100755
File size: 77.0 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);
285 break;
286 case 'b':
287 cout << Verbose(0) << "Centering atoms in config file on center of gravity." << endl;
288 mol->CenterPeriodic((ofstream *)&cout);
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->Center.AddVector(&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;
439 int axis;
440 double tmp1, tmp2;
441 char choice; // menu choice char
442
443 cout << Verbose(0) << "===========REMOVE ATOMS=========================" << endl;
444 cout << Verbose(0) << " a - state atom for removal by number" << endl;
445 cout << Verbose(0) << " b - keep only in radius around atom" << endl;
446 cout << Verbose(0) << " c - remove this with one axis greater value" << endl;
447 cout << Verbose(0) << "all else - go back" << endl;
448 cout << Verbose(0) << "===============================================" << endl;
449 cout << Verbose(0) << "INPUT: ";
450 cin >> choice;
451
452 switch (choice) {
453 default:
454 case 'a':
455 if (mol->RemoveAtom(mol->AskAtom("Enter number of atom within molecule: ")))
456 cout << Verbose(1) << "Atom removed." << endl;
457 else
458 cout << Verbose(1) << "Atom not found." << endl;
459 break;
460 case 'b':
461 second = mol->AskAtom("Enter number of atom as reference point: ");
462 cout << Verbose(0) << "Enter radius: ";
463 cin >> tmp1;
464 first = mol->start;
465 while(first->next != mol->end) {
466 first = first->next;
467 if (first->x.DistanceSquared((const Vector *)&second->x) > tmp1*tmp1) // distance to first above radius ...
468 mol->RemoveAtom(first);
469 }
470 break;
471 case 'c':
472 cout << Verbose(0) << "Which axis is it: ";
473 cin >> axis;
474 cout << Verbose(0) << "Left inward boundary: ";
475 cin >> tmp1;
476 cout << Verbose(0) << "Right inward boundary: ";
477 cin >> tmp2;
478 first = mol->start;
479 while(first->next != mol->end) {
480 first = first->next;
481 if ((first->x.x[axis] > tmp2) || (first->x.x[axis] < tmp1)) // out of boundary ...
482 mol->RemoveAtom(first);
483 }
484 break;
485 };
486 //mol->Output((ofstream *)&cout);
487 choice = 'r';
488};
489
490/** Submenu for measuring out the atoms in the molecule.
491 * \param *periode periodentafel
492 * \param *mol molecule with all the atoms
493 */
494static void MeasureAtoms(periodentafel *periode, molecule *mol, config *configuration)
495{
496 atom *first, *second, *third;
497 Vector x,y;
498 double min[256], tmp1, tmp2, tmp3;
499 int Z;
500 char choice; // menu choice char
501
502 cout << Verbose(0) << "===========MEASURE ATOMS=========================" << endl;
503 cout << Verbose(0) << " a - calculate bond length between one atom and all others" << endl;
504 cout << Verbose(0) << " b - calculate bond length between two atoms" << endl;
505 cout << Verbose(0) << " c - calculate bond angle" << endl;
506 cout << Verbose(0) << " d - calculate principal axis of the system" << endl;
507 cout << Verbose(0) << " e - calculate volume of the convex envelope" << endl;
508 cout << Verbose(0) << " f - calculate temperature from current velocity" << endl;
509 cout << Verbose(0) << " g - output all temperatures per step from velocities" << endl;
510 cout << Verbose(0) << "all else - go back" << endl;
511 cout << Verbose(0) << "===============================================" << endl;
512 cout << Verbose(0) << "INPUT: ";
513 cin >> choice;
514
515 switch(choice) {
516 default:
517 cout << Verbose(1) << "Not a valid choice." << endl;
518 break;
519 case 'a':
520 first = mol->AskAtom("Enter first atom: ");
521 for (int i=MAX_ELEMENTS;i--;)
522 min[i] = 0.;
523
524 second = mol->start;
525 while ((second->next != mol->end)) {
526 second = second->next; // advance
527 Z = second->type->Z;
528 tmp1 = 0.;
529 if (first != second) {
530 x.CopyVector((const Vector *)&first->x);
531 x.SubtractVector((const Vector *)&second->x);
532 tmp1 = x.Norm();
533 }
534 if ((tmp1 != 0.) && ((min[Z] == 0.) || (tmp1 < min[Z]))) min[Z] = tmp1;
535 //cout << Verbose(0) << "Bond length between Atom " << first->nr << " and " << second->nr << ": " << tmp1 << " a.u." << endl;
536 }
537 for (int i=MAX_ELEMENTS;i--;)
538 if (min[i] != 0.) cout << Verbose(0) << "Minimum Bond length between " << first->type->name << " Atom " << first->nr << " and next Ion of type " << (periode->FindElement(i))->name << ": " << min[i] << " a.u." << endl;
539 break;
540
541 case 'b':
542 first = mol->AskAtom("Enter first atom: ");
543 second = mol->AskAtom("Enter second atom: ");
544 for (int i=NDIM;i--;)
545 min[i] = 0.;
546 x.CopyVector((const Vector *)&first->x);
547 x.SubtractVector((const Vector *)&second->x);
548 tmp1 = x.Norm();
549 cout << Verbose(1) << "Distance vector is ";
550 x.Output((ofstream *)&cout);
551 cout << "." << endl << "Norm of distance is " << tmp1 << "." << endl;
552 break;
553
554 case 'c':
555 cout << Verbose(0) << "Evaluating bond angle between three - first, central, last - atoms." << endl;
556 first = mol->AskAtom("Enter first atom: ");
557 second = mol->AskAtom("Enter central atom: ");
558 third = mol->AskAtom("Enter last atom: ");
559 tmp1 = tmp2 = tmp3 = 0.;
560 x.CopyVector((const Vector *)&first->x);
561 x.SubtractVector((const Vector *)&second->x);
562 y.CopyVector((const Vector *)&third->x);
563 y.SubtractVector((const Vector *)&second->x);
564 cout << Verbose(0) << "Bond angle between first atom Nr." << first->nr << ", central atom Nr." << second->nr << " and last atom Nr." << third->nr << ": ";
565 cout << Verbose(0) << (acos(x.ScalarProduct((const Vector *)&y)/(y.Norm()*x.Norm()))/M_PI*180.) << " degrees" << endl;
566 break;
567 case 'd':
568 cout << Verbose(0) << "Evaluating prinicipal axis." << endl;
569 cout << Verbose(0) << "Shall we rotate? [0/1]: ";
570 cin >> Z;
571 if ((Z >=0) && (Z <=1))
572 mol->PrincipalAxisSystem((ofstream *)&cout, (bool)Z);
573 else
574 mol->PrincipalAxisSystem((ofstream *)&cout, false);
575 break;
576 case 'e':
577 cout << Verbose(0) << "Evaluating volume of the convex envelope.";
578 VolumeOfConvexEnvelope((ofstream *)&cout, NULL, configuration, NULL, mol);
579 break;
580 case 'f':
581 mol->OutputTemperatureFromTrajectories((ofstream *)&cout, mol->MDSteps-1, mol->MDSteps, (ofstream *)&cout);
582 break;
583 case 'g':
584 {
585 char filename[255];
586 cout << "Please enter filename: " << endl;
587 cin >> filename;
588 cout << Verbose(1) << "Storing temperatures in " << filename << "." << endl;
589 ofstream *output = new ofstream(filename, ios::trunc);
590 if (!mol->OutputTemperatureFromTrajectories((ofstream *)&cout, 0, mol->MDSteps, output))
591 cout << Verbose(2) << "File could not be written." << endl;
592 else
593 cout << Verbose(2) << "File stored." << endl;
594 output->close();
595 delete(output);
596 }
597 break;
598 }
599};
600
601/** Submenu for measuring out the atoms in the molecule.
602 * \param *mol molecule with all the atoms
603 * \param *configuration configuration structure for the to be written config files of all fragments
604 */
605static void FragmentAtoms(molecule *mol, config *configuration)
606{
607 int Order1;
608 clock_t start, end;
609
610 cout << Verbose(0) << "Fragmenting molecule with current connection matrix ..." << endl;
611 cout << Verbose(0) << "What's the desired bond order: ";
612 cin >> Order1;
613 if (mol->first->next != mol->last) { // there are bonds
614 start = clock();
615 mol->FragmentMolecule((ofstream *)&cout, Order1, configuration);
616 end = clock();
617 cout << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl;
618 } else
619 cout << Verbose(0) << "Connection matrix has not yet been generated!" << endl;
620};
621
622/********************************************** Submenu routine **************************************/
623
624/** Submenu for manipulating atoms.
625 * \param *periode periodentafel
626 * \param *molecules list of molecules whose atoms are to be manipulated
627 */
628static void ManipulateAtoms(periodentafel *periode, MoleculeListClass *molecules, config *configuration)
629{
630 atom *first, *second, *third, *fourth;
631 Vector **atoms;
632 molecule *mol = NULL;
633 Vector x,y,z,n; // coordinates for absolute point in cell volume
634 double *factor; // unit factor if desired
635 double a,b,c;
636 double bond, min_bond;
637 char choice; // menu choice char
638 bool valid;
639
640 cout << Verbose(0) << "=========MANIPULATE ATOMS======================" << endl;
641 cout << Verbose(0) << "a - add an atom" << endl;
642 cout << Verbose(0) << "r - remove an atom" << endl;
643 cout << Verbose(0) << "b - scale a bond between atoms" << endl;
644 cout << Verbose(0) << "u - change an atoms element" << endl;
645 cout << Verbose(0) << "l - measure lengths, angles, ... for an atom" << endl;
646 cout << Verbose(0) << "all else - go back" << endl;
647 cout << Verbose(0) << "===============================================" << endl;
648 if (molecules->NumberOfActiveMolecules() > 1)
649 cout << Verbose(0) << "WARNING: There is more than one molecule active! Atoms will be added to each." << endl;
650 cout << Verbose(0) << "INPUT: ";
651 cin >> choice;
652
653 switch (choice) {
654 default:
655 cout << Verbose(0) << "Not a valid choice." << endl;
656 break;
657
658 case 'a': // add atom
659 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
660 if ((*ListRunner)->ActiveFlag) {
661 mol = *ListRunner;
662 cout << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
663 AddAtoms(periode, mol);
664 }
665 break;
666
667 case 'b': // scale a bond
668 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
669 if ((*ListRunner)->ActiveFlag) {
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 if ((*ListRunner)->ActiveFlag) {
693 mol = *ListRunner;
694 cout << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
695 cout << Verbose(0) << "Angstroem -> Bohrradius: 1.8897261\t\tBohrradius -> Angstroem: 0.52917721" << endl;
696 cout << Verbose(0) << "Enter three factors: ";
697 factor = new double[NDIM];
698 cin >> factor[0];
699 cin >> factor[1];
700 cin >> factor[2];
701 valid = true;
702 mol->Scale(&factor);
703 delete[](factor);
704 }
705 break;
706
707 case 'l': // measure distances or angles
708 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
709 if ((*ListRunner)->ActiveFlag) {
710 mol = *ListRunner;
711 cout << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
712 MeasureAtoms(periode, mol, configuration);
713 }
714 break;
715
716 case 'r': // remove atom
717 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
718 if ((*ListRunner)->ActiveFlag) {
719 mol = *ListRunner;
720 cout << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
721 RemoveAtoms(mol);
722 }
723 break;
724
725 case 'u': // change an atom's element
726 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
727 if ((*ListRunner)->ActiveFlag) {
728 int Z;
729 mol = *ListRunner;
730 cout << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
731 first = NULL;
732 do {
733 cout << Verbose(0) << "Change the element of which atom: ";
734 cin >> Z;
735 } while ((first = mol->FindAtom(Z)) == NULL);
736 cout << Verbose(0) << "New element by atomic number Z: ";
737 cin >> Z;
738 first->type = periode->FindElement(Z);
739 cout << Verbose(0) << "Atom " << first->nr << "'s element is " << first->type->name << "." << endl;
740 }
741 break;
742 }
743};
744
745/** Submenu for manipulating molecules.
746 * \param *periode periodentafel
747 * \param *molecules list of molecule to manipulate
748 */
749static void ManipulateMolecules(periodentafel *periode, MoleculeListClass *molecules, config *configuration)
750{
751 atom *first, *second, *third, *fourth;
752 Vector **atoms;
753 Vector x,y,z,n; // coordinates for absolute point in cell volume
754 double a,b,c;
755 int j, axis, count, faktor;
756 char choice; // menu choice char
757 bool valid;
758 molecule *mol = NULL;
759 element **Elements;
760 Vector **vectors;
761 MoleculeLeafClass *Subgraphs = NULL;
762
763 cout << Verbose(0) << "=========MANIPULATE GLOBALLY===================" << endl;
764 cout << Verbose(0) << "c - scale by unit transformation" << endl;
765 cout << Verbose(0) << "d - duplicate molecule/periodic cell" << endl;
766 cout << Verbose(0) << "f - fragment molecule many-body bond order style" << endl;
767 cout << Verbose(0) << "g - center atoms in box" << endl;
768 cout << Verbose(0) << "i - realign molecule" << endl;
769 cout << Verbose(0) << "m - mirror all molecules" << endl;
770 cout << Verbose(0) << "o - create connection matrix" << endl;
771 cout << Verbose(0) << "t - translate molecule by vector" << endl;
772 cout << Verbose(0) << "all else - go back" << endl;
773 cout << Verbose(0) << "===============================================" << endl;
774 if (molecules->NumberOfActiveMolecules() > 1)
775 cout << Verbose(0) << "WARNING: There is more than one molecule active! Atoms will be added to each." << endl;
776 cout << Verbose(0) << "INPUT: ";
777 cin >> choice;
778
779 switch (choice) {
780 default:
781 cout << Verbose(0) << "Not a valid choice." << endl;
782 break;
783
784 case 'd': // duplicate the periodic cell along a given axis, given times
785 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
786 if ((*ListRunner)->ActiveFlag) {
787 mol = *ListRunner;
788 cout << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
789 cout << Verbose(0) << "State the axis [(+-)123]: ";
790 cin >> axis;
791 cout << Verbose(0) << "State the factor: ";
792 cin >> faktor;
793
794 mol->CountAtoms((ofstream *)&cout); // recount atoms
795 if (mol->AtomCount != 0) { // if there is more than none
796 count = mol->AtomCount; // is changed becausing of adding, thus has to be stored away beforehand
797 Elements = new element *[count];
798 vectors = new Vector *[count];
799 j = 0;
800 first = mol->start;
801 while (first->next != mol->end) { // make a list of all atoms with coordinates and element
802 first = first->next;
803 Elements[j] = first->type;
804 vectors[j] = &first->x;
805 j++;
806 }
807 if (count != j)
808 cout << Verbose(0) << "ERROR: AtomCount " << count << " is not equal to number of atoms in molecule " << j << "!" << endl;
809 x.Zero();
810 y.Zero();
811 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
812 for (int i=1;i<faktor;i++) { // then add this list with respective translation factor times
813 x.AddVector(&y); // per factor one cell width further
814 for (int k=count;k--;) { // go through every atom of the original cell
815 first = new atom(); // create a new body
816 first->x.CopyVector(vectors[k]); // use coordinate of original atom
817 first->x.AddVector(&x); // translate the coordinates
818 first->type = Elements[k]; // insert original element
819 mol->AddAtom(first); // and add to the molecule (which increments ElementsInMolecule, AtomCount, ...)
820 }
821 }
822 if (mol->first->next != mol->last) // if connect matrix is present already, redo it
823 mol->CreateAdjacencyList((ofstream *)&cout, mol->BondDistance, configuration->GetIsAngstroem());
824 // free memory
825 delete[](Elements);
826 delete[](vectors);
827 // correct cell size
828 if (axis < 0) { // if sign was negative, we have to translate everything
829 x.Zero();
830 x.AddVector(&y);
831 x.Scale(-(faktor-1));
832 mol->Translate(&x);
833 }
834 mol->cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] *= faktor;
835 }
836 }
837 break;
838
839 case 'f':
840 FragmentAtoms(mol, configuration);
841 break;
842
843 case 'g': // center the atoms
844 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
845 if ((*ListRunner)->ActiveFlag) {
846 mol = *ListRunner;
847 cout << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
848 CenterAtoms(mol);
849 }
850 break;
851
852 case 'i': // align all atoms
853 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
854 if ((*ListRunner)->ActiveFlag) {
855 mol = *ListRunner;
856 cout << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
857 AlignAtoms(periode, mol);
858 }
859 break;
860
861 case 'm': // mirror atoms along a given axis
862 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
863 if ((*ListRunner)->ActiveFlag) {
864 mol = *ListRunner;
865 cout << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
866 MirrorAtoms(mol);
867 }
868 break;
869
870 case 'o': // create the connection matrix
871 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
872 if ((*ListRunner)->ActiveFlag) {
873 double bonddistance;
874 clock_t start,end;
875 cout << Verbose(0) << "What's the maximum bond distance: ";
876 cin >> bonddistance;
877 start = clock();
878 mol->CreateAdjacencyList((ofstream *)&cout, bonddistance, configuration->GetIsAngstroem());
879 mol->CreateListOfBondsPerAtom((ofstream *)&cout);
880 end = clock();
881 cout << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl;
882 }
883 break;
884
885 case 't': // translate all atoms
886 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
887 if ((*ListRunner)->ActiveFlag) {
888 mol = *ListRunner;
889 cout << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
890 cout << Verbose(0) << "Enter translation vector." << endl;
891 x.AskPosition(mol->cell_size,0);
892 mol->Center.AddVector((const Vector *)&x);
893 }
894 break;
895 }
896 // Free all
897 if (Subgraphs != NULL) { // free disconnected subgraph list of DFS analysis was performed
898 while (Subgraphs->next != NULL) {
899 Subgraphs = Subgraphs->next;
900 delete(Subgraphs->previous);
901 }
902 delete(Subgraphs);
903 }
904};
905
906
907/** Submenu for creating new molecules.
908 * \param *periode periodentafel
909 * \param *molecules list of molecules to add to
910 */
911static void EditMolecules(periodentafel *periode, MoleculeListClass *molecules)
912{
913 char choice; // menu choice char
914 bool valid;
915 Vector center;
916 int nr, count;
917 molecule *mol = NULL;
918 char *molname = NULL;
919 int length;
920
921 cout << Verbose(0) << "==========EDIT MOLECULES=====================" << endl;
922 cout << Verbose(0) << "c - create new molecule" << endl;
923 cout << Verbose(0) << "l - load molecule from xyz file" << endl;
924 cout << Verbose(0) << "n - change molecule's name" << endl;
925 cout << Verbose(0) << "N - give molecules filename" << endl;
926 cout << Verbose(0) << "p - parse atoms in xyz file into molecule" << endl;
927 cout << Verbose(0) << "r - remove a molecule" << endl;
928 cout << Verbose(0) << "all else - go back" << endl;
929 cout << Verbose(0) << "===============================================" << endl;
930 cout << Verbose(0) << "INPUT: ";
931 cin >> choice;
932
933 switch (choice) {
934 default:
935 cout << Verbose(0) << "Not a valid choice." << endl;
936 break;
937 case 'c':
938 mol = new molecule(periode);
939 molecules->insert(mol);
940 break;
941
942 case 'l': // load from XYZ file
943 {
944 char filename[MAXSTRINGSIZE];
945 cout << Verbose(0) << "Format should be XYZ with: ShorthandOfElement\tX\tY\tZ" << endl;
946 mol = new molecule(periode);
947 do {
948 cout << Verbose(0) << "Enter file name: ";
949 cin >> filename;
950 } while (!mol->AddXYZFile(filename));
951 mol->SetNameFromFilename(filename);
952 // center at set box dimensions
953 mol->CenterEdge((ofstream *)&cout, &center);
954 mol->cell_size[0] = center.x[0];
955 mol->cell_size[1] = 0;
956 mol->cell_size[2] = center.x[1];
957 mol->cell_size[3] = 0;
958 mol->cell_size[4] = 0;
959 mol->cell_size[5] = center.x[2];
960 molecules->insert(mol);
961 }
962 break;
963
964 case 'n':
965 {
966 char filename[MAXSTRINGSIZE];
967 do {
968 cout << Verbose(0) << "Enter index of molecule: ";
969 cin >> nr;
970 mol = molecules->ReturnIndex(nr);
971 } while (mol == NULL);
972 cout << Verbose(0) << "Enter name: ";
973 cin >> filename;
974 strcpy(mol->name, filename);
975 }
976 break;
977
978 case 'N':
979 {
980 char filename[MAXSTRINGSIZE];
981 do {
982 cout << Verbose(0) << "Enter index of molecule: ";
983 cin >> nr;
984 mol = molecules->ReturnIndex(nr);
985 } while (mol == NULL);
986 cout << Verbose(0) << "Enter name: ";
987 cin >> filename;
988 mol->SetNameFromFilename(filename);
989 }
990 break;
991
992 case 'p': // parse XYZ file
993 {
994 char filename[MAXSTRINGSIZE];
995 mol = NULL;
996 do {
997 cout << Verbose(0) << "Enter index of molecule: ";
998 cin >> nr;
999 mol = molecules->ReturnIndex(nr);
1000 } while (mol == NULL);
1001 cout << Verbose(0) << "Format should be XYZ with: ShorthandOfElement\tX\tY\tZ" << endl;
1002 do {
1003 cout << Verbose(0) << "Enter file name: ";
1004 cin >> filename;
1005 } while (!mol->AddXYZFile(filename));
1006 mol->SetNameFromFilename(filename);
1007 }
1008 break;
1009
1010 case 'r':
1011 cout << Verbose(0) << "Enter index of molecule: ";
1012 cin >> nr;
1013 count = 1;
1014 for( MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
1015 if (nr == (*ListRunner)->IndexNr) {
1016 mol = *ListRunner;
1017 molecules->ListOfMolecules.erase(ListRunner);
1018 delete(mol);
1019 }
1020 break;
1021 }
1022};
1023
1024
1025/** Submenu for merging molecules.
1026 * \param *periode periodentafel
1027 * \param *molecules list of molecules to add to
1028 */
1029static void MergeMolecules(periodentafel *periode, MoleculeListClass *molecules)
1030{
1031 char choice; // menu choice char
1032 bool valid;
1033
1034 cout << Verbose(0) << "===========MERGE MOLECULES=====================" << endl;
1035 cout << Verbose(0) << "a - simple add of one molecule to another" << endl;
1036 cout << Verbose(0) << "e - embedding merge of two molecules" << endl;
1037 cout << Verbose(0) << "m - multi-merge of all molecules" << endl;
1038 cout << Verbose(0) << "s - scatter merge of two molecules" << endl;
1039 cout << Verbose(0) << "t - simple merge of two molecules" << endl;
1040 cout << Verbose(0) << "all else - go back" << endl;
1041 cout << Verbose(0) << "===============================================" << endl;
1042 cout << Verbose(0) << "INPUT: ";
1043 cin >> choice;
1044
1045 switch (choice) {
1046 default:
1047 cout << Verbose(0) << "Not a valid choice." << endl;
1048 break;
1049
1050 case 'a':
1051 {
1052 int src, dest;
1053 molecule *srcmol = NULL, *destmol = NULL;
1054 {
1055 do {
1056 cout << Verbose(0) << "Enter index of destination molecule: ";
1057 cin >> dest;
1058 destmol = molecules->ReturnIndex(dest);
1059 } while ((destmol == NULL) && (dest != -1));
1060 do {
1061 cout << Verbose(0) << "Enter index of source molecule to add from: ";
1062 cin >> src;
1063 srcmol = molecules->ReturnIndex(src);
1064 } while ((srcmol == NULL) && (src != -1));
1065 if ((src != -1) && (dest != -1))
1066 molecules->SimpleAdd(srcmol, destmol);
1067 }
1068 }
1069 break;
1070
1071 case 'e':
1072 cout << Verbose(0) << "Not implemented yet." << endl;
1073 break;
1074
1075 case 'm':
1076 {
1077 int nr;
1078 molecule *mol = NULL;
1079 do {
1080 cout << Verbose(0) << "Enter index of molecule to merge into: ";
1081 cin >> nr;
1082 mol = molecules->ReturnIndex(nr);
1083 } while ((mol == NULL) && (nr != -1));
1084 if (nr != -1) {
1085 int N = molecules->ListOfMolecules.size()-1;
1086 int *src = new int(N);
1087 for(MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
1088 if ((*ListRunner)->IndexNr != nr)
1089 src[N++] = (*ListRunner)->IndexNr;
1090 molecules->SimpleMultiMerge(mol, src, N);
1091 delete[](src);
1092 }
1093 }
1094 break;
1095
1096 case 's':
1097 cout << Verbose(0) << "Not implemented yet." << endl;
1098 break;
1099
1100 case 't':
1101 {
1102 int src, dest;
1103 molecule *srcmol = NULL, *destmol = NULL;
1104 {
1105 do {
1106 cout << Verbose(0) << "Enter index of destination molecule: ";
1107 cin >> dest;
1108 destmol = molecules->ReturnIndex(dest);
1109 } while ((destmol == NULL) && (dest != -1));
1110 do {
1111 cout << Verbose(0) << "Enter index of source molecule to merge into: ";
1112 cin >> src;
1113 srcmol = molecules->ReturnIndex(src);
1114 } while ((srcmol == NULL) && (src != -1));
1115 if ((src != -1) && (dest != -1))
1116 molecules->SimpleMerge(srcmol, destmol);
1117 }
1118 }
1119 break;
1120 }
1121};
1122
1123
1124/********************************************** Test routine **************************************/
1125
1126/** Is called always as option 'T' in the menu.
1127 * \param *molecules list of molecules
1128 */
1129static void testroutine(MoleculeListClass *molecules)
1130{
1131 // the current test routine checks the functionality of the KeySet&Graph concept:
1132 // We want to have a multiindex (the KeySet) describing a unique subgraph
1133 int i, comp, counter=0;
1134
1135 // create a clone
1136 molecule *mol = NULL;
1137 if (molecules->ListOfMolecules.size() != 0) // clone
1138 mol = (molecules->ListOfMolecules.front())->CopyMolecule();
1139 else {
1140 cerr << "I don't have anything to test on ... ";
1141 return;
1142 }
1143 atom *Walker = mol->start;
1144
1145 // generate some KeySets
1146 cout << "Generating KeySets." << endl;
1147 KeySet TestSets[mol->AtomCount+1];
1148 i=1;
1149 while (Walker->next != mol->end) {
1150 Walker = Walker->next;
1151 for (int j=0;j<i;j++) {
1152 TestSets[j].insert(Walker->nr);
1153 }
1154 i++;
1155 }
1156 cout << "Testing insertion of already present item in KeySets." << endl;
1157 KeySetTestPair test;
1158 test = TestSets[mol->AtomCount-1].insert(Walker->nr);
1159 if (test.second) {
1160 cout << Verbose(1) << "Insertion worked?!" << endl;
1161 } else {
1162 cout << Verbose(1) << "Insertion rejected: Present object is " << (*test.first) << "." << endl;
1163 }
1164 TestSets[mol->AtomCount].insert(mol->end->previous->nr);
1165 TestSets[mol->AtomCount].insert(mol->end->previous->previous->previous->nr);
1166
1167 // constructing Graph structure
1168 cout << "Generating Subgraph class." << endl;
1169 Graph Subgraphs;
1170
1171 // insert KeySets into Subgraphs
1172 cout << "Inserting KeySets into Subgraph class." << endl;
1173 for (int j=0;j<mol->AtomCount;j++) {
1174 Subgraphs.insert(GraphPair (TestSets[j],pair<int, double>(counter++, 1.)));
1175 }
1176 cout << "Testing insertion of already present item in Subgraph." << endl;
1177 GraphTestPair test2;
1178 test2 = Subgraphs.insert(GraphPair (TestSets[mol->AtomCount],pair<int, double>(counter++, 1.)));
1179 if (test2.second) {
1180 cout << Verbose(1) << "Insertion worked?!" << endl;
1181 } else {
1182 cout << Verbose(1) << "Insertion rejected: Present object is " << (*(test2.first)).second.first << "." << endl;
1183 }
1184
1185 // show graphs
1186 cout << "Showing Subgraph's contents, checking that it's sorted." << endl;
1187 Graph::iterator A = Subgraphs.begin();
1188 while (A != Subgraphs.end()) {
1189 cout << (*A).second.first << ": ";
1190 KeySet::iterator key = (*A).first.begin();
1191 comp = -1;
1192 while (key != (*A).first.end()) {
1193 if ((*key) > comp)
1194 cout << (*key) << " ";
1195 else
1196 cout << (*key) << "! ";
1197 comp = (*key);
1198 key++;
1199 }
1200 cout << endl;
1201 A++;
1202 }
1203 delete(mol);
1204};
1205
1206/** Tries given filename or standard on saving the config file.
1207 * \param *ConfigFileName name of file
1208 * \param *configuration pointer to configuration structure with all the values
1209 * \param *periode pointer to periodentafel structure with all the elements
1210 * \param *molecules list of molecules structure with all the atoms and coordinates
1211 */
1212static void SaveConfig(char *ConfigFileName, config *configuration, periodentafel *periode, MoleculeListClass *molecules)
1213{
1214 char filename[MAXSTRINGSIZE];
1215 ofstream output;
1216 molecule *mol = new molecule(periode);
1217
1218 // translate each to its center and merge all molecules in MoleculeListClass into this molecule
1219 int N = molecules->ListOfMolecules.size();
1220 int *src = new int(N);
1221 N=0;
1222 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) {
1223 src[N++] = (*ListRunner)->IndexNr;
1224 (*ListRunner)->Translate(&(*ListRunner)->Center);
1225 }
1226 molecules->SimpleMultiAdd(mol, src, N);
1227 delete[](src);
1228 // ... and translate back
1229 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) {
1230 (*ListRunner)->Center.Scale(-1.);
1231 (*ListRunner)->Translate(&(*ListRunner)->Center);
1232 (*ListRunner)->Center.Scale(-1.);
1233 }
1234
1235 cout << Verbose(0) << "Storing configuration ... " << endl;
1236 // get correct valence orbitals
1237 mol->CalculateOrbitals(*configuration);
1238 configuration->InitMaxMinStopStep = configuration->MaxMinStopStep = configuration->MaxPsiDouble;
1239 if (ConfigFileName != NULL) { // test the file name
1240 strcpy(filename, ConfigFileName);
1241 output.open(filename, ios::trunc);
1242 } else if (strlen(configuration->configname) != 0) {
1243 strcpy(filename, configuration->configname);
1244 output.open(configuration->configname, ios::trunc);
1245 } else {
1246 strcpy(filename, DEFAULTCONFIG);
1247 output.open(DEFAULTCONFIG, ios::trunc);
1248 }
1249 output.close();
1250 output.clear();
1251 cout << Verbose(0) << "Saving of config file ";
1252 if (configuration->Save(filename, periode, mol))
1253 cout << "successful." << endl;
1254 else
1255 cout << "failed." << endl;
1256
1257 // and save to xyz file
1258 if (ConfigFileName != NULL) {
1259 strcpy(filename, ConfigFileName);
1260 strcat(filename, ".xyz");
1261 output.open(filename, ios::trunc);
1262 }
1263 if (output == NULL) {
1264 strcpy(filename,"main_pcp_linux");
1265 strcat(filename, ".xyz");
1266 output.open(filename, ios::trunc);
1267 }
1268 cout << Verbose(0) << "Saving of XYZ file ";
1269 if (mol->MDSteps <= 1) {
1270 if (mol->OutputXYZ(&output))
1271 cout << "successful." << endl;
1272 else
1273 cout << "failed." << endl;
1274 } else {
1275 if (mol->OutputTrajectoriesXYZ(&output))
1276 cout << "successful." << endl;
1277 else
1278 cout << "failed." << endl;
1279 }
1280 output.close();
1281 output.clear();
1282
1283 // and save as MPQC configuration
1284 if (ConfigFileName != NULL)
1285 strcpy(filename, ConfigFileName);
1286 if (output == NULL)
1287 strcpy(filename,"main_pcp_linux");
1288 cout << Verbose(0) << "Saving as mpqc input ";
1289 if (configuration->SaveMPQC(filename, mol))
1290 cout << "done." << endl;
1291 else
1292 cout << "failed." << endl;
1293
1294 if (!strcmp(configuration->configpath, configuration->GetDefaultPath())) {
1295 cerr << "WARNING: config is found under different path then stated in config file::defaultpath!" << endl;
1296 }
1297 delete(mol);
1298};
1299
1300/** Parses the command line options.
1301 * \param argc argument count
1302 * \param **argv arguments array
1303 * \param *molecules list of molecules structure
1304 * \param *periode elements structure
1305 * \param configuration config file structure
1306 * \param *ConfigFileName pointer to config file name in **argv
1307 * \param *PathToDatabases pointer to db's path in **argv
1308 * \return exit code (0 - successful, all else - something's wrong)
1309 */
1310static int ParseCommandLineOptions(int argc, char **argv, MoleculeListClass *&molecules, periodentafel *&periode, config& configuration, char *ConfigFileName, char *&PathToDatabases)
1311{
1312 Vector x,y,z,n; // coordinates for absolute point in cell volume
1313 double *factor; // unit factor if desired
1314 ifstream test;
1315 ofstream output;
1316 string line;
1317 atom *first;
1318 bool SaveFlag = false;
1319 int ExitFlag = 0;
1320 int j;
1321 double volume = 0.;
1322 enum ConfigStatus config_present = absent;
1323 clock_t start,end;
1324 int argptr;
1325 PathToDatabases = LocalPath;
1326
1327 // simply create a new molecule, wherein the config file is loaded and the manipulation takes place
1328 molecule *mol = new molecule(periode);
1329 mol->ActiveFlag = true;
1330 molecules->insert(mol);
1331
1332 if (argc > 1) { // config file specified as option
1333 // 1. : Parse options that just set variables or print help
1334 argptr = 1;
1335 do {
1336 if (argv[argptr][0] == '-') {
1337 cout << Verbose(0) << "Recognized command line argument: " << argv[argptr][1] << ".\n";
1338 argptr++;
1339 switch(argv[argptr-1][1]) {
1340 case 'h':
1341 case 'H':
1342 case '?':
1343 cout << "MoleCuilder suite" << endl << "==================" << endl << endl;
1344 cout << "Usage: " << argv[0] << "[config file] [-{acefpsthH?vfrp}] [further arguments]" << endl;
1345 cout << "or simply " << argv[0] << " without arguments for interactive session." << endl;
1346 cout << "\t-a Z x1 x2 x3\tAdd new atom of element Z at coordinates (x1,x2,x3)." << endl;
1347 cout << "\t-A <source>\tCreate adjacency list from bonds parsed from 'dbond'-style file." <<endl;
1348 cout << "\t-b x1 x2 x3\tCenter atoms in domain with given edge lengths of (x1,x2,x3)." << endl;
1349 cout << "\t-B <basis>\tSetting basis to store to MPQC config files." << endl;
1350 cout << "\t-c x1 x2 x3\tCenter atoms in domain with a minimum distance to boundary of (x1,x2,x3)." << endl;
1351 cout << "\t-D <bond distance>\tDepth-First-Search Analysis of the molecule, giving cycles and tree/back edges." << endl;
1352 cout << "\t-O\tCenter atoms in origin." << endl;
1353 cout << "\t-d x1 x2 x3\tDuplicate cell along each axis by given factor." << endl;
1354 cout << "\t-e <file>\tSets the databases path to be parsed (default: ./)." << endl;
1355 cout << "\t-E <id> <Z>\tChange atom <id>'s element to <Z>, <id> begins at 0." << endl;
1356 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;
1357 cout << "\t-h/-H/-?\tGive this help screen." << endl;
1358 cout << "\t-m <0/1>\tCalculate (0)/ Align in(1) PAS with greatest EV along z axis." << endl;
1359 cout << "\t-n\tFast parsing (i.e. no trajectories are looked for)." << endl;
1360 cout << "\t-N\tGet non-convex-envelope." << endl;
1361 cout << "\t-o <out>\tGet volume of the convex envelope (and store to tecplot file)." << endl;
1362 cout << "\t-p <file>\tParse given xyz file and create raw config file from it." << endl;
1363 cout << "\t-P <file>\tParse given forces file and append as an MD step to config file via Verlet." << endl;
1364 cout << "\t-r\t\tConvert file from an old pcp syntax." << endl;
1365 cout << "\t-t x1 x2 x3\tTranslate all atoms by this vector (x1,x2,x3)." << endl;
1366 cout << "\t-T <file> Store temperatures from the config file in <file>." << endl;
1367 cout << "\t-s x1 x2 x3\tScale all atom coordinates by this vector (x1,x2,x3)." << endl;
1368 cout << "\t-u rho\tsuspend in water solution and output necessary cell lengths, average density rho and repetition." << endl;
1369 cout << "\t-v/-V\t\tGives version information." << endl;
1370 cout << "Note: config files must not begin with '-' !" << endl;
1371 delete(mol);
1372 delete(periode);
1373 return (1);
1374 break;
1375 case 'v':
1376 case 'V':
1377 cout << argv[0] << " " << VERSIONSTRING << endl;
1378 cout << "Build your own molecule position set." << endl;
1379 delete(mol);
1380 delete(periode);
1381 return (1);
1382 break;
1383 case 'e':
1384 if ((argptr >= argc) || (argv[argptr][0] == '-')) {
1385 cerr << "Not enough or invalid arguments for specifying element db: -e <db file>" << endl;
1386 } else {
1387 cout << "Using " << argv[argptr] << " as elements database." << endl;
1388 PathToDatabases = argv[argptr];
1389 argptr+=1;
1390 }
1391 break;
1392 case 'n':
1393 cout << "I won't parse trajectories." << endl;
1394 configuration.FastParsing = true;
1395 break;
1396 default: // no match? Step on
1397 argptr++;
1398 break;
1399 }
1400 } else
1401 argptr++;
1402 } while (argptr < argc);
1403
1404 // 2. Parse the element database
1405 if (periode->LoadPeriodentafel(PathToDatabases)) {
1406 cout << Verbose(0) << "Element list loaded successfully." << endl;
1407 //periode->Output((ofstream *)&cout);
1408 } else {
1409 cout << Verbose(0) << "Element list loading failed." << endl;
1410 return 1;
1411 }
1412 // 3. Find config file name and parse if possible
1413 if (argv[1][0] != '-') {
1414 cout << Verbose(0) << "Config file given." << endl;
1415 test.open(argv[1], ios::in);
1416 if (test == NULL) {
1417 //return (1);
1418 output.open(argv[1], ios::out);
1419 if (output == NULL) {
1420 cout << Verbose(1) << "Specified config file " << argv[1] << " not found." << endl;
1421 config_present = absent;
1422 } else {
1423 cout << "Empty configuration file." << endl;
1424 strcpy(ConfigFileName, argv[1]);
1425 config_present = empty;
1426 output.close();
1427 }
1428 } else {
1429 test.close();
1430 strcpy(ConfigFileName, argv[1]);
1431 cout << Verbose(1) << "Specified config file found, parsing ... ";
1432 switch (configuration.TestSyntax(ConfigFileName, periode, mol)) {
1433 case 1:
1434 cout << "new syntax." << endl;
1435 configuration.Load(ConfigFileName, periode, mol);
1436 config_present = present;
1437 break;
1438 case 0:
1439 cout << "old syntax." << endl;
1440 configuration.LoadOld(ConfigFileName, periode, mol);
1441 config_present = present;
1442 break;
1443 default:
1444 cout << "Unknown syntax or empty, yet present file." << endl;
1445 config_present = empty;
1446 }
1447 }
1448 } else
1449 config_present = absent;
1450 // 4. parse again through options, now for those depending on elements db and config presence
1451 argptr = 1;
1452 do {
1453 cout << "Current Command line argument: " << argv[argptr] << "." << endl;
1454 if (argv[argptr][0] == '-') {
1455 argptr++;
1456 if ((config_present == present) || (config_present == empty)) {
1457 switch(argv[argptr-1][1]) {
1458 case 'p':
1459 ExitFlag = 1;
1460 if ((argptr >= argc) || (argv[argptr][0] == '-')) {
1461 ExitFlag = 255;
1462 cerr << "Not enough arguments for parsing: -p <xyz file>" << endl;
1463 } else {
1464 SaveFlag = true;
1465 cout << Verbose(1) << "Parsing xyz file for new atoms." << endl;
1466 if (!mol->AddXYZFile(argv[argptr]))
1467 cout << Verbose(2) << "File not found." << endl;
1468 else {
1469 cout << Verbose(2) << "File found and parsed." << endl;
1470 config_present = present;
1471 }
1472 }
1473 break;
1474 case 'a':
1475 ExitFlag = 1;
1476 if ((argptr >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr+1]))) {
1477 ExitFlag = 255;
1478 cerr << "Not enough or invalid arguments for adding atom: -a <element> <x> <y> <z>" << endl;
1479 } else {
1480 SaveFlag = true;
1481 cout << Verbose(1) << "Adding new atom with element " << argv[argptr] << " at (" << argv[argptr+1] << "," << argv[argptr+2] << "," << argv[argptr+3] << "), ";
1482 first = new atom;
1483 first->type = periode->FindElement(atoi(argv[argptr]));
1484 if (first->type != NULL)
1485 cout << Verbose(2) << "found element " << first->type->name << endl;
1486 for (int i=NDIM;i--;)
1487 first->x.x[i] = atof(argv[argptr+1+i]);
1488 if (first->type != NULL) {
1489 mol->AddAtom(first); // add to molecule
1490 if ((config_present == empty) && (mol->AtomCount != 0))
1491 config_present = present;
1492 } else
1493 cerr << Verbose(1) << "Could not find the specified element." << endl;
1494 argptr+=4;
1495 }
1496 break;
1497 default: // no match? Don't step on (this is done in next switch's default)
1498 break;
1499 }
1500 }
1501 if (config_present == present) {
1502 switch(argv[argptr-1][1]) {
1503 case 'B':
1504 if ((argptr >= argc) || (argv[argptr][0] == '-')) {
1505 ExitFlag = 255;
1506 cerr << "Not enough or invalid arguments given for setting MPQC basis: -B <basis name>" << endl;
1507 } else {
1508 configuration.basis = argv[argptr];
1509 cout << Verbose(1) << "Setting MPQC basis to " << configuration.basis << "." << endl;
1510 argptr+=1;
1511 }
1512 break;
1513 case 'D':
1514 ExitFlag = 1;
1515 {
1516 cout << Verbose(1) << "Depth-First-Search Analysis." << endl;
1517 MoleculeLeafClass *Subgraphs = NULL; // list of subgraphs from DFS analysis
1518 int *MinimumRingSize = new int[mol->AtomCount];
1519 atom ***ListOfLocalAtoms = NULL;
1520 int FragmentCounter = 0;
1521 class StackClass<bond *> *BackEdgeStack = NULL;
1522 class StackClass<bond *> *LocalBackEdgeStack = NULL;
1523 mol->CreateAdjacencyList((ofstream *)&cout, atof(argv[argptr]), configuration.GetIsAngstroem());
1524 mol->CreateListOfBondsPerAtom((ofstream *)&cout);
1525 Subgraphs = mol->DepthFirstSearchAnalysis((ofstream *)&cout, BackEdgeStack);
1526 if (Subgraphs != NULL) {
1527 Subgraphs->next->FillBondStructureFromReference((ofstream *)&cout, mol, (FragmentCounter = 0), ListOfLocalAtoms, false); // we want to keep the created ListOfLocalAtoms
1528 while (Subgraphs->next != NULL) {
1529 Subgraphs = Subgraphs->next;
1530 LocalBackEdgeStack = new StackClass<bond *> (Subgraphs->Leaf->BondCount);
1531 Subgraphs->Leaf->PickLocalBackEdges((ofstream *)&cout, ListOfLocalAtoms[FragmentCounter++], BackEdgeStack, LocalBackEdgeStack);
1532 Subgraphs->Leaf->CyclicStructureAnalysis((ofstream *)&cout, BackEdgeStack, MinimumRingSize);
1533 delete(LocalBackEdgeStack);
1534 delete(Subgraphs->previous);
1535 }
1536 delete(Subgraphs);
1537 for (int i=0;i<FragmentCounter;i++)
1538 Free((void **)&ListOfLocalAtoms[FragmentCounter], "ParseCommandLineOptions: **ListOfLocalAtoms[]");
1539 Free((void **)&ListOfLocalAtoms, "ParseCommandLineOptions: ***ListOfLocalAtoms");
1540 }
1541 delete(BackEdgeStack);
1542 delete[](MinimumRingSize);
1543 }
1544 //argptr+=1;
1545 break;
1546 case 'E':
1547 ExitFlag = 1;
1548 if ((argptr+1 >= argc) || (!IsValidNumber(argv[argptr])) || (argv[argptr+1][0] == '-')) {
1549 ExitFlag = 255;
1550 cerr << "Not enough or invalid arguments given for changing element: -E <atom nr.> <element>" << endl;
1551 } else {
1552 SaveFlag = true;
1553 cout << Verbose(1) << "Changing atom " << argv[argptr] << " to element " << argv[argptr+1] << "." << endl;
1554 first = mol->FindAtom(atoi(argv[argptr]));
1555 first->type = periode->FindElement(atoi(argv[argptr+1]));
1556 argptr+=2;
1557 }
1558 break;
1559 case 'A':
1560 ExitFlag = 1;
1561 if ((argptr >= argc) || (argv[argptr][0] == '-')) {
1562 ExitFlag =255;
1563 cerr << "Missing source file for bonds in molecule: -A <bond sourcefile>" << endl;
1564 } else {
1565 cout << "Parsing bonds from " << argv[argptr] << "." << endl;
1566 ifstream *input = new ifstream(argv[argptr]);
1567 mol->CreateAdjacencyList2((ofstream *)&cout, input);
1568 input->close();
1569 argptr+=1;
1570 }
1571 break;
1572 case 'N':
1573 ExitFlag = 1;
1574 if ((argptr+1 >= argc) || (argv[argptr+1][0] == '-')){
1575 ExitFlag = 255;
1576 cerr << "Not enough or invalid arguments given for non-convex envelope: -o <radius> <tecplot output file>" << endl;
1577 } else {
1578 class Tesselation T;
1579 int N = 15;
1580 int number = 100;
1581 string filename(argv[argptr+1]);
1582 filename.append(".csv");
1583 cout << Verbose(0) << "Evaluating non-convex envelope.";
1584 cout << Verbose(1) << "Using rolling ball of radius " << atof(argv[argptr]) << " and storing tecplot data in " << argv[argptr+1] << "." << endl;
1585 LinkedCell LCList(mol, atof(argv[argptr])); // \NOTE not twice the radius??
1586 Find_non_convex_border((ofstream *)&cout, mol, &T, &LCList, argv[argptr+1], atof(argv[argptr]));
1587 FindDistributionOfEllipsoids((ofstream *)&cout, &T, &LCList, N, number, filename.c_str());
1588 argptr+=2;
1589 }
1590 break;
1591 case 'T':
1592 ExitFlag = 1;
1593 if ((argptr >= argc) || (argv[argptr][0] == '-')) {
1594 ExitFlag = 255;
1595 cerr << "Not enough or invalid arguments given for storing tempature: -T <temperature file>" << endl;
1596 } else {
1597 cout << Verbose(1) << "Storing temperatures in " << argv[argptr] << "." << endl;
1598 ofstream *output = new ofstream(argv[argptr], ios::trunc);
1599 if (!mol->OutputTemperatureFromTrajectories((ofstream *)&cout, 0, mol->MDSteps, output))
1600 cout << Verbose(2) << "File could not be written." << endl;
1601 else
1602 cout << Verbose(2) << "File stored." << endl;
1603 output->close();
1604 delete(output);
1605 argptr+=1;
1606 }
1607 break;
1608 case 'P':
1609 ExitFlag = 1;
1610 if ((argptr >= argc) || (argv[argptr][0] == '-')) {
1611 ExitFlag = 255;
1612 cerr << "Not enough or invalid arguments given for parsing and integrating forces: -P <forces file>" << endl;
1613 } else {
1614 SaveFlag = true;
1615 cout << Verbose(1) << "Parsing forces file and Verlet integrating." << endl;
1616 if (!mol->VerletForceIntegration(argv[argptr], configuration.Deltat, configuration.GetIsAngstroem()))
1617 cout << Verbose(2) << "File not found." << endl;
1618 else
1619 cout << Verbose(2) << "File found and parsed." << endl;
1620 argptr+=1;
1621 }
1622 break;
1623 case 't':
1624 ExitFlag = 1;
1625 if ((argptr+2 >= argc) || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) {
1626 ExitFlag = 255;
1627 cerr << "Not enough or invalid arguments given for translation: -t <x> <y> <z>" << endl;
1628 } else {
1629 ExitFlag = 1;
1630 SaveFlag = true;
1631 cout << Verbose(1) << "Translating all ions to new origin." << endl;
1632 for (int i=NDIM;i--;)
1633 x.x[i] = atof(argv[argptr+i]);
1634 mol->Translate((const Vector *)&x);
1635 argptr+=3;
1636 }
1637 break;
1638 case 's':
1639 ExitFlag = 1;
1640 if ((argptr >= argc) || (!IsValidNumber(argv[argptr])) ) {
1641 ExitFlag = 255;
1642 cerr << "Not enough or invalid arguments given for scaling: -s <factor/[factor_x]> [factor_y] [factor_z]" << endl;
1643 } else {
1644 SaveFlag = true;
1645 j = -1;
1646 cout << Verbose(1) << "Scaling all ion positions by factor." << endl;
1647 factor = new double[NDIM];
1648 factor[0] = atof(argv[argptr]);
1649 if ((argptr < argc) && (IsValidNumber(argv[argptr])))
1650 argptr++;
1651 factor[1] = atof(argv[argptr]);
1652 if ((argptr < argc) && (IsValidNumber(argv[argptr])))
1653 argptr++;
1654 factor[2] = atof(argv[argptr]);
1655 mol->Scale(&factor);
1656 for (int i=0;i<NDIM;i++) {
1657 j += i+1;
1658 x.x[i] = atof(argv[NDIM+i]);
1659 mol->cell_size[j]*=factor[i];
1660 }
1661 delete[](factor);
1662 argptr+=1;
1663 }
1664 break;
1665 case 'b':
1666 ExitFlag = 1;
1667 if ((argptr+2 >= argc) || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) {
1668 ExitFlag = 255;
1669 cerr << "Not enough or invalid arguments given for centering in box: -b <length_x> <length_y> <length_z>" << endl;
1670 } else {
1671 SaveFlag = true;
1672 j = -1;
1673 cout << Verbose(1) << "Centering atoms in config file within given simulation box." << endl;
1674 j=-1;
1675 for (int i=0;i<NDIM;i++) {
1676 j += i+1;
1677 x.x[i] = atof(argv[argptr++]);
1678 mol->cell_size[j] += x.x[i]*2.;
1679 }
1680 // center
1681 mol->CenterInBox((ofstream *)&cout, &x);
1682 // update Box of atoms by boundary
1683 mol->SetBoxDimension(&x);
1684 }
1685 break;
1686 case 'c':
1687 ExitFlag = 1;
1688 if ((argptr+2 >= argc) || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) {
1689 ExitFlag = 255;
1690 cerr << "Not enough or invalid arguments given for centering with boundary: -c <boundary_x> <boundary_y> <boundary_z>" << endl;
1691 } else {
1692 SaveFlag = true;
1693 j = -1;
1694 cout << Verbose(1) << "Centering atoms in config file within given additional boundary." << endl;
1695 // make every coordinate positive
1696 mol->CenterEdge((ofstream *)&cout, &x);
1697 // update Box of atoms by boundary
1698 mol->SetBoxDimension(&x);
1699 // translate each coordinate by boundary
1700 j=-1;
1701 for (int i=0;i<NDIM;i++) {
1702 j += i+1;
1703 x.x[i] = atof(argv[argptr++]);
1704 mol->cell_size[j] += x.x[i]*2.;
1705 }
1706 mol->Translate((const Vector *)&x);
1707 }
1708 break;
1709 case 'O':
1710 ExitFlag = 1;
1711 SaveFlag = true;
1712 cout << Verbose(1) << "Centering atoms on edge and setting box dimensions." << endl;
1713 mol->CenterEdge((ofstream *)&cout, &x);
1714 mol->SetBoxDimension(&x);
1715 break;
1716 case 'r':
1717 ExitFlag = 1;
1718 SaveFlag = true;
1719 cout << Verbose(1) << "Converting config file from supposed old to new syntax." << endl;
1720 break;
1721 case 'F':
1722 case 'f':
1723 ExitFlag = 1;
1724 if ((argptr+1 >= argc) || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1]))) {
1725 ExitFlag = 255;
1726 cerr << "Not enough or invalid arguments for fragmentation: -f <max. bond distance> <bond order>" << endl;
1727 } else {
1728 cout << "Fragmenting molecule with bond distance " << argv[argptr] << " angstroem, order of " << argv[argptr+1] << "." << endl;
1729 cout << Verbose(0) << "Creating connection matrix..." << endl;
1730 start = clock();
1731 mol->CreateAdjacencyList((ofstream *)&cout, atof(argv[argptr++]), configuration.GetIsAngstroem());
1732 cout << Verbose(0) << "Fragmenting molecule with current connection matrix ..." << endl;
1733 if (mol->first->next != mol->last) {
1734 ExitFlag = mol->FragmentMolecule((ofstream *)&cout, atoi(argv[argptr]), &configuration);
1735 }
1736 end = clock();
1737 cout << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl;
1738 argptr+=2;
1739 }
1740 break;
1741 case 'm':
1742 ExitFlag = 1;
1743 j = atoi(argv[argptr++]);
1744 if ((j<0) || (j>1)) {
1745 cerr << Verbose(1) << "ERROR: Argument of '-m' should be either 0 for no-rotate or 1 for rotate." << endl;
1746 j = 0;
1747 }
1748 if (j) {
1749 SaveFlag = true;
1750 cout << Verbose(0) << "Converting to prinicipal axis system." << endl;
1751 } else
1752 cout << Verbose(0) << "Evaluating prinicipal axis." << endl;
1753 mol->PrincipalAxisSystem((ofstream *)&cout, (bool)j);
1754 break;
1755 case 'o':
1756 ExitFlag = 1;
1757 if ((argptr >= argc) || (argv[argptr][0] == '-')){
1758 ExitFlag = 255;
1759 cerr << "Not enough or invalid arguments given for convex envelope: -o <tecplot output file>" << endl;
1760 } else {
1761 cout << Verbose(0) << "Evaluating volume of the convex envelope.";
1762 cout << Verbose(1) << "Storing tecplot data in " << argv[argptr] << "." << endl;
1763 VolumeOfConvexEnvelope((ofstream *)&cout, argv[argptr], &configuration, NULL, mol);
1764 argptr+=1;
1765 }
1766 break;
1767 case 'U':
1768 ExitFlag = 1;
1769 if ((argptr+1 >= argc) || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) ) {
1770 ExitFlag = 255;
1771 cerr << "Not enough or invalid arguments given for suspension with specified volume: -U <volume> <density>" << endl;
1772 volume = -1; // for case 'u': don't print error again
1773 } else {
1774 volume = atof(argv[argptr++]);
1775 cout << Verbose(0) << "Using " << volume << " angstrom^3 as the volume instead of convex envelope one's." << endl;
1776 }
1777 case 'u':
1778 ExitFlag = 1;
1779 if ((argptr >= argc) || (!IsValidNumber(argv[argptr])) ) {
1780 if (volume != -1)
1781 ExitFlag = 255;
1782 cerr << "Not enough arguments given for suspension: -u <density>" << endl;
1783 } else {
1784 double density;
1785 SaveFlag = true;
1786 cout << Verbose(0) << "Evaluating necessary cell volume for a cluster suspended in water.";
1787 density = atof(argv[argptr++]);
1788 if (density < 1.0) {
1789 cerr << Verbose(0) << "Density must be greater than 1.0g/cm^3 !" << endl;
1790 density = 1.3;
1791 }
1792// for(int i=0;i<NDIM;i++) {
1793// repetition[i] = atoi(argv[argptr++]);
1794// if (repetition[i] < 1)
1795// cerr << Verbose(0) << "ERROR: repetition value must be greater 1!" << endl;
1796// repetition[i] = 1;
1797// }
1798 PrepareClustersinWater((ofstream *)&cout, &configuration, mol, volume, density); // if volume == 0, will calculate from ConvexEnvelope
1799 }
1800 break;
1801 case 'd':
1802 ExitFlag = 1;
1803 if ((argptr+2 >= argc) || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) {
1804 ExitFlag = 255;
1805 cerr << "Not enough or invalid arguments given for repeating cells: -d <repeat_x> <repeat_y> <repeat_z>" << endl;
1806 } else {
1807 SaveFlag = true;
1808 for (int axis = 1; axis <= NDIM; axis++) {
1809 int faktor = atoi(argv[argptr++]);
1810 int count;
1811 element ** Elements;
1812 Vector ** vectors;
1813 if (faktor < 1) {
1814 cerr << Verbose(0) << "ERROR: Repetition faktor mus be greater than 1!" << endl;
1815 faktor = 1;
1816 }
1817 mol->CountAtoms((ofstream *)&cout); // recount atoms
1818 if (mol->AtomCount != 0) { // if there is more than none
1819 count = mol->AtomCount; // is changed becausing of adding, thus has to be stored away beforehand
1820 Elements = new element *[count];
1821 vectors = new Vector *[count];
1822 j = 0;
1823 first = mol->start;
1824 while (first->next != mol->end) { // make a list of all atoms with coordinates and element
1825 first = first->next;
1826 Elements[j] = first->type;
1827 vectors[j] = &first->x;
1828 j++;
1829 }
1830 if (count != j)
1831 cout << Verbose(0) << "ERROR: AtomCount " << count << " is not equal to number of atoms in molecule " << j << "!" << endl;
1832 x.Zero();
1833 y.Zero();
1834 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
1835 for (int i=1;i<faktor;i++) { // then add this list with respective translation factor times
1836 x.AddVector(&y); // per factor one cell width further
1837 for (int k=count;k--;) { // go through every atom of the original cell
1838 first = new atom(); // create a new body
1839 first->x.CopyVector(vectors[k]); // use coordinate of original atom
1840 first->x.AddVector(&x); // translate the coordinates
1841 first->type = Elements[k]; // insert original element
1842 mol->AddAtom(first); // and add to the molecule (which increments ElementsInMolecule, AtomCount, ...)
1843 }
1844 }
1845 // free memory
1846 delete[](Elements);
1847 delete[](vectors);
1848 // correct cell size
1849 if (axis < 0) { // if sign was negative, we have to translate everything
1850 x.Zero();
1851 x.AddVector(&y);
1852 x.Scale(-(faktor-1));
1853 mol->Translate(&x);
1854 }
1855 mol->cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] *= faktor;
1856 }
1857 }
1858 }
1859 break;
1860 default: // no match? Step on
1861 if ((argptr < argc) && (argv[argptr][0] != '-')) // if it started with a '-' we've already made a step!
1862 argptr++;
1863 break;
1864 }
1865 }
1866 } else argptr++;
1867 } while (argptr < argc);
1868 if (SaveFlag)
1869 SaveConfig(ConfigFileName, &configuration, periode, molecules);
1870 if ((ExitFlag >= 1)) {
1871 delete(mol);
1872 delete(periode);
1873 return (ExitFlag);
1874 }
1875 } else { // no arguments, hence scan the elements db
1876 if (periode->LoadPeriodentafel(PathToDatabases))
1877 cout << Verbose(0) << "Element list loaded successfully." << endl;
1878 else
1879 cout << Verbose(0) << "Element list loading failed." << endl;
1880 configuration.RetrieveConfigPathAndName("main_pcp_linux");
1881 }
1882 return(0);
1883};
1884
1885/********************************************** Main routine **************************************/
1886
1887int main(int argc, char **argv)
1888{
1889 periodentafel *periode = new periodentafel; // and a period table of all elements
1890 MoleculeListClass *molecules = new MoleculeListClass; // list of all molecules
1891 molecule *mol = NULL;
1892 config configuration;
1893 double tmp1;
1894 atom *first, *second;
1895 char choice; // menu choice char
1896 Vector x,y,z,n; // coordinates for absolute point in cell volume
1897 bool valid; // flag if input was valid or not
1898 ifstream test;
1899 ofstream output;
1900 string line;
1901 char ConfigFileName[MAXSTRINGSIZE];
1902 char *ElementsFileName = NULL;
1903 int Z;
1904 int j, axis, count, faktor;
1905
1906 // =========================== PARSE COMMAND LINE OPTIONS ====================================
1907 ConfigFileName[0] = '\0';
1908 j = ParseCommandLineOptions(argc, argv, molecules, periode, configuration, ConfigFileName, ElementsFileName);
1909 if (j == 1) return 0; // just for -v and -h options
1910 if (j) return j; // something went wrong
1911
1912 // General stuff
1913 if (molecules->ListOfMolecules.size() == 0) {
1914 mol = new molecule(periode);
1915 if (mol->cell_size[0] == 0.) {
1916 cout << Verbose(0) << "enter lower tridiagonal form of basis matrix" << endl << endl;
1917 for (int i=0;i<6;i++) {
1918 cout << Verbose(1) << "Cell size" << i << ": ";
1919 cin >> mol->cell_size[i];
1920 }
1921 }
1922 molecules->insert(mol);
1923 }
1924 if (strlen(ConfigFileName) == 0)
1925 strcpy(ConfigFileName, DEFAULTCONFIG);
1926
1927
1928 // =========================== START INTERACTIVE SESSION ====================================
1929
1930 // now the main construction loop
1931 cout << Verbose(0) << endl << "Now comes the real construction..." << endl;
1932 do {
1933 cout << Verbose(0) << endl << endl;
1934 cout << Verbose(0) << "============Molecule list=======================" << endl;
1935 molecules->Enumerate((ofstream *)&cout);
1936 cout << Verbose(0) << "============Menu===============================" << endl;
1937 cout << Verbose(0) << "a - set molecule (in)active" << endl;
1938 cout << Verbose(0) << "e - edit molecules (load, parse, save)" << endl;
1939 cout << Verbose(0) << "g - globally manipulate atoms in molecule" << endl;
1940 cout << Verbose(0) << "M - Merge molecules" << endl;
1941 cout << Verbose(0) << "m - manipulate atoms" << endl;
1942 cout << Verbose(0) << "-----------------------------------------------" << endl;
1943 cout << Verbose(0) << "c - edit the current configuration" << endl;
1944 cout << Verbose(0) << "-----------------------------------------------" << endl;
1945 cout << Verbose(0) << "s - save current setup to config file" << endl;
1946 cout << Verbose(0) << "T - call the current test routine" << endl;
1947 cout << Verbose(0) << "q - quit" << endl;
1948 cout << Verbose(0) << "===============================================" << endl;
1949 cout << Verbose(0) << "Input: ";
1950 cin >> choice;
1951
1952 switch (choice) {
1953 case 'a': // (in)activate molecule
1954 {
1955 cout << "Enter index of molecule: ";
1956 cin >> j;
1957 for(MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
1958 if ((*ListRunner)->IndexNr == j)
1959 (*ListRunner)->ActiveFlag = !(*ListRunner)->ActiveFlag;
1960 }
1961 break;
1962
1963 case 'c': // edit each field of the configuration
1964 configuration.Edit();
1965 break;
1966
1967 case 'e': // create molecule
1968 EditMolecules(periode, molecules);
1969 break;
1970
1971 case 'g': // manipulate molecules
1972 ManipulateMolecules(periode, molecules, &configuration);
1973 break;
1974
1975 case 'M': // merge molecules
1976 MergeMolecules(periode, molecules);
1977 break;
1978
1979 case 'm': // manipulate atoms
1980 ManipulateAtoms(periode, molecules, &configuration);
1981 break;
1982
1983 case 'q': // quit
1984 break;
1985
1986 case 's': // save to config file
1987 SaveConfig(ConfigFileName, &configuration, periode, molecules);
1988 break;
1989
1990 case 'T':
1991 testroutine(molecules);
1992 break;
1993
1994 default:
1995 break;
1996 };
1997 } while (choice != 'q');
1998
1999 // save element data base
2000 if (periode->StorePeriodentafel(ElementsFileName)) //ElementsFileName
2001 cout << Verbose(0) << "Saving of elements.db successful." << endl;
2002 else
2003 cout << Verbose(0) << "Saving of elements.db failed." << endl;
2004
2005 delete(molecules);
2006 delete(periode);
2007 return (0);
2008}
2009
2010/********************************************** E N D **************************************************/
Note: See TracBrowser for help on using the repository browser.