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