source: src/builder.cpp@ 5f612ee

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 5f612ee was 5f612ee, checked in by Frederik Heber <heber@…>, 15 years ago

Merge branch 'Analysis_PairCorrelation' into StructureRefactoring

Conflicts:

molecuilder/src/Makefile.am
molecuilder/src/World.cpp
molecuilder/src/World.hpp
molecuilder/src/boundary.cpp
molecuilder/src/builder.cpp
molecuilder/src/log.cpp
molecuilder/src/moleculelist.cpp
molecuilder/src/periodentafel.cpp
molecuilder/src/tesselation.cpp
molecuilder/src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp
molecuilder/src/unittests/Makefile.am
molecuilder/src/unittests/bondgraphunittest.cpp
molecuilder/src/unittests/gslvectorunittest.cpp
molecuilder/src/unittests/logunittest.cpp
molecuilder/src/unittests/tesselation_boundarytriangleunittest.hpp
molecuilder/src/vector.cpp
molecuilder/tests/Tesselations/defs.in

Conflicts have been many and too numerous to listen here, just the few general cases

  • new molecule() replaced by World::getInstance().createMolecule()
  • new atom() replaced by World::getInstance().createAtom() where appropriate.
  • Some DoLog()s added interfered with changes to the message produced by Log() << Verbose(.) << ...
  • DoLog() has been erroneously added to TestRunner.cpp as well, there cout is appropriate
  • ...

Additionally, there was a bug in atom::clone(), sort was set to atom::nr of the atom to clone not of the clone itself. This caused a failure of the fragmentation.

This merge has been fully checked from a clean build directory with subsequent configure,make all install and make check.
It configures, compiles and runs all test cases and the test suite without errors.

Signed-off-by: Frederik Heber <heber@…>

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