source: src/builder.cpp@ d30402

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

Split VolumeOfConvexEnvelope() into find_convex_border() and remainder.

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