source: src/builder.cpp@ cdee6b

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

fastparse enabled by "-n"

  • Property mode set to 100644
File size: 49.5 KB
Line 
1/** \file builder.cpp
2 *
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
8 *
9 */
10
11/*! \mainpage Molecuilder - a molecular set builder
12 *
13 * This introductory shall briefly make aquainted with the program, helping in installing and a first run.
14 *
15 * \section about About the Program
16 *
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.
20 *
21 * A configuration file may be written that is compatible to the format used by PCP - a parallel Car-Parrinello
22 * molecular dynamics implementation.
23 *
24 * \section install Installation
25 *
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
30 *
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
34 *
35 * \section run Running
36 *
37 * The program can be executed by running: ./molecuilder
38 *
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.
42 *
43 * \section ref References
44 *
45 * For the special configuration file format, see the documentation of pcp.
46 *
47 */
48
49
50using namespace std;
51
52#include "helpers.hpp"
53#include "molecules.hpp"
54
55/********************************************** Submenu routine **************************************/
56
57/** Submenu for adding atoms to the molecule.
58 * \param *periode periodentafel
59 * \param *mol the molecule to add to
60 */
61static void AddAtoms(periodentafel *periode, molecule *mol)
62{
63 atom *first, *second, *third, *fourth;
64 vector **atoms;
65 vector x,y,z,n; // coordinates for absolute point in cell volume
66 double a,b,c;
67 char choice; // menu choice char
68 bool valid;
69
70 cout << Verbose(0) << "===========ADD ATOM============================" << endl;
71 cout << Verbose(0) << " a - state absolute coordinates of atom" << endl;
72 cout << Verbose(0) << " b - state relative coordinates of atom wrt to reference point" << endl;
73 cout << Verbose(0) << " c - state relative coordinates of atom wrt to already placed atom" << endl;
74 cout << Verbose(0) << " d - state two atoms, two angles and a distance" << endl;
75 cout << Verbose(0) << " e - least square distance position to a set of atoms" << endl;
76 cout << Verbose(0) << "all else - go back" << endl;
77 cout << Verbose(0) << "===============================================" << endl;
78 cout << Verbose(0) << "Note: Specifiy angles in degrees not multiples of Pi!" << endl;
79 cout << Verbose(0) << "INPUT: ";
80 cin >> choice;
81
82 switch (choice) {
83 case 'a': // absolute coordinates of atom
84 cout << Verbose(0) << "Enter absolute coordinates." << endl;
85 first = new atom;
86 first->x.AskPosition(mol->cell_size, false);
87 first->type = periode->AskElement(); // give type
88 mol->AddAtom(first); // add to molecule
89 break;
90
91 case 'b': // relative coordinates of atom wrt to reference point
92 first = new atom;
93 valid = true;
94 do {
95 if (!valid) cout << Verbose(0) << "Resulting position out of cell." << endl;
96 cout << Verbose(0) << "Enter reference coordinates." << endl;
97 x.AskPosition(mol->cell_size, true);
98 cout << Verbose(0) << "Enter relative coordinates." << endl;
99 first->x.AskPosition(mol->cell_size, false);
100 first->x.AddVector((const vector *)&x);
101 cout << Verbose(0) << "\n";
102 } while (!(valid = mol->CheckBounds((const vector *)&first->x)));
103 first->type = periode->AskElement(); // give type
104 mol->AddAtom(first); // add to molecule
105 break;
106
107 case 'c': // relative coordinates of atom wrt to already placed atom
108 first = new atom;
109 valid = true;
110 do {
111 if (!valid) cout << Verbose(0) << "Resulting position out of cell." << endl;
112 second = mol->AskAtom("Enter atom number: ");
113 cout << Verbose(0) << "Enter relative coordinates." << endl;
114 first->x.AskPosition(mol->cell_size, false);
115 for (int i=NDIM;i--;) {
116 first->x.x[i] += second->x.x[i];
117 }
118 } while (!(valid = mol->CheckBounds((const vector *)&first->x)));
119 first->type = periode->AskElement(); // give type
120 mol->AddAtom(first); // add to molecule
121 break;
122
123 case 'd': // two atoms, two angles and a distance
124 first = new atom;
125 valid = true;
126 do {
127 if (!valid) {
128 cout << Verbose(0) << "Resulting coordinates out of cell - ";
129 first->x.Output((ofstream *)&cout);
130 cout << Verbose(0) << endl;
131 }
132 cout << Verbose(0) << "First, we need two atoms, the first atom is the central, while the second is the outer one." << endl;
133 second = mol->AskAtom("Enter central atom: ");
134 third = mol->AskAtom("Enter second atom (specifying the axis for first angle): ");
135 fourth = mol->AskAtom("Enter third atom (specifying a plane for second angle): ");
136 a = ask_value("Enter distance between central (first) and new atom: ");
137 b = ask_value("Enter angle between new, first and second atom (degrees): ");
138 b *= M_PI/180.;
139 bound(&b, 0., 2.*M_PI);
140 c = ask_value("Enter second angle between new and normal vector of plane defined by first, second and third atom (degrees): ");
141 c *= M_PI/180.;
142 bound(&c, -M_PI, M_PI);
143 cout << Verbose(0) << "radius: " << a << "\t phi: " << b*180./M_PI << "\t theta: " << c*180./M_PI << endl;
144/*
145 second->Output(1,1,(ofstream *)&cout);
146 third->Output(1,2,(ofstream *)&cout);
147 fourth->Output(1,3,(ofstream *)&cout);
148 n.MakeNormalVector((const vector *)&second->x, (const vector *)&third->x, (const vector *)&fourth->x);
149 x.CopyVector(&second->x);
150 x.SubtractVector(&third->x);
151 x.CopyVector(&fourth->x);
152 x.SubtractVector(&third->x);
153
154 if (!z.SolveSystem(&x,&y,&n, b, c, a)) {
155 cout << Verbose(0) << "Failure solving self-dependent linear system!" << endl;
156 continue;
157 }
158 cout << Verbose(0) << "resulting relative coordinates: ";
159 z.Output((ofstream *)&cout);
160 cout << Verbose(0) << endl;
161 */
162 // calc axis vector
163 x.CopyVector(&second->x);
164 x.SubtractVector(&third->x);
165 x.Normalize();
166 cout << "x: ",
167 x.Output((ofstream *)&cout);
168 cout << endl;
169 z.MakeNormalVector(&second->x,&third->x,&fourth->x);
170 cout << "z: ",
171 z.Output((ofstream *)&cout);
172 cout << endl;
173 y.MakeNormalVector(&x,&z);
174 cout << "y: ",
175 y.Output((ofstream *)&cout);
176 cout << endl;
177
178 // rotate vector around first angle
179 first->x.CopyVector(&x);
180 first->x.RotateVector(&z,b - M_PI);
181 cout << "Rotated vector: ",
182 first->x.Output((ofstream *)&cout);
183 cout << endl;
184 // remove the projection onto the rotation plane of the second angle
185 n.CopyVector(&y);
186 n.Scale(first->x.Projection(&y));
187 cout << "N1: ",
188 n.Output((ofstream *)&cout);
189 cout << endl;
190 first->x.SubtractVector(&n);
191 cout << "Subtracted vector: ",
192 first->x.Output((ofstream *)&cout);
193 cout << endl;
194 n.CopyVector(&z);
195 n.Scale(first->x.Projection(&z));
196 cout << "N2: ",
197 n.Output((ofstream *)&cout);
198 cout << endl;
199 first->x.SubtractVector(&n);
200 cout << "2nd subtracted vector: ",
201 first->x.Output((ofstream *)&cout);
202 cout << endl;
203
204 // rotate another vector around second angle
205 n.CopyVector(&y);
206 n.RotateVector(&x,c - M_PI);
207 cout << "2nd Rotated vector: ",
208 n.Output((ofstream *)&cout);
209 cout << endl;
210
211 // add the two linear independent vectors
212 first->x.AddVector(&n);
213 first->x.Normalize();
214 first->x.Scale(a);
215 first->x.AddVector(&second->x);
216
217 cout << Verbose(0) << "resulting coordinates: ";
218 first->x.Output((ofstream *)&cout);
219 cout << Verbose(0) << endl;
220 } while (!(valid = mol->CheckBounds((const vector *)&first->x)));
221 first->type = periode->AskElement(); // give type
222 mol->AddAtom(first); // add to molecule
223 break;
224
225 case 'e': // least square distance position to a set of atoms
226 first = new atom;
227 atoms = new (vector*[128]);
228 valid = true;
229 for(int i=128;i--;)
230 atoms[i] = NULL;
231 int i=0, j=0;
232 cout << Verbose(0) << "Now we need at least three molecules.\n";
233 do {
234 cout << Verbose(0) << "Enter " << i+1 << "th atom: ";
235 cin >> j;
236 if (j != -1) {
237 second = mol->FindAtom(j);
238 atoms[i++] = &(second->x);
239 }
240 } while ((j != -1) && (i<128));
241 if (i >= 2) {
242 first->x.LSQdistance(atoms, i);
243
244 first->x.Output((ofstream *)&cout);
245 first->type = periode->AskElement(); // give type
246 mol->AddAtom(first); // add to molecule
247 } else {
248 delete first;
249 cout << Verbose(0) << "Please enter at least two vectors!\n";
250 }
251 break;
252 };
253};
254
255/** Submenu for centering the atoms in the molecule.
256 * \param *mol the molecule with all the atoms
257 */
258static void CenterAtoms(molecule *mol)
259{
260 vector x, y;
261 char choice; // menu choice char
262
263 cout << Verbose(0) << "===========CENTER ATOMS=========================" << endl;
264 cout << Verbose(0) << " a - on origin" << endl;
265 cout << Verbose(0) << " b - on center of gravity" << endl;
266 cout << Verbose(0) << " c - within box with additional boundary" << endl;
267 cout << Verbose(0) << " d - within given simulation box" << endl;
268 cout << Verbose(0) << "all else - go back" << endl;
269 cout << Verbose(0) << "===============================================" << endl;
270 cout << Verbose(0) << "INPUT: ";
271 cin >> choice;
272
273 switch (choice) {
274 default:
275 cout << Verbose(0) << "Not a valid choice." << endl;
276 break;
277 case 'a':
278 cout << Verbose(0) << "Centering atoms in config file on origin." << endl;
279 mol->CenterOrigin((ofstream *)&cout, &x);
280 break;
281 case 'b':
282 cout << Verbose(0) << "Centering atoms in config file on center of gravity." << endl;
283 mol->CenterGravity((ofstream *)&cout, &x);
284 break;
285 case 'c':
286 cout << Verbose(0) << "Centering atoms in config file within given additional boundary." << endl;
287 for (int i=0;i<NDIM;i++) {
288 cout << Verbose(0) << "Enter axis " << i << " boundary: ";
289 cin >> y.x[i];
290 }
291 mol->CenterEdge((ofstream *)&cout, &x); // make every coordinate positive
292 mol->Translate(&y); // translate by boundary
293 mol->SetBoxDimension(&(x+y*2)); // update Box of atoms by boundary
294 break;
295 case 'd':
296 cout << Verbose(1) << "Centering atoms in config file within given simulation box." << endl;
297 for (int i=0;i<NDIM;i++) {
298 cout << Verbose(0) << "Enter axis " << i << " boundary: ";
299 cin >> x.x[i];
300 }
301 // center
302 mol->CenterInBox((ofstream *)&cout, &x);
303 // update Box of atoms by boundary
304 mol->SetBoxDimension(&x);
305 break;
306 }
307};
308
309/** Submenu for aligning the atoms in the molecule.
310 * \param *periode periodentafel
311 * \param *mol the molecule with all the atoms
312 */
313static void AlignAtoms(periodentafel *periode, molecule *mol)
314{
315 atom *first, *second, *third;
316 vector x,n;
317 char choice; // menu choice char
318
319 cout << Verbose(0) << "===========ALIGN ATOMS=========================" << endl;
320 cout << Verbose(0) << " a - state three atoms defining align plane" << endl;
321 cout << Verbose(0) << " b - state alignment vector" << endl;
322 cout << Verbose(0) << " c - state two atoms in alignment direction" << endl;
323 cout << Verbose(0) << " d - align automatically by least square fit" << endl;
324 cout << Verbose(0) << "all else - go back" << endl;
325 cout << Verbose(0) << "===============================================" << endl;
326 cout << Verbose(0) << "INPUT: ";
327 cin >> choice;
328
329 switch (choice) {
330 default:
331 case 'a': // three atoms defining mirror plane
332 first = mol->AskAtom("Enter first atom: ");
333 second = mol->AskAtom("Enter second atom: ");
334 third = mol->AskAtom("Enter third atom: ");
335
336 n.MakeNormalVector((const vector *)&first->x,(const vector *)&second->x,(const vector *)&third->x);
337 break;
338 case 'b': // normal vector of mirror plane
339 cout << Verbose(0) << "Enter normal vector of mirror plane." << endl;
340 n.AskPosition(mol->cell_size,0);
341 n.Normalize();
342 break;
343 case 'c': // three atoms defining mirror plane
344 first = mol->AskAtom("Enter first atom: ");
345 second = mol->AskAtom("Enter second atom: ");
346
347 n.CopyVector((const vector *)&first->x);
348 n.SubtractVector((const vector *)&second->x);
349 n.Normalize();
350 break;
351 case 'd':
352 char shorthand[4];
353 vector a;
354 struct lsq_params param;
355 do {
356 fprintf(stdout, "Enter the element of atoms to be chosen: ");
357 fscanf(stdin, "%3s", shorthand);
358 } while ((param.type = periode->FindElement(shorthand)) == NULL);
359 cout << Verbose(0) << "Element is " << param.type->name << endl;
360 mol->GetAlignVector(&param);
361 for (int i=NDIM;i--;) {
362 x.x[i] = gsl_vector_get(param.x,i);
363 n.x[i] = gsl_vector_get(param.x,i+NDIM);
364 }
365 gsl_vector_free(param.x);
366 cout << Verbose(0) << "Offset vector: ";
367 x.Output((ofstream *)&cout);
368 cout << Verbose(0) << endl;
369 n.Normalize();
370 break;
371 };
372 cout << Verbose(0) << "Alignment vector: ";
373 n.Output((ofstream *)&cout);
374 cout << Verbose(0) << endl;
375 mol->Align(&n);
376};
377
378/** Submenu for mirroring the atoms in the molecule.
379 * \param *mol the molecule with all the atoms
380 */
381static void MirrorAtoms(molecule *mol)
382{
383 atom *first, *second, *third;
384 vector n;
385 char choice; // menu choice char
386
387 cout << Verbose(0) << "===========MIRROR ATOMS=========================" << endl;
388 cout << Verbose(0) << " a - state three atoms defining mirror plane" << endl;
389 cout << Verbose(0) << " b - state normal vector of mirror plane" << endl;
390 cout << Verbose(0) << " c - state two atoms in normal direction" << endl;
391 cout << Verbose(0) << "all else - go back" << endl;
392 cout << Verbose(0) << "===============================================" << endl;
393 cout << Verbose(0) << "INPUT: ";
394 cin >> choice;
395
396 switch (choice) {
397 default:
398 case 'a': // three atoms defining mirror plane
399 first = mol->AskAtom("Enter first atom: ");
400 second = mol->AskAtom("Enter second atom: ");
401 third = mol->AskAtom("Enter third atom: ");
402
403 n.MakeNormalVector((const vector *)&first->x,(const vector *)&second->x,(const vector *)&third->x);
404 break;
405 case 'b': // normal vector of mirror plane
406 cout << Verbose(0) << "Enter normal vector of mirror plane." << endl;
407 n.AskPosition(mol->cell_size,0);
408 n.Normalize();
409 break;
410 case 'c': // three atoms defining mirror plane
411 first = mol->AskAtom("Enter first atom: ");
412 second = mol->AskAtom("Enter second atom: ");
413
414 n.CopyVector((const vector *)&first->x);
415 n.SubtractVector((const vector *)&second->x);
416 n.Normalize();
417 break;
418 };
419 cout << Verbose(0) << "Normal vector: ";
420 n.Output((ofstream *)&cout);
421 cout << Verbose(0) << endl;
422 mol->Mirror((const vector *)&n);
423};
424
425/** Submenu for removing the atoms from the molecule.
426 * \param *mol the molecule with all the atoms
427 */
428static void RemoveAtoms(molecule *mol)
429{
430 atom *first, *second;
431 int axis;
432 double tmp1, tmp2;
433 char choice; // menu choice char
434
435 cout << Verbose(0) << "===========REMOVE ATOMS=========================" << endl;
436 cout << Verbose(0) << " a - state atom for removal by number" << endl;
437 cout << Verbose(0) << " b - keep only in radius around atom" << endl;
438 cout << Verbose(0) << " c - remove this with one axis greater value" << endl;
439 cout << Verbose(0) << "all else - go back" << endl;
440 cout << Verbose(0) << "===============================================" << endl;
441 cout << Verbose(0) << "INPUT: ";
442 cin >> choice;
443
444 switch (choice) {
445 default:
446 case 'a':
447 if (mol->RemoveAtom(mol->AskAtom("Enter number of atom within molecule: ")))
448 cout << Verbose(1) << "Atom removed." << endl;
449 else
450 cout << Verbose(1) << "Atom not found." << endl;
451 break;
452 case 'b':
453 second = mol->AskAtom("Enter number of atom as reference point: ");
454 cout << Verbose(0) << "Enter radius: ";
455 cin >> tmp1;
456 first = mol->start;
457 while(first->next != mol->end) {
458 first = first->next;
459 if (first->x.Distance((const vector *)&second->x) > tmp1*tmp1) // distance to first above radius ...
460 mol->RemoveAtom(first);
461 }
462 break;
463 case 'c':
464 cout << Verbose(0) << "Which axis is it: ";
465 cin >> axis;
466 cout << Verbose(0) << "Left inward boundary: ";
467 cin >> tmp1;
468 cout << Verbose(0) << "Right inward boundary: ";
469 cin >> tmp2;
470 first = mol->start;
471 while(first->next != mol->end) {
472 first = first->next;
473 if ((first->x.x[axis] > tmp2) || (first->x.x[axis] < tmp1)) // out of boundary ...
474 mol->RemoveAtom(first);
475 }
476 break;
477 };
478 //mol->Output((ofstream *)&cout);
479 choice = 'r';
480};
481
482/** Submenu for measuring out the atoms in the molecule.
483 * \param *periode periodentafel
484 * \param *mol the molecule with all the atoms
485 */
486static void MeasureAtoms(periodentafel *periode, molecule *mol, config *configuration)
487{
488 atom *first, *second, *third;
489 vector x,y;
490 double min[256], tmp1, tmp2, tmp3;
491 int Z;
492 char choice; // menu choice char
493
494 cout << Verbose(0) << "===========MEASURE ATOMS=========================" << endl;
495 cout << Verbose(0) << " a - calculate bond length between one atom and all others" << endl;
496 cout << Verbose(0) << " b - calculate bond length between two atoms" << endl;
497 cout << Verbose(0) << " c - calculate bond angle" << endl;
498 cout << Verbose(0) << " d - calculate principal axis of the system" << endl;
499 cout << Verbose(0) << " e - calculate volume of the convex envelope" << endl;
500 cout << Verbose(0) << "all else - go back" << endl;
501 cout << Verbose(0) << "===============================================" << endl;
502 cout << Verbose(0) << "INPUT: ";
503 cin >> choice;
504
505 switch(choice) {
506 default:
507 cout << Verbose(1) << "Not a valid choice." << endl;
508 break;
509 case 'a':
510 first = mol->AskAtom("Enter first atom: ");
511 for (int i=MAX_ELEMENTS;i--;)
512 min[i] = 0.;
513
514 second = mol->start;
515 while ((second->next != mol->end)) {
516 second = second->next; // advance
517 Z = second->type->Z;
518 tmp1 = 0.;
519 if (first != second) {
520 x.CopyVector((const vector *)&first->x);
521 x.SubtractVector((const vector *)&second->x);
522 tmp1 = x.Norm();
523 }
524 if ((tmp1 != 0.) && ((min[Z] == 0.) || (tmp1 < min[Z]))) min[Z] = tmp1;
525 //cout << Verbose(0) << "Bond length between Atom " << first->nr << " and " << second->nr << ": " << tmp1 << " a.u." << endl;
526 }
527 for (int i=MAX_ELEMENTS;i--;)
528 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;
529 break;
530
531 case 'b':
532 first = mol->AskAtom("Enter first atom: ");
533 second = mol->AskAtom("Enter second atom: ");
534 for (int i=NDIM;i--;)
535 min[i] = 0.;
536 x.CopyVector((const vector *)&first->x);
537 x.SubtractVector((const vector *)&second->x);
538 tmp1 = x.Norm();
539 cout << Verbose(1) << "Distance vector is ";
540 x.Output((ofstream *)&cout);
541 cout << "." << endl << "Norm of distance is " << tmp1 << "." << endl;
542 break;
543
544 case 'c':
545 cout << Verbose(0) << "Evaluating bond angle between three - first, central, last - atoms." << endl;
546 first = mol->AskAtom("Enter first atom: ");
547 second = mol->AskAtom("Enter central atom: ");
548 third = mol->AskAtom("Enter last atom: ");
549 tmp1 = tmp2 = tmp3 = 0.;
550 x.CopyVector((const vector *)&first->x);
551 x.SubtractVector((const vector *)&second->x);
552 y.CopyVector((const vector *)&third->x);
553 y.SubtractVector((const vector *)&second->x);
554 cout << Verbose(0) << "Bond angle between first atom Nr." << first->nr << ", central atom Nr." << second->nr << " and last atom Nr." << third->nr << ": ";
555 cout << Verbose(0) << (acos(x.ScalarProduct((const vector *)&y)/(y.Norm()*x.Norm()))/M_PI*180.) << " degrees" << endl;
556 break;
557 case 'd':
558 cout << Verbose(0) << "Evaluating prinicipal axis." << endl;
559 cout << Verbose(0) << "Shall we rotate? [0/1]: ";
560 cin >> Z;
561 if ((Z >=0) && (Z <=1))
562 mol->PrincipalAxisSystem((ofstream *)&cout, (bool)Z);
563 else
564 mol->PrincipalAxisSystem((ofstream *)&cout, false);
565 break;
566 case 'e':
567 cout << Verbose(0) << "Evaluating volume of the convex envelope.";
568 mol->VolumeOfConvexEnvelope((ofstream *)&cout, configuration->GetIsAngstroem());
569 break;
570 }
571};
572
573/** Submenu for measuring out the atoms in the molecule.
574 * \param *mol the molecule with all the atoms
575 * \param *configuration configuration structure for the to be written config files of all fragments
576 */
577static void FragmentAtoms(molecule *mol, config *configuration)
578{
579 int Order1;
580 clock_t start, end;
581
582 cout << Verbose(0) << "Fragmenting molecule with current connection matrix ..." << endl;
583 cout << Verbose(0) << "What's the desired bond order: ";
584 cin >> Order1;
585 if (mol->first->next != mol->last) { // there are bonds
586 start = clock();
587 mol->FragmentMolecule((ofstream *)&cout, Order1, configuration);
588 end = clock();
589 cout << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl;
590 } else
591 cout << Verbose(0) << "Connection matrix has not yet been generated!" << endl;
592};
593
594/********************************************** Test routine **************************************/
595
596/** Is called always as option 'T' in the menu.
597 */
598static void testroutine(molecule *mol)
599{
600 // the current test routine checks the functionality of the KeySet&Graph concept:
601 // We want to have a multiindex (the KeySet) describing a unique subgraph
602 atom *Walker = mol->start;
603 int i, comp, counter=0;
604
605 // generate some KeySets
606 cout << "Generating KeySets." << endl;
607 KeySet TestSets[mol->AtomCount+1];
608 i=1;
609 while (Walker->next != mol->end) {
610 Walker = Walker->next;
611 for (int j=0;j<i;j++) {
612 TestSets[j].insert(Walker->nr);
613 }
614 i++;
615 }
616 cout << "Testing insertion of already present item in KeySets." << endl;
617 KeySetTestPair test;
618 test = TestSets[mol->AtomCount-1].insert(Walker->nr);
619 if (test.second) {
620 cout << Verbose(1) << "Insertion worked?!" << endl;
621 } else {
622 cout << Verbose(1) << "Insertion rejected: Present object is " << (*test.first) << "." << endl;
623 }
624 TestSets[mol->AtomCount].insert(mol->end->previous->nr);
625 TestSets[mol->AtomCount].insert(mol->end->previous->previous->previous->nr);
626
627 // constructing Graph structure
628 cout << "Generating Subgraph class." << endl;
629 Graph Subgraphs;
630
631 // insert KeySets into Subgraphs
632 cout << "Inserting KeySets into Subgraph class." << endl;
633 for (int j=0;j<mol->AtomCount;j++) {
634 Subgraphs.insert(GraphPair (TestSets[j],pair<int, double>(counter++, 1.)));
635 }
636 cout << "Testing insertion of already present item in Subgraph." << endl;
637 GraphTestPair test2;
638 test2 = Subgraphs.insert(GraphPair (TestSets[mol->AtomCount],pair<int, double>(counter++, 1.)));
639 if (test2.second) {
640 cout << Verbose(1) << "Insertion worked?!" << endl;
641 } else {
642 cout << Verbose(1) << "Insertion rejected: Present object is " << (*(test2.first)).second.first << "." << endl;
643 }
644
645 // show graphs
646 cout << "Showing Subgraph's contents, checking that it's sorted." << endl;
647 Graph::iterator A = Subgraphs.begin();
648 while (A != Subgraphs.end()) {
649 cout << (*A).second.first << ": ";
650 KeySet::iterator key = (*A).first.begin();
651 comp = -1;
652 while (key != (*A).first.end()) {
653 if ((*key) > comp)
654 cout << (*key) << " ";
655 else
656 cout << (*key) << "! ";
657 comp = (*key);
658 key++;
659 }
660 cout << endl;
661 A++;
662 }
663};
664
665/** Tries given filename or standard on saving the config file.
666 * \param *ConfigFileName name of file
667 * \param *configuration pointer to configuration structure with all the values
668 * \param *periode pointer to periodentafel structure with all the elements
669 * \param *mol pointer to molecule structure with all the atoms and coordinates
670 */
671static void SaveConfig(char *ConfigFileName, config *configuration, periodentafel *periode, molecule *mol)
672{
673 char filename[MAXSTRINGSIZE];
674 ofstream output;
675
676 cout << Verbose(0) << "Storing configuration ... " << endl;
677 // get correct valence orbitals
678 mol->CalculateOrbitals(*configuration);
679 configuration->InitMaxMinStopStep = configuration->MaxMinStopStep = configuration->MaxPsiDouble;
680 if (ConfigFileName != NULL) {
681 output.open(ConfigFileName, ios::trunc);
682 } else if (strlen(configuration->configname) != 0) {
683 output.open(configuration->configname, ios::trunc);
684 } else {
685 output.open(DEFAULTCONFIG, ios::trunc);
686 }
687 if (configuration->Save(&output, periode, mol))
688 cout << Verbose(0) << "Saving of config file successful." << endl;
689 else
690 cout << Verbose(0) << "Saving of config file failed." << endl;
691 output.close();
692 output.clear();
693 // and save to xyz file
694 if (ConfigFileName != NULL) {
695 strcpy(filename, ConfigFileName);
696 strcat(filename, ".xyz");
697 output.open(filename, ios::trunc);
698 }
699 if (output == NULL) {
700 strcpy(filename,"main_pcp_linux");
701 strcat(filename, ".xyz");
702 output.open(filename, ios::trunc);
703 }
704 if (mol->OutputXYZ(&output))
705 cout << Verbose(0) << "Saving of XYZ file successful." << endl;
706 else
707 cout << Verbose(0) << "Saving of XYZ file failed." << endl;
708 output.close();
709 output.clear();
710
711 if (!strcmp(configuration->configpath, configuration->GetDefaultPath())) {
712 cerr << "WARNING: config is found under different path then stated in config file::defaultpath!" << endl;
713 }
714};
715
716/** Parses the command line options.
717 * \param argc argument count
718 * \param **argv arguments array
719 * \param *mol molecule structure
720 * \param *periode elements structure
721 * \param configuration config file structure
722 * \param *ConfigFileName pointer to config file name in **argv
723 * \param *PathToDatabases pointer to db's path in **argv
724 * \return exit code (0 - successful, all else - something's wrong)
725 */
726static int ParseCommandLineOptions(int argc, char **argv, molecule *&mol, periodentafel *&periode, config& configuration, char *&ConfigFileName, char *&PathToDatabases)
727{
728 element *finder;
729 vector x,y,z,n; // coordinates for absolute point in cell volume
730 double *factor; // unit factor if desired
731 ifstream test;
732 ofstream output;
733 string line;
734 atom *first;
735 int ExitFlag = 0;
736 int j;
737 enum ConfigStatus config_present = absent;
738 clock_t start,end;
739 int argptr;
740 PathToDatabases = LocalPath;
741
742 if (argc > 1) { // config file specified as option
743 // 1. : Parse options that just set variables or print help
744 argptr = 1;
745 do {
746 if (argv[argptr][0] == '-') {
747 cout << Verbose(0) << "Recognized command line argument: " << argv[argptr][1] << ".\n";
748 argptr++;
749 switch(argv[argptr-1][1]) {
750 case 'h':
751 case 'H':
752 case '?':
753 cout << "MoleCuilder suite" << endl << "==================" << endl << endl;
754 cout << "Usage: " << argv[0] << "[config file] [-{acefpsthH?vfrp}] [further arguments]" << endl;
755 cout << "or simply " << argv[0] << " without arguments for interactive session." << endl;
756 cout << "\t-a Z x1 x2 x3\tAdd new atom of element Z at coordinates (x1,x2,x3)." << endl;
757 cout << "\t-b x1 x2 x3\tCenter atoms in domain with given edge lengths of (x1,x2,x3)." << endl;
758 cout << "\t-c x1 x2 x3\tCenter atoms in domain with a minimum distance to boundary of (x1,x2,x3)." << endl;
759 cout << "\t-e <file>\tSets the databases path to be parsed (default: ./)." << endl;
760 cout << "\t-f <dist> <order>\tFragments the molecule in BOSSANOVA manner and stores config files in same dir as config." << endl;
761 cout << "\t-h/-H/-?\tGive this help screen." << endl;
762 cout << "\t-m\tAlign in PAS with greatest EV along z axis." << endl;
763 cout << "\t-n\tFast parsing (i.e. no trajectories are looked for)." << endl;
764 cout << "\t-p <file>\tParse given xyz file and create raw config file from it." << endl;
765 cout << "\t-r\t\tConvert file from an old pcp syntax." << endl;
766 cout << "\t-t x1 x2 x3\tTranslate all atoms by this vector (x1,x2,x3)." << endl;
767 cout << "\t-s x1 x2 x3\tScale all atom coordinates by this vector (x1,x2,x3)." << endl;
768 cout << "\t-v/-V\t\tGives version information." << endl;
769 cout << "Note: config files must not begin with '-' !" << endl;
770 delete(mol);
771 delete(periode);
772 return (1);
773 break;
774 case 'v':
775 case 'V':
776 cout << argv[0] << " " << VERSIONSTRING << endl;
777 cout << "Build your own molecule position set." << endl;
778 delete(mol);
779 delete(periode);
780 return (1);
781 break;
782 case 'e':
783 cout << "Using " << argv[argptr] << " as elements database." << endl;
784 PathToDatabases = argv[argptr];
785 argptr+=1;
786 break;
787 case 'n':
788 cout << "I won't parse trajectories." << endl;
789 configuration.FastParsing = true;
790 default: // no match? Step on
791 argptr++;
792 break;
793 }
794 } else
795 argptr++;
796 } while (argptr < argc);
797
798 // 2. Parse the element database
799 if (periode->LoadPeriodentafel(PathToDatabases)) {
800 cout << Verbose(0) << "Element list loaded successfully." << endl;
801 periode->Output((ofstream *)&cout);
802 } else
803 cout << Verbose(0) << "Element list loading failed." << endl;
804
805 // 3. Find config file name and parse if possible
806 if (argv[1][0] != '-') {
807 cout << Verbose(0) << "Config file given." << endl;
808 test.open(argv[1], ios::in);
809 if (test == NULL) {
810 //return (1);
811 output.open(argv[1], ios::out);
812 if (output == NULL) {
813 cout << Verbose(1) << "Specified config file " << argv[1] << " not found." << endl;
814 config_present = absent;
815 } else {
816 cout << "Empty configuration file." << endl;
817 ConfigFileName = argv[1];
818 config_present = empty;
819 output.close();
820 }
821 } else {
822 test.close();
823 ConfigFileName = argv[1];
824 cout << Verbose(1) << "Specified config file found, parsing ... ";
825 switch (configuration.TestSyntax(ConfigFileName, periode, mol)) {
826 case 1:
827 cout << "new syntax." << endl;
828 configuration.Load(ConfigFileName, periode, mol);
829 config_present = present;
830 break;
831 case 0:
832 cout << "old syntax." << endl;
833 configuration.LoadOld(ConfigFileName, periode, mol);
834 config_present = present;
835 break;
836 default:
837 cout << "Unknown syntax or empty, yet present file." << endl;
838 config_present = empty;
839 }
840 }
841 } else
842 config_present = absent;
843
844 // 4. parse again through options, now for those depending on elements db and config presence
845 argptr = 1;
846 do {
847 cout << "Current Command line argument: " << argv[argptr] << "." << endl;
848 if (argv[argptr][0] == '-') {
849 argptr++;
850 if ((config_present == present) || (config_present == empty)) {
851 switch(argv[argptr-1][1]) {
852 case 'p':
853 ExitFlag = 1;
854 cout << Verbose(1) << "Parsing xyz file for new atoms." << endl;
855 if (!mol->AddXYZFile(argv[argptr]))
856 cout << Verbose(2) << "File not found." << endl;
857 else
858 cout << Verbose(2) << "File found and parsed." << endl;
859 config_present = present;
860 break;
861 default: // no match? Don't step on (this is done in next switch's default)
862 break;
863 }
864 }
865 if (config_present == present) {
866 switch(argv[argptr-1][1]) {
867 case 't':
868 ExitFlag = 1;
869 cout << Verbose(1) << "Translating all ions to new origin." << endl;
870 for (int i=NDIM;i--;)
871 x.x[i] = atof(argv[argptr+i]);
872 mol->Translate((const vector *)&x);
873 argptr+=3;
874 break;
875 case 'a':
876 ExitFlag = 1;
877 cout << Verbose(1) << "Adding new atom." << endl;
878 first = new atom;
879 for (int i=NDIM;i--;)
880 first->x.x[i] = atof(argv[argptr+1+i]);
881 finder = periode->start;
882 while (finder != periode->end) {
883 finder = finder->next;
884 if (strncmp(finder->symbol,argv[argptr+1],3) == 0) {
885 first->type = finder;
886 break;
887 }
888 }
889 mol->AddAtom(first); // add to molecule
890 argptr+=4;
891 break;
892 case 's':
893 ExitFlag = 1;
894 j = -1;
895 cout << Verbose(1) << "Scaling all ion positions by factor." << endl;
896 factor = new double[NDIM];
897 factor[0] = atof(argv[argptr]);
898 if (argc > argptr+1)
899 argptr++;
900 factor[1] = atof(argv[argptr]);
901 if (argc > argptr+1)
902 argptr++;
903 factor[2] = atof(argv[argptr]);
904 mol->Scale(&factor);
905 for (int i=0;i<NDIM;i++) {
906 j += i+1;
907 x.x[i] = atof(argv[NDIM+i]);
908 mol->cell_size[j]*=factor[i];
909 }
910 delete[](factor);
911 argptr+=1;
912 break;
913 case 'b':
914 ExitFlag = 1;
915 j = -1;
916 cout << Verbose(1) << "Centering atoms in config file within given simulation box." << endl;
917 j=-1;
918 for (int i=0;i<NDIM;i++) {
919 j += i+1;
920 x.x[i] = atof(argv[argptr++]);
921 mol->cell_size[j] += x.x[i]*2.;
922 }
923 // center
924 mol->CenterInBox((ofstream *)&cout, &x);
925 // update Box of atoms by boundary
926 mol->SetBoxDimension(&x);
927 break;
928 case 'c':
929 ExitFlag = 1;
930 j = -1;
931 cout << Verbose(1) << "Centering atoms in config file within given additional boundary." << endl;
932 // make every coordinate positive
933 mol->CenterEdge((ofstream *)&cout, &x);
934 // update Box of atoms by boundary
935 mol->SetBoxDimension(&x);
936 // translate each coordinate by boundary
937 j=-1;
938 for (int i=0;i<NDIM;i++) {
939 j += i+1;
940 x.x[i] = atof(argv[argptr++]);
941 mol->cell_size[j] += x.x[i]*2.;
942 }
943 mol->Translate((const vector *)&x);
944 break;
945 case 'r':
946 ExitFlag = 1;
947 cout << Verbose(1) << "Converting config file from supposed old to new syntax." << endl;
948 break;
949 case 'f':
950 if (ExitFlag ==0) ExitFlag = 2; // only set if not already by other command line switch
951 cout << "Fragmenting molecule with bond distance " << argv[argptr] << " angstroem, order of " << argv[argptr+1] << "." << endl;
952 if (argc >= argptr+2) {
953 cout << Verbose(0) << "Creating connection matrix..." << endl;
954 start = clock();
955 mol->CreateAdjacencyList((ofstream *)&cout, atof(argv[argptr++]), configuration.GetIsAngstroem());
956 cout << Verbose(0) << "Fragmenting molecule with current connection matrix ..." << endl;
957 if (mol->first->next != mol->last) {
958 mol->FragmentMolecule((ofstream *)&cout, atoi(argv[argptr]), &configuration);
959 }
960 end = clock();
961 cout << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl;
962 argptr+=1;
963 } else {
964 cerr << "Not enough arguments for fragmentation: -f <max. bond distance> <bond order>" << endl;
965 }
966 break;
967 case 'm':
968 ExitFlag = 1;
969 cout << Verbose(0) << "Evaluating prinicipal axis." << endl;
970 mol->PrincipalAxisSystem((ofstream *)&cout, true);
971 break;
972 default: // no match? Step on
973 argptr++;
974 break;
975 }
976 }
977 } else argptr++;
978 } while (argptr < argc);
979 if (ExitFlag == 1) // 1 means save and exit
980 SaveConfig(ConfigFileName, &configuration, periode, mol);
981 if (ExitFlag >= 1) { // 2 means just exit
982 delete(mol);
983 delete(periode);
984 return (1);
985 }
986 } else { // no arguments, hence scan the elements db
987 if (periode->LoadPeriodentafel(PathToDatabases))
988 cout << Verbose(0) << "Element list loaded successfully." << endl;
989 else
990 cout << Verbose(0) << "Element list loading failed." << endl;
991 configuration.RetrieveConfigPathAndName("main_pcp_linux");
992 }
993 return(0);
994};
995
996/********************************************** Main routine **************************************/
997
998int main(int argc, char **argv)
999{
1000 periodentafel *periode = new periodentafel; // and a period table of all elements
1001 molecule *mol = new molecule(periode); // first we need an empty molecule
1002 config configuration;
1003 double tmp1;
1004 double bond, min_bond;
1005 atom *first, *second;
1006 char choice; // menu choice char
1007 vector x,y,z,n; // coordinates for absolute point in cell volume
1008 double *factor; // unit factor if desired
1009 bool valid; // flag if input was valid or not
1010 ifstream test;
1011 ofstream output;
1012 string line;
1013 char filename[MAXSTRINGSIZE];
1014 char *ConfigFileName = NULL;
1015 char *ElementsFileName = NULL;
1016 int Z;
1017 int j, axis, count, faktor;
1018 int *MinimumRingSize = NULL;
1019 MoleculeLeafClass *Subgraphs = NULL;
1020 clock_t start,end;
1021 element **Elements;
1022 vector **Vectors;
1023
1024 // =========================== PARSE COMMAND LINE OPTIONS ====================================
1025 j = ParseCommandLineOptions(argc, argv, mol, periode, configuration, ConfigFileName, ElementsFileName);
1026 if (j == 1) return 0; // just for -v and -h options
1027 if (j) return j; // something went wrong
1028
1029 // General stuff
1030 if (mol->cell_size[0] == 0.) {
1031 cout << Verbose(0) << "enter lower triadiagonal form of basis matrix" << endl << endl;
1032 for (int i=0;i<6;i++) {
1033 cout << Verbose(1) << "Cell size" << i << ": ";
1034 cin >> mol->cell_size[i];
1035 }
1036 }
1037
1038 // =========================== START INTERACTIVE SESSION ====================================
1039
1040 // now the main construction loop
1041 cout << Verbose(0) << endl << "Now comes the real construction..." << endl;
1042 do {
1043 cout << Verbose(0) << endl << endl;
1044 cout << Verbose(0) << "============Element list=======================" << endl;
1045 mol->Checkout((ofstream *)&cout);
1046 cout << Verbose(0) << "============Atom list==========================" << endl;
1047 mol->Output((ofstream *)&cout);
1048 cout << Verbose(0) << "============Menu===============================" << endl;
1049 cout << Verbose(0) << "a - add an atom" << endl;
1050 cout << Verbose(0) << "r - remove an atom" << endl;
1051 cout << Verbose(0) << "b - scale a bond between atoms" << endl;
1052 cout << Verbose(0) << "u - change an atoms element" << endl;
1053 cout << Verbose(0) << "l - measure lengths, angles, ... for an atom" << endl;
1054 cout << Verbose(0) << "-----------------------------------------------" << endl;
1055 cout << Verbose(0) << "p - Parse xyz file" << endl;
1056 cout << Verbose(0) << "e - edit the current configuration" << endl;
1057 cout << Verbose(0) << "o - create connection matrix" << endl;
1058 cout << Verbose(0) << "f - fragment molecule many-body bond order style" << endl;
1059 cout << Verbose(0) << "-----------------------------------------------" << endl;
1060 cout << Verbose(0) << "d - duplicate molecule/periodic cell" << endl;
1061 cout << Verbose(0) << "i - realign molecule" << endl;
1062 cout << Verbose(0) << "m - mirror all molecules" << endl;
1063 cout << Verbose(0) << "t - translate molecule by vector" << endl;
1064 cout << Verbose(0) << "c - scale by unit transformation" << endl;
1065 cout << Verbose(0) << "g - center atoms in box" << endl;
1066 cout << Verbose(0) << "-----------------------------------------------" << endl;
1067 cout << Verbose(0) << "s - save current setup to config file" << endl;
1068 cout << Verbose(0) << "T - call the current test routine" << endl;
1069 cout << Verbose(0) << "q - quit" << endl;
1070 cout << Verbose(0) << "===============================================" << endl;
1071 cout << Verbose(0) << "Input: ";
1072 cin >> choice;
1073
1074 switch (choice) {
1075 default:
1076 case 'a': // add atom
1077 AddAtoms(periode, mol);
1078 choice = 'a';
1079 break;
1080
1081 case 'b': // scale a bond
1082 cout << Verbose(0) << "Scaling bond length between two atoms." << endl;
1083 first = mol->AskAtom("Enter first (fixed) atom: ");
1084 second = mol->AskAtom("Enter second (shifting) atom: ");
1085 min_bond = 0.;
1086 for (int i=NDIM;i--;)
1087 min_bond += (first->x.x[i]-second->x.x[i])*(first->x.x[i] - second->x.x[i]);
1088 min_bond = sqrt(min_bond);
1089 cout << Verbose(0) << "Current Bond length between " << first->type->name << " Atom " << first->nr << " and " << second->type->name << " Atom " << second->nr << ": " << min_bond << " a.u." << endl;
1090 cout << Verbose(0) << "Enter new bond length [a.u.]: ";
1091 cin >> bond;
1092 for (int i=NDIM;i--;) {
1093 second->x.x[i] -= (second->x.x[i]-first->x.x[i])/min_bond*(min_bond-bond);
1094 }
1095 //cout << Verbose(0) << "New coordinates of Atom " << second->nr << " are: ";
1096 //second->Output(second->type->No, 1, (ofstream *)&cout);
1097 break;
1098
1099 case 'c': // unit scaling of the metric
1100 cout << Verbose(0) << "Angstroem -> Bohrradius: 1.8897261\t\tBohrradius -> Angstroem: 0.52917721" << endl;
1101 cout << Verbose(0) << "Enter three factors: ";
1102 factor = new double[NDIM];
1103 cin >> factor[0];
1104 cin >> factor[1];
1105 cin >> factor[2];
1106 valid = true;
1107 mol->Scale(&factor);
1108 delete[](factor);
1109 break;
1110
1111 case 'd': // duplicate the periodic cell along a given axis, given times
1112 cout << Verbose(0) << "State the axis [(+-)123]: ";
1113 cin >> axis;
1114 cout << Verbose(0) << "State the factor: ";
1115 cin >> faktor;
1116
1117 mol->CountAtoms((ofstream *)&cout); // recount atoms
1118 if (mol->AtomCount != 0) { // if there is more than none
1119 count = mol->AtomCount; // is changed becausing of adding, thus has to be stored away beforehand
1120 Elements = new element *[count];
1121 Vectors = new vector *[count];
1122 j = 0;
1123 first = mol->start;
1124 while (first->next != mol->end) { // make a list of all atoms with coordinates and element
1125 first = first->next;
1126 Elements[j] = first->type;
1127 Vectors[j] = &first->x;
1128 j++;
1129 }
1130 if (count != j)
1131 cout << Verbose(0) << "ERROR: AtomCount " << count << " is not equal to number of atoms in molecule " << j << "!" << endl;
1132 x.Zero();
1133 y.Zero();
1134 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
1135 for (int i=1;i<faktor;i++) { // then add this list with respective translation factor times
1136 x.AddVector(&y); // per factor one cell width further
1137 for (int k=count;k--;) { // go through every atom of the original cell
1138 first = new atom(); // create a new body
1139 first->x.CopyVector(Vectors[k]); // use coordinate of original atom
1140 first->x.AddVector(&x); // translate the coordinates
1141 first->type = Elements[k]; // insert original element
1142 mol->AddAtom(first); // and add to the molecule (which increments ElementsInMolecule, AtomCount, ...)
1143 }
1144 }
1145 if (mol->first->next != mol->last) // if connect matrix is present already, redo it
1146 mol->CreateAdjacencyList((ofstream *)&cout, mol->BondDistance, configuration.GetIsAngstroem());
1147 // free memory
1148 delete[](Elements);
1149 delete[](Vectors);
1150 // correct cell size
1151 if (axis < 0) { // if sign was negative, we have to translate everything
1152 x.Zero();
1153 x.AddVector(&y);
1154 x.Scale(-(faktor-1));
1155 mol->Translate(&x);
1156 }
1157 mol->cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] *= faktor;
1158 }
1159 break;
1160
1161 case 'e': // edit each field of the configuration
1162 configuration.Edit(mol);
1163 break;
1164
1165 case 'f':
1166 FragmentAtoms(mol, &configuration);
1167 break;
1168
1169 case 'g': // center the atoms
1170 CenterAtoms(mol);
1171 break;
1172
1173 case 'i': // align all atoms
1174 AlignAtoms(periode, mol);
1175 break;
1176
1177 case 'l': // measure distances or angles
1178 MeasureAtoms(periode, mol, &configuration);
1179 break;
1180
1181 case 'm': // mirror atoms along a given axis
1182 MirrorAtoms(mol);
1183 break;
1184
1185 case 'o': // create the connection matrix
1186 cout << Verbose(0) << "What's the maximum bond distance: ";
1187 cin >> tmp1;
1188 start = clock();
1189 mol->CreateAdjacencyList((ofstream *)&cout, tmp1, configuration.GetIsAngstroem());
1190 //mol->CreateListOfBondsPerAtom((ofstream *)&cout);
1191 Subgraphs = mol->DepthFirstSearchAnalysis((ofstream *)&cout, MinimumRingSize);
1192 while (Subgraphs->next != NULL) {
1193 Subgraphs = Subgraphs->next;
1194 delete(Subgraphs->previous);
1195 }
1196 delete(Subgraphs); // we don't need the list here, so free everything
1197 delete[](MinimumRingSize);
1198 Subgraphs = NULL;
1199 end = clock();
1200 cout << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl;
1201 break;
1202
1203 case 'p': // parse and XYZ file
1204 cout << Verbose(0) << "Format should be XYZ with: ShorthandOfElement\tX\tY\tZ" << endl;
1205 do {
1206 cout << Verbose(0) << "Enter file name: ";
1207 cin >> filename;
1208 } while (!mol->AddXYZFile(filename));
1209 break;
1210
1211 case 'q': // quit
1212 break;
1213
1214 case 'r': // remove atom
1215 RemoveAtoms(mol);
1216 break;
1217
1218 case 's': // save to config file
1219 SaveConfig(ConfigFileName, &configuration, periode, mol);
1220 break;
1221
1222 case 't': // translate all atoms
1223 cout << Verbose(0) << "Enter translation vector." << endl;
1224 x.AskPosition(mol->cell_size,0);
1225 mol->Translate((const vector *)&x);
1226 break;
1227
1228 case 'T':
1229 testroutine(mol);
1230 break;
1231
1232 case 'u': // change an atom's element
1233 first = NULL;
1234 do {
1235 cout << Verbose(0) << "Change the element of which atom: ";
1236 cin >> Z;
1237 } while ((first = mol->FindAtom(Z)) == NULL);
1238 cout << Verbose(0) << "New element by atomic number Z: ";
1239 cin >> Z;
1240 first->type = periode->FindElement(Z);
1241 cout << Verbose(0) << "Atom " << first->nr << "'s element is " << first->type->name << "." << endl;
1242 break;
1243 };
1244 } while (choice != 'q');
1245
1246 // save element data base
1247 if (periode->StorePeriodentafel()) //ElementsFileName
1248 cout << Verbose(0) << "Saving of elements.db successful." << endl;
1249 else
1250 cout << Verbose(0) << "Saving of elements.db failed." << endl;
1251
1252 // Free all
1253 if (Subgraphs != NULL) { // free disconnected subgraph list of DFS analysis was performed
1254 while (Subgraphs->next != NULL) {
1255 Subgraphs = Subgraphs->next;
1256 delete(Subgraphs->previous);
1257 }
1258 delete(Subgraphs);
1259 }
1260 delete(mol);
1261 delete(periode);
1262 return (0);
1263}
1264
1265/********************************************** E N D **************************************************/
Note: See TracBrowser for help on using the repository browser.