source: src/molecule.cpp@ 4b5cf8

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

BondedParticle::OutputBondOfAtom() now takes stream to print to.

  • Property mode set to 100755
File size: 41.0 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/** \file molecules.cpp
9 *
10 * Functions for the class molecule.
11 *
12 */
13
14// include config.h
15#ifdef HAVE_CONFIG_H
16#include <config.h>
17#endif
18
19#include "CodePatterns/MemDebug.hpp"
20
21#include <cstring>
22#include <boost/bind.hpp>
23#include <boost/foreach.hpp>
24
25#include <gsl/gsl_inline.h>
26#include <gsl/gsl_heapsort.h>
27
28#include "atom.hpp"
29#include "bond.hpp"
30#include "bondgraph.hpp"
31#include "Box.hpp"
32#include "CodePatterns/enumeration.hpp"
33#include "CodePatterns/Log.hpp"
34#include "config.hpp"
35#include "element.hpp"
36#include "Exceptions/LinearDependenceException.hpp"
37#include "graph.hpp"
38#include "Helpers/helpers.hpp"
39#include "LinearAlgebra/leastsquaremin.hpp"
40#include "LinearAlgebra/Plane.hpp"
41#include "LinearAlgebra/RealSpaceMatrix.hpp"
42#include "LinearAlgebra/Vector.hpp"
43#include "linkedcell.hpp"
44#include "molecule.hpp"
45#include "periodentafel.hpp"
46#include "tesselation.hpp"
47#include "World.hpp"
48#include "WorldTime.hpp"
49
50
51/************************************* Functions for class molecule *********************************/
52
53/** Constructor of class molecule.
54 * Initialises molecule list with correctly referenced start and end, and sets molecule::last_atom to zero.
55 */
56molecule::molecule(const periodentafel * const teil) :
57 Observable("molecule"),
58 elemente(teil),
59 MDSteps(0),
60 NoNonHydrogen(0),
61 NoNonBonds(0),
62 NoCyclicBonds(0),
63 ActiveFlag(false),
64 IndexNr(-1),
65 AtomCount(this,boost::bind(&molecule::doCountAtoms,this),"AtomCount"),
66 BondCount(this,boost::bind(&molecule::doCountBonds,this),"BondCount"),
67 last_atom(0)
68{
69
70 strcpy(name,World::getInstance().getDefaultName().c_str());
71};
72
73molecule *NewMolecule(){
74 return new molecule(World::getInstance().getPeriode());
75}
76
77/** Destructor of class molecule.
78 * Initialises molecule list with correctly referenced start and end, and sets molecule::last_atom to zero.
79 */
80molecule::~molecule()
81{
82 CleanupMolecule();
83};
84
85
86void DeleteMolecule(molecule *mol){
87 delete mol;
88}
89
90// getter and setter
91const std::string molecule::getName() const{
92 return std::string(name);
93}
94
95int molecule::getAtomCount() const{
96 return *AtomCount;
97}
98
99int molecule::getBondCount() const{
100 return *BondCount;
101}
102
103void molecule::setName(const std::string _name){
104 OBSERVE;
105 cout << "Set name of molecule " << getId() << " to " << _name << endl;
106 strncpy(name,_name.c_str(),MAXSTRINGSIZE);
107}
108
109bool molecule::changeId(moleculeId_t newId){
110 // first we move ourselves in the world
111 // the world lets us know if that succeeded
112 if(World::getInstance().changeMoleculeId(id,newId,this)){
113 id = newId;
114 return true;
115 }
116 else{
117 return false;
118 }
119}
120
121
122moleculeId_t molecule::getId() const {
123 return id;
124}
125
126void molecule::setId(moleculeId_t _id){
127 id =_id;
128}
129
130const Formula &molecule::getFormula() const {
131 return formula;
132}
133
134unsigned int molecule::getElementCount() const{
135 return formula.getElementCount();
136}
137
138bool molecule::hasElement(const element *element) const{
139 return formula.hasElement(element);
140}
141
142bool molecule::hasElement(atomicNumber_t Z) const{
143 return formula.hasElement(Z);
144}
145
146bool molecule::hasElement(const string &shorthand) const{
147 return formula.hasElement(shorthand);
148}
149
150/************************** Access to the List of Atoms ****************/
151
152
153molecule::iterator molecule::begin(){
154 return molecule::iterator(atoms.begin(),this);
155}
156
157molecule::const_iterator molecule::begin() const{
158 return atoms.begin();
159}
160
161molecule::iterator molecule::end(){
162 return molecule::iterator(atoms.end(),this);
163}
164
165molecule::const_iterator molecule::end() const{
166 return atoms.end();
167}
168
169bool molecule::empty() const
170{
171 return (begin() == end());
172}
173
174size_t molecule::size() const
175{
176 size_t counter = 0;
177 for (molecule::const_iterator iter = begin(); iter != end (); ++iter)
178 counter++;
179 return counter;
180}
181
182molecule::const_iterator molecule::erase( const_iterator loc )
183{
184 OBSERVE;
185 molecule::const_iterator iter = loc;
186 iter--;
187 atom* atom = *loc;
188 atomIds.erase( atom->getId() );
189 atoms.remove( atom );
190 formula-=atom->getType();
191 atom->removeFromMolecule();
192 return iter;
193}
194
195molecule::const_iterator molecule::erase( atom * key )
196{
197 OBSERVE;
198 molecule::const_iterator iter = find(key);
199 if (iter != end()){
200 atomIds.erase( key->getId() );
201 atoms.remove( key );
202 formula-=key->getType();
203 key->removeFromMolecule();
204 }
205 return iter;
206}
207
208molecule::const_iterator molecule::find ( atom * key ) const
209{
210 molecule::const_iterator iter;
211 for (molecule::const_iterator Runner = begin(); Runner != end(); ++Runner) {
212 if (*Runner == key)
213 return molecule::const_iterator(Runner);
214 }
215 return molecule::const_iterator(atoms.end());
216}
217
218pair<molecule::iterator,bool> molecule::insert ( atom * const key )
219{
220 OBSERVE;
221 pair<atomIdSet::iterator,bool> res = atomIds.insert(key->getId());
222 if (res.second) { // push atom if went well
223 atoms.push_back(key);
224 formula+=key->getType();
225 return pair<iterator,bool>(molecule::iterator(--end()),res.second);
226 } else {
227 return pair<iterator,bool>(molecule::iterator(end()),res.second);
228 }
229}
230
231bool molecule::containsAtom(atom* key){
232 return (find(key) != end());
233}
234
235/** Adds given atom \a *pointer from molecule list.
236 * Increases molecule::last_atom and gives last number to added atom and names it according to its element::abbrev and molecule::AtomCount
237 * \param *pointer allocated and set atom
238 * \return true - succeeded, false - atom not found in list
239 */
240bool molecule::AddAtom(atom *pointer)
241{
242 OBSERVE;
243 if (pointer != NULL) {
244 if (pointer->getType() != NULL) {
245 if (pointer->getType()->getAtomicNumber() != 1)
246 NoNonHydrogen++;
247 if(pointer->getName() == "Unknown"){
248 stringstream sstr;
249 sstr << pointer->getType()->getSymbol() << pointer->getNr()+1;
250 pointer->setName(sstr.str());
251 }
252 }
253 insert(pointer);
254 pointer->setMolecule(this);
255 }
256 return true;
257};
258
259/** Adds a copy of the given atom \a *pointer from molecule list.
260 * Increases molecule::last_atom and gives last number to added atom.
261 * \param *pointer allocated and set atom
262 * \return pointer to the newly added atom
263 */
264atom * molecule::AddCopyAtom(atom *pointer)
265{
266 atom *retval = NULL;
267 OBSERVE;
268 if (pointer != NULL) {
269 atom *walker = pointer->clone();
270 walker->setName(pointer->getName());
271 walker->setNr(last_atom++); // increase number within molecule
272 insert(walker);
273 if ((pointer->getType() != NULL) && (pointer->getType()->getAtomicNumber() != 1))
274 NoNonHydrogen++;
275 walker->setMolecule(this);
276 retval=walker;
277 }
278 return retval;
279};
280
281/** Adds a Hydrogen atom in replacement for the given atom \a *partner in bond with a *origin.
282 * Here, we have to distinguish between single, double or triple bonds as stated by \a BondDegree, that each demand
283 * a different scheme when adding \a *replacement atom for the given one.
284 * -# Single Bond: Simply add new atom with bond distance rescaled to typical hydrogen one
285 * -# Double Bond: Here, we need the **BondList of the \a *origin atom, by scanning for the other bonds instead of
286 * *Bond, we use the through these connected atoms to determine the plane they lie in, vector::MakeNormalvector().
287 * The orthonormal vector to this plane along with the vector in *Bond direction determines the plane the two
288 * replacing hydrogens shall lie in. Now, all remains to do is take the usual hydrogen double bond angle for the
289 * element of *origin and form the sin/cos admixture of both plane vectors for the new coordinates of the two
290 * hydrogens forming this angle with *origin.
291 * -# Triple Bond: The idea is to set up a tetraoid (C1-H1-H2-H3) (however the lengths \f$b\f$ of the sides of the base
292 * triangle formed by the to be added hydrogens are not equal to the typical bond distance \f$l\f$ but have to be
293 * determined from the typical angle \f$\alpha\f$ for a hydrogen triple connected to the element of *origin):
294 * We have the height \f$d\f$ as the vector in *Bond direction (from triangle C1-H1-H2).
295 * \f[ h = l \cdot \cos{\left (\frac{\alpha}{2} \right )} \qquad b = 2l \cdot \sin{\left (\frac{\alpha}{2} \right)} \quad \rightarrow \quad d = l \cdot \sqrt{\cos^2{\left (\frac{\alpha}{2} \right)}-\frac{1}{3}\cdot\sin^2{\left (\frac{\alpha}{2}\right )}}
296 * \f]
297 * vector::GetNormalvector() creates one orthonormal vector from this *Bond vector and vector::MakeNormalvector creates
298 * the third one from the former two vectors. The latter ones form the plane of the base triangle mentioned above.
299 * The lengths for these are \f$f\f$ and \f$g\f$ (from triangle H1-H2-(center of H1-H2-H3)) with knowledge that
300 * the median lines in an isosceles triangle meet in the center point with a ratio 2:1.
301 * \f[ f = \frac{b}{\sqrt{3}} \qquad g = \frac{b}{2}
302 * \f]
303 * as the coordination of all three atoms in the coordinate system of these three vectors:
304 * \f$\pmatrix{d & f & 0}\f$, \f$\pmatrix{d & -0.5 \cdot f & g}\f$ and \f$\pmatrix{d & -0.5 \cdot f & -g}\f$.
305 *
306 * \param *out output stream for debugging
307 * \param *Bond pointer to bond between \a *origin and \a *replacement
308 * \param *TopOrigin son of \a *origin of upper level molecule (the atom added to this molecule as a copy of \a *origin)
309 * \param *origin pointer to atom which acts as the origin for scaling the added hydrogen to correct bond length
310 * \param *replacement pointer to the atom which shall be copied as a hydrogen atom in this molecule
311 * \param isAngstroem whether the coordination of the given atoms is in AtomicLength (false) or Angstrom(true)
312 * \return number of atoms added, if < bond::BondDegree then something went wrong
313 * \todo double and triple bonds splitting (always use the tetraeder angle!)
314 */
315bool molecule::AddHydrogenReplacementAtom(bond *TopBond, atom *BottomOrigin, atom *TopOrigin, atom *TopReplacement, bool IsAngstroem)
316{
317 bool AllWentWell = true; // flag gathering the boolean return value of molecule::AddAtom and other functions, as return value on exit
318 OBSERVE;
319 double bondlength; // bond length of the bond to be replaced/cut
320 double bondangle; // bond angle of the bond to be replaced/cut
321 double BondRescale; // rescale value for the hydrogen bond length
322 bond *FirstBond = NULL, *SecondBond = NULL; // Other bonds in double bond case to determine "other" plane
323 atom *FirstOtherAtom = NULL, *SecondOtherAtom = NULL, *ThirdOtherAtom = NULL; // pointer to hydrogen atoms to be added
324 double b,l,d,f,g, alpha, factors[NDIM]; // hold temporary values in triple bond case for coordination determination
325 Vector Orthovector1, Orthovector2; // temporary vectors in coordination construction
326 Vector InBondvector; // vector in direction of *Bond
327 const RealSpaceMatrix &matrix = World::getInstance().getDomain().getM();
328 bond *Binder = NULL;
329
330// Log() << Verbose(3) << "Begin of AddHydrogenReplacementAtom." << endl;
331 // create vector in direction of bond
332 InBondvector = TopReplacement->getPosition() - TopOrigin->getPosition();
333 bondlength = InBondvector.Norm();
334
335 // is greater than typical bond distance? Then we have to correct periodically
336 // the problem is not the H being out of the box, but InBondvector have the wrong direction
337 // due to TopReplacement or Origin being on the wrong side!
338 double MinBondDistance;
339 double MaxBondDistance;
340 World::getInstance().getBondGraph()->getMinMaxDistance(
341 TopOrigin,
342 TopReplacement,
343 MinBondDistance,MaxBondDistance,IsAngstroem);
344 std::cout << "bondlength > MaxBondDistance: " << bondlength << " > " << MaxBondDistance << std::endl;
345 std::cout << "bondlength < MinBondDistance: " << bondlength << " < " << MinBondDistance << std::endl;
346 if ((bondlength < MinBondDistance) || (bondlength > MaxBondDistance)) {
347// Log() << Verbose(4) << "InBondvector is: ";
348// InBondvector.Output(out);
349// Log() << Verbose(0) << endl;
350 Orthovector1.Zero();
351 for (int i=NDIM;i--;) {
352 l = TopReplacement->at(i) - TopOrigin->at(i);
353 if (fabs(l) > MaxBondDistance) { // is component greater than bond distance (check against min not useful here)
354 Orthovector1[i] = (l < 0) ? -1. : +1.;
355 } // (signs are correct, was tested!)
356 }
357 Orthovector1 *= matrix;
358 InBondvector -= Orthovector1; // subtract just the additional translation
359 bondlength = InBondvector.Norm();
360// Log() << Verbose(4) << "Corrected InBondvector is now: ";
361// InBondvector.Output(out);
362// Log() << Verbose(0) << endl;
363 } // periodic correction finished
364
365 InBondvector.Normalize();
366 // get typical bond length and store as scale factor for later
367 ASSERT(TopOrigin->getType() != NULL, "AddHydrogenReplacementAtom: element of TopOrigin is not given.");
368 BondRescale = TopOrigin->getType()->getHBondDistance(TopBond->BondDegree-1);
369 if (BondRescale == -1) {
370 DoeLog(1) && (eLog()<< Verbose(1) << "There is no typical hydrogen bond distance in replacing bond (" << TopOrigin->getName() << "<->" << TopReplacement->getName() << ") of degree " << TopBond->BondDegree << "!" << endl);
371 return false;
372 BondRescale = bondlength;
373 } else {
374 if (!IsAngstroem)
375 BondRescale /= (1.*AtomicLengthToAngstroem);
376 }
377
378 // discern single, double and triple bonds
379 switch(TopBond->BondDegree) {
380 case 1:
381 FirstOtherAtom = World::getInstance().createAtom(); // new atom
382 FirstOtherAtom->setType(1); // element is Hydrogen
383 FirstOtherAtom->setAtomicVelocity(TopReplacement->getAtomicVelocity()); // copy velocity
384 FirstOtherAtom->setFixedIon(TopReplacement->getFixedIon());
385 if (TopReplacement->getType()->getAtomicNumber() == 1) { // neither rescale nor replace if it's already hydrogen
386 FirstOtherAtom->father = TopReplacement;
387 BondRescale = bondlength;
388 } else {
389 FirstOtherAtom->father = NULL; // if we replace hydrogen, we mark it as our father, otherwise we are just an added hydrogen with no father
390 }
391 InBondvector *= BondRescale; // rescale the distance vector to Hydrogen bond length
392 FirstOtherAtom->setPosition(TopOrigin->getPosition() + InBondvector); // set coordination to origin and add distance vector to replacement atom
393 AllWentWell = AllWentWell && AddAtom(FirstOtherAtom);
394// Log() << Verbose(4) << "Added " << *FirstOtherAtom << " at: ";
395// FirstOtherAtom->x.Output(out);
396// Log() << Verbose(0) << endl;
397 Binder = AddBond(BottomOrigin, FirstOtherAtom, 1);
398 Binder->Cyclic = false;
399 Binder->Type = TreeEdge;
400 break;
401 case 2:
402 {
403 // determine two other bonds (warning if there are more than two other) plus valence sanity check
404 const BondList& ListOfBonds = TopOrigin->getListOfBonds();
405 for (BondList::const_iterator Runner = ListOfBonds.begin();
406 Runner != ListOfBonds.end();
407 ++Runner) {
408 if ((*Runner) != TopBond) {
409 if (FirstBond == NULL) {
410 FirstBond = (*Runner);
411 FirstOtherAtom = (*Runner)->GetOtherAtom(TopOrigin);
412 } else if (SecondBond == NULL) {
413 SecondBond = (*Runner);
414 SecondOtherAtom = (*Runner)->GetOtherAtom(TopOrigin);
415 } else {
416 DoeLog(2) && (eLog()<< Verbose(2) << "Detected more than four bonds for atom " << TopOrigin->getName());
417 }
418 }
419 }
420 }
421 if (SecondOtherAtom == NULL) { // then we have an atom with valence four, but only 3 bonds: one to replace and one which is TopBond (third is FirstBond)
422 SecondBond = TopBond;
423 SecondOtherAtom = TopReplacement;
424 }
425 if (FirstOtherAtom != NULL) { // then we just have this double bond and the plane does not matter at all
426// Log() << Verbose(3) << "Regarding the double bond (" << TopOrigin->Name << "<->" << TopReplacement->Name << ") to be constructed: Taking " << FirstOtherAtom->Name << " and " << SecondOtherAtom->Name << " along with " << TopOrigin->Name << " to determine orthogonal plane." << endl;
427
428 // determine the plane of these two with the *origin
429 try {
430 Orthovector1 =Plane(TopOrigin->getPosition(), FirstOtherAtom->getPosition(), SecondOtherAtom->getPosition()).getNormal();
431 }
432 catch(LinearDependenceException &excp){
433 Log() << Verbose(0) << excp;
434 // TODO: figure out what to do with the Orthovector in this case
435 AllWentWell = false;
436 }
437 } else {
438 Orthovector1.GetOneNormalVector(InBondvector);
439 }
440 //Log() << Verbose(3)<< "Orthovector1: ";
441 //Orthovector1.Output(out);
442 //Log() << Verbose(0) << endl;
443 // orthogonal vector and bond vector between origin and replacement form the new plane
444 Orthovector1.MakeNormalTo(InBondvector);
445 Orthovector1.Normalize();
446 //Log() << Verbose(3) << "ReScaleCheck: " << Orthovector1.Norm() << " and " << InBondvector.Norm() << "." << endl;
447
448 // create the two Hydrogens ...
449 FirstOtherAtom = World::getInstance().createAtom();
450 SecondOtherAtom = World::getInstance().createAtom();
451 FirstOtherAtom->setType(1);
452 SecondOtherAtom->setType(1);
453 FirstOtherAtom->setAtomicVelocity(TopReplacement->getAtomicVelocity()); // copy velocity
454 FirstOtherAtom->setFixedIon(TopReplacement->getFixedIon());
455 SecondOtherAtom->setAtomicVelocity(TopReplacement->getAtomicVelocity()); // copy velocity
456 SecondOtherAtom->setFixedIon(TopReplacement->getFixedIon());
457 FirstOtherAtom->father = NULL; // we are just an added hydrogen with no father
458 SecondOtherAtom->father = NULL; // we are just an added hydrogen with no father
459 bondangle = TopOrigin->getType()->getHBondAngle(1);
460 if (bondangle == -1) {
461 DoeLog(1) && (eLog()<< Verbose(1) << "There is no typical hydrogen bond angle in replacing bond (" << TopOrigin->getName() << "<->" << TopReplacement->getName() << ") of degree " << TopBond->BondDegree << "!" << endl);
462 return false;
463 bondangle = 0;
464 }
465 bondangle *= M_PI/180./2.;
466// Log() << Verbose(3) << "ReScaleCheck: InBondvector ";
467// InBondvector.Output(out);
468// Log() << Verbose(0) << endl;
469// Log() << Verbose(3) << "ReScaleCheck: Orthovector ";
470// Orthovector1.Output(out);
471// Log() << Verbose(0) << endl;
472// Log() << Verbose(3) << "Half the bond angle is " << bondangle << ", sin and cos of it: " << sin(bondangle) << ", " << cos(bondangle) << endl;
473 FirstOtherAtom->Zero();
474 SecondOtherAtom->Zero();
475 for(int i=NDIM;i--;) { // rotate by half the bond angle in both directions (InBondvector is bondangle = 0 direction)
476 FirstOtherAtom->set(i, InBondvector[i] * cos(bondangle) + Orthovector1[i] * (sin(bondangle)));
477 SecondOtherAtom->set(i, InBondvector[i] * cos(bondangle) + Orthovector1[i] * (-sin(bondangle)));
478 }
479 FirstOtherAtom->Scale(BondRescale); // rescale by correct BondDistance
480 SecondOtherAtom->Scale(BondRescale);
481 //Log() << Verbose(3) << "ReScaleCheck: " << FirstOtherAtom->x.Norm() << " and " << SecondOtherAtom->x.Norm() << "." << endl;
482 *FirstOtherAtom += TopOrigin->getPosition();
483 *SecondOtherAtom += TopOrigin->getPosition();
484 // ... and add to molecule
485 AllWentWell = AllWentWell && AddAtom(FirstOtherAtom);
486 AllWentWell = AllWentWell && AddAtom(SecondOtherAtom);
487// Log() << Verbose(4) << "Added " << *FirstOtherAtom << " at: ";
488// FirstOtherAtom->x.Output(out);
489// Log() << Verbose(0) << endl;
490// Log() << Verbose(4) << "Added " << *SecondOtherAtom << " at: ";
491// SecondOtherAtom->x.Output(out);
492// Log() << Verbose(0) << endl;
493 Binder = AddBond(BottomOrigin, FirstOtherAtom, 1);
494 Binder->Cyclic = false;
495 Binder->Type = TreeEdge;
496 Binder = AddBond(BottomOrigin, SecondOtherAtom, 1);
497 Binder->Cyclic = false;
498 Binder->Type = TreeEdge;
499 break;
500 case 3:
501 // take the "usual" tetraoidal angle and add the three Hydrogen in direction of the bond (height of the tetraoid)
502 FirstOtherAtom = World::getInstance().createAtom();
503 SecondOtherAtom = World::getInstance().createAtom();
504 ThirdOtherAtom = World::getInstance().createAtom();
505 FirstOtherAtom->setType(1);
506 SecondOtherAtom->setType(1);
507 ThirdOtherAtom->setType(1);
508 FirstOtherAtom->setAtomicVelocity(TopReplacement->getAtomicVelocity()); // copy velocity
509 FirstOtherAtom->setFixedIon(TopReplacement->getFixedIon());
510 SecondOtherAtom->setAtomicVelocity(TopReplacement->getAtomicVelocity()); // copy velocity
511 SecondOtherAtom->setFixedIon(TopReplacement->getFixedIon());
512 ThirdOtherAtom->setAtomicVelocity(TopReplacement->getAtomicVelocity()); // copy velocity
513 ThirdOtherAtom->setFixedIon(TopReplacement->getFixedIon());
514 FirstOtherAtom->father = NULL; // we are just an added hydrogen with no father
515 SecondOtherAtom->father = NULL; // we are just an added hydrogen with no father
516 ThirdOtherAtom->father = NULL; // we are just an added hydrogen with no father
517
518 // we need to vectors orthonormal the InBondvector
519 AllWentWell = AllWentWell && Orthovector1.GetOneNormalVector(InBondvector);
520// Log() << Verbose(3) << "Orthovector1: ";
521// Orthovector1.Output(out);
522// Log() << Verbose(0) << endl;
523 try{
524 Orthovector2 = Plane(InBondvector, Orthovector1,0).getNormal();
525 }
526 catch(LinearDependenceException &excp) {
527 Log() << Verbose(0) << excp;
528 AllWentWell = false;
529 }
530// Log() << Verbose(3) << "Orthovector2: ";
531// Orthovector2.Output(out);
532// Log() << Verbose(0) << endl;
533
534 // create correct coordination for the three atoms
535 alpha = (TopOrigin->getType()->getHBondAngle(2))/180.*M_PI/2.; // retrieve triple bond angle from database
536 l = BondRescale; // desired bond length
537 b = 2.*l*sin(alpha); // base length of isosceles triangle
538 d = l*sqrt(cos(alpha)*cos(alpha) - sin(alpha)*sin(alpha)/3.); // length for InBondvector
539 f = b/sqrt(3.); // length for Orthvector1
540 g = b/2.; // length for Orthvector2
541// Log() << Verbose(3) << "Bond length and half-angle: " << l << ", " << alpha << "\t (b,d,f,g) = " << b << ", " << d << ", " << f << ", " << g << ", " << endl;
542// Log() << Verbose(3) << "The three Bond lengths: " << sqrt(d*d+f*f) << ", " << sqrt(d*d+(-0.5*f)*(-0.5*f)+g*g) << ", " << sqrt(d*d+(-0.5*f)*(-0.5*f)+g*g) << endl;
543 factors[0] = d;
544 factors[1] = f;
545 factors[2] = 0.;
546 FirstOtherAtom->LinearCombinationOfVectors(InBondvector, Orthovector1, Orthovector2, factors);
547 factors[1] = -0.5*f;
548 factors[2] = g;
549 SecondOtherAtom->LinearCombinationOfVectors(InBondvector, Orthovector1, Orthovector2, factors);
550 factors[2] = -g;
551 ThirdOtherAtom->LinearCombinationOfVectors(InBondvector, Orthovector1, Orthovector2, factors);
552
553 // rescale each to correct BondDistance
554// FirstOtherAtom->x.Scale(&BondRescale);
555// SecondOtherAtom->x.Scale(&BondRescale);
556// ThirdOtherAtom->x.Scale(&BondRescale);
557
558 // and relative to *origin atom
559 *FirstOtherAtom += TopOrigin->getPosition();
560 *SecondOtherAtom += TopOrigin->getPosition();
561 *ThirdOtherAtom += TopOrigin->getPosition();
562
563 // ... and add to molecule
564 AllWentWell = AllWentWell && AddAtom(FirstOtherAtom);
565 AllWentWell = AllWentWell && AddAtom(SecondOtherAtom);
566 AllWentWell = AllWentWell && AddAtom(ThirdOtherAtom);
567// Log() << Verbose(4) << "Added " << *FirstOtherAtom << " at: ";
568// FirstOtherAtom->x.Output(out);
569// Log() << Verbose(0) << endl;
570// Log() << Verbose(4) << "Added " << *SecondOtherAtom << " at: ";
571// SecondOtherAtom->x.Output(out);
572// Log() << Verbose(0) << endl;
573// Log() << Verbose(4) << "Added " << *ThirdOtherAtom << " at: ";
574// ThirdOtherAtom->x.Output(out);
575// Log() << Verbose(0) << endl;
576 Binder = AddBond(BottomOrigin, FirstOtherAtom, 1);
577 Binder->Cyclic = false;
578 Binder->Type = TreeEdge;
579 Binder = AddBond(BottomOrigin, SecondOtherAtom, 1);
580 Binder->Cyclic = false;
581 Binder->Type = TreeEdge;
582 Binder = AddBond(BottomOrigin, ThirdOtherAtom, 1);
583 Binder->Cyclic = false;
584 Binder->Type = TreeEdge;
585 break;
586 default:
587 DoeLog(1) && (eLog()<< Verbose(1) << "BondDegree does not state single, double or triple bond!" << endl);
588 AllWentWell = false;
589 break;
590 }
591
592// Log() << Verbose(3) << "End of AddHydrogenReplacementAtom." << endl;
593 return AllWentWell;
594};
595
596/** Adds given atom \a *pointer from molecule list.
597 * Increases molecule::last_atom and gives last number to added atom.
598 * \param filename name and path of xyz file
599 * \return true - succeeded, false - file not found
600 */
601bool molecule::AddXYZFile(string filename)
602{
603
604 istringstream *input = NULL;
605 int NumberOfAtoms = 0; // atom number in xyz read
606 int i; // loop variables
607 atom *Walker = NULL; // pointer to added atom
608 char shorthand[3]; // shorthand for atom name
609 ifstream xyzfile; // xyz file
610 string line; // currently parsed line
611 double x[3]; // atom coordinates
612
613 xyzfile.open(filename.c_str());
614 if (!xyzfile)
615 return false;
616
617 OBSERVE;
618 getline(xyzfile,line,'\n'); // Read numer of atoms in file
619 input = new istringstream(line);
620 *input >> NumberOfAtoms;
621 DoLog(0) && (Log() << Verbose(0) << "Parsing " << NumberOfAtoms << " atoms in file." << endl);
622 getline(xyzfile,line,'\n'); // Read comment
623 DoLog(1) && (Log() << Verbose(1) << "Comment: " << line << endl);
624
625 if (MDSteps == 0) // no atoms yet present
626 MDSteps++;
627 for(i=0;i<NumberOfAtoms;i++){
628 Walker = World::getInstance().createAtom();
629 getline(xyzfile,line,'\n');
630 istringstream *item = new istringstream(line);
631 //istringstream input(line);
632 //Log() << Verbose(1) << "Reading: " << line << endl;
633 *item >> shorthand;
634 *item >> x[0];
635 *item >> x[1];
636 *item >> x[2];
637 Walker->setType(elemente->FindElement(shorthand));
638 if (Walker->getType() == NULL) {
639 DoeLog(1) && (eLog()<< Verbose(1) << "Could not parse the element at line: '" << line << "', setting to H.");
640 Walker->setType(1);
641 }
642
643 Walker->setPosition(Vector(x));
644 Walker->setPositionAtStep(MDSteps-1, Vector(x));
645 Walker->setAtomicVelocityAtStep(MDSteps-1, zeroVec);
646 Walker->setAtomicForceAtStep(MDSteps-1, zeroVec);
647 AddAtom(Walker); // add to molecule
648 delete(item);
649 }
650 xyzfile.close();
651 delete(input);
652 return true;
653};
654
655/** Creates a copy of this molecule.
656 * \return copy of molecule
657 */
658molecule *molecule::CopyMolecule() const
659{
660 molecule *copy = World::getInstance().createMolecule();
661
662 // copy all atoms
663 for_each(atoms.begin(),atoms.end(),bind1st(mem_fun(&molecule::AddCopyAtom),copy));
664
665 // copy all bonds
666 for(molecule::const_iterator AtomRunner = begin(); AtomRunner != end(); ++AtomRunner) {
667 const BondList& ListOfBonds = (*AtomRunner)->getListOfBonds();
668 for(BondList::const_iterator BondRunner = ListOfBonds.begin();
669 BondRunner != ListOfBonds.end();
670 ++BondRunner)
671 if ((*BondRunner)->leftatom == *AtomRunner) {
672 bond *Binder = (*BondRunner);
673 // get the pendant atoms of current bond in the copy molecule
674 atomSet::iterator leftiter=find_if(copy->atoms.begin(),copy->atoms.end(),bind2nd(mem_fun(&atom::isFather),Binder->leftatom));
675 atomSet::iterator rightiter=find_if(copy->atoms.begin(),copy->atoms.end(),bind2nd(mem_fun(&atom::isFather),Binder->rightatom));
676 ASSERT(leftiter!=copy->atoms.end(),"No copy of original left atom for bond copy found");
677 ASSERT(leftiter!=copy->atoms.end(),"No copy of original right atom for bond copy found");
678 atom *LeftAtom = *leftiter;
679 atom *RightAtom = *rightiter;
680
681 bond *NewBond = copy->AddBond(LeftAtom, RightAtom, Binder->BondDegree);
682 NewBond->Cyclic = Binder->Cyclic;
683 if (Binder->Cyclic)
684 copy->NoCyclicBonds++;
685 NewBond->Type = Binder->Type;
686 }
687 }
688 // correct fathers
689 for_each(atoms.begin(),atoms.end(),mem_fun(&atom::CorrectFather));
690
691 return copy;
692};
693
694
695/** Destroys all atoms inside this molecule.
696 */
697void molecule::removeAtomsinMolecule()
698{
699 // remove each atom from world
700 for(molecule::const_iterator AtomRunner = begin(); !empty(); AtomRunner = begin())
701 World::getInstance().destroyAtom(*AtomRunner);
702};
703
704
705/**
706 * Copies all atoms of a molecule which are within the defined parallelepiped.
707 *
708 * @param offest for the origin of the parallelepiped
709 * @param three vectors forming the matrix that defines the shape of the parallelpiped
710 */
711molecule* molecule::CopyMoleculeFromSubRegion(const Shape &region) const {
712 molecule *copy = World::getInstance().createMolecule();
713
714 BOOST_FOREACH(atom *iter,atoms){
715 if(iter->IsInShape(region)){
716 copy->AddCopyAtom(iter);
717 }
718 }
719
720 //TODO: copy->BuildInducedSubgraph(this);
721
722 return copy;
723}
724
725/** Adds a bond to a the molecule specified by two atoms, \a *first and \a *second.
726 * Also updates molecule::BondCount and molecule::NoNonBonds.
727 * \param *first first atom in bond
728 * \param *second atom in bond
729 * \return pointer to bond or NULL on failure
730 */
731bond * molecule::AddBond(atom *atom1, atom *atom2, int degree)
732{
733 OBSERVE;
734 bond *Binder = NULL;
735
736 // some checks to make sure we are able to create the bond
737 ASSERT(atom1, "First atom in bond-creation was an invalid pointer");
738 ASSERT(atom2, "Second atom in bond-creation was an invalid pointer");
739 ASSERT(FindAtom(atom1->getNr()),"First atom in bond-creation was not part of molecule");
740 ASSERT(FindAtom(atom2->getNr()),"Second atom in bond-creation was not part of molecule");
741
742 Binder = new bond(atom1, atom2, degree, getBondCount());
743 atom1->RegisterBond(WorldTime::getTime(), Binder);
744 atom2->RegisterBond(WorldTime::getTime(), Binder);
745 if ((atom1->getType() != NULL) && (atom1->getType()->getAtomicNumber() != 1) && (atom2->getType() != NULL) && (atom2->getType()->getAtomicNumber() != 1))
746 NoNonBonds++;
747
748 return Binder;
749};
750
751/** Remove bond from bond chain list and from the both atom::ListOfBonds.
752 * Bond::~Bond takes care of bond removal
753 * \param *pointer bond pointer
754 * \return true - bound found and removed, false - bond not found/removed
755 */
756bool molecule::RemoveBond(bond *pointer)
757{
758 //DoeLog(1) && (eLog()<< Verbose(1) << "molecule::RemoveBond: Function not implemented yet." << endl);
759 delete(pointer);
760 return true;
761};
762
763/** Remove every bond from bond chain list that atom \a *BondPartner is a constituent of.
764 * \todo Function not implemented yet
765 * \param *BondPartner atom to be removed
766 * \return true - bounds found and removed, false - bonds not found/removed
767 */
768bool molecule::RemoveBonds(atom *BondPartner)
769{
770 //DoeLog(1) && (eLog()<< Verbose(1) << "molecule::RemoveBond: Function not implemented yet." << endl);
771 BondList::const_iterator ForeRunner;
772 BondList& ListOfBonds = BondPartner->getListOfBonds();
773 while (!ListOfBonds.empty()) {
774 ForeRunner = ListOfBonds.begin();
775 RemoveBond(*ForeRunner);
776 }
777 return false;
778};
779
780/** Set molecule::name from the basename without suffix in the given \a *filename.
781 * \param *filename filename
782 */
783void molecule::SetNameFromFilename(const char *filename)
784{
785 int length = 0;
786 const char *molname = strrchr(filename, '/');
787 if (molname != NULL)
788 molname += sizeof(char); // search for filename without dirs
789 else
790 molname = filename; // contains no slashes
791 const char *endname = strchr(molname, '.');
792 if ((endname == NULL) || (endname < molname))
793 length = strlen(molname);
794 else
795 length = strlen(molname) - strlen(endname);
796 cout << "Set name of molecule " << getId() << " to " << molname << endl;
797 strncpy(name, molname, length);
798 name[length]='\0';
799};
800
801/** Sets the molecule::cell_size to the components of \a *dim (rectangular box)
802 * \param *dim vector class
803 */
804void molecule::SetBoxDimension(Vector *dim)
805{
806 RealSpaceMatrix domain;
807 for(int i =0; i<NDIM;++i)
808 domain.at(i,i) = dim->at(i);
809 World::getInstance().setDomain(domain);
810};
811
812/** Removes atom from molecule list and removes all of its bonds.
813 * \param *pointer atom to be removed
814 * \return true - succeeded, false - atom not found in list
815 */
816bool molecule::RemoveAtom(atom *pointer)
817{
818 ASSERT(pointer, "Null pointer passed to molecule::RemoveAtom().");
819 OBSERVE;
820 RemoveBonds(pointer);
821 erase(pointer);
822 return true;
823};
824
825/** Removes atom from molecule list, but does not delete it.
826 * \param *pointer atom to be removed
827 * \return true - succeeded, false - atom not found in list
828 */
829bool molecule::UnlinkAtom(atom *pointer)
830{
831 if (pointer == NULL)
832 return false;
833 erase(pointer);
834 return true;
835};
836
837/** Removes every atom from molecule list.
838 * \return true - succeeded, false - atom not found in list
839 */
840bool molecule::CleanupMolecule()
841{
842 for (molecule::iterator iter = begin(); !empty(); iter = begin())
843 erase(*iter);
844 return empty();
845};
846
847/** Finds an atom specified by its continuous number.
848 * \param Nr number of atom withim molecule
849 * \return pointer to atom or NULL
850 */
851atom * molecule::FindAtom(int Nr) const
852{
853 molecule::const_iterator iter = begin();
854 for (; iter != end(); ++iter)
855 if ((*iter)->getNr() == Nr)
856 break;
857 if (iter != end()) {
858 //Log() << Verbose(0) << "Found Atom Nr. " << walker->getNr() << endl;
859 return (*iter);
860 } else {
861 DoLog(0) && (Log() << Verbose(0) << "Atom not found in list." << endl);
862 return NULL;
863 }
864};
865
866/** Asks for atom number, and checks whether in list.
867 * \param *text question before entering
868 */
869atom * molecule::AskAtom(string text)
870{
871 int No;
872 atom *ion = NULL;
873 do {
874 //Log() << Verbose(0) << "============Atom list==========================" << endl;
875 //mol->Output((ofstream *)&cout);
876 //Log() << Verbose(0) << "===============================================" << endl;
877 DoLog(0) && (Log() << Verbose(0) << text);
878 cin >> No;
879 ion = this->FindAtom(No);
880 } while (ion == NULL);
881 return ion;
882};
883
884/** Checks if given coordinates are within cell volume.
885 * \param *x array of coordinates
886 * \return true - is within, false - out of cell
887 */
888bool molecule::CheckBounds(const Vector *x) const
889{
890 const RealSpaceMatrix &domain = World::getInstance().getDomain().getM();
891 bool result = true;
892 for (int i=0;i<NDIM;i++) {
893 result = result && ((x->at(i) >= 0) && (x->at(i) < domain.at(i,i)));
894 }
895 //return result;
896 return true; /// probably not gonna use the check no more
897};
898
899/** Prints molecule to *out.
900 * \param *out output stream
901 */
902bool molecule::Output(ostream * const output) const
903{
904 if (output == NULL) {
905 return false;
906 } else {
907 int AtomNo[MAX_ELEMENTS];
908 memset(AtomNo,0,(MAX_ELEMENTS-1)*sizeof(*AtomNo));
909 enumeration<const element*> elementLookup = formula.enumerateElements();
910 *output << "#Ion_TypeNr._Nr.R[0] R[1] R[2] MoveType (0 MoveIon, 1 FixedIon)" << endl;
911 for_each(atoms.begin(),atoms.end(),boost::bind(&atom::OutputArrayIndexed,_1,output,elementLookup,AtomNo,(const char*)0));
912 return true;
913 }
914};
915
916/** Prints molecule with all atomic trajectory positions to *out.
917 * \param *out output stream
918 */
919bool molecule::OutputTrajectories(ofstream * const output) const
920{
921 if (output == NULL) {
922 return false;
923 } else {
924 for (int step = 0; step < MDSteps; step++) {
925 if (step == 0) {
926 *output << "#Ion_TypeNr._Nr.R[0] R[1] R[2] MoveType (0 MoveIon, 1 FixedIon)" << endl;
927 } else {
928 *output << "# ====== MD step " << step << " =========" << endl;
929 }
930 int AtomNo[MAX_ELEMENTS];
931 memset(AtomNo,0,(MAX_ELEMENTS-1)*sizeof(*AtomNo));
932 enumeration<const element*> elementLookup = formula.enumerateElements();
933 for_each(atoms.begin(),atoms.end(),boost::bind(&atom::OutputTrajectory,_1,output,elementLookup, AtomNo, (const int)step));
934 }
935 return true;
936 }
937};
938
939/** Outputs contents of each atom::ListOfBonds.
940 * \param *out output stream
941 */
942void molecule::OutputListOfBonds() const
943{
944 std::stringstream output;
945 LOG(2, "From Contents of ListOfBonds, all atoms:");
946 for (molecule::const_iterator iter = begin();
947 iter != end();
948 ++iter) {
949 (*iter)->OutputBondOfAtom(output);
950 output << std::endl << "\t\t";
951 }
952 LOG(2, output.str());
953}
954
955/** Output of element before the actual coordination list.
956 * \param *out stream pointer
957 */
958bool molecule::Checkout(ofstream * const output) const
959{
960 return formula.checkOut(output);
961};
962
963/** Prints molecule with all its trajectories to *out as xyz file.
964 * \param *out output stream
965 */
966bool molecule::OutputTrajectoriesXYZ(ofstream * const output)
967{
968 time_t now;
969
970 if (output != NULL) {
971 now = time((time_t *)NULL); // Get the system time and put it into 'now' as 'calender time'
972 for (int step=0;step<MDSteps;step++) {
973 *output << getAtomCount() << "\n\tCreated by molecuilder, step " << step << ", on " << ctime(&now);
974 for_each(atoms.begin(),atoms.end(),boost::bind(&atom::OutputTrajectoryXYZ,_1,output,step));
975 }
976 return true;
977 } else
978 return false;
979};
980
981/** Prints molecule to *out as xyz file.
982* \param *out output stream
983 */
984bool molecule::OutputXYZ(ofstream * const output) const
985{
986 time_t now;
987
988 if (output != NULL) {
989 now = time((time_t *)NULL); // Get the system time and put it into 'now' as 'calender time'
990 *output << getAtomCount() << "\n\tCreated by molecuilder on " << ctime(&now);
991 for_each(atoms.begin(),atoms.end(),bind2nd(mem_fun(&atom::OutputXYZLine),output));
992 return true;
993 } else
994 return false;
995};
996
997/** Brings molecule::AtomCount and atom::*Name up-to-date.
998 * \param *out output stream for debugging
999 */
1000int molecule::doCountAtoms()
1001{
1002 int res = size();
1003 int i = 0;
1004 NoNonHydrogen = 0;
1005 for (molecule::const_iterator iter = atoms.begin(); iter != atoms.end(); ++iter) {
1006 (*iter)->setNr(i); // update number in molecule (for easier referencing in FragmentMolecule lateron)
1007 if ((*iter)->getType()->getAtomicNumber() != 1) // count non-hydrogen atoms whilst at it
1008 NoNonHydrogen++;
1009 stringstream sstr;
1010 sstr << (*iter)->getType()->getSymbol() << (*iter)->getNr()+1;
1011 (*iter)->setName(sstr.str());
1012 DoLog(3) && (Log() << Verbose(3) << "Naming atom nr. " << (*iter)->getNr() << " " << (*iter)->getName() << "." << endl);
1013 i++;
1014 }
1015 return res;
1016};
1017
1018/** Counts the number of present bonds.
1019 * \return number of bonds
1020 */
1021int molecule::doCountBonds() const
1022{
1023 unsigned int counter = 0;
1024 for(molecule::const_iterator AtomRunner = begin(); AtomRunner != end(); ++AtomRunner) {
1025 const BondList& ListOfBonds = (*AtomRunner)->getListOfBonds();
1026 for(BondList::const_iterator BondRunner = ListOfBonds.begin();
1027 BondRunner != ListOfBonds.end();
1028 ++BondRunner)
1029 if ((*BondRunner)->leftatom == *AtomRunner)
1030 counter++;
1031 }
1032 return counter;
1033}
1034
1035
1036/** Returns an index map for two father-son-molecules.
1037 * The map tells which atom in this molecule corresponds to which one in the other molecul with their fathers.
1038 * \param *out output stream for debugging
1039 * \param *OtherMolecule corresponding molecule with fathers
1040 * \return allocated map of size molecule::AtomCount with map
1041 * \todo make this with a good sort O(n), not O(n^2)
1042 */
1043int * molecule::GetFatherSonAtomicMap(molecule *OtherMolecule)
1044{
1045 DoLog(3) && (Log() << Verbose(3) << "Begin of GetFatherAtomicMap." << endl);
1046 int *AtomicMap = new int[getAtomCount()];
1047 for (int i=getAtomCount();i--;)
1048 AtomicMap[i] = -1;
1049 if (OtherMolecule == this) { // same molecule
1050 for (int i=getAtomCount();i--;) // no need as -1 means already that there is trivial correspondence
1051 AtomicMap[i] = i;
1052 DoLog(4) && (Log() << Verbose(4) << "Map is trivial." << endl);
1053 } else {
1054 DoLog(4) && (Log() << Verbose(4) << "Map is ");
1055 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
1056 if ((*iter)->father == NULL) {
1057 AtomicMap[(*iter)->getNr()] = -2;
1058 } else {
1059 for (molecule::const_iterator runner = OtherMolecule->begin(); runner != OtherMolecule->end(); ++runner) {
1060 //for (int i=0;i<AtomCount;i++) { // search atom
1061 //for (int j=0;j<OtherMolecule->getAtomCount();j++) {
1062 //Log() << Verbose(4) << "Comparing father " << (*iter)->father << " with the other one " << (*runner)->father << "." << endl;
1063 if ((*iter)->father == (*runner))
1064 AtomicMap[(*iter)->getNr()] = (*runner)->getNr();
1065 }
1066 }
1067 DoLog(0) && (Log() << Verbose(0) << AtomicMap[(*iter)->getNr()] << "\t");
1068 }
1069 DoLog(0) && (Log() << Verbose(0) << endl);
1070 }
1071 DoLog(3) && (Log() << Verbose(3) << "End of GetFatherAtomicMap." << endl);
1072 return AtomicMap;
1073};
1074
1075/** Stores the temperature evaluated from velocities in molecule::Trajectories.
1076 * We simply use the formula equivaleting temperature and kinetic energy:
1077 * \f$k_B T = \sum_i m_i v_i^2\f$
1078 * \param *output output stream of temperature file
1079 * \param startstep first MD step in molecule::Trajectories
1080 * \param endstep last plus one MD step in molecule::Trajectories
1081 * \return file written (true), failure on writing file (false)
1082 */
1083bool molecule::OutputTemperatureFromTrajectories(ofstream * const output, int startstep, int endstep)
1084{
1085 double temperature;
1086 // test stream
1087 if (output == NULL)
1088 return false;
1089 else
1090 *output << "# Step Temperature [K] Temperature [a.u.]" << endl;
1091 for (int step=startstep;step < endstep; step++) { // loop over all time steps
1092 temperature = atoms.totalTemperatureAtStep(step);
1093 *output << step << "\t" << temperature*AtomicEnergyToKelvin << "\t" << temperature << endl;
1094 }
1095 return true;
1096};
1097
1098void molecule::flipActiveFlag(){
1099 ActiveFlag = !ActiveFlag;
1100}
Note: See TracBrowser for help on using the repository browser.