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