[af9be32] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
| 4 | * Copyright (C) 2012 University of Bonn. All rights reserved.
|
---|
[94d5ac6] | 5 | *
|
---|
| 6 | *
|
---|
| 7 | * This file is part of MoleCuilder.
|
---|
| 8 | *
|
---|
| 9 | * MoleCuilder is free software: you can redistribute it and/or modify
|
---|
| 10 | * it under the terms of the GNU General Public License as published by
|
---|
| 11 | * the Free Software Foundation, either version 2 of the License, or
|
---|
| 12 | * (at your option) any later version.
|
---|
| 13 | *
|
---|
| 14 | * MoleCuilder is distributed in the hope that it will be useful,
|
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 17 | * GNU General Public License for more details.
|
---|
| 18 | *
|
---|
| 19 | * You should have received a copy of the GNU General Public License
|
---|
| 20 | * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
|
---|
[af9be32] | 21 | */
|
---|
| 22 |
|
---|
| 23 | /*
|
---|
| 24 | * BondInfo.cpp
|
---|
| 25 | *
|
---|
| 26 | * Created on: Apr 5, 2012
|
---|
| 27 | * Author: heber
|
---|
| 28 | */
|
---|
| 29 |
|
---|
| 30 |
|
---|
| 31 | // include config.h
|
---|
| 32 | #ifdef HAVE_CONFIG_H
|
---|
| 33 | #include <config.h>
|
---|
| 34 | #endif
|
---|
| 35 |
|
---|
| 36 | #include "CodePatterns/MemDebug.hpp"
|
---|
| 37 |
|
---|
| 38 | #include "BondInfo.hpp"
|
---|
| 39 |
|
---|
| 40 | #include <algorithm>
|
---|
| 41 | #include <boost/bind.hpp>
|
---|
| 42 | #include <boost/function.hpp>
|
---|
| 43 |
|
---|
| 44 | #include "Atom/atom.hpp"
|
---|
| 45 | #include "Bond/bond.hpp"
|
---|
| 46 | #include "CodePatterns/Log.hpp"
|
---|
| 47 | #include "Descriptors/AtomIdDescriptor.hpp"
|
---|
| 48 | #include "World.hpp"
|
---|
| 49 | #include "WorldTime.hpp"
|
---|
| 50 |
|
---|
| 51 | BondInfo::BondInfo(const bond * _bond) :
|
---|
| 52 | leftid(_bond->leftatom->getId()),
|
---|
| 53 | rightid(_bond->rightatom->getId()),
|
---|
| 54 | degree(_bond->BondDegree)
|
---|
| 55 | {}
|
---|
| 56 |
|
---|
| 57 | bool BondInfo::RecreateBond() const
|
---|
| 58 | {
|
---|
| 59 | atom * const leftatom = World::getInstance().getAtom(AtomById(leftid));
|
---|
| 60 | atom * const rightatom = World::getInstance().getAtom(AtomById(rightid));
|
---|
| 61 | if ((leftatom == NULL) || (rightatom == NULL)) {
|
---|
| 62 | ELOG(1, "Either of the two atoms " << leftid << " or "
|
---|
| 63 | << rightid << " does not exists in the world.");
|
---|
| 64 | return false;
|
---|
| 65 | }
|
---|
| 66 | const BondList &leftbonds = leftatom->getListOfBonds();
|
---|
| 67 | boost::function< bool (const bond *)> predicate =
|
---|
| 68 | boost::bind(static_cast<bool (bond::*)(const int) const>(&bond::Contains), _1, rightid);
|
---|
| 69 | if (std::find_if(leftbonds.begin(), leftbonds.end(), predicate) != leftbonds.end())
|
---|
| 70 | return false;
|
---|
| 71 |
|
---|
| 72 | const BondList &rightbonds = rightatom->getListOfBonds();
|
---|
| 73 | if (std::find_if(rightbonds.begin(), rightbonds.end(), predicate) != rightbonds.end())
|
---|
| 74 | return false;
|
---|
| 75 |
|
---|
| 76 | // create bond
|
---|
| 77 | LOG(3, "DEBUG: Re-creating bond " << leftid << "<->" << rightid << ".");
|
---|
| 78 | bond * const _bond = leftatom->addBond(WorldTime::getTime(), rightatom);
|
---|
| 79 | _bond->BondDegree = degree;
|
---|
| 80 | return true;
|
---|
| 81 | }
|
---|