/*
* Project: MoleCuilder
* Description: creates and alters molecular systems
* Copyright (C) 2012 University of Bonn. All rights reserved.
* Please see the COPYING file or "Copyright notice" in builder.cpp for details.
*
*
* 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 .
*/
/*
* HomologyGraph_getFromKeyset.cpp
*
* Created on: Sep 25, 2012
* Author: heber
*/
// include config.h
#ifdef HAVE_CONFIG_H
#include
#endif
#include "CodePatterns/MemDebug.hpp"
#include "Fragmentation/Homology/HomologyGraph.hpp"
#include "CodePatterns/Log.hpp"
#include "Atom/atom.hpp"
#include "Bond/bond.hpp"
#include "Descriptors/AtomIdDescriptor.hpp"
#include "Fragmentation/KeySet.hpp"
#include "Fragmentation/Summation/IndexSet.hpp"
#include "World.hpp"
// we have placed these functions into an extra module to allow compiling the
// unit tests which do no require them against dummy units which do not pull
// in all the cludder of World, atom, molecule, and so on ...
template
const HomologyGraph::nodes_t getNodesFromSet(const std::set &keyset)
{
HomologyGraph::nodes_t nodes;
for (typename std::set::const_iterator iter = keyset.begin();
iter != keyset.end(); ++iter) {
// LOG(2, "DEBUG: Current global id is " << *iter << ".");
const atom *Walker = World::getInstance().getAtom(AtomById(*iter));
if (Walker != NULL) {
size_t NoBonds = 0;
const BondList& ListOfBonds = Walker->getListOfBonds();
for (BondList::const_iterator bonditer = ListOfBonds.begin();
bonditer != ListOfBonds.end(); ++bonditer) {
const atom *OtherWalker = (*bonditer)->GetOtherAtom(Walker);
if (keyset.count(OtherWalker->getId()))
++NoBonds;
}
// LOG(2, "DEBUG: Adding node " << Walker->getId() << " with element "
// << Walker->getElementNo() << " and " << NoBonds << " bonds.");
std::pair inserter =
nodes.insert( std::make_pair(FragmentNode(Walker->getElementNo(), NoBonds), (size_t)1) );
if (!inserter.second)
inserter.first->second += (size_t)1;
} else {
ELOG(3, "Skipping id " << *iter << ", is not associated with any atom.");
}
}
return nodes;
}
template
const HomologyGraph::edges_t getEdgesFromSet(const std::set &keyset)
{
HomologyGraph::edges_t edges;
for (typename std::set::const_iterator iter = keyset.begin();
iter != keyset.end(); ++iter) {
// LOG(2, "DEBUG: Current global id is " << *iter << ".");
const atom *Walker = World::getInstance().getAtom(AtomById(*iter));
if (Walker != NULL) {
const BondList& ListOfBonds = Walker->getListOfBonds();
for (BondList::const_iterator bonditer = ListOfBonds.begin();
bonditer != ListOfBonds.end(); ++bonditer) {
const atom *OtherWalker = (*bonditer)->GetOtherAtom(Walker);
// LOG(2, "DEBUG: Neighbor is " << OtherWalker->getId() << ".");
if ((keyset.count(OtherWalker->getId())) && (Walker->getId() < OtherWalker->getId())) {
// LOG(1, "DEBUG: Adding edge " << Walker->getId() << " and " << OtherWalker->getId() << ".");
std::pair inserter =
edges.insert( std::make_pair(FragmentEdge( Walker->getElementNo(), OtherWalker->getElementNo()), (size_t)1) );
if (!inserter.second)
inserter.first->second += (size_t)1;
}
}
} else {
ELOG(3, "Skipping id " << *iter << ", is not associated with any atom.");
}
}
return edges;
}
namespace detail {
const HomologyGraph::nodes_t getNodesFromKeySet(const KeySet &keyset) {
return getNodesFromSet(keyset);
}
const HomologyGraph::nodes_t getNodesFromIndexSet(const IndexSet &keyset) {
return getNodesFromSet(keyset);
}
const HomologyGraph::edges_t getEdgesFromKeySet(const KeySet &keyset) {
return getEdgesFromSet(keyset);
}
const HomologyGraph::edges_t getEdgesFromIndexSet(const IndexSet &keyset) {
return getEdgesFromSet(keyset);
}
}; /* namespace detail */