[d45ed9] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
| 4 | * Copyright (C) 2016 Frederik Heber. All rights reserved.
|
---|
| 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/>.
|
---|
| 21 | */
|
---|
| 22 |
|
---|
| 23 | /*
|
---|
| 24 | * AtomFragmentsMap.cpp
|
---|
| 25 | *
|
---|
| 26 | * Created on: Mar 7, 2016
|
---|
| 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 "CodePatterns/Log.hpp"
|
---|
[d713ce] | 39 | #include "CodePatterns/Singleton_impl.hpp"
|
---|
[d45ed9] | 40 |
|
---|
| 41 | #include "AtomFragmentsMap.hpp"
|
---|
| 42 |
|
---|
| 43 | #include "AtomIdSet.hpp"
|
---|
| 44 | #include "Fragmentation/Graph.hpp"
|
---|
| 45 | #include "Fragmentation/KeySet.hpp"
|
---|
| 46 |
|
---|
[d713ce] | 47 | void AtomFragmentsMap::insert(
|
---|
[d45ed9] | 48 | const Graph &_graph,
|
---|
| 49 | size_t _MaxOrder)
|
---|
| 50 | {
|
---|
| 51 | /// create a map of atom to keyset (below equal MaxOrder)
|
---|
[d713ce] | 52 | LOG(1, "INFO: Placing all atoms and their keysets into internal map.");
|
---|
[d45ed9] | 53 | for (Graph::const_iterator keysetiter = _graph.begin();
|
---|
| 54 | keysetiter != _graph.end(); ++keysetiter) {
|
---|
| 55 | const KeySet &keyset = keysetiter->first;
|
---|
| 56 | LOG(2, "DEBUG: Current keyset is " << keyset);
|
---|
[bd6e5c] | 57 | if ((keyset.size() > _MaxOrder) || (keyset.empty()))
|
---|
[d45ed9] | 58 | continue;
|
---|
[bd6e5c] | 59 | for (KeySet::const_iterator keyiter = keyset.begin();
|
---|
| 60 | keyiter != keyset.end(); ++keyiter) {
|
---|
[d45ed9] | 61 | // either create new list ...
|
---|
| 62 | std::pair<AtomFragmentsMap_t::iterator, bool> inserter =
|
---|
[bd6e5c] | 63 | atommap.insert( std::make_pair(*keyiter, keysets_t(1, keyset) ));
|
---|
[d45ed9] | 64 | // ... or push to end
|
---|
| 65 | if (inserter.second) {
|
---|
| 66 | LOG(3, "DEBUG: Created new entry in map.");
|
---|
| 67 | } else {
|
---|
| 68 | LOG(3, "DEBUG: Added keyset to present entry.");
|
---|
[bd6e5c] | 69 | inserter.first->second.push_back(keyset);
|
---|
[d45ed9] | 70 | }
|
---|
| 71 | }
|
---|
| 72 | }
|
---|
[d713ce] | 73 | LOG(2, "DEBUG: There are now " << atommap.size() << " entries in lookup.");
|
---|
[d45ed9] | 74 | }
|
---|
[d713ce] | 75 |
|
---|
| 76 | CONSTRUCT_SINGLETON(AtomFragmentsMap)
|
---|
[16d67a] | 77 |
|
---|
| 78 |
|
---|
| 79 | // we need to explicitly instantiate the serialization functions
|
---|
| 80 | BOOST_CLASS_EXPORT_IMPLEMENT(AtomFragmentsMap)
|
---|
| 81 |
|
---|