| [bcf653] | 1 | /* | 
|---|
|  | 2 | * Project: MoleCuilder | 
|---|
|  | 3 | * Description: creates and alters molecular systems | 
|---|
| [0aa122] | 4 | * Copyright (C)  2010-2012 University of Bonn. All rights reserved. | 
|---|
| [5aaa43] | 5 | * Copyright (C)  2013 Frederik Heber. All rights reserved. | 
|---|
| [94d5ac6] | 6 | * | 
|---|
|  | 7 | * | 
|---|
|  | 8 | *   This file is part of MoleCuilder. | 
|---|
|  | 9 | * | 
|---|
|  | 10 | *    MoleCuilder is free software: you can redistribute it and/or modify | 
|---|
|  | 11 | *    it under the terms of the GNU General Public License as published by | 
|---|
|  | 12 | *    the Free Software Foundation, either version 2 of the License, or | 
|---|
|  | 13 | *    (at your option) any later version. | 
|---|
|  | 14 | * | 
|---|
|  | 15 | *    MoleCuilder is distributed in the hope that it will be useful, | 
|---|
|  | 16 | *    but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
|  | 17 | *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
|  | 18 | *    GNU General Public License for more details. | 
|---|
|  | 19 | * | 
|---|
|  | 20 | *    You should have received a copy of the GNU General Public License | 
|---|
|  | 21 | *    along with MoleCuilder.  If not, see <http://www.gnu.org/licenses/>. | 
|---|
| [bcf653] | 22 | */ | 
|---|
|  | 23 |  | 
|---|
| [14de469] | 24 | /** \file molecules.cpp | 
|---|
| [69eb71] | 25 | * | 
|---|
| [14de469] | 26 | * Functions for the class molecule. | 
|---|
| [69eb71] | 27 | * | 
|---|
| [14de469] | 28 | */ | 
|---|
|  | 29 |  | 
|---|
| [bf3817] | 30 | // include config.h | 
|---|
| [aafd77] | 31 | #ifdef HAVE_CONFIG_H | 
|---|
|  | 32 | #include <config.h> | 
|---|
|  | 33 | #endif | 
|---|
|  | 34 |  | 
|---|
| [ad011c] | 35 | #include "CodePatterns/MemDebug.hpp" | 
|---|
| [112b09] | 36 |  | 
|---|
| [49e1ae] | 37 | #include <cstring> | 
|---|
| [ac9b56] | 38 | #include <boost/bind.hpp> | 
|---|
| [9df5c6] | 39 | #include <boost/foreach.hpp> | 
|---|
| [49e1ae] | 40 |  | 
|---|
| [aafd77] | 41 | #include <gsl/gsl_inline.h> | 
|---|
|  | 42 | #include <gsl/gsl_heapsort.h> | 
|---|
|  | 43 |  | 
|---|
| [560bbe] | 44 | #include "molecule.hpp" | 
|---|
|  | 45 |  | 
|---|
| [6f0841] | 46 | #include "Atom/atom.hpp" | 
|---|
| [129204] | 47 | #include "Bond/bond.hpp" | 
|---|
| [9d83b6] | 48 | #include "Box.hpp" | 
|---|
|  | 49 | #include "CodePatterns/enumeration.hpp" | 
|---|
|  | 50 | #include "CodePatterns/Log.hpp" | 
|---|
| [c32d21] | 51 | #include "CodePatterns/Observer/Notification.hpp" | 
|---|
| [a80fbdf] | 52 | #include "config.hpp" | 
|---|
| [560bbe] | 53 | #include "Descriptors/AtomIdDescriptor.hpp" | 
|---|
| [3bdb6d] | 54 | #include "Element/element.hpp" | 
|---|
| [129204] | 55 | #include "Graph/BondGraph.hpp" | 
|---|
| [783e88] | 56 | #include "LinearAlgebra/Exceptions.hpp" | 
|---|
| [13d150] | 57 | #include "LinearAlgebra/leastsquaremin.hpp" | 
|---|
| [9d83b6] | 58 | #include "LinearAlgebra/Plane.hpp" | 
|---|
|  | 59 | #include "LinearAlgebra/RealSpaceMatrix.hpp" | 
|---|
|  | 60 | #include "LinearAlgebra/Vector.hpp" | 
|---|
| [53c7fc] | 61 | #include "LinkedCell/linkedcell.hpp" | 
|---|
| [560bbe] | 62 | #include "IdPool_impl.hpp" | 
|---|
| [c67ff9] | 63 | #include "Shapes/BaseShapes.hpp" | 
|---|
| [d127c8] | 64 | #include "Tesselation/tesselation.hpp" | 
|---|
| [b34306] | 65 | #include "World.hpp" | 
|---|
| [9d83b6] | 66 | #include "WorldTime.hpp" | 
|---|
| [14de469] | 67 |  | 
|---|
|  | 68 |  | 
|---|
|  | 69 | /************************************* Functions for class molecule *********************************/ | 
|---|
|  | 70 |  | 
|---|
|  | 71 | /** Constructor of class molecule. | 
|---|
|  | 72 | * Initialises molecule list with correctly referenced start and end, and sets molecule::last_atom to zero. | 
|---|
|  | 73 | */ | 
|---|
| [4d2b33] | 74 | molecule::molecule() : | 
|---|
| [cd5047] | 75 | Observable("molecule"), | 
|---|
| [458c31] | 76 | MDSteps(0), | 
|---|
|  | 77 | NoNonBonds(0), | 
|---|
|  | 78 | NoCyclicBonds(0), | 
|---|
|  | 79 | ActiveFlag(false), | 
|---|
|  | 80 | IndexNr(-1), | 
|---|
| [e791dc] | 81 | NoNonHydrogen(this,boost::bind(&molecule::doCountNoNonHydrogen,this),"NoNonHydrogen"), | 
|---|
| [458c31] | 82 | BondCount(this,boost::bind(&molecule::doCountBonds,this),"BondCount"), | 
|---|
| [52ed5b] | 83 | atomIdPool(1, 20, 100), | 
|---|
| [458c31] | 84 | last_atom(0) | 
|---|
| [69eb71] | 85 | { | 
|---|
| [6a3c83] | 86 | // add specific channels | 
|---|
|  | 87 | Channels *OurChannel = new Channels; | 
|---|
| [708277] | 88 | NotificationChannels.insert( std::make_pair( static_cast<Observable *>(this), OurChannel) ); | 
|---|
| [6a3c83] | 89 | for (size_t type = 0; type < (size_t)NotificationType_MAX; ++type) | 
|---|
|  | 90 | OurChannel->addChannel(type); | 
|---|
| [fa649a] | 91 |  | 
|---|
| [387b36] | 92 | strcpy(name,World::getInstance().getDefaultName().c_str()); | 
|---|
| [14de469] | 93 | }; | 
|---|
|  | 94 |  | 
|---|
| [cbc5fb] | 95 | molecule *NewMolecule(){ | 
|---|
| [4d2b33] | 96 | return new molecule(); | 
|---|
| [cbc5fb] | 97 | } | 
|---|
|  | 98 |  | 
|---|
| [14de469] | 99 | /** Destructor of class molecule. | 
|---|
|  | 100 | * Initialises molecule list with correctly referenced start and end, and sets molecule::last_atom to zero. | 
|---|
|  | 101 | */ | 
|---|
| [69eb71] | 102 | molecule::~molecule() | 
|---|
| [14de469] | 103 | { | 
|---|
| [042f82] | 104 | CleanupMolecule(); | 
|---|
| [14de469] | 105 | }; | 
|---|
|  | 106 |  | 
|---|
| [357fba] | 107 |  | 
|---|
| [cbc5fb] | 108 | void DeleteMolecule(molecule *mol){ | 
|---|
|  | 109 | delete mol; | 
|---|
|  | 110 | } | 
|---|
|  | 111 |  | 
|---|
| [520c8b] | 112 | // getter and setter | 
|---|
| [73a857] | 113 | const std::string molecule::getName() const{ | 
|---|
| [520c8b] | 114 | return std::string(name); | 
|---|
|  | 115 | } | 
|---|
|  | 116 |  | 
|---|
| [ea7176] | 117 | int molecule::getAtomCount() const{ | 
|---|
| [e791dc] | 118 | return atomIds.size(); | 
|---|
|  | 119 | } | 
|---|
|  | 120 |  | 
|---|
|  | 121 | size_t molecule::getNoNonHydrogen() const{ | 
|---|
|  | 122 | return *NoNonHydrogen; | 
|---|
| [ea7176] | 123 | } | 
|---|
|  | 124 |  | 
|---|
| [458c31] | 125 | int molecule::getBondCount() const{ | 
|---|
|  | 126 | return *BondCount; | 
|---|
|  | 127 | } | 
|---|
|  | 128 |  | 
|---|
| [520c8b] | 129 | void molecule::setName(const std::string _name){ | 
|---|
| [2ba827] | 130 | OBSERVE; | 
|---|
| [6a3c83] | 131 | NOTIFY(MoleculeNameChanged); | 
|---|
| [35b698] | 132 | cout << "Set name of molecule " << getId() << " to " << _name << endl; | 
|---|
| [520c8b] | 133 | strncpy(name,_name.c_str(),MAXSTRINGSIZE); | 
|---|
|  | 134 | } | 
|---|
|  | 135 |  | 
|---|
| [c6ab91] | 136 | void molecule::InsertLocalToGlobalId(atom * const pointer) | 
|---|
|  | 137 | { | 
|---|
|  | 138 | #ifndef NDEBUG | 
|---|
|  | 139 | std::pair< LocalToGlobalId_t::iterator, bool > inserter = | 
|---|
|  | 140 | #endif | 
|---|
|  | 141 | LocalToGlobalId.insert( std::make_pair(pointer->getNr(), pointer) ); | 
|---|
|  | 142 | ASSERT( inserter.second, | 
|---|
|  | 143 | "molecule::AddAtom() - local number "+toString(pointer->getNr())+" appears twice."); | 
|---|
|  | 144 | } | 
|---|
|  | 145 |  | 
|---|
| [560bbe] | 146 | bool molecule::changeAtomNr(int oldNr, int newNr, atom* target){ | 
|---|
|  | 147 | OBSERVE; | 
|---|
|  | 148 | if(atomIdPool.reserveId(newNr)){ | 
|---|
| [8c001a] | 149 | _lastchangedatom = target; | 
|---|
| [6a3c83] | 150 | NOTIFY(AtomNrChanged); | 
|---|
| [560bbe] | 151 | if (oldNr != -1)  // -1 is reserved and indicates no number | 
|---|
|  | 152 | atomIdPool.releaseId(oldNr); | 
|---|
| [c6ab91] | 153 | LocalToGlobalId.erase(oldNr); | 
|---|
| [560bbe] | 154 | ASSERT (target, | 
|---|
|  | 155 | "molecule::changeAtomNr() - given target is NULL, cannot set Nr or name."); | 
|---|
|  | 156 | target->setNr(newNr); | 
|---|
| [c6ab91] | 157 | InsertLocalToGlobalId(target); | 
|---|
| [560bbe] | 158 | setAtomName(target); | 
|---|
|  | 159 | return true; | 
|---|
|  | 160 | } else{ | 
|---|
|  | 161 | return false; | 
|---|
|  | 162 | } | 
|---|
|  | 163 | } | 
|---|
|  | 164 |  | 
|---|
| [a7a087] | 165 | bool molecule::changeId(moleculeId_t newId){ | 
|---|
|  | 166 | // first we move ourselves in the world | 
|---|
|  | 167 | // the world lets us know if that succeeded | 
|---|
|  | 168 | if(World::getInstance().changeMoleculeId(id,newId,this)){ | 
|---|
|  | 169 | id = newId; | 
|---|
|  | 170 | return true; | 
|---|
|  | 171 | } | 
|---|
|  | 172 | else{ | 
|---|
|  | 173 | return false; | 
|---|
|  | 174 | } | 
|---|
|  | 175 | } | 
|---|
|  | 176 |  | 
|---|
|  | 177 |  | 
|---|
| [73a857] | 178 | moleculeId_t molecule::getId() const { | 
|---|
| [cbc5fb] | 179 | return id; | 
|---|
|  | 180 | } | 
|---|
|  | 181 |  | 
|---|
|  | 182 | void molecule::setId(moleculeId_t _id){ | 
|---|
|  | 183 | id =_id; | 
|---|
|  | 184 | } | 
|---|
|  | 185 |  | 
|---|
| [73a857] | 186 | const Formula &molecule::getFormula() const { | 
|---|
| [f17e1c] | 187 | return formula; | 
|---|
| [ac9b56] | 188 | } | 
|---|
|  | 189 |  | 
|---|
| [73a857] | 190 | unsigned int molecule::getElementCount() const{ | 
|---|
| [389cc8] | 191 | return formula.getElementCount(); | 
|---|
|  | 192 | } | 
|---|
|  | 193 |  | 
|---|
|  | 194 | bool molecule::hasElement(const element *element) const{ | 
|---|
|  | 195 | return formula.hasElement(element); | 
|---|
|  | 196 | } | 
|---|
|  | 197 |  | 
|---|
|  | 198 | bool molecule::hasElement(atomicNumber_t Z) const{ | 
|---|
|  | 199 | return formula.hasElement(Z); | 
|---|
|  | 200 | } | 
|---|
|  | 201 |  | 
|---|
|  | 202 | bool molecule::hasElement(const string &shorthand) const{ | 
|---|
|  | 203 | return formula.hasElement(shorthand); | 
|---|
|  | 204 | } | 
|---|
|  | 205 |  | 
|---|
| [bd58fb] | 206 | /************************** Access to the List of Atoms ****************/ | 
|---|
|  | 207 |  | 
|---|
| [9879f6] | 208 | molecule::const_iterator molecule::erase( const_iterator loc ) | 
|---|
|  | 209 | { | 
|---|
| [bf8e20] | 210 | OBSERVE; | 
|---|
| [59fff1] | 211 | const_iterator iter = loc; | 
|---|
| [30c753] | 212 | ++iter; | 
|---|
| [59fff1] | 213 | atom * const _atom = const_cast<atom *>(*loc); | 
|---|
| [8c001a] | 214 | { | 
|---|
|  | 215 | _lastchangedatom = _atom; | 
|---|
|  | 216 | NOTIFY(AtomRemoved); | 
|---|
|  | 217 | } | 
|---|
| [59fff1] | 218 | atomIds.erase( _atom->getId() ); | 
|---|
| [6a3c83] | 219 | { | 
|---|
|  | 220 | NOTIFY(AtomNrChanged); | 
|---|
|  | 221 | atomIdPool.releaseId(_atom->getNr()); | 
|---|
| [c6ab91] | 222 | LocalToGlobalId.erase(_atom->getNr()); | 
|---|
| [6a3c83] | 223 | _atom->setNr(-1); | 
|---|
|  | 224 | } | 
|---|
| [59fff1] | 225 | formula-=_atom->getType(); | 
|---|
|  | 226 | _atom->removeFromMolecule(); | 
|---|
| [9879f6] | 227 | return iter; | 
|---|
|  | 228 | } | 
|---|
|  | 229 |  | 
|---|
| [6cfa36] | 230 | molecule::const_iterator molecule::erase( atom * key ) | 
|---|
| [9879f6] | 231 | { | 
|---|
| [bf8e20] | 232 | OBSERVE; | 
|---|
| [8c001a] | 233 | { | 
|---|
|  | 234 | _lastchangedatom = key; | 
|---|
|  | 235 | NOTIFY(AtomRemoved); | 
|---|
|  | 236 | } | 
|---|
| [59fff1] | 237 | const_iterator iter = find(key); | 
|---|
| [a7b761b] | 238 | if (iter != end()){ | 
|---|
| [30c753] | 239 | ++iter; | 
|---|
| [274d45] | 240 | atomIds.erase( key->getId() ); | 
|---|
| [6a3c83] | 241 | { | 
|---|
|  | 242 | NOTIFY(AtomNrChanged); | 
|---|
|  | 243 | atomIdPool.releaseId(key->getNr()); | 
|---|
| [c6ab91] | 244 | LocalToGlobalId.erase(key->getNr()); | 
|---|
| [6a3c83] | 245 | key->setNr(-1); | 
|---|
|  | 246 | } | 
|---|
| [8f4df1] | 247 | formula-=key->getType(); | 
|---|
| [6cfa36] | 248 | key->removeFromMolecule(); | 
|---|
| [a7b761b] | 249 | } | 
|---|
|  | 250 | return iter; | 
|---|
| [9879f6] | 251 | } | 
|---|
|  | 252 |  | 
|---|
|  | 253 | pair<molecule::iterator,bool> molecule::insert ( atom * const key ) | 
|---|
|  | 254 | { | 
|---|
| [bf8e20] | 255 | OBSERVE; | 
|---|
| [6a3c83] | 256 | NOTIFY(AtomInserted); | 
|---|
| [8c001a] | 257 | _lastchangedatom = key; | 
|---|
| [8e1f901] | 258 | std::pair<iterator,bool> res = atomIds.insert(key->getId()); | 
|---|
| [274d45] | 259 | if (res.second) { // push atom if went well | 
|---|
| [6a3c83] | 260 | NOTIFY(AtomNrChanged); | 
|---|
| [560bbe] | 261 | key->setNr(atomIdPool.getNextId()); | 
|---|
| [c6ab91] | 262 | InsertLocalToGlobalId(key); | 
|---|
| [560bbe] | 263 | setAtomName(key); | 
|---|
| [8f4df1] | 264 | formula+=key->getType(); | 
|---|
| [8e1f901] | 265 | return res; | 
|---|
| [274d45] | 266 | } else { | 
|---|
| [30c753] | 267 | return pair<iterator,bool>(end(),res.second); | 
|---|
| [274d45] | 268 | } | 
|---|
| [9879f6] | 269 | } | 
|---|
| [520c8b] | 270 |  | 
|---|
| [560bbe] | 271 | void molecule::setAtomName(atom *_atom) const | 
|---|
|  | 272 | { | 
|---|
|  | 273 | std::stringstream sstr; | 
|---|
| [52ed5b] | 274 | sstr << _atom->getType()->getSymbol() << _atom->getNr(); | 
|---|
| [560bbe] | 275 | _atom->setName(sstr.str()); | 
|---|
|  | 276 | } | 
|---|
|  | 277 |  | 
|---|
| [9317be] | 278 | World::AtomComposite molecule::getAtomSet() const | 
|---|
| [3738f0] | 279 | { | 
|---|
| [9317be] | 280 | World::AtomComposite vector_of_atoms; | 
|---|
| [59fff1] | 281 | for (molecule::iterator iter = begin(); iter != end(); ++iter) | 
|---|
| [30c753] | 282 | vector_of_atoms.push_back(*iter); | 
|---|
| [3738f0] | 283 | return vector_of_atoms; | 
|---|
|  | 284 | } | 
|---|
|  | 285 |  | 
|---|
| [14de469] | 286 | /** Adds given atom \a *pointer from molecule list. | 
|---|
| [69eb71] | 287 | * Increases molecule::last_atom and gives last number to added atom and names it according to its element::abbrev and molecule::AtomCount | 
|---|
| [14de469] | 288 | * \param *pointer allocated and set atom | 
|---|
|  | 289 | * \return true - succeeded, false - atom not found in list | 
|---|
|  | 290 | */ | 
|---|
|  | 291 | bool molecule::AddAtom(atom *pointer) | 
|---|
| [69eb71] | 292 | { | 
|---|
| [042f82] | 293 | if (pointer != NULL) { | 
|---|
| [356ae4] | 294 | // molecule::insert() is called by setMolecule() | 
|---|
| [6cfa36] | 295 | pointer->setMolecule(this); | 
|---|
| [f721c6] | 296 | } | 
|---|
| [9879f6] | 297 | return true; | 
|---|
| [14de469] | 298 | }; | 
|---|
|  | 299 |  | 
|---|
|  | 300 | /** Adds a copy of the given atom \a *pointer from molecule list. | 
|---|
|  | 301 | * Increases molecule::last_atom and gives last number to added atom. | 
|---|
|  | 302 | * \param *pointer allocated and set atom | 
|---|
| [89c8b2] | 303 | * \return pointer to the newly added atom | 
|---|
| [14de469] | 304 | */ | 
|---|
|  | 305 | atom * molecule::AddCopyAtom(atom *pointer) | 
|---|
| [69eb71] | 306 | { | 
|---|
| [f721c6] | 307 | atom *retval = NULL; | 
|---|
| [042f82] | 308 | if (pointer != NULL) { | 
|---|
| [46d958] | 309 | atom *walker = pointer->clone(); | 
|---|
| [c6ab91] | 310 | AddAtom(walker); | 
|---|
| [f721c6] | 311 | retval=walker; | 
|---|
|  | 312 | } | 
|---|
|  | 313 | return retval; | 
|---|
| [14de469] | 314 | }; | 
|---|
|  | 315 |  | 
|---|
|  | 316 | /** Adds a Hydrogen atom in replacement for the given atom \a *partner in bond with a *origin. | 
|---|
|  | 317 | * Here, we have to distinguish between single, double or triple bonds as stated by \a BondDegree, that each demand | 
|---|
|  | 318 | * a different scheme when adding \a *replacement atom for the given one. | 
|---|
|  | 319 | * -# Single Bond: Simply add new atom with bond distance rescaled to typical hydrogen one | 
|---|
|  | 320 | * -# Double Bond: Here, we need the **BondList of the \a *origin atom, by scanning for the other bonds instead of | 
|---|
| [042f82] | 321 | *    *Bond, we use the through these connected atoms to determine the plane they lie in, vector::MakeNormalvector(). | 
|---|
|  | 322 | *    The orthonormal vector to this plane along with the vector in *Bond direction determines the plane the two | 
|---|
|  | 323 | *    replacing hydrogens shall lie in. Now, all remains to do is take the usual hydrogen double bond angle for the | 
|---|
|  | 324 | *    element of *origin and form the sin/cos admixture of both plane vectors for the new coordinates of the two | 
|---|
|  | 325 | *    hydrogens forming this angle with *origin. | 
|---|
| [14de469] | 326 | * -# 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 | 
|---|
| [042f82] | 327 | *    triangle formed by the to be added hydrogens are not equal to the typical bond distance \f$l\f$ but have to be | 
|---|
|  | 328 | *    determined from the typical angle \f$\alpha\f$ for a hydrogen triple connected to the element of *origin): | 
|---|
|  | 329 | *    We have the height \f$d\f$ as the vector in *Bond direction (from triangle C1-H1-H2). | 
|---|
|  | 330 | *    \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 )}} | 
|---|
|  | 331 | *    \f] | 
|---|
|  | 332 | *    vector::GetNormalvector() creates one orthonormal vector from this *Bond vector and vector::MakeNormalvector creates | 
|---|
|  | 333 | *    the third one from the former two vectors. The latter ones form the plane of the base triangle mentioned above. | 
|---|
|  | 334 | *    The lengths for these are \f$f\f$ and \f$g\f$ (from triangle H1-H2-(center of H1-H2-H3)) with knowledge that | 
|---|
|  | 335 | *    the median lines in an isosceles triangle meet in the center point with a ratio 2:1. | 
|---|
|  | 336 | *    \f[ f = \frac{b}{\sqrt{3}} \qquad g = \frac{b}{2} | 
|---|
|  | 337 | *    \f] | 
|---|
|  | 338 | *    as the coordination of all three atoms in the coordinate system of these three vectors: | 
|---|
|  | 339 | *    \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$. | 
|---|
| [69eb71] | 340 | * | 
|---|
| [14de469] | 341 | * \param *out output stream for debugging | 
|---|
| [69eb71] | 342 | * \param *Bond pointer to bond between \a *origin and \a *replacement | 
|---|
|  | 343 | * \param *TopOrigin son of \a *origin of upper level molecule (the atom added to this molecule as a copy of \a *origin) | 
|---|
| [14de469] | 344 | * \param *origin pointer to atom which acts as the origin for scaling the added hydrogen to correct bond length | 
|---|
|  | 345 | * \param *replacement pointer to the atom which shall be copied as a hydrogen atom in this molecule | 
|---|
|  | 346 | * \param isAngstroem whether the coordination of the given atoms is in AtomicLength (false) or Angstrom(true) | 
|---|
|  | 347 | * \return number of atoms added, if < bond::BondDegree then something went wrong | 
|---|
|  | 348 | * \todo double and triple bonds splitting (always use the tetraeder angle!) | 
|---|
|  | 349 | */ | 
|---|
| [06804b] | 350 | //bool molecule::AddHydrogenReplacementAtom(bond::ptr TopBond, atom *BottomOrigin, atom *TopOrigin, atom *TopReplacement, bool IsAngstroem) | 
|---|
|  | 351 | //{ | 
|---|
|  | 352 | ////  Info info(__func__); | 
|---|
|  | 353 | //  bool AllWentWell = true;    // flag gathering the boolean return value of molecule::AddAtom and other functions, as return value on exit | 
|---|
|  | 354 | //  double bondlength;  // bond length of the bond to be replaced/cut | 
|---|
|  | 355 | //  double bondangle;  // bond angle of the bond to be replaced/cut | 
|---|
|  | 356 | //  double BondRescale;   // rescale value for the hydrogen bond length | 
|---|
|  | 357 | //  bond::ptr FirstBond; | 
|---|
|  | 358 | //  bond::ptr SecondBond; // Other bonds in double bond case to determine "other" plane | 
|---|
|  | 359 | //  atom *FirstOtherAtom = NULL, *SecondOtherAtom = NULL, *ThirdOtherAtom = NULL; // pointer to hydrogen atoms to be added | 
|---|
|  | 360 | //  double b,l,d,f,g, alpha, factors[NDIM];    // hold temporary values in triple bond case for coordination determination | 
|---|
|  | 361 | //  Vector Orthovector1, Orthovector2;  // temporary vectors in coordination construction | 
|---|
|  | 362 | //  Vector InBondvector;    // vector in direction of *Bond | 
|---|
|  | 363 | //  const RealSpaceMatrix &matrix =  World::getInstance().getDomain().getM(); | 
|---|
|  | 364 | //  bond::ptr Binder; | 
|---|
|  | 365 | // | 
|---|
|  | 366 | //  // create vector in direction of bond | 
|---|
|  | 367 | //  InBondvector = TopReplacement->getPosition() - TopOrigin->getPosition(); | 
|---|
|  | 368 | //  bondlength = InBondvector.Norm(); | 
|---|
|  | 369 | // | 
|---|
|  | 370 | //   // is greater than typical bond distance? Then we have to correct periodically | 
|---|
|  | 371 | //   // the problem is not the H being out of the box, but InBondvector have the wrong direction | 
|---|
|  | 372 | //   // due to TopReplacement or Origin being on the wrong side! | 
|---|
|  | 373 | //  const BondGraph * const BG = World::getInstance().getBondGraph(); | 
|---|
|  | 374 | //  const range<double> MinMaxBondDistance( | 
|---|
|  | 375 | //      BG->getMinMaxDistance(TopOrigin,TopReplacement)); | 
|---|
|  | 376 | //  if (!MinMaxBondDistance.isInRange(bondlength)) { | 
|---|
|  | 377 | ////    LOG(4, "InBondvector is: " << InBondvector << "."); | 
|---|
|  | 378 | //    Orthovector1.Zero(); | 
|---|
|  | 379 | //    for (int i=NDIM;i--;) { | 
|---|
|  | 380 | //      l = TopReplacement->at(i) - TopOrigin->at(i); | 
|---|
|  | 381 | //      if (fabs(l) > MinMaxBondDistance.last) { // is component greater than bond distance (check against min not useful here) | 
|---|
|  | 382 | //        Orthovector1[i] = (l < 0) ? -1. : +1.; | 
|---|
|  | 383 | //      } // (signs are correct, was tested!) | 
|---|
|  | 384 | //    } | 
|---|
|  | 385 | //    Orthovector1 *= matrix; | 
|---|
|  | 386 | //    InBondvector -= Orthovector1; // subtract just the additional translation | 
|---|
|  | 387 | //    bondlength = InBondvector.Norm(); | 
|---|
|  | 388 | ////    LOG(4, "INFO: Corrected InBondvector is now: " << InBondvector << "."); | 
|---|
|  | 389 | //  } // periodic correction finished | 
|---|
|  | 390 | // | 
|---|
|  | 391 | //  InBondvector.Normalize(); | 
|---|
|  | 392 | //  // get typical bond length and store as scale factor for later | 
|---|
|  | 393 | //  ASSERT(TopOrigin->getType() != NULL, "AddHydrogenReplacementAtom: element of TopOrigin is not given."); | 
|---|
|  | 394 | //  BondRescale = TopOrigin->getType()->getHBondDistance(TopBond->getDegree()-1); | 
|---|
|  | 395 | //  if (BondRescale == -1) { | 
|---|
|  | 396 | //    ELOG(1, "There is no typical hydrogen bond distance in replacing bond (" << TopOrigin->getName() << "<->" << TopReplacement->getName() << ") of degree " << TopBond->getDegree() << "!"); | 
|---|
|  | 397 | //    return false; | 
|---|
|  | 398 | //    BondRescale = bondlength; | 
|---|
|  | 399 | //  } else { | 
|---|
|  | 400 | //    if (!IsAngstroem) | 
|---|
|  | 401 | //      BondRescale /= (1.*AtomicLengthToAngstroem); | 
|---|
|  | 402 | //  } | 
|---|
|  | 403 | // | 
|---|
|  | 404 | //  // discern single, double and triple bonds | 
|---|
|  | 405 | //  switch(TopBond->getDegree()) { | 
|---|
|  | 406 | //    case 1: | 
|---|
|  | 407 | //      FirstOtherAtom = World::getInstance().createAtom();    // new atom | 
|---|
|  | 408 | //      FirstOtherAtom->setType(1);  // element is Hydrogen | 
|---|
|  | 409 | //      FirstOtherAtom->setAtomicVelocity(TopReplacement->getAtomicVelocity()); // copy velocity | 
|---|
|  | 410 | //      FirstOtherAtom->setFixedIon(TopReplacement->getFixedIon()); | 
|---|
|  | 411 | //      if (TopReplacement->getType()->getAtomicNumber() == 1) { // neither rescale nor replace if it's already hydrogen | 
|---|
|  | 412 | //        FirstOtherAtom->father = TopReplacement; | 
|---|
|  | 413 | //        BondRescale = bondlength; | 
|---|
|  | 414 | //      } else { | 
|---|
|  | 415 | //        FirstOtherAtom->father = NULL;  // if we replace hydrogen, we mark it as our father, otherwise we are just an added hydrogen with no father | 
|---|
|  | 416 | //      } | 
|---|
|  | 417 | //      InBondvector *= BondRescale;   // rescale the distance vector to Hydrogen bond length | 
|---|
|  | 418 | //      FirstOtherAtom->setPosition(TopOrigin->getPosition() + InBondvector); // set coordination to origin and add distance vector to replacement atom | 
|---|
|  | 419 | //      AllWentWell = AllWentWell && AddAtom(FirstOtherAtom); | 
|---|
|  | 420 | ////      LOG(4, "INFO: Added " << *FirstOtherAtom << " at: " << FirstOtherAtom->x << "."); | 
|---|
|  | 421 | //      Binder = AddBond(BottomOrigin, FirstOtherAtom, 1); | 
|---|
|  | 422 | //      Binder->Cyclic = false; | 
|---|
|  | 423 | //      Binder->Type = GraphEdge::TreeEdge; | 
|---|
|  | 424 | //      break; | 
|---|
|  | 425 | //    case 2: | 
|---|
|  | 426 | //      { | 
|---|
|  | 427 | //        // determine two other bonds (warning if there are more than two other) plus valence sanity check | 
|---|
|  | 428 | //        const BondList& ListOfBonds = TopOrigin->getListOfBonds(); | 
|---|
|  | 429 | //        for (BondList::const_iterator Runner = ListOfBonds.begin(); | 
|---|
|  | 430 | //            Runner != ListOfBonds.end(); | 
|---|
|  | 431 | //            ++Runner) { | 
|---|
|  | 432 | //          if ((*Runner) != TopBond) { | 
|---|
|  | 433 | //            if (FirstBond == NULL) { | 
|---|
|  | 434 | //              FirstBond = (*Runner); | 
|---|
|  | 435 | //              FirstOtherAtom = (*Runner)->GetOtherAtom(TopOrigin); | 
|---|
|  | 436 | //            } else if (SecondBond == NULL) { | 
|---|
|  | 437 | //              SecondBond = (*Runner); | 
|---|
|  | 438 | //              SecondOtherAtom = (*Runner)->GetOtherAtom(TopOrigin); | 
|---|
|  | 439 | //            } else { | 
|---|
|  | 440 | //              ELOG(2, "Detected more than four bonds for atom " << TopOrigin->getName()); | 
|---|
|  | 441 | //            } | 
|---|
|  | 442 | //          } | 
|---|
|  | 443 | //        } | 
|---|
|  | 444 | //      } | 
|---|
|  | 445 | //      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) | 
|---|
|  | 446 | //        SecondBond = TopBond; | 
|---|
|  | 447 | //        SecondOtherAtom = TopReplacement; | 
|---|
|  | 448 | //      } | 
|---|
|  | 449 | //      if (FirstOtherAtom != NULL) { // then we just have this double bond and the plane does not matter at all | 
|---|
|  | 450 | ////        LOG(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."); | 
|---|
|  | 451 | // | 
|---|
|  | 452 | //        // determine the plane of these two with the *origin | 
|---|
|  | 453 | //        try { | 
|---|
|  | 454 | //          Orthovector1 = Plane(TopOrigin->getPosition(), FirstOtherAtom->getPosition(), SecondOtherAtom->getPosition()).getNormal(); | 
|---|
|  | 455 | //        } | 
|---|
|  | 456 | //        catch(LinearDependenceException &excp){ | 
|---|
|  | 457 | //          LOG(0, boost::diagnostic_information(excp)); | 
|---|
|  | 458 | //          // TODO: figure out what to do with the Orthovector in this case | 
|---|
|  | 459 | //          AllWentWell = false; | 
|---|
|  | 460 | //        } | 
|---|
|  | 461 | //      } else { | 
|---|
|  | 462 | //        Orthovector1.GetOneNormalVector(InBondvector); | 
|---|
|  | 463 | //      } | 
|---|
|  | 464 | //      //LOG(3, "INFO: Orthovector1: " << Orthovector1 << "."); | 
|---|
|  | 465 | //      // orthogonal vector and bond vector between origin and replacement form the new plane | 
|---|
|  | 466 | //      Orthovector1.MakeNormalTo(InBondvector); | 
|---|
|  | 467 | //      Orthovector1.Normalize(); | 
|---|
|  | 468 | //      //LOG(3, "ReScaleCheck: " << Orthovector1.Norm() << " and " << InBondvector.Norm() << "."); | 
|---|
|  | 469 | // | 
|---|
|  | 470 | //      // create the two Hydrogens ... | 
|---|
|  | 471 | //      FirstOtherAtom = World::getInstance().createAtom(); | 
|---|
|  | 472 | //      SecondOtherAtom = World::getInstance().createAtom(); | 
|---|
|  | 473 | //      FirstOtherAtom->setType(1); | 
|---|
|  | 474 | //      SecondOtherAtom->setType(1); | 
|---|
|  | 475 | //      FirstOtherAtom->setAtomicVelocity(TopReplacement->getAtomicVelocity()); // copy velocity | 
|---|
|  | 476 | //      FirstOtherAtom->setFixedIon(TopReplacement->getFixedIon()); | 
|---|
|  | 477 | //      SecondOtherAtom->setAtomicVelocity(TopReplacement->getAtomicVelocity()); // copy velocity | 
|---|
|  | 478 | //      SecondOtherAtom->setFixedIon(TopReplacement->getFixedIon()); | 
|---|
|  | 479 | //      FirstOtherAtom->father = NULL;  // we are just an added hydrogen with no father | 
|---|
|  | 480 | //      SecondOtherAtom->father = NULL;  //  we are just an added hydrogen with no father | 
|---|
|  | 481 | //      bondangle = TopOrigin->getType()->getHBondAngle(1); | 
|---|
|  | 482 | //      if (bondangle == -1) { | 
|---|
|  | 483 | //        ELOG(1, "There is no typical hydrogen bond angle in replacing bond (" << TopOrigin->getName() << "<->" << TopReplacement->getName() << ") of degree " << TopBond->getDegree() << "!"); | 
|---|
|  | 484 | //        return false; | 
|---|
|  | 485 | //        bondangle = 0; | 
|---|
|  | 486 | //      } | 
|---|
|  | 487 | //      bondangle *= M_PI/180./2.; | 
|---|
|  | 488 | ////      LOG(3, "INFO: ReScaleCheck: InBondvector " << InBondvector << ", " << Orthovector1 << "."); | 
|---|
|  | 489 | ////      LOG(3, "Half the bond angle is " << bondangle << ", sin and cos of it: " << sin(bondangle) << ", " << cos(bondangle)); | 
|---|
|  | 490 | //      FirstOtherAtom->Zero(); | 
|---|
|  | 491 | //      SecondOtherAtom->Zero(); | 
|---|
|  | 492 | //      for(int i=NDIM;i--;) { // rotate by half the bond angle in both directions (InBondvector is bondangle = 0 direction) | 
|---|
|  | 493 | //        FirstOtherAtom->set(i, InBondvector[i] * cos(bondangle) + Orthovector1[i] * (sin(bondangle))); | 
|---|
|  | 494 | //        SecondOtherAtom->set(i, InBondvector[i] * cos(bondangle) + Orthovector1[i] * (-sin(bondangle))); | 
|---|
|  | 495 | //      } | 
|---|
|  | 496 | //      FirstOtherAtom->Scale(BondRescale);  // rescale by correct BondDistance | 
|---|
|  | 497 | //      SecondOtherAtom->Scale(BondRescale); | 
|---|
|  | 498 | //      //LOG(3, "ReScaleCheck: " << FirstOtherAtom->x.Norm() << " and " << SecondOtherAtom->x.Norm() << "."); | 
|---|
|  | 499 | //      *FirstOtherAtom += TopOrigin->getPosition(); | 
|---|
|  | 500 | //      *SecondOtherAtom += TopOrigin->getPosition(); | 
|---|
|  | 501 | //      // ... and add to molecule | 
|---|
|  | 502 | //      AllWentWell = AllWentWell && AddAtom(FirstOtherAtom); | 
|---|
|  | 503 | //      AllWentWell = AllWentWell && AddAtom(SecondOtherAtom); | 
|---|
|  | 504 | ////      LOG(4, "INFO: Added " << *FirstOtherAtom << " at: " << FirstOtherAtom->x << "."); | 
|---|
|  | 505 | ////      LOG(4, "INFO: Added " << *SecondOtherAtom << " at: " << SecondOtherAtom->x << "."); | 
|---|
|  | 506 | //      Binder = AddBond(BottomOrigin, FirstOtherAtom, 1); | 
|---|
|  | 507 | //      Binder->Cyclic = false; | 
|---|
|  | 508 | //      Binder->Type = GraphEdge::TreeEdge; | 
|---|
|  | 509 | //      Binder = AddBond(BottomOrigin, SecondOtherAtom, 1); | 
|---|
|  | 510 | //      Binder->Cyclic = false; | 
|---|
|  | 511 | //      Binder->Type = GraphEdge::TreeEdge; | 
|---|
|  | 512 | //      break; | 
|---|
|  | 513 | //    case 3: | 
|---|
|  | 514 | //      // take the "usual" tetraoidal angle and add the three Hydrogen in direction of the bond (height of the tetraoid) | 
|---|
|  | 515 | //      FirstOtherAtom = World::getInstance().createAtom(); | 
|---|
|  | 516 | //      SecondOtherAtom = World::getInstance().createAtom(); | 
|---|
|  | 517 | //      ThirdOtherAtom = World::getInstance().createAtom(); | 
|---|
|  | 518 | //      FirstOtherAtom->setType(1); | 
|---|
|  | 519 | //      SecondOtherAtom->setType(1); | 
|---|
|  | 520 | //      ThirdOtherAtom->setType(1); | 
|---|
|  | 521 | //      FirstOtherAtom->setAtomicVelocity(TopReplacement->getAtomicVelocity()); // copy velocity | 
|---|
|  | 522 | //      FirstOtherAtom->setFixedIon(TopReplacement->getFixedIon()); | 
|---|
|  | 523 | //      SecondOtherAtom->setAtomicVelocity(TopReplacement->getAtomicVelocity()); // copy velocity | 
|---|
|  | 524 | //      SecondOtherAtom->setFixedIon(TopReplacement->getFixedIon()); | 
|---|
|  | 525 | //      ThirdOtherAtom->setAtomicVelocity(TopReplacement->getAtomicVelocity()); // copy velocity | 
|---|
|  | 526 | //      ThirdOtherAtom->setFixedIon(TopReplacement->getFixedIon()); | 
|---|
|  | 527 | //      FirstOtherAtom->father = NULL;  //  we are just an added hydrogen with no father | 
|---|
|  | 528 | //      SecondOtherAtom->father = NULL;  //  we are just an added hydrogen with no father | 
|---|
|  | 529 | //      ThirdOtherAtom->father = NULL;  //  we are just an added hydrogen with no father | 
|---|
|  | 530 | // | 
|---|
|  | 531 | //      // we need to vectors orthonormal the InBondvector | 
|---|
|  | 532 | //      AllWentWell = AllWentWell && Orthovector1.GetOneNormalVector(InBondvector); | 
|---|
|  | 533 | ////      LOG(3, "INFO: Orthovector1: " << Orthovector1 << "."); | 
|---|
|  | 534 | //      try{ | 
|---|
|  | 535 | //        Orthovector2 = Plane(InBondvector, Orthovector1,0).getNormal(); | 
|---|
|  | 536 | //      } | 
|---|
|  | 537 | //      catch(LinearDependenceException &excp) { | 
|---|
|  | 538 | //        LOG(0, boost::diagnostic_information(excp)); | 
|---|
|  | 539 | //        AllWentWell = false; | 
|---|
|  | 540 | //      } | 
|---|
|  | 541 | ////      LOG(3, "INFO: Orthovector2: " << Orthovector2 << ".") | 
|---|
|  | 542 | // | 
|---|
|  | 543 | //      // create correct coordination for the three atoms | 
|---|
|  | 544 | //      alpha = (TopOrigin->getType()->getHBondAngle(2))/180.*M_PI/2.;  // retrieve triple bond angle from database | 
|---|
|  | 545 | //      l = BondRescale;        // desired bond length | 
|---|
|  | 546 | //      b = 2.*l*sin(alpha);    // base length of isosceles triangle | 
|---|
|  | 547 | //      d = l*sqrt(cos(alpha)*cos(alpha) - sin(alpha)*sin(alpha)/3.);   // length for InBondvector | 
|---|
|  | 548 | //      f = b/sqrt(3.);   // length for Orthvector1 | 
|---|
|  | 549 | //      g = b/2.;         // length for Orthvector2 | 
|---|
|  | 550 | ////      LOG(3, "Bond length and half-angle: " << l << ", " << alpha << "\t (b,d,f,g) = " << b << ", " << d << ", " << f << ", " << g << ", "); | 
|---|
|  | 551 | ////      LOG(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)); | 
|---|
|  | 552 | //      factors[0] = d; | 
|---|
|  | 553 | //      factors[1] = f; | 
|---|
|  | 554 | //      factors[2] = 0.; | 
|---|
|  | 555 | //      FirstOtherAtom->LinearCombinationOfVectors(InBondvector, Orthovector1, Orthovector2, factors); | 
|---|
|  | 556 | //      factors[1] = -0.5*f; | 
|---|
|  | 557 | //      factors[2] = g; | 
|---|
|  | 558 | //      SecondOtherAtom->LinearCombinationOfVectors(InBondvector, Orthovector1, Orthovector2, factors); | 
|---|
|  | 559 | //      factors[2] = -g; | 
|---|
|  | 560 | //      ThirdOtherAtom->LinearCombinationOfVectors(InBondvector, Orthovector1, Orthovector2, factors); | 
|---|
|  | 561 | // | 
|---|
|  | 562 | //      // rescale each to correct BondDistance | 
|---|
|  | 563 | ////      FirstOtherAtom->x.Scale(&BondRescale); | 
|---|
|  | 564 | ////      SecondOtherAtom->x.Scale(&BondRescale); | 
|---|
|  | 565 | ////      ThirdOtherAtom->x.Scale(&BondRescale); | 
|---|
|  | 566 | // | 
|---|
|  | 567 | //      // and relative to *origin atom | 
|---|
|  | 568 | //      *FirstOtherAtom += TopOrigin->getPosition(); | 
|---|
|  | 569 | //      *SecondOtherAtom += TopOrigin->getPosition(); | 
|---|
|  | 570 | //      *ThirdOtherAtom += TopOrigin->getPosition(); | 
|---|
|  | 571 | // | 
|---|
|  | 572 | //      // ... and add to molecule | 
|---|
|  | 573 | //      AllWentWell = AllWentWell && AddAtom(FirstOtherAtom); | 
|---|
|  | 574 | //      AllWentWell = AllWentWell && AddAtom(SecondOtherAtom); | 
|---|
|  | 575 | //      AllWentWell = AllWentWell && AddAtom(ThirdOtherAtom); | 
|---|
|  | 576 | ////      LOG(4, "INFO: Added " << *FirstOtherAtom << " at: " << FirstOtherAtom->x << "."); | 
|---|
|  | 577 | ////      LOG(4, "INFO: Added " << *SecondOtherAtom << " at: " << SecondOtherAtom->x << "."); | 
|---|
|  | 578 | ////      LOG(4, "INFO: Added " << *ThirdOtherAtom << " at: " << ThirdOtherAtom->x << "."); | 
|---|
|  | 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 | //      ELOG(1, "BondDegree does not state single, double or triple bond!"); | 
|---|
|  | 591 | //      AllWentWell = false; | 
|---|
|  | 592 | //      break; | 
|---|
|  | 593 | //  } | 
|---|
|  | 594 | // | 
|---|
|  | 595 | //  return AllWentWell; | 
|---|
|  | 596 | //}; | 
|---|
| [14de469] | 597 |  | 
|---|
|  | 598 | /** Creates a copy of this molecule. | 
|---|
| [c67ff9] | 599 | * \param offset translation Vector for the new molecule relative to old one | 
|---|
| [14de469] | 600 | * \return copy of molecule | 
|---|
|  | 601 | */ | 
|---|
| [c67ff9] | 602 | molecule *molecule::CopyMolecule(const Vector &offset) const | 
|---|
| [14de469] | 603 | { | 
|---|
| [5f612ee] | 604 | molecule *copy = World::getInstance().createMolecule(); | 
|---|
| [042f82] | 605 |  | 
|---|
|  | 606 | // copy all atoms | 
|---|
| [30c753] | 607 | std::map< const atom *, atom *> FatherFinder; | 
|---|
| [59fff1] | 608 | for (iterator iter = begin(); iter != end(); ++iter) { | 
|---|
|  | 609 | atom * const copy_atom = copy->AddCopyAtom(*iter); | 
|---|
| [c67ff9] | 610 | copy_atom->setPosition(copy_atom->getPosition() + offset); | 
|---|
| [30c753] | 611 | FatherFinder.insert( std::make_pair( *iter, copy_atom ) ); | 
|---|
|  | 612 | } | 
|---|
| [042f82] | 613 |  | 
|---|
|  | 614 | // copy all bonds | 
|---|
| [30c753] | 615 | for(const_iterator AtomRunner = begin(); AtomRunner != end(); ++AtomRunner) { | 
|---|
| [9d83b6] | 616 | const BondList& ListOfBonds = (*AtomRunner)->getListOfBonds(); | 
|---|
|  | 617 | for(BondList::const_iterator BondRunner = ListOfBonds.begin(); | 
|---|
|  | 618 | BondRunner != ListOfBonds.end(); | 
|---|
|  | 619 | ++BondRunner) | 
|---|
| [e08c46] | 620 | if ((*BondRunner)->leftatom == *AtomRunner) { | 
|---|
| [88c8ec] | 621 | bond::ptr Binder = (*BondRunner); | 
|---|
| [e08c46] | 622 | // get the pendant atoms of current bond in the copy molecule | 
|---|
| [30c753] | 623 | ASSERT(FatherFinder.count(Binder->leftatom), | 
|---|
| [59fff1] | 624 | "molecule::CopyMolecule() - No copy of original left atom " | 
|---|
|  | 625 | +toString(Binder->leftatom)+" for bond copy found"); | 
|---|
| [30c753] | 626 | ASSERT(FatherFinder.count(Binder->rightatom), | 
|---|
| [59fff1] | 627 | "molecule::CopyMolecule() - No copy of original right atom " | 
|---|
|  | 628 | +toString(Binder->rightatom)+"  for bond copy found"); | 
|---|
| [30c753] | 629 | atom * const LeftAtom = FatherFinder[Binder->leftatom]; | 
|---|
|  | 630 | atom * const RightAtom = FatherFinder[Binder->rightatom]; | 
|---|
|  | 631 |  | 
|---|
| [1f693d] | 632 | bond::ptr const NewBond = copy->AddBond(LeftAtom, RightAtom, Binder->getDegree()); | 
|---|
| [e08c46] | 633 | NewBond->Cyclic = Binder->Cyclic; | 
|---|
|  | 634 | if (Binder->Cyclic) | 
|---|
|  | 635 | copy->NoCyclicBonds++; | 
|---|
|  | 636 | NewBond->Type = Binder->Type; | 
|---|
|  | 637 | } | 
|---|
| [9d83b6] | 638 | } | 
|---|
| [042f82] | 639 | // correct fathers | 
|---|
| [30c753] | 640 | //for_each(begin(),end(),mem_fun(&atom::CorrectFather)); | 
|---|
| [cee0b57] | 641 |  | 
|---|
| [042f82] | 642 | return copy; | 
|---|
| [14de469] | 643 | }; | 
|---|
|  | 644 |  | 
|---|
| [89c8b2] | 645 |  | 
|---|
| [9df680] | 646 | /** Destroys all atoms inside this molecule. | 
|---|
|  | 647 | */ | 
|---|
| [a7aebd] | 648 | void removeAtomsinMolecule(molecule *&_mol) | 
|---|
| [9df680] | 649 | { | 
|---|
|  | 650 | // remove each atom from world | 
|---|
| [a7aebd] | 651 | for(molecule::iterator AtomRunner = _mol->begin(); !_mol->empty(); AtomRunner = _mol->begin()) | 
|---|
| [9df680] | 652 | World::getInstance().destroyAtom(*AtomRunner); | 
|---|
| [a7aebd] | 653 | // make sure that pointer os not usable | 
|---|
|  | 654 | _mol = NULL; | 
|---|
| [9df680] | 655 | }; | 
|---|
|  | 656 |  | 
|---|
|  | 657 |  | 
|---|
| [89c8b2] | 658 | /** | 
|---|
|  | 659 | * Copies all atoms of a molecule which are within the defined parallelepiped. | 
|---|
|  | 660 | * | 
|---|
|  | 661 | * @param offest for the origin of the parallelepiped | 
|---|
|  | 662 | * @param three vectors forming the matrix that defines the shape of the parallelpiped | 
|---|
|  | 663 | */ | 
|---|
| [c550dd] | 664 | molecule* molecule::CopyMoleculeFromSubRegion(const Shape ®ion) const { | 
|---|
| [5f612ee] | 665 | molecule *copy = World::getInstance().createMolecule(); | 
|---|
| [89c8b2] | 666 |  | 
|---|
| [30c753] | 667 | // copy all atoms | 
|---|
|  | 668 | std::map< const atom *, atom *> FatherFinder; | 
|---|
| [59fff1] | 669 | for (iterator iter = begin(); iter != end(); ++iter) { | 
|---|
| [4e904b] | 670 | if (region.isInside((*iter)->getPosition())) { | 
|---|
| [59fff1] | 671 | atom * const copy_atom = copy->AddCopyAtom(*iter); | 
|---|
| [30c753] | 672 | FatherFinder.insert( std::make_pair( *iter, copy_atom ) ); | 
|---|
| [9df5c6] | 673 | } | 
|---|
|  | 674 | } | 
|---|
| [89c8b2] | 675 |  | 
|---|
| [30c753] | 676 | // copy all bonds | 
|---|
|  | 677 | for(molecule::const_iterator AtomRunner = begin(); AtomRunner != end(); ++AtomRunner) { | 
|---|
|  | 678 | const BondList& ListOfBonds = (*AtomRunner)->getListOfBonds(); | 
|---|
|  | 679 | for(BondList::const_iterator BondRunner = ListOfBonds.begin(); | 
|---|
|  | 680 | BondRunner != ListOfBonds.end(); | 
|---|
|  | 681 | ++BondRunner) | 
|---|
|  | 682 | if ((*BondRunner)->leftatom == *AtomRunner) { | 
|---|
| [88c8ec] | 683 | bond::ptr Binder = (*BondRunner); | 
|---|
| [30c753] | 684 | if ((FatherFinder.count(Binder->leftatom)) | 
|---|
|  | 685 | && (FatherFinder.count(Binder->rightatom))) { | 
|---|
|  | 686 | // if copy present, then it must be from subregion | 
|---|
|  | 687 | atom * const LeftAtom = FatherFinder[Binder->leftatom]; | 
|---|
|  | 688 | atom * const RightAtom = FatherFinder[Binder->rightatom]; | 
|---|
|  | 689 |  | 
|---|
| [1f693d] | 690 | bond::ptr const NewBond = copy->AddBond(LeftAtom, RightAtom, Binder->getDegree()); | 
|---|
| [30c753] | 691 | NewBond->Cyclic = Binder->Cyclic; | 
|---|
|  | 692 | if (Binder->Cyclic) | 
|---|
|  | 693 | copy->NoCyclicBonds++; | 
|---|
|  | 694 | NewBond->Type = Binder->Type; | 
|---|
|  | 695 | } | 
|---|
|  | 696 | } | 
|---|
|  | 697 | } | 
|---|
|  | 698 | // correct fathers | 
|---|
|  | 699 | //for_each(begin(),end(),mem_fun(&atom::CorrectFather)); | 
|---|
|  | 700 |  | 
|---|
| [e138de] | 701 | //TODO: copy->BuildInducedSubgraph(this); | 
|---|
| [89c8b2] | 702 |  | 
|---|
|  | 703 | return copy; | 
|---|
|  | 704 | } | 
|---|
|  | 705 |  | 
|---|
| [14de469] | 706 | /** Adds a bond to a the molecule specified by two atoms, \a *first and \a *second. | 
|---|
|  | 707 | * Also updates molecule::BondCount and molecule::NoNonBonds. | 
|---|
|  | 708 | * \param *first first atom in bond | 
|---|
|  | 709 | * \param *second atom in bond | 
|---|
|  | 710 | * \return pointer to bond or NULL on failure | 
|---|
|  | 711 | */ | 
|---|
| [88c8ec] | 712 | bond::ptr molecule::AddBond(atom *atom1, atom *atom2, int degree) | 
|---|
| [14de469] | 713 | { | 
|---|
| [7d82a5] | 714 | bond::ptr Binder; | 
|---|
| [05a97c] | 715 |  | 
|---|
|  | 716 | // some checks to make sure we are able to create the bond | 
|---|
| [59fff1] | 717 | ASSERT(atom1, | 
|---|
|  | 718 | "molecule::AddBond() - First atom "+toString(atom1) | 
|---|
|  | 719 | +" is not a invalid pointer"); | 
|---|
|  | 720 | ASSERT(atom2, | 
|---|
|  | 721 | "molecule::AddBond() - Second atom "+toString(atom2) | 
|---|
|  | 722 | +" is not a invalid pointer"); | 
|---|
|  | 723 | ASSERT(isInMolecule(atom1), | 
|---|
|  | 724 | "molecule::AddBond() - First atom "+toString(atom1) | 
|---|
|  | 725 | +" is not part of molecule"); | 
|---|
|  | 726 | ASSERT(isInMolecule(atom2), | 
|---|
|  | 727 | "molecule::AddBond() - Second atom "+toString(atom2) | 
|---|
|  | 728 | +" is not part of molecule"); | 
|---|
| [05a97c] | 729 |  | 
|---|
| [7d82a5] | 730 | Binder.reset(new bond(atom1, atom2, degree)); | 
|---|
| [073a9e4] | 731 | atom1->RegisterBond(WorldTime::getTime(), Binder); | 
|---|
|  | 732 | atom2->RegisterBond(WorldTime::getTime(), Binder); | 
|---|
| [59fff1] | 733 | if ((atom1->getType() != NULL) | 
|---|
|  | 734 | && (atom1->getType()->getAtomicNumber() != 1) | 
|---|
|  | 735 | && (atom2->getType() != NULL) | 
|---|
|  | 736 | && (atom2->getType()->getAtomicNumber() != 1)) | 
|---|
| [05a97c] | 737 | NoNonBonds++; | 
|---|
|  | 738 |  | 
|---|
| [042f82] | 739 | return Binder; | 
|---|
| [14de469] | 740 | }; | 
|---|
|  | 741 |  | 
|---|
| [1907a7] | 742 | /** Set molecule::name from the basename without suffix in the given \a *filename. | 
|---|
|  | 743 | * \param *filename filename | 
|---|
|  | 744 | */ | 
|---|
| [d67150] | 745 | void molecule::SetNameFromFilename(const char *filename) | 
|---|
| [1907a7] | 746 | { | 
|---|
| [575343] | 747 | OBSERVE; | 
|---|
| [1907a7] | 748 | int length = 0; | 
|---|
| [f7f7a4] | 749 | const char *molname = strrchr(filename, '/'); | 
|---|
|  | 750 | if (molname != NULL) | 
|---|
|  | 751 | molname += sizeof(char);  // search for filename without dirs | 
|---|
|  | 752 | else | 
|---|
|  | 753 | molname = filename; // contains no slashes | 
|---|
| [49e1ae] | 754 | const char *endname = strchr(molname, '.'); | 
|---|
| [1907a7] | 755 | if ((endname == NULL) || (endname < molname)) | 
|---|
|  | 756 | length = strlen(molname); | 
|---|
|  | 757 | else | 
|---|
|  | 758 | length = strlen(molname) - strlen(endname); | 
|---|
| [35b698] | 759 | cout << "Set name of molecule " << getId() << " to " << molname << endl; | 
|---|
| [1907a7] | 760 | strncpy(name, molname, length); | 
|---|
| [d67150] | 761 | name[length]='\0'; | 
|---|
| [1907a7] | 762 | }; | 
|---|
|  | 763 |  | 
|---|
| [cee0b57] | 764 | /** Removes atom from molecule list, but does not delete it. | 
|---|
|  | 765 | * \param *pointer atom to be removed | 
|---|
|  | 766 | * \return true - succeeded, false - atom not found in list | 
|---|
| [f3278b] | 767 | */ | 
|---|
| [cee0b57] | 768 | bool molecule::UnlinkAtom(atom *pointer) | 
|---|
| [f3278b] | 769 | { | 
|---|
| [cee0b57] | 770 | if (pointer == NULL) | 
|---|
|  | 771 | return false; | 
|---|
| [2e4105] | 772 | pointer->removeFromMolecule(); | 
|---|
| [cee0b57] | 773 | return true; | 
|---|
| [f3278b] | 774 | }; | 
|---|
|  | 775 |  | 
|---|
| [cee0b57] | 776 | /** Removes every atom from molecule list. | 
|---|
|  | 777 | * \return true - succeeded, false - atom not found in list | 
|---|
| [14de469] | 778 | */ | 
|---|
| [cee0b57] | 779 | bool molecule::CleanupMolecule() | 
|---|
| [14de469] | 780 | { | 
|---|
| [9879f6] | 781 | for (molecule::iterator iter = begin(); !empty(); iter = begin()) | 
|---|
| [2e4105] | 782 | (*iter)->removeFromMolecule(); | 
|---|
| [274d45] | 783 | return empty(); | 
|---|
| [69eb71] | 784 | }; | 
|---|
| [14de469] | 785 |  | 
|---|
| [cee0b57] | 786 | /** Finds an atom specified by its continuous number. | 
|---|
|  | 787 | * \param Nr number of atom withim molecule | 
|---|
|  | 788 | * \return pointer to atom or NULL | 
|---|
| [14de469] | 789 | */ | 
|---|
| [9879f6] | 790 | atom * molecule::FindAtom(int Nr)  const | 
|---|
|  | 791 | { | 
|---|
| [c6ab91] | 792 | LocalToGlobalId_t::const_iterator iter = LocalToGlobalId.find(Nr); | 
|---|
|  | 793 | if (iter != LocalToGlobalId.end()) { | 
|---|
| [47d041] | 794 | //LOG(0, "Found Atom Nr. " << walker->getNr()); | 
|---|
| [c6ab91] | 795 | return iter->second; | 
|---|
| [cee0b57] | 796 | } else { | 
|---|
| [ca8bea] | 797 | ELOG(1, "Atom with Nr " << Nr << " not found in molecule " << getName() << "'s list."); | 
|---|
| [cee0b57] | 798 | return NULL; | 
|---|
| [042f82] | 799 | } | 
|---|
| [59fff1] | 800 | } | 
|---|
|  | 801 |  | 
|---|
|  | 802 | /** Checks whether the given atom is a member of this molecule. | 
|---|
|  | 803 | * | 
|---|
|  | 804 | *  We make use here of molecule::atomIds to get a result on | 
|---|
|  | 805 | * | 
|---|
|  | 806 | * @param _atom atom to check | 
|---|
|  | 807 | * @return true - is member, false - is not | 
|---|
|  | 808 | */ | 
|---|
|  | 809 | bool molecule::isInMolecule(const atom * const _atom) | 
|---|
|  | 810 | { | 
|---|
|  | 811 | ASSERT(_atom->getMolecule() == this, | 
|---|
|  | 812 | "molecule::isInMolecule() - atom is not designated to be in molecule '" | 
|---|
|  | 813 | +toString(this->getName())+"'."); | 
|---|
| [8e1f901] | 814 | molecule::const_iterator iter = atomIds.find(_atom->getId()); | 
|---|
| [59fff1] | 815 | return (iter != atomIds.end()); | 
|---|
|  | 816 | } | 
|---|
| [14de469] | 817 |  | 
|---|
| [cee0b57] | 818 | /** Asks for atom number, and checks whether in list. | 
|---|
|  | 819 | * \param *text question before entering | 
|---|
| [a6b7fb] | 820 | */ | 
|---|
| [955b91] | 821 | atom * molecule::AskAtom(std::string text) | 
|---|
| [a6b7fb] | 822 | { | 
|---|
| [cee0b57] | 823 | int No; | 
|---|
|  | 824 | atom *ion = NULL; | 
|---|
|  | 825 | do { | 
|---|
| [47d041] | 826 | //std::cout << "============Atom list==========================" << std::endl; | 
|---|
| [cee0b57] | 827 | //mol->Output((ofstream *)&cout); | 
|---|
| [47d041] | 828 | //std::cout << "===============================================" << std::endl; | 
|---|
|  | 829 | std::cout << text; | 
|---|
| [cee0b57] | 830 | cin >> No; | 
|---|
|  | 831 | ion = this->FindAtom(No); | 
|---|
|  | 832 | } while (ion == NULL); | 
|---|
|  | 833 | return ion; | 
|---|
| [a6b7fb] | 834 | }; | 
|---|
|  | 835 |  | 
|---|
| [cee0b57] | 836 | /** Checks if given coordinates are within cell volume. | 
|---|
|  | 837 | * \param *x array of coordinates | 
|---|
|  | 838 | * \return true - is within, false - out of cell | 
|---|
| [14de469] | 839 | */ | 
|---|
| [cee0b57] | 840 | bool molecule::CheckBounds(const Vector *x) const | 
|---|
| [14de469] | 841 | { | 
|---|
| [cca9ef] | 842 | const RealSpaceMatrix &domain = World::getInstance().getDomain().getM(); | 
|---|
| [cee0b57] | 843 | bool result = true; | 
|---|
|  | 844 | for (int i=0;i<NDIM;i++) { | 
|---|
| [84c494] | 845 | result = result && ((x->at(i) >= 0) && (x->at(i) < domain.at(i,i))); | 
|---|
| [042f82] | 846 | } | 
|---|
| [cee0b57] | 847 | //return result; | 
|---|
|  | 848 | return true; /// probably not gonna use the check no more | 
|---|
| [69eb71] | 849 | }; | 
|---|
| [14de469] | 850 |  | 
|---|
| [cee0b57] | 851 | /** Prints molecule to *out. | 
|---|
|  | 852 | * \param *out output stream | 
|---|
| [14de469] | 853 | */ | 
|---|
| [e4afb4] | 854 | bool molecule::Output(ostream * const output) const | 
|---|
| [14de469] | 855 | { | 
|---|
| [e138de] | 856 | if (output == NULL) { | 
|---|
| [cee0b57] | 857 | return false; | 
|---|
|  | 858 | } else { | 
|---|
| [0ba410] | 859 | int AtomNo[MAX_ELEMENTS]; | 
|---|
|  | 860 | memset(AtomNo,0,(MAX_ELEMENTS-1)*sizeof(*AtomNo)); | 
|---|
|  | 861 | enumeration<const element*> elementLookup = formula.enumerateElements(); | 
|---|
|  | 862 | *output << "#Ion_TypeNr._Nr.R[0]    R[1]    R[2]    MoveType (0 MoveIon, 1 FixedIon)" << endl; | 
|---|
| [30c753] | 863 | for_each(begin(),end(),boost::bind(&atom::OutputArrayIndexed,_1,output,elementLookup,AtomNo,(const char*)0)); | 
|---|
| [cee0b57] | 864 | return true; | 
|---|
| [042f82] | 865 | } | 
|---|
| [14de469] | 866 | }; | 
|---|
|  | 867 |  | 
|---|
| [266237] | 868 | /** Outputs contents of each atom::ListOfBonds. | 
|---|
| [cee0b57] | 869 | * \param *out output stream | 
|---|
| [14de469] | 870 | */ | 
|---|
| [e138de] | 871 | void molecule::OutputListOfBonds() const | 
|---|
| [14de469] | 872 | { | 
|---|
| [4b5cf8] | 873 | std::stringstream output; | 
|---|
|  | 874 | LOG(2, "From Contents of ListOfBonds, all atoms:"); | 
|---|
|  | 875 | for (molecule::const_iterator iter = begin(); | 
|---|
|  | 876 | iter != end(); | 
|---|
|  | 877 | ++iter) { | 
|---|
|  | 878 | (*iter)->OutputBondOfAtom(output); | 
|---|
|  | 879 | output << std::endl << "\t\t"; | 
|---|
|  | 880 | } | 
|---|
|  | 881 | LOG(2, output.str()); | 
|---|
|  | 882 | } | 
|---|
| [14de469] | 883 |  | 
|---|
| [cee0b57] | 884 | /** Brings molecule::AtomCount and atom::*Name up-to-date. | 
|---|
| [14de469] | 885 | * \param *out output stream for debugging | 
|---|
|  | 886 | */ | 
|---|
| [e791dc] | 887 | size_t molecule::doCountNoNonHydrogen() const | 
|---|
| [14de469] | 888 | { | 
|---|
| [e791dc] | 889 | int temp = 0; | 
|---|
| [560bbe] | 890 | // go through atoms and look for new ones | 
|---|
|  | 891 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) | 
|---|
| [83f176] | 892 | if ((*iter)->getType()->getAtomicNumber() != 1) // count non-hydrogen atoms whilst at it | 
|---|
| [e791dc] | 893 | ++temp; | 
|---|
|  | 894 | return temp; | 
|---|
| [cee0b57] | 895 | }; | 
|---|
| [042f82] | 896 |  | 
|---|
| [458c31] | 897 | /** Counts the number of present bonds. | 
|---|
|  | 898 | * \return number of bonds | 
|---|
|  | 899 | */ | 
|---|
|  | 900 | int molecule::doCountBonds() const | 
|---|
|  | 901 | { | 
|---|
|  | 902 | unsigned int counter = 0; | 
|---|
|  | 903 | for(molecule::const_iterator AtomRunner = begin(); AtomRunner != end(); ++AtomRunner) { | 
|---|
|  | 904 | const BondList& ListOfBonds = (*AtomRunner)->getListOfBonds(); | 
|---|
|  | 905 | for(BondList::const_iterator BondRunner = ListOfBonds.begin(); | 
|---|
|  | 906 | BondRunner != ListOfBonds.end(); | 
|---|
|  | 907 | ++BondRunner) | 
|---|
|  | 908 | if ((*BondRunner)->leftatom == *AtomRunner) | 
|---|
|  | 909 | counter++; | 
|---|
|  | 910 | } | 
|---|
|  | 911 | return counter; | 
|---|
|  | 912 | } | 
|---|
|  | 913 |  | 
|---|
|  | 914 |  | 
|---|
| [14de469] | 915 | /** Returns an index map for two father-son-molecules. | 
|---|
|  | 916 | * The map tells which atom in this molecule corresponds to which one in the other molecul with their fathers. | 
|---|
|  | 917 | * \param *out output stream for debugging | 
|---|
|  | 918 | * \param *OtherMolecule corresponding molecule with fathers | 
|---|
|  | 919 | * \return allocated map of size molecule::AtomCount with map | 
|---|
|  | 920 | * \todo make this with a good sort O(n), not O(n^2) | 
|---|
|  | 921 | */ | 
|---|
| [e138de] | 922 | int * molecule::GetFatherSonAtomicMap(molecule *OtherMolecule) | 
|---|
| [14de469] | 923 | { | 
|---|
| [47d041] | 924 | LOG(3, "Begin of GetFatherAtomicMap."); | 
|---|
| [1024cb] | 925 | int *AtomicMap = new int[getAtomCount()]; | 
|---|
| [ea7176] | 926 | for (int i=getAtomCount();i--;) | 
|---|
| [042f82] | 927 | AtomicMap[i] = -1; | 
|---|
|  | 928 | if (OtherMolecule == this) {  // same molecule | 
|---|
| [ea7176] | 929 | for (int i=getAtomCount();i--;) // no need as -1 means already that there is trivial correspondence | 
|---|
| [042f82] | 930 | AtomicMap[i] = i; | 
|---|
| [47d041] | 931 | LOG(4, "Map is trivial."); | 
|---|
| [042f82] | 932 | } else { | 
|---|
| [47d041] | 933 | std::stringstream output; | 
|---|
|  | 934 | output << "Map is "; | 
|---|
| [9879f6] | 935 | for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { | 
|---|
|  | 936 | if ((*iter)->father == NULL) { | 
|---|
| [735b1c] | 937 | AtomicMap[(*iter)->getNr()] = -2; | 
|---|
| [042f82] | 938 | } else { | 
|---|
| [9879f6] | 939 | for (molecule::const_iterator runner = OtherMolecule->begin(); runner != OtherMolecule->end(); ++runner) { | 
|---|
| [042f82] | 940 | //for (int i=0;i<AtomCount;i++) { // search atom | 
|---|
| [1024cb] | 941 | //for (int j=0;j<OtherMolecule->getAtomCount();j++) { | 
|---|
| [47d041] | 942 | //LOG(4, "Comparing father " << (*iter)->father << " with the other one " << (*runner)->father << "."); | 
|---|
| [9879f6] | 943 | if ((*iter)->father == (*runner)) | 
|---|
| [735b1c] | 944 | AtomicMap[(*iter)->getNr()] = (*runner)->getNr(); | 
|---|
| [042f82] | 945 | } | 
|---|
|  | 946 | } | 
|---|
| [47d041] | 947 | output << AtomicMap[(*iter)->getNr()] << "\t"; | 
|---|
| [042f82] | 948 | } | 
|---|
| [47d041] | 949 | LOG(4, output.str()); | 
|---|
| [042f82] | 950 | } | 
|---|
| [47d041] | 951 | LOG(3, "End of GetFatherAtomicMap."); | 
|---|
| [042f82] | 952 | return AtomicMap; | 
|---|
| [14de469] | 953 | }; | 
|---|
|  | 954 |  | 
|---|
| [4a7776a] | 955 |  | 
|---|
| [c68025] | 956 | void molecule::flipActiveFlag(){ | 
|---|
|  | 957 | ActiveFlag = !ActiveFlag; | 
|---|
|  | 958 | } | 
|---|
| [560bbe] | 959 |  | 
|---|
| [aeb694] | 960 | Shape molecule::getBoundingShape(const double scale) const | 
|---|
|  | 961 | { | 
|---|
|  | 962 | // create Sphere around every atom | 
|---|
|  | 963 | if (empty()) | 
|---|
|  | 964 | return Nowhere(); | 
|---|
|  | 965 | const_iterator iter = begin(); | 
|---|
|  | 966 | const Vector center = (*iter)->getPosition(); | 
|---|
|  | 967 | const double vdWRadius = (*iter)->getElement().getVanDerWaalsRadius(); | 
|---|
|  | 968 | Shape BoundingShape = Sphere(center, vdWRadius*scale); | 
|---|
|  | 969 | for(++iter; iter != end(); ++iter) { | 
|---|
|  | 970 | const Vector center = (*iter)->getPosition(); | 
|---|
|  | 971 | const double vdWRadius = (*iter)->getElement().getVanDerWaalsRadius(); | 
|---|
|  | 972 | if (vdWRadius*scale != 0.) | 
|---|
|  | 973 | BoundingShape = Sphere(center, vdWRadius*scale) || BoundingShape; | 
|---|
|  | 974 | } | 
|---|
|  | 975 | return BoundingShape; | 
|---|
|  | 976 | } | 
|---|
|  | 977 |  | 
|---|
|  | 978 | Shape molecule::getBoundingSphere(const double boundary) const | 
|---|
| [c67ff9] | 979 | { | 
|---|
|  | 980 | // get center and radius | 
|---|
|  | 981 | Vector center; | 
|---|
|  | 982 | double radius = 0.; | 
|---|
|  | 983 | { | 
|---|
|  | 984 | center.Zero(); | 
|---|
|  | 985 | for(const_iterator iter = begin(); iter != end(); ++iter) | 
|---|
|  | 986 | center += (*iter)->getPosition(); | 
|---|
| [8c001a] | 987 | if (begin() != end()) | 
|---|
|  | 988 | center *= 1./(double)size(); | 
|---|
| [c67ff9] | 989 | for(const_iterator iter = begin(); iter != end(); ++iter) { | 
|---|
|  | 990 | const Vector &position = (*iter)->getPosition(); | 
|---|
|  | 991 | const double temp_distance = position.DistanceSquared(center); | 
|---|
|  | 992 | if (temp_distance > radius) | 
|---|
|  | 993 | radius = temp_distance; | 
|---|
|  | 994 | } | 
|---|
|  | 995 | } | 
|---|
|  | 996 | // convert radius to true value and add some small boundary | 
|---|
| [55feea1] | 997 | radius = sqrt(radius) + boundary + 1e+6*std::numeric_limits<double>::epsilon(); | 
|---|
| [c67ff9] | 998 | LOG(1, "INFO: The " << size() << " atoms of the molecule are contained in a sphere at " | 
|---|
|  | 999 | << center << " with radius " << radius << "."); | 
|---|
|  | 1000 |  | 
|---|
| [f24af7] | 1001 | // TODO: When we do not use a Sphere here anymore, then FillRegularGridAction will | 
|---|
|  | 1002 | // will not work as it expects a sphere due to possible random rotations. | 
|---|
| [c67ff9] | 1003 | Shape BoundingShape(Sphere(center, radius)); | 
|---|
|  | 1004 | LOG(1, "INFO: Created sphere at " << BoundingShape.getCenter() << " and radius " | 
|---|
|  | 1005 | << BoundingShape.getRadius() << "."); | 
|---|
|  | 1006 | return BoundingShape; | 
|---|
|  | 1007 | } | 
|---|
|  | 1008 |  | 
|---|
| [c32d21] | 1009 | void molecule::update(Observable *publisher) | 
|---|
|  | 1010 | { | 
|---|
|  | 1011 | ASSERT(0, "molecule::update() - did not sign on for any general updates."); | 
|---|
|  | 1012 | } | 
|---|
|  | 1013 |  | 
|---|
|  | 1014 | void molecule::recieveNotification(Observable *publisher, Notification_ptr notification) | 
|---|
|  | 1015 | { | 
|---|
|  | 1016 | const atom * const _atom = dynamic_cast<atom *>(publisher); | 
|---|
|  | 1017 | if ((_atom != NULL) && containsAtom(_atom)) { | 
|---|
|  | 1018 | #ifdef LOG_OBSERVER | 
|---|
|  | 1019 | observerLog().addMessage() << "++ Update of Observer "<< observerLog().getName(static_cast<Observer *>(this)) | 
|---|
|  | 1020 | << " received notification from atom " << _atom->getId() << " for channel " | 
|---|
|  | 1021 | << notification->getChannelNo() << "."; | 
|---|
|  | 1022 | #endif | 
|---|
|  | 1023 | switch (notification->getChannelNo()) { | 
|---|
|  | 1024 | case AtomObservable::PositionChanged: | 
|---|
|  | 1025 | { | 
|---|
|  | 1026 | // emit others about one of our atoms moved | 
|---|
|  | 1027 | _lastchangedatom = const_cast<atom *>(_atom); | 
|---|
|  | 1028 | OBSERVE; | 
|---|
|  | 1029 | NOTIFY(AtomMoved); | 
|---|
|  | 1030 | break; | 
|---|
|  | 1031 | } | 
|---|
|  | 1032 | default: | 
|---|
|  | 1033 | ASSERT( 0, "molecule::recieveNotification() - we did not sign up for channel " | 
|---|
|  | 1034 | +toString(notification->getChannelNo())); | 
|---|
|  | 1035 | break; | 
|---|
|  | 1036 | } | 
|---|
|  | 1037 | } | 
|---|
|  | 1038 | } | 
|---|
|  | 1039 |  | 
|---|
|  | 1040 | void molecule::subjectKilled(Observable *publisher) | 
|---|
|  | 1041 | { | 
|---|
|  | 1042 | // do nothing, atom does it all | 
|---|
|  | 1043 | } | 
|---|
|  | 1044 |  | 
|---|
|  | 1045 |  | 
|---|
| [560bbe] | 1046 | // construct idpool | 
|---|
|  | 1047 | CONSTRUCT_IDPOOL(atomId_t, continuousId) | 
|---|
| [c67ff9] | 1048 |  | 
|---|