source: src/builder.cpp@ b8b75d

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

Renamed and rewritten CreateAdjacencyList2().

  • rename CreateAdjacencyList2() -> CreateAdjacencyListFromDbondFile()
  • initially written by Christian Neuen who was at that time not familiar with all the functions already present. The code is now shortened and tighter.

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

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