source: src/molecule.cpp@ 5309ba

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

ParticleInfo::ParticleInfo_nr is protected and accessed via getter/setter.

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