source: src/molecule.cpp@ d3abb1

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 d3abb1 was ba94c5, checked in by Frederik Heber <heber@…>, 13 years ago

Removed modules graph.[ch]pp.

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