source: src/builder.cpp@ fdd840

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 fdd840 was 68d781, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Merge branch 'MenuRefactoring' into QT4Refactoring

Conflicts:

molecuilder/src/Makefile.am
molecuilder/src/defs.hpp

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