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/Log.hpp"
|
---|
40 |
|
---|
41 | #include "Atom/atom.hpp"
|
---|
42 | #include "Bond/bond.hpp"
|
---|
43 | #include "Element/element.hpp"
|
---|
44 | #include "Fragmentation/fragmentation_helpers.hpp"
|
---|
45 | #include "Fragmentation/Graph.hpp"
|
---|
46 | #include "Fragmentation/KeySet.hpp"
|
---|
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) {
|
---|
68 | LOG(2, "KeySet " << FragmentCounter << " successfully inserted.");
|
---|
69 | FragmentCounter++;
|
---|
70 | } else {
|
---|
71 | LOG(2, "KeySet " << FragmentCounter << " failed to insert, present fragment is " << ((*(testGraphInsert.first)).second).first);
|
---|
72 | ((*(testGraphInsert.first)).second).second += TEFactor; // increase the "created" counter
|
---|
73 | LOG(2, "New factor is " << ((*(testGraphInsert.first)).second).second << ".");
|
---|
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 | */
|
---|
82 | void UniqueFragments::Init(atom *_Root)
|
---|
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 | }
|
---|
97 |
|
---|
98 | /** Getter for UniqueFragments:Root.
|
---|
99 | *
|
---|
100 | * @return const ref to root atom.
|
---|
101 | */
|
---|
102 | atom * const UniqueFragments::getRoot() const
|
---|
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 | }
|
---|
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 | }
|
---|