source: src/builder.cpp@ 2ededc2

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 Candidate_v1.7.0 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 2ededc2 was 04b6f9, checked in by Tillmann Crueger <crueger@…>, 16 years ago

Merge commit 'heber/Analysis_PairCorrelation' into MenuRefactoring

Conflicts:

molecuilder/src/unittests/Makefile.am

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