/* * Project: MoleCuilder * Description: creates and alters molecular systems * Copyright (C) 2012 University of Bonn. All rights reserved. * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. */ /* * 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 * _bond) : leftid(_bond->leftatom->getId()), rightid(_bond->rightatom->getId()), degree(_bond->BondDegree) {} 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)) { ELOG(1, "Either of the two atoms " << leftid << " or " << rightid << " does not exists in the world."); return false; } const BondList &leftbonds = leftatom->getListOfBonds(); boost::function< bool (const bond *)> predicate = boost::bind(static_cast(&bond::Contains), _1, rightid); if (std::find_if(leftbonds.begin(), leftbonds.end(), predicate) != leftbonds.end()) return false; const BondList &rightbonds = rightatom->getListOfBonds(); if (std::find_if(rightbonds.begin(), rightbonds.end(), predicate) != rightbonds.end()) return false; // create bond LOG(3, "DEBUG: Re-creating bond " << leftid << "<->" << rightid << "."); bond * const _bond = leftatom->addBond(WorldTime::getTime(), rightatom); _bond->BondDegree = degree; return true; }