source: src/molecule.cpp@ 7adf0f

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

Removed molecule::BondDistance, replaced by BondGraph::getMinMaxDistance().

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