source: src/molecule.cpp@ b0a2e3

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

bonds::previous and ::next removed, lists.hpp deleted.

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