source: src/builder.cpp@ 2ededc2

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 2ededc2 was 04b6f9, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Merge commit 'heber/Analysis_PairCorrelation' into MenuRefactoring

Conflicts:

molecuilder/src/unittests/Makefile.am

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