| [a03d25] | 1 | /* | 
|---|
|  | 2 | * Project: MoleCuilder | 
|---|
|  | 3 | * Description: creates and alters molecular systems | 
|---|
| [0aa122] | 4 | * Copyright (C)  2010-2012 University of Bonn. All rights reserved. | 
|---|
| [94d5ac6] | 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/>. | 
|---|
| [a03d25] | 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/Log.hpp" | 
|---|
|  | 40 |  | 
|---|
| [6f0841] | 41 | #include "Atom/atom.hpp" | 
|---|
| [a03d25] | 42 | #include "Bond/bond.hpp" | 
|---|
|  | 43 | #include "Element/element.hpp" | 
|---|
| [ba94c5] | 44 | #include "Fragmentation/fragmentation_helpers.hpp" | 
|---|
| [dadc74] | 45 | #include "Fragmentation/Graph.hpp" | 
|---|
| [f0674a] | 46 | #include "Fragmentation/KeySet.hpp" | 
|---|
| [a03d25] | 47 |  | 
|---|
|  | 48 | /** Constructor of class UniqueFragments. | 
|---|
|  | 49 | * | 
|---|
|  | 50 | */ | 
|---|
|  | 51 | UniqueFragments::UniqueFragments() | 
|---|
|  | 52 | {} | 
|---|
|  | 53 |  | 
|---|
|  | 54 | /** Destructor of class UniqueFragments. | 
|---|
|  | 55 | * | 
|---|
|  | 56 | */ | 
|---|
|  | 57 | UniqueFragments::~UniqueFragments() | 
|---|
|  | 58 | {} | 
|---|
|  | 59 |  | 
|---|
|  | 60 | /** Checking whether KeySet is not already present in Graph, if so just adds factor. | 
|---|
|  | 61 | */ | 
|---|
|  | 62 | void UniqueFragments::InsertFragmentIntoGraph() | 
|---|
|  | 63 | { | 
|---|
|  | 64 | GraphTestPair testGraphInsert; | 
|---|
|  | 65 |  | 
|---|
|  | 66 | testGraphInsert = Leaflet->insert(GraphPair (*FragmentSet,std::pair<int,double>(FragmentCounter,TEFactor)));  // store fragment number and current factor | 
|---|
|  | 67 | if (testGraphInsert.second) { | 
|---|
| [47d041] | 68 | LOG(2, "KeySet " << FragmentCounter << " successfully inserted."); | 
|---|
| [a03d25] | 69 | FragmentCounter++; | 
|---|
|  | 70 | } else { | 
|---|
| [47d041] | 71 | LOG(2, "KeySet " << FragmentCounter << " failed to insert, present fragment is " << ((*(testGraphInsert.first)).second).first); | 
|---|
| [a03d25] | 72 | ((*(testGraphInsert.first)).second).second += TEFactor;  // increase the "created" counter | 
|---|
| [47d041] | 73 | LOG(2, "New factor is " << ((*(testGraphInsert.first)).second).second << "."); | 
|---|
| [a03d25] | 74 | } | 
|---|
|  | 75 | }; | 
|---|
|  | 76 |  | 
|---|
|  | 77 | /** Initialization for UniqueFragments. | 
|---|
|  | 78 | * | 
|---|
|  | 79 | * \param _Root ref to atom to start from (with graph algorithms, hence root node) | 
|---|
|  | 80 | * \param AtomCount number of nodes/atoms | 
|---|
|  | 81 | */ | 
|---|
| [d0b375b] | 82 | void UniqueFragments::Init(atom *_Root) | 
|---|
| [a03d25] | 83 | { | 
|---|
|  | 84 | // initialise the fragments structure | 
|---|
|  | 85 | FragmentCounter = 0; | 
|---|
|  | 86 | FragmentSet = new KeySet; | 
|---|
|  | 87 | Root = _Root; | 
|---|
|  | 88 | } | 
|---|
|  | 89 |  | 
|---|
|  | 90 | /** Removes some allocated memory. | 
|---|
|  | 91 | * | 
|---|
|  | 92 | */ | 
|---|
|  | 93 | void UniqueFragments::Cleanup() | 
|---|
|  | 94 | { | 
|---|
|  | 95 | delete(FragmentSet); | 
|---|
|  | 96 | } | 
|---|
| [23fb72] | 97 |  | 
|---|
|  | 98 | /** Getter for UniqueFragments:Root. | 
|---|
|  | 99 | * | 
|---|
|  | 100 | * @return const ref to root atom. | 
|---|
|  | 101 | */ | 
|---|
| [212c179] | 102 | atom * const UniqueFragments::getRoot() const | 
|---|
| [23fb72] | 103 | { | 
|---|
|  | 104 | return Root; | 
|---|
|  | 105 | } | 
|---|
|  | 106 |  | 
|---|
|  | 107 | /** Setter for UniqueFragments:Root. | 
|---|
|  | 108 | * | 
|---|
|  | 109 | * @param _root root atom to set | 
|---|
|  | 110 | */ | 
|---|
|  | 111 | void UniqueFragments::setRoot(atom *_root) | 
|---|
|  | 112 | { | 
|---|
|  | 113 | Root=_root; | 
|---|
|  | 114 | } | 
|---|
| [212c179] | 115 |  | 
|---|
|  | 116 | /** Sets initial values before PowerSetGenerator uses this class. | 
|---|
|  | 117 | * | 
|---|
|  | 118 | * @param _TEFactor total energy factor | 
|---|
|  | 119 | * @param _Leaflet current graph to work on | 
|---|
|  | 120 | * @param _Root root atom | 
|---|
|  | 121 | */ | 
|---|
|  | 122 | void UniqueFragments::PrepareForPowersetGeneration(double _TEFactor, Graph *_Leaflet, atom *_Root) | 
|---|
|  | 123 | { | 
|---|
|  | 124 | TEFactor = _TEFactor; | 
|---|
|  | 125 | Leaflet = _Leaflet; | 
|---|
|  | 126 | Root = _Root; | 
|---|
|  | 127 | } | 
|---|