source: src/molecule.cpp@ e670e4

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

BondedParticle no more hands out non-const ListOfBonds.

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