source: src/molecule.cpp@ 8d1dd4

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 8d1dd4 was 900402, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Made the molecule::OutputTemperatureFromTrajectories() method use the totalTemperature method provided by the AtomSet

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