source: src/builder.cpp@ 5f612ee

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

Merge branch 'Analysis_PairCorrelation' into StructureRefactoring

Conflicts:

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

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

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

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

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

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

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