| 1 | /*
 | 
|---|
| 2 |  * Project: MoleCuilder
 | 
|---|
| 3 |  * Description: creates and alters molecular systems
 | 
|---|
| 4 |  * Copyright (C)  2012 University of Bonn. All rights reserved.
 | 
|---|
| 5 |  * Please see the COPYING file or "Copyright notice" in builder.cpp for details.
 | 
|---|
| 6 |  * 
 | 
|---|
| 7 |  *
 | 
|---|
| 8 |  *   This file is part of MoleCuilder.
 | 
|---|
| 9 |  *
 | 
|---|
| 10 |  *    MoleCuilder is free software: you can redistribute it and/or modify
 | 
|---|
| 11 |  *    it under the terms of the GNU General Public License as published by
 | 
|---|
| 12 |  *    the Free Software Foundation, either version 2 of the License, or
 | 
|---|
| 13 |  *    (at your option) any later version.
 | 
|---|
| 14 |  *
 | 
|---|
| 15 |  *    MoleCuilder is distributed in the hope that it will be useful,
 | 
|---|
| 16 |  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
|---|
| 17 |  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
|---|
| 18 |  *    GNU General Public License for more details.
 | 
|---|
| 19 |  *
 | 
|---|
| 20 |  *    You should have received a copy of the GNU General Public License
 | 
|---|
| 21 |  *    along with MoleCuilder.  If not, see <http://www.gnu.org/licenses/>. 
 | 
|---|
| 22 |  */
 | 
|---|
| 23 | 
 | 
|---|
| 24 | /*
 | 
|---|
| 25 |  * HomologyGraph_getFromKeyset.cpp
 | 
|---|
| 26 |  *
 | 
|---|
| 27 |  *  Created on: Sep 25, 2012
 | 
|---|
| 28 |  *      Author: heber
 | 
|---|
| 29 |  */
 | 
|---|
| 30 | 
 | 
|---|
| 31 | 
 | 
|---|
| 32 | // include config.h
 | 
|---|
| 33 | #ifdef HAVE_CONFIG_H
 | 
|---|
| 34 | #include <config.h>
 | 
|---|
| 35 | #endif
 | 
|---|
| 36 | 
 | 
|---|
| 37 | #include "CodePatterns/MemDebug.hpp"
 | 
|---|
| 38 | 
 | 
|---|
| 39 | #include "Fragmentation/Homology/HomologyGraph.hpp"
 | 
|---|
| 40 | 
 | 
|---|
| 41 | #include "CodePatterns/Log.hpp"
 | 
|---|
| 42 | 
 | 
|---|
| 43 | #include "Atom/atom.hpp"
 | 
|---|
| 44 | #include "Bond/bond.hpp"
 | 
|---|
| 45 | #include "Descriptors/AtomIdDescriptor.hpp"
 | 
|---|
| 46 | #include "Fragmentation/KeySet.hpp"
 | 
|---|
| 47 | #include "World.hpp"
 | 
|---|
| 48 | 
 | 
|---|
| 49 | // we have placed these functions into an extra module to allow compiling the
 | 
|---|
| 50 | // unit tests which do no require them against dummy units which do not pull
 | 
|---|
| 51 | // in all the cludder of World, atom, molecule, and so on ...
 | 
|---|
| 52 | 
 | 
|---|
| 53 | namespace detail {
 | 
|---|
| 54 |   const HomologyGraph::nodes_t getNodesFromKeySet(const KeySet &keyset)
 | 
|---|
| 55 |   {
 | 
|---|
| 56 |     HomologyGraph::nodes_t nodes;
 | 
|---|
| 57 |     for (KeySet::const_iterator iter = keyset.begin();
 | 
|---|
| 58 |         iter != keyset.end(); ++iter) {
 | 
|---|
| 59 |       const atom *Walker = World::getInstance().getAtom(AtomById(*iter));
 | 
|---|
| 60 |       if (Walker != NULL) {
 | 
|---|
| 61 |         const BondList& ListOfBonds = Walker->getListOfBonds();
 | 
|---|
| 62 |   #ifndef NDEBUG
 | 
|---|
| 63 |       std::pair<HomologyGraph::nodes_t::iterator,bool> inserter =
 | 
|---|
| 64 |   #endif
 | 
|---|
| 65 |           nodes.insert( FragmentNode(Walker->getElementNo(), ListOfBonds.size()) );
 | 
|---|
| 66 |       } else {
 | 
|---|
| 67 |         ELOG(0, "Id " << *iter << " is not associated with any atom.");
 | 
|---|
| 68 |       }
 | 
|---|
| 69 |     }
 | 
|---|
| 70 |     return nodes;
 | 
|---|
| 71 |   }
 | 
|---|
| 72 | 
 | 
|---|
| 73 |   const HomologyGraph::edges_t getEdgesFromKeySet(const KeySet &keyset)
 | 
|---|
| 74 |   {
 | 
|---|
| 75 |     HomologyGraph::edges_t edges;
 | 
|---|
| 76 |     for (KeySet::const_iterator iter = keyset.begin();
 | 
|---|
| 77 |         iter != keyset.end(); ++iter) {
 | 
|---|
| 78 |       const atom *Walker = World::getInstance().getAtom(AtomById(*iter));
 | 
|---|
| 79 |       if (Walker != NULL) {
 | 
|---|
| 80 |         const BondList& ListOfBonds = Walker->getListOfBonds();
 | 
|---|
| 81 |         for (BondList::const_iterator bonditer = ListOfBonds.begin();
 | 
|---|
| 82 |             bonditer != ListOfBonds.begin(); ++iter) {
 | 
|---|
| 83 |           const atom *OtherWalker = (*bonditer)->GetOtherAtom(Walker);
 | 
|---|
| 84 |           if (Walker->getId() < OtherWalker->getId())
 | 
|---|
| 85 |             edges.insert( FragmentEdge( Walker->getElementNo(), OtherWalker->getElementNo()) );
 | 
|---|
| 86 |         }
 | 
|---|
| 87 |       } else {
 | 
|---|
| 88 |         ELOG(0, "Id " << *iter << " is not associated with any atom.");
 | 
|---|
| 89 |       }
 | 
|---|
| 90 |     }
 | 
|---|
| 91 |     return edges;
 | 
|---|
| 92 |   }
 | 
|---|
| 93 | };  /* namespace detail */
 | 
|---|
| 94 | 
 | 
|---|