source: src/Fragmentation/KeySetsContainer.cpp@ dcbb5d

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 dcbb5d was 94d5ac6, checked in by Frederik Heber <heber@…>, 12 years ago

FIX: As we use GSL internally, we are as of now required to use GPL v2 license.

  • GNU Scientific Library is used at every place in the code, especially the sub-package LinearAlgebra is based on it which in turn is used really everywhere in the remainder of MoleCuilder. Hence, we have to use the GPL license for the whole of MoleCuilder. In effect, GPL's COPYING was present all along and stated the terms of the GPL v2 license.
  • Hence, I added the default GPL v2 disclaimer to every source file and removed the note about a (actually missing) LICENSE file.
  • also, I added a help-redistribute action which again gives the disclaimer of the GPL v2.
  • also, I changed in the disclaimer that is printed at every program start in builder_init.cpp.
  • TEST: Added check on GPL statement present in every module to test CodeChecks project-disclaimer.
  • Property mode set to 100644
File size: 6.3 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 *
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 * KeySetsContainer.cpp
25 *
26 * Created on: Sep 15, 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 <fstream>
38#include <sstream>
39
40#include "CodePatterns/Log.hpp"
41
42#include "Fragmentation/defs.hpp"
43#include "Fragmentation/helpers.hpp"
44#include "Helpers/defs.hpp"
45#include "KeySetsContainer.hpp"
46
47/** Constructor of KeySetsContainer class.
48 */
49KeySetsContainer::KeySetsContainer() :
50 FragmentCounter(0),
51 Order(0),
52 FragmentsPerOrder(0)
53{};
54
55/** Destructor of KeySetsContainer class.
56 */
57KeySetsContainer::~KeySetsContainer() {
58// for(int i=FragmentCounter;i--;)
59// delete[](KeySets[i]);
60// for(int i=Order;i--;)
61// delete[](OrderSet[i]);
62// delete[](KeySets);
63// delete[](OrderSet);
64// delete[](AtomCounter);
65// delete[](FragmentsPerOrder);
66};
67
68/** Parsing KeySets into array.
69 * \param *name directory with keyset file
70 * \param *ACounter number of atoms per fragment
71 * \param FCounter number of fragments
72 * \return parsing succesful
73 */
74bool KeySetsContainer::ParseKeySets(const std::string name, const IntVector ACounter, const int FCounter) {
75 ifstream input;
76 char *FragmentNumber = NULL;
77 stringstream file;
78 char filename[1023];
79
80 FragmentCounter = FCounter;
81 LOG(0, "Parsing key sets.");
82 KeySets.resize(FragmentCounter);
83 file << name << FRAGMENTPREFIX << KEYSETFILE;
84 input.open(file.str().c_str(), ios::in);
85 if (input.fail()) {
86 LOG(0, endl << "KeySetsContainer::ParseKeySets: Unable to open " << file.str() << ", is the directory correct?");
87 return false;
88 }
89
90 AtomCounter.resize(FragmentCounter);
91 for(int i=0;(i<FragmentCounter) && (!input.eof());i++) {
92 stringstream line;
93 AtomCounter[i] = ACounter[i];
94 // parse the values
95 KeySets[i].resize(AtomCounter[i]);
96 for(int j=AtomCounter[i];j--;)
97 KeySets[i][j] = -1;
98 FragmentNumber = FixedDigitNumber(FragmentCounter, i);
99 //std::stringstream output;
100 //output << FRAGMENTPREFIX << FragmentNumber << "[" << AtomCounter[i] << "]:";
101 delete[](FragmentNumber);
102 input.getline(filename, 1023);
103 line.str(filename);
104 for(int j=0;(j<AtomCounter[i]) && (!line.eof());j++) {
105 line >> KeySets[i][j];
106 //output << " " << KeySets[i][j];
107 }
108 //LOG(0, output.str());
109 }
110 input.close();
111 return true;
112};
113
114/** Parse many body terms, associating each fragment to a certain bond order.
115 * \return parsing succesful
116 */
117bool KeySetsContainer::ParseManyBodyTerms()
118{
119 int Counter;
120
121 LOG(0, "Creating Fragment terms.");
122 // scan through all to determine maximum order
123 Order=0;
124 for(int i=FragmentCounter;i--;) {
125 Counter=0;
126 for(int j=AtomCounter[i];j--;)
127 if (KeySets[i][j] != -1)
128 Counter++;
129 if (Counter > Order)
130 Order = Counter;
131 }
132 LOG(0, "Found Order is " << Order << ".");
133
134 // scan through all to determine fragments per order
135 FragmentsPerOrder.resize(Order);
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 FragmentsPerOrder[Counter-1]++;
144 }
145 for(int i=0;i<Order;i++)
146 LOG(0, "Found No. of Fragments of Order " << i+1 << " is " << FragmentsPerOrder[i] << ".");
147
148 // scan through all to gather indices to each order set
149 OrderSet.resize(Order);
150 for(int i=Order;i--;)
151 OrderSet[i].resize(FragmentsPerOrder[i]);
152 for(int i=Order;i--;)
153 FragmentsPerOrder[i] = 0;
154 for(int i=FragmentCounter;i--;) {
155 Counter=0;
156 for(int j=AtomCounter[i];j--;)
157 if (KeySets[i][j] != -1)
158 Counter++;
159 OrderSet[Counter-1][FragmentsPerOrder[Counter-1]] = i;
160 FragmentsPerOrder[Counter-1]++;
161 }
162 std::stringstream output;
163 output << "Printing OrderSet: " << std::endl;
164 for(int i=0;i<Order;i++) {
165 for (int j=0;j<FragmentsPerOrder[i];j++) {
166 output << " " << OrderSet[i][j];
167 }
168 output << std::endl;
169 }
170 LOG(0, output.str());
171
172 return true;
173};
174
175/** Compares each entry in \a *SmallerSet if it is containted in \a *GreaterSet.
176 * \param GreaterSet index to greater set
177 * \param SmallerSet index to smaller set
178 * \return true if all keys of SmallerSet contained in GreaterSet
179 */
180bool KeySetsContainer::Contains(const int GreaterSet, const int SmallerSet)
181{
182 bool result = true;
183 bool intermediate;
184 if ((GreaterSet < 0) || (SmallerSet < 0) || (GreaterSet > FragmentCounter) || (SmallerSet > FragmentCounter)) // index out of bounds
185 return false;
186 for(int i=AtomCounter[SmallerSet];i--;) {
187 intermediate = false;
188 for (int j=AtomCounter[GreaterSet];j--;)
189 intermediate = (intermediate || ((KeySets[SmallerSet][i] == KeySets[GreaterSet][j]) || (KeySets[SmallerSet][i] == -1)));
190 result = result && intermediate;
191 }
192
193 return result;
194};
195
196/** Comparison operator for class KeySetsContainer.
197 *
198 * @param other instance to compare to
199 * @return true - both instances are the same in each member variable.
200 */
201bool KeySetsContainer::operator==(const KeySetsContainer &other) const
202{
203 // compare KeySets
204 if (KeySets != other.KeySets)
205 return false;
206 // compare OrderSet
207 if (OrderSet != other.OrderSet)
208 return false;
209 // compare AtomCounter
210 if (AtomCounter != other.AtomCounter)
211 return false;
212 // compare FragmentCounter
213 if (FragmentCounter != other.FragmentCounter)
214 return false;
215 // compare Order
216 if (Order != other.Order)
217 return false;
218 // compare FragmentsPerOrder
219 if (FragmentsPerOrder != other.FragmentsPerOrder)
220 return false;
221
222 return true;
223}
Note: See TracBrowser for help on using the repository browser.