source: src/builder.cpp@ 51c910

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 Candidate_v1.7.0 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 51c910 was 51c910, checked in by Frederik Heber <heber@…>, 16 years ago

Merge branch 'AtomRemoval'

Conflicts:

molecuilder/src/builder.cpp
molecuilder/src/molecules.cpp

merges:

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