source: molecuilder/src/builder.cpp@ 7e4dc3f

Last change on this file since 7e4dc3f was 7e4dc3f, checked in by Frederik Heber <heber@…>, 16 years ago

Implemented counting of bonds over all atoms.

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

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