source: src/builder.cpp@ a7c344

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

Fixes and changes to tesselation and concavity measurements.

Here, we implement two attempts for a concavity measure:

  1. Measure concavity per point by looking at neighbouring triangles
    • BoundaryLineSet::CheckConvexityCriterion() split up (calculation of angle outsourced to CalculateConvexity())
    • CHANGE: CalculateConcavityPerBoundaryPoint() uses new concavity measure per BoundaryPointSet containing:
      • concavity per line uses angle instead of +/-1 for line, averaged by number of lines
      • also concavity over all attached triangles uses area of triangle and only in case of concavity, averaged by total area
    • new functions
      • BoundaryLineSet::CalculateConvexity() - calculates the angle between two triangles.
      • BoundaryLineSet::GetOtherTriangle() - for a closed line returns the other triangle for a given one
      • BoundaryTriangleSet::GetThirdLine() - for a given boundary point returns the line of the three which does not contain it (opposite line to a point)
      • CalculateAreaofGeneralTriangle() - calculates area of arbitrary triangle
  1. Measure concavity by the distance to a more convex envelope (i.e. created with bigger sphere radius)

Other unrelated stuff:

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

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