source: src/builder.cpp@ ea7176

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

FIX: Made AtomCount a Cacheable so that the number of atoms in a molecule will always be correct

All unittests working.
All Complete testcases fail.

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