source: src/molecule.cpp@ 6625c3

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

Removed atom_trajectoryparticle*, replaced by AtomInfo class now having std::vector<> for trajectories.

AtomInfo:

Other changes:

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