| 1 | /* | 
|---|
| 2 | * Project: MoleCuilder | 
|---|
| 3 | * Description: creates and alters molecular systems | 
|---|
| 4 | * Copyright (C)  2010-2012 University of Bonn. 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 | * UniqueFragments.cpp | 
|---|
| 25 | * | 
|---|
| 26 | *  Created on: Oct 18, 2011 | 
|---|
| 27 | *      Author: heber | 
|---|
| 28 | */ | 
|---|
| 29 |  | 
|---|
| 30 | // include config.h | 
|---|
| 31 | #ifdef HAVE_CONFIG_H | 
|---|
| 32 | #include <config.h> | 
|---|
| 33 | #endif | 
|---|
| 34 |  | 
|---|
| 35 | //#include "CodePatterns/MemDebug.hpp" | 
|---|
| 36 |  | 
|---|
| 37 | #include "UniqueFragments.hpp" | 
|---|
| 38 |  | 
|---|
| 39 | #include "CodePatterns/Assert.hpp" | 
|---|
| 40 | #include "CodePatterns/Log.hpp" | 
|---|
| 41 |  | 
|---|
| 42 | #include "Atom/atom.hpp" | 
|---|
| 43 | #include "Bond/bond.hpp" | 
|---|
| 44 | #include "Element/element.hpp" | 
|---|
| 45 | #include "Fragmentation/fragmentation_helpers.hpp" | 
|---|
| 46 | #include "Fragmentation/Graph.hpp" | 
|---|
| 47 | #include "Fragmentation/KeySet.hpp" | 
|---|
| 48 |  | 
|---|
| 49 | /** Constructor of class UniqueFragments. | 
|---|
| 50 | * | 
|---|
| 51 | * @param _TEFactor total energy factor | 
|---|
| 52 | * @param _Leaflet current graph to work on | 
|---|
| 53 | * @param _Root root atom | 
|---|
| 54 | */ | 
|---|
| 55 | UniqueFragments::UniqueFragments(double _TEFactor, std::vector<Graph*> &_Leaflets, atom *_Root) : | 
|---|
| 56 | FragmentCounter(0), | 
|---|
| 57 | Root(_Root), | 
|---|
| 58 | TEFactor(_TEFactor), | 
|---|
| 59 | Leaflets(_Leaflets) | 
|---|
| 60 | { | 
|---|
| 61 | FragmentSet = new KeySet; | 
|---|
| 62 | } | 
|---|
| 63 |  | 
|---|
| 64 | /** Destructor of class UniqueFragments. | 
|---|
| 65 | * | 
|---|
| 66 | */ | 
|---|
| 67 | UniqueFragments::~UniqueFragments() | 
|---|
| 68 | { | 
|---|
| 69 | Cleanup(); | 
|---|
| 70 | } | 
|---|
| 71 |  | 
|---|
| 72 | /** Checking whether KeySet is not already present in Graph, if so just adds factor. | 
|---|
| 73 | * | 
|---|
| 74 | * \param order order at which to insert | 
|---|
| 75 | */ | 
|---|
| 76 | void UniqueFragments::InsertFragmentIntoGraph(const size_t order) | 
|---|
| 77 | { | 
|---|
| 78 | GraphTestPair testGraphInsert; | 
|---|
| 79 |  | 
|---|
| 80 | ASSERT( Leaflets.size() > order, | 
|---|
| 81 | "UniqueFragments::InsertFragmentIntoGraph() - Leaflets has only " | 
|---|
| 82 | +toString(Leaflets.size())+" entries, not enough for "+toString(order)); | 
|---|
| 83 | testGraphInsert = Leaflets[order]->insert(GraphPair (*FragmentSet,std::pair<int,double>(FragmentCounter,TEFactor)));  // store fragment number and current factor | 
|---|
| 84 | if (testGraphInsert.second) { | 
|---|
| 85 | LOG(2, "KeySet " << FragmentCounter << " successfully inserted."); | 
|---|
| 86 | FragmentCounter++; | 
|---|
| 87 | } else { | 
|---|
| 88 | LOG(2, "KeySet " << FragmentCounter << " failed to insert, present fragment is " << ((*(testGraphInsert.first)).second).first); | 
|---|
| 89 | ((*(testGraphInsert.first)).second).second += TEFactor;  // increase the "created" counter | 
|---|
| 90 | LOG(2, "New factor is " << ((*(testGraphInsert.first)).second).second << "."); | 
|---|
| 91 | } | 
|---|
| 92 | }; | 
|---|
| 93 |  | 
|---|
| 94 | /** Removes some allocated memory. | 
|---|
| 95 | * | 
|---|
| 96 | */ | 
|---|
| 97 | void UniqueFragments::Cleanup() | 
|---|
| 98 | { | 
|---|
| 99 | delete FragmentSet; | 
|---|
| 100 | } | 
|---|
| 101 |  | 
|---|
| 102 | /** Getter for UniqueFragments:Root. | 
|---|
| 103 | * | 
|---|
| 104 | * @return const ref to root atom. | 
|---|
| 105 | */ | 
|---|
| 106 | atom * const UniqueFragments::getRoot() const | 
|---|
| 107 | { | 
|---|
| 108 | return Root; | 
|---|
| 109 | } | 
|---|
| 110 |  | 
|---|
| 111 | /** Setter for UniqueFragments:Root. | 
|---|
| 112 | * | 
|---|
| 113 | * @param _root root atom to set | 
|---|
| 114 | */ | 
|---|
| 115 | void UniqueFragments::setRoot(atom *_root) | 
|---|
| 116 | { | 
|---|
| 117 | Root=_root; | 
|---|
| 118 | } | 
|---|