source: src/Fragmentation/KeySetsContainer.cpp@ d1831e

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since d1831e was 5aaa43, checked in by Frederik Heber <heber@…>, 12 years ago

FIX: Fixed new copyright line since start of 2013 in CodeChecks test.

  • we must look for either Uni Bonn or myself.
  • added second copyright line since from 1st of Jan 2013 I am not employed by University of Bonn anymore, hence changes to the code are my own copyright.
  • Property mode set to 100644
File size: 7.7 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
5 * Copyright (C) 2013 Frederik Heber. All rights reserved.
6 *
7 *
8 * This file is part of MoleCuilder.
9 *
10 * MoleCuilder is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * MoleCuilder is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24/*
25 * KeySetsContainer.cpp
26 *
27 * Created on: Sep 15, 2011
28 * Author: heber
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 <fstream>
39#include <sstream>
40
41#include <boost/lexical_cast.hpp>
42#include <boost/tokenizer.hpp>
43
44#include "CodePatterns/Log.hpp"
45
46#include "Fragmentation/defs.hpp"
47#include "Fragmentation/helpers.hpp"
48#include "Helpers/defs.hpp"
49#include "KeySetsContainer.hpp"
50
51/** Constructor of KeySetsContainer class.
52 */
53KeySetsContainer::KeySetsContainer() :
54 FragmentCounter(0),
55 Order(0),
56 FragmentsPerOrder(0)
57{};
58
59/** Destructor of KeySetsContainer class.
60 */
61KeySetsContainer::~KeySetsContainer() {
62// for(int i=FragmentCounter;i--;)
63// delete[](KeySets[i]);
64// for(int i=Order;i--;)
65// delete[](OrderSet[i]);
66// delete[](KeySets);
67// delete[](OrderSet);
68// delete[](AtomCounter);
69// delete[](FragmentsPerOrder);
70};
71
72/** Parsing KeySets into array.
73 * \param *name directory with keyset file
74 * \param *ACounter number of atoms per fragment
75 * \param FCounter number of fragments
76 * \return parsing succesful
77 */
78bool KeySetsContainer::ParseKeySets(const std::string path, const std::string name, const int FCounter) {
79 ifstream input;
80 //char *FragmentNumber = NULL;
81 stringstream file;
82 char filename[1023];
83
84 FragmentCounter = FCounter;
85 KeySets.resize(FragmentCounter);
86 AtomCounter.resize(FragmentCounter);
87
88 // open file
89 file << path << "/" << name;
90 input.open(file.str().c_str(), ios::in);
91 if (input.fail()) {
92 LOG(0, endl << "KeySetsContainer::ParseKeySets: Unable to open " << file.str() << ", is the directory correct?");
93 return false;
94 }
95
96 // parse each line, i.e. get the index set per fragment
97 LOG(0, "Parsing key sets.");
98 for(int i=0;(i<FragmentCounter) && (!input.eof());i++) {
99 input.getline(filename, 1023);
100 string line(filename);
101// LOG(2, "DEBUG: line is " << line << ".");
102 std::stringstream set_output;
103 typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
104 boost::char_separator<char> sep(" \t");
105 tokenizer tok(line, sep);
106 for(tokenizer::iterator beg=tok.begin();
107 beg != tok.end();++beg){
108 const int tempvalue = boost::lexical_cast<int>(*beg);
109 KeySets[i].push_back(tempvalue);
110// set_output << " " << KeySets[i].back();
111 }
112// LOG(2, "DEBUG: Scanned keys are '" << set_output.str() << "'.");
113 AtomCounter[i] = KeySets[i].size();
114// {
115// std::stringstream output;
116// FragmentNumber = FixedDigitNumber(FragmentCounter, i);
117// output << FRAGMENTPREFIX << FragmentNumber << "[" << AtomCounter[i] << "]:" << set_output.str();
118// delete[](FragmentNumber);
119// LOG(0, output.str());
120// }
121 }
122 input.close();
123 return true;
124};
125
126/** Parse many body terms, associating each fragment to a certain bond order.
127 * \return parsing succesful
128 */
129bool KeySetsContainer::ParseManyBodyTerms()
130{
131 int Counter;
132
133 LOG(0, "Creating Fragment terms.");
134 // scan through all to determine maximum order
135 Order=0;
136 for(int i=FragmentCounter;i--;) {
137 Counter=0;
138 for(int j=AtomCounter[i];j--;)
139 if (KeySets[i][j] != -1)
140 Counter++;
141 if (Counter > Order)
142 Order = Counter;
143 }
144 LOG(0, "Found Order is " << Order << ".");
145
146 // scan through all to determine fragments per order
147 FragmentsPerOrder.resize(Order);
148// for(int i=Order;i--;)
149// FragmentsPerOrder[i] = 0;
150 for(int i=FragmentCounter;i--;) {
151 Counter=0;
152 for(int j=AtomCounter[i];j--;)
153 if (KeySets[i][j] != -1)
154 Counter++;
155 FragmentsPerOrder[Counter-1]++;
156 }
157 for(int i=0;i<Order;i++)
158 LOG(0, "Found No. of Fragments of Order " << i+1 << " is " << FragmentsPerOrder[i] << ".");
159
160 // scan through all to gather indices to each order set
161 OrderSet.resize(Order);
162 for(int i=Order;i--;)
163 OrderSet[i].resize(FragmentsPerOrder[i]);
164 for(int i=Order;i--;)
165 FragmentsPerOrder[i] = 0;
166 for(int i=FragmentCounter;i--;) {
167 Counter=0;
168 for(int j=AtomCounter[i];j--;)
169 if (KeySets[i][j] != -1)
170 Counter++;
171 OrderSet[Counter-1][FragmentsPerOrder[Counter-1]] = i;
172 FragmentsPerOrder[Counter-1]++;
173 }
174 std::stringstream output;
175 output << "Printing OrderSet: " << std::endl;
176 for(int i=0;i<Order;i++) {
177 for (int j=0;j<FragmentsPerOrder[i];j++) {
178 output << " " << OrderSet[i][j];
179 }
180 output << std::endl;
181 }
182 LOG(0, output.str());
183
184 return true;
185};
186
187/** Compares each entry in \a *SmallerSet if it is containted in \a *GreaterSet.
188 * \param GreaterSet index to greater set
189 * \param SmallerSet index to smaller set
190 * \return true if all keys of SmallerSet contained in GreaterSet
191 */
192bool KeySetsContainer::Contains(const int GreaterSet, const int SmallerSet)
193{
194 bool result = true;
195 bool intermediate;
196 if ((GreaterSet < 0) || (SmallerSet < 0) || (GreaterSet > FragmentCounter) || (SmallerSet > FragmentCounter)) // index out of bounds
197 return false;
198 for(int i=AtomCounter[SmallerSet];i--;) {
199 intermediate = false;
200 for (int j=AtomCounter[GreaterSet];j--;)
201 intermediate = (intermediate || ((KeySets[SmallerSet][i] == KeySets[GreaterSet][j]) || (KeySets[SmallerSet][i] == -1)));
202 result = result && intermediate;
203 }
204
205 return result;
206};
207
208/** Comparison operator for class KeySetsContainer.
209 *
210 * @param other instance to compare to
211 * @return true - both instances are the same in each member variable.
212 */
213bool KeySetsContainer::operator==(const KeySetsContainer &other) const
214{
215 // compare KeySets
216 if (KeySets != other.KeySets)
217 return false;
218 // compare OrderSet
219 if (OrderSet != other.OrderSet)
220 return false;
221 // compare AtomCounter
222 if (AtomCounter != other.AtomCounter)
223 return false;
224 // compare FragmentCounter
225 if (FragmentCounter != other.FragmentCounter)
226 return false;
227 // compare Order
228 if (Order != other.Order)
229 return false;
230 // compare FragmentsPerOrder
231 if (FragmentsPerOrder != other.FragmentsPerOrder)
232 return false;
233
234 return true;
235}
236
237void KeySetsContainer::clear()
238{
239 KeySets.clear();
240 OrderSet.clear();
241 AtomCounter.clear();
242 FragmentCounter = 0;
243 Order = 0;
244 FragmentsPerOrder.clear();
245}
246
247void KeySetsContainer::insert(const KeySetsContainer &other)
248{
249 KeySets.reserve(KeySets.size()+other.KeySets.size());
250 AtomCounter.reserve(AtomCounter.size()+other.AtomCounter.size());
251 for (ArrayOfIntVectors::const_iterator iter = other.KeySets.begin();
252 iter != other.KeySets.end(); ++iter)
253 insert(*iter, iter->size());
254}
255
256void KeySetsContainer::insert(const IntVector &indices, const size_t order)
257{
258 KeySets.push_back(indices);
259 AtomCounter.push_back(indices.size());
260 if (order > OrderSet.size() )
261 OrderSet.resize(order);
262 OrderSet[order-1].push_back(FragmentCounter);
263 if (order > FragmentsPerOrder.size())
264 FragmentsPerOrder.resize(order);
265 ++(FragmentsPerOrder[order-1]);
266 ++FragmentCounter;
267}
Note: See TracBrowser for help on using the repository browser.