source: src/builder.cpp@ 986c80

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

Merge branch 'Thermostat'

Conflicts:

.gitignore
Makefile.am
molecuilder/src/analyzer.cpp
molecuilder/src/builder.cpp
molecuilder/src/config.cpp
molecuilder/src/moleculelist.cpp
molecuilder/src/molecules.cpp
molecuilder/src/molecules.hpp

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