source: src/molecule.cpp@ 1e6249

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

BondedParticle::(Un)RegisterBond,AddBond,IsBondedTo with step.

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