| [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 | 
 | 
|---|
| [9eb71b3] | 35 | //#include "CodePatterns/MemDebug.hpp"
 | 
|---|
| [a03d25] | 36 | 
 | 
|---|
 | 37 | #include "UniqueFragments.hpp"
 | 
|---|
 | 38 | 
 | 
|---|
| [d760bb] | 39 | #include "CodePatterns/Assert.hpp"
 | 
|---|
| [a03d25] | 40 | #include "CodePatterns/Log.hpp"
 | 
|---|
 | 41 | 
 | 
|---|
| [6f0841] | 42 | #include "Atom/atom.hpp"
 | 
|---|
| [a03d25] | 43 | #include "Bond/bond.hpp"
 | 
|---|
 | 44 | #include "Element/element.hpp"
 | 
|---|
| [ba94c5] | 45 | #include "Fragmentation/fragmentation_helpers.hpp"
 | 
|---|
| [dadc74] | 46 | #include "Fragmentation/Graph.hpp"
 | 
|---|
| [f0674a] | 47 | #include "Fragmentation/KeySet.hpp"
 | 
|---|
| [a03d25] | 48 | 
 | 
|---|
 | 49 | /** Constructor of class UniqueFragments.
 | 
|---|
 | 50 |  *
 | 
|---|
| [d760bb] | 51 |  * @param _TEFactor total energy factor
 | 
|---|
 | 52 |  * @param _Leaflet current graph to work on
 | 
|---|
 | 53 |  * @param _Root root atom
 | 
|---|
| [a03d25] | 54 |  */
 | 
|---|
| [d760bb] | 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 | }
 | 
|---|
| [a03d25] | 63 | 
 | 
|---|
 | 64 | /** Destructor of class UniqueFragments.
 | 
|---|
 | 65 |  *
 | 
|---|
 | 66 |  */
 | 
|---|
 | 67 | UniqueFragments::~UniqueFragments()
 | 
|---|
| [d760bb] | 68 | {
 | 
|---|
 | 69 |   Cleanup();
 | 
|---|
 | 70 | }
 | 
|---|
| [a03d25] | 71 | 
 | 
|---|
 | 72 | /** Checking whether KeySet is not already present in Graph, if so just adds factor.
 | 
|---|
| [d760bb] | 73 |  *
 | 
|---|
 | 74 |  * \param order order at which to insert
 | 
|---|
| [a03d25] | 75 |  */
 | 
|---|
| [d760bb] | 76 | void UniqueFragments::InsertFragmentIntoGraph(const size_t order)
 | 
|---|
| [a03d25] | 77 | {
 | 
|---|
 | 78 |   GraphTestPair testGraphInsert;
 | 
|---|
 | 79 | 
 | 
|---|
| [d760bb] | 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
 | 
|---|
| [a03d25] | 84 |   if (testGraphInsert.second) {
 | 
|---|
| [47d041] | 85 |     LOG(2, "KeySet " << FragmentCounter << " successfully inserted.");
 | 
|---|
| [a03d25] | 86 |     FragmentCounter++;
 | 
|---|
 | 87 |   } else {
 | 
|---|
| [47d041] | 88 |     LOG(2, "KeySet " << FragmentCounter << " failed to insert, present fragment is " << ((*(testGraphInsert.first)).second).first);
 | 
|---|
| [a03d25] | 89 |     ((*(testGraphInsert.first)).second).second += TEFactor;  // increase the "created" counter
 | 
|---|
| [47d041] | 90 |     LOG(2, "New factor is " << ((*(testGraphInsert.first)).second).second << ".");
 | 
|---|
| [a03d25] | 91 |   }
 | 
|---|
 | 92 | };
 | 
|---|
 | 93 | 
 | 
|---|
 | 94 | /** Removes some allocated memory.
 | 
|---|
 | 95 |  *
 | 
|---|
 | 96 |  */
 | 
|---|
 | 97 | void UniqueFragments::Cleanup()
 | 
|---|
 | 98 | {
 | 
|---|
| [d760bb] | 99 |   delete FragmentSet;
 | 
|---|
| [a03d25] | 100 | }
 | 
|---|
| [23fb72] | 101 | 
 | 
|---|
 | 102 | /** Getter for UniqueFragments:Root.
 | 
|---|
 | 103 |  *
 | 
|---|
 | 104 |  * @return const ref to root atom.
 | 
|---|
 | 105 |  */
 | 
|---|
| [212c179] | 106 | atom * const UniqueFragments::getRoot() const
 | 
|---|
| [23fb72] | 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 | }
 | 
|---|