source: src/Fragmentation/KeySetsContainer.cpp@ 730d7a

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 730d7a was 1b145f, checked in by Frederik Heber <heber@…>, 13 years ago

Added operator==() to KeySetsContainer and MatrixContainer.

  • also added unit test functions for both.
  • Property mode set to 100644
File size: 5.9 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * KeySetsContainer.cpp
10 *
11 * Created on: Sep 15, 2011
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "CodePatterns/MemDebug.hpp"
21
22#include <fstream>
23#include <sstream>
24
25#include "CodePatterns/Log.hpp"
26
27#include "Fragmentation/defs.hpp"
28#include "Fragmentation/helpers.hpp"
29#include "Helpers/defs.hpp"
30#include "KeySetsContainer.hpp"
31
32/** Constructor of KeySetsContainer class.
33 */
34KeySetsContainer::KeySetsContainer() :
35 FragmentCounter(0),
36 Order(0),
37 FragmentsPerOrder(0)
38{};
39
40/** Destructor of KeySetsContainer class.
41 */
42KeySetsContainer::~KeySetsContainer() {
43// for(int i=FragmentCounter;i--;)
44// delete[](KeySets[i]);
45// for(int i=Order;i--;)
46// delete[](OrderSet[i]);
47// delete[](KeySets);
48// delete[](OrderSet);
49// delete[](AtomCounter);
50// delete[](FragmentsPerOrder);
51};
52
53/** Parsing KeySets into array.
54 * \param *name directory with keyset file
55 * \param *ACounter number of atoms per fragment
56 * \param FCounter number of fragments
57 * \return parsing succesful
58 */
59bool KeySetsContainer::ParseKeySets(const std::string name, const IntVector ACounter, const int FCounter) {
60 ifstream input;
61 char *FragmentNumber = NULL;
62 stringstream file;
63 char filename[1023];
64
65 FragmentCounter = FCounter;
66 DoLog(0) && (Log() << Verbose(0) << "Parsing key sets." << endl);
67 KeySets.resize(FragmentCounter);
68 file << name << FRAGMENTPREFIX << KEYSETFILE;
69 input.open(file.str().c_str(), ios::in);
70 if (input.fail()) {
71 DoLog(0) && (Log() << Verbose(0) << endl << "KeySetsContainer::ParseKeySets: Unable to open " << file.str() << ", is the directory correct?" << endl);
72 return false;
73 }
74
75 AtomCounter.resize(FragmentCounter);
76 for(int i=0;(i<FragmentCounter) && (!input.eof());i++) {
77 stringstream line;
78 AtomCounter[i] = ACounter[i];
79 // parse the values
80 KeySets[i].resize(AtomCounter[i]);
81 for(int j=AtomCounter[i];j--;)
82 KeySets[i][j] = -1;
83 FragmentNumber = FixedDigitNumber(FragmentCounter, i);
84 //Log() << Verbose(0) << FRAGMENTPREFIX << FragmentNumber << "[" << AtomCounter[i] << "]:";
85 delete[](FragmentNumber);
86 input.getline(filename, 1023);
87 line.str(filename);
88 for(int j=0;(j<AtomCounter[i]) && (!line.eof());j++) {
89 line >> KeySets[i][j];
90 //Log() << Verbose(0) << " " << KeySets[i][j];
91 }
92 //Log() << Verbose(0) << endl;
93 }
94 input.close();
95 return true;
96};
97
98/** Parse many body terms, associating each fragment to a certain bond order.
99 * \return parsing succesful
100 */
101bool KeySetsContainer::ParseManyBodyTerms()
102{
103 int Counter;
104
105 DoLog(0) && (Log() << Verbose(0) << "Creating Fragment terms." << endl);
106 // scan through all to determine maximum order
107 Order=0;
108 for(int i=FragmentCounter;i--;) {
109 Counter=0;
110 for(int j=AtomCounter[i];j--;)
111 if (KeySets[i][j] != -1)
112 Counter++;
113 if (Counter > Order)
114 Order = Counter;
115 }
116 DoLog(0) && (Log() << Verbose(0) << "Found Order is " << Order << "." << endl);
117
118 // scan through all to determine fragments per order
119 FragmentsPerOrder.resize(Order);
120// for(int i=Order;i--;)
121// FragmentsPerOrder[i] = 0;
122 for(int i=FragmentCounter;i--;) {
123 Counter=0;
124 for(int j=AtomCounter[i];j--;)
125 if (KeySets[i][j] != -1)
126 Counter++;
127 FragmentsPerOrder[Counter-1]++;
128 }
129 for(int i=0;i<Order;i++)
130 DoLog(0) && (Log() << Verbose(0) << "Found No. of Fragments of Order " << i+1 << " is " << FragmentsPerOrder[i] << "." << endl);
131
132 // scan through all to gather indices to each order set
133 OrderSet.resize(Order);
134 for(int i=Order;i--;)
135 OrderSet[i].resize(FragmentsPerOrder[i]);
136 for(int i=Order;i--;)
137 FragmentsPerOrder[i] = 0;
138 for(int i=FragmentCounter;i--;) {
139 Counter=0;
140 for(int j=AtomCounter[i];j--;)
141 if (KeySets[i][j] != -1)
142 Counter++;
143 OrderSet[Counter-1][FragmentsPerOrder[Counter-1]] = i;
144 FragmentsPerOrder[Counter-1]++;
145 }
146 DoLog(0) && (Log() << Verbose(0) << "Printing OrderSet." << endl);
147 for(int i=0;i<Order;i++) {
148 for (int j=0;j<FragmentsPerOrder[i];j++) {
149 DoLog(0) && (Log() << Verbose(0) << " " << OrderSet[i][j]);
150 }
151 DoLog(0) && (Log() << Verbose(0) << endl);
152 }
153 DoLog(0) && (Log() << Verbose(0) << endl);
154
155
156 return true;
157};
158
159/** Compares each entry in \a *SmallerSet if it is containted in \a *GreaterSet.
160 * \param GreaterSet index to greater set
161 * \param SmallerSet index to smaller set
162 * \return true if all keys of SmallerSet contained in GreaterSet
163 */
164bool KeySetsContainer::Contains(const int GreaterSet, const int SmallerSet)
165{
166 bool result = true;
167 bool intermediate;
168 if ((GreaterSet < 0) || (SmallerSet < 0) || (GreaterSet > FragmentCounter) || (SmallerSet > FragmentCounter)) // index out of bounds
169 return false;
170 for(int i=AtomCounter[SmallerSet];i--;) {
171 intermediate = false;
172 for (int j=AtomCounter[GreaterSet];j--;)
173 intermediate = (intermediate || ((KeySets[SmallerSet][i] == KeySets[GreaterSet][j]) || (KeySets[SmallerSet][i] == -1)));
174 result = result && intermediate;
175 }
176
177 return result;
178};
179
180/** Comparison operator for class KeySetsContainer.
181 *
182 * @param other instance to compare to
183 * @return true - both instances are the same in each member variable.
184 */
185bool KeySetsContainer::operator==(const KeySetsContainer &other) const
186{
187 // compare KeySets
188 if (KeySets != other.KeySets)
189 return false;
190 // compare OrderSet
191 if (OrderSet != other.OrderSet)
192 return false;
193 // compare AtomCounter
194 if (AtomCounter != other.AtomCounter)
195 return false;
196 // compare FragmentCounter
197 if (FragmentCounter != other.FragmentCounter)
198 return false;
199 // compare Order
200 if (Order != other.Order)
201 return false;
202 // compare FragmentsPerOrder
203 if (FragmentsPerOrder != other.FragmentsPerOrder)
204 return false;
205
206 return true;
207}
Note: See TracBrowser for help on using the repository browser.