/*
* Project: MoleCuilder
* Description: creates and alters molecular systems
* Copyright (C) 2012 University of Bonn. All rights reserved.
* Copyright (C) 2013 Frederik Heber. All rights reserved.
*
*
* This file is part of MoleCuilder.
*
* MoleCuilder is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* MoleCuilder is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MoleCuilder. If not, see .
*/
/*
* BondInfo.cpp
*
* Created on: Apr 5, 2012
* Author: heber
*/
// include config.h
#ifdef HAVE_CONFIG_H
#include
#endif
#include "CodePatterns/MemDebug.hpp"
#include "BondInfo.hpp"
#include
#include
#include
#include "Atom/atom.hpp"
#include "Bond/bond.hpp"
#include "CodePatterns/Log.hpp"
#include "Descriptors/AtomIdDescriptor.hpp"
#include "World.hpp"
#include "WorldTime.hpp"
BondInfo::BondInfo(const bond::ptr _bond) :
leftid(_bond->leftatom->getId()),
rightid(_bond->rightatom->getId()),
degree(_bond->getDegree())
{}
bool BondInfo::RecreateBond() const
{
atom * const leftatom = World::getInstance().getAtom(AtomById(leftid));
atom * const rightatom = World::getInstance().getAtom(AtomById(rightid));
if ((leftatom == NULL) || (rightatom == NULL)) {
// LOG(3, "DEBUG: Either of the two atoms " << leftid << " or "
// << rightid << " does not exist in the world.");
return false;
}
const BondList &leftbonds = leftatom->getListOfBonds();
const BondList &rightbonds = rightatom->getListOfBonds();
boost::function< bool (const bond::ptr )> leftpredicate =
boost::bind(static_cast(&bond::ContainsId), _1, rightid);
boost::function< bool (const bond::ptr )> rightpredicate =
boost::bind(static_cast(&bond::ContainsId), _1, leftid);
if ((std::find_if(leftbonds.begin(), leftbonds.end(), leftpredicate) != leftbonds.end())
|| (std::find_if(rightbonds.begin(), rightbonds.end(), rightpredicate) != rightbonds.end())) {
// LOG(3, "DEBUG: Bond between atoms " << leftid << " or "111
// << rightid << " is already present in the world.");
return true;
}
// create bond
LOG(3, "DEBUG: Re-creating bond " << leftid << "<->" << rightid << ".");
bond::ptr const _bond = leftatom->addBond(WorldTime::getTime(), rightatom);
_bond->setDegree(degree);
return true;
}
void BondInfo::RemoveBond() const
{
atom * const leftatom = World::getInstance().getAtom(AtomById(leftid));
atom * const rightatom = World::getInstance().getAtom(AtomById(rightid));
leftatom->removeBond(rightatom);
}