source: src/builder.cpp@ d067d45

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 d067d45 was d067d45, checked in by Frederik Heber <heber@…>, 16 years ago

Merge branch 'MultipleMolecules'

Conflicts:

molecuilder/src/analyzer.cpp
molecuilder/src/atom.cpp
molecuilder/src/boundary.cpp
molecuilder/src/boundary.hpp
molecuilder/src/builder.cpp
molecuilder/src/config.cpp
molecuilder/src/datacreator.hpp
molecuilder/src/helpers.cpp
molecuilder/src/joiner.cpp
molecuilder/src/moleculelist.cpp
molecuilder/src/molecules.cpp
molecuilder/src/molecules.hpp
molecuilder/src/parser.cpp
molecuilder/src/parser.hpp
molecuilder/src/vector.cpp
molecuilder/src/verbose.cpp

merges:

compilation fixes:

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