source: src/builder.cpp@ 86466e

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 86466e was 148d8f0, checked in by Frederik Heber <heber@…>, 15 years ago

FIX: cleanup() still deleted configuration although is part of the World now.

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