source: src/Fragmentation/KeySetsContainer.cpp@ 509014

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 509014 was 0aa122, checked in by Frederik Heber <heber@…>, 13 years ago

Updated all source files's copyright note to current year 2012.

  • Property mode set to 100644
File size: 5.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 * 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 LOG(0, "Parsing key sets.");
67 KeySets.resize(FragmentCounter);
68 file << name << FRAGMENTPREFIX << KEYSETFILE;
69 input.open(file.str().c_str(), ios::in);
70 if (input.fail()) {
71 LOG(0, endl << "KeySetsContainer::ParseKeySets: Unable to open " << file.str() << ", is the directory correct?");
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 //std::stringstream output;
85 //output << FRAGMENTPREFIX << FragmentNumber << "[" << AtomCounter[i] << "]:";
86 delete[](FragmentNumber);
87 input.getline(filename, 1023);
88 line.str(filename);
89 for(int j=0;(j<AtomCounter[i]) && (!line.eof());j++) {
90 line >> KeySets[i][j];
91 //output << " " << KeySets[i][j];
92 }
93 //LOG(0, output.str());
94 }
95 input.close();
96 return true;
97};
98
99/** Parse many body terms, associating each fragment to a certain bond order.
100 * \return parsing succesful
101 */
102bool KeySetsContainer::ParseManyBodyTerms()
103{
104 int Counter;
105
106 LOG(0, "Creating Fragment terms.");
107 // scan through all to determine maximum order
108 Order=0;
109 for(int i=FragmentCounter;i--;) {
110 Counter=0;
111 for(int j=AtomCounter[i];j--;)
112 if (KeySets[i][j] != -1)
113 Counter++;
114 if (Counter > Order)
115 Order = Counter;
116 }
117 LOG(0, "Found Order is " << Order << ".");
118
119 // scan through all to determine fragments per order
120 FragmentsPerOrder.resize(Order);
121// for(int i=Order;i--;)
122// FragmentsPerOrder[i] = 0;
123 for(int i=FragmentCounter;i--;) {
124 Counter=0;
125 for(int j=AtomCounter[i];j--;)
126 if (KeySets[i][j] != -1)
127 Counter++;
128 FragmentsPerOrder[Counter-1]++;
129 }
130 for(int i=0;i<Order;i++)
131 LOG(0, "Found No. of Fragments of Order " << i+1 << " is " << FragmentsPerOrder[i] << ".");
132
133 // scan through all to gather indices to each order set
134 OrderSet.resize(Order);
135 for(int i=Order;i--;)
136 OrderSet[i].resize(FragmentsPerOrder[i]);
137 for(int i=Order;i--;)
138 FragmentsPerOrder[i] = 0;
139 for(int i=FragmentCounter;i--;) {
140 Counter=0;
141 for(int j=AtomCounter[i];j--;)
142 if (KeySets[i][j] != -1)
143 Counter++;
144 OrderSet[Counter-1][FragmentsPerOrder[Counter-1]] = i;
145 FragmentsPerOrder[Counter-1]++;
146 }
147 std::stringstream output;
148 output << "Printing OrderSet: " << std::endl;
149 for(int i=0;i<Order;i++) {
150 for (int j=0;j<FragmentsPerOrder[i];j++) {
151 output << " " << OrderSet[i][j];
152 }
153 output << std::endl;
154 }
155 LOG(0, output.str());
156
157 return true;
158};
159
160/** Compares each entry in \a *SmallerSet if it is containted in \a *GreaterSet.
161 * \param GreaterSet index to greater set
162 * \param SmallerSet index to smaller set
163 * \return true if all keys of SmallerSet contained in GreaterSet
164 */
165bool KeySetsContainer::Contains(const int GreaterSet, const int SmallerSet)
166{
167 bool result = true;
168 bool intermediate;
169 if ((GreaterSet < 0) || (SmallerSet < 0) || (GreaterSet > FragmentCounter) || (SmallerSet > FragmentCounter)) // index out of bounds
170 return false;
171 for(int i=AtomCounter[SmallerSet];i--;) {
172 intermediate = false;
173 for (int j=AtomCounter[GreaterSet];j--;)
174 intermediate = (intermediate || ((KeySets[SmallerSet][i] == KeySets[GreaterSet][j]) || (KeySets[SmallerSet][i] == -1)));
175 result = result && intermediate;
176 }
177
178 return result;
179};
180
181/** Comparison operator for class KeySetsContainer.
182 *
183 * @param other instance to compare to
184 * @return true - both instances are the same in each member variable.
185 */
186bool KeySetsContainer::operator==(const KeySetsContainer &other) const
187{
188 // compare KeySets
189 if (KeySets != other.KeySets)
190 return false;
191 // compare OrderSet
192 if (OrderSet != other.OrderSet)
193 return false;
194 // compare AtomCounter
195 if (AtomCounter != other.AtomCounter)
196 return false;
197 // compare FragmentCounter
198 if (FragmentCounter != other.FragmentCounter)
199 return false;
200 // compare Order
201 if (Order != other.Order)
202 return false;
203 // compare FragmentsPerOrder
204 if (FragmentsPerOrder != other.FragmentsPerOrder)
205 return false;
206
207 return true;
208}
Note: See TracBrowser for help on using the repository browser.