source: src/builder.cpp@ 992fd7

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 992fd7 was 67c75b, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Merge branch 'MenuRefactoring' into QT4Refactoring

Conflicts:

molecuilder/src/Makefile.am
molecuilder/src/builder.cpp
molecuilder/src/unittests/Makefile.am
molecuilder/src/vector.cpp

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