source: src/molecule_fragmentation.cpp@ 3c58f8

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 3c58f8 was 3c58f8, checked in by Frederik Heber <heber@…>, 14 years ago

Changed molecule::ScanForPeriodicCorrection().

  • it still used templated link stuff for the bonds which is deprecated and hence not usable.
  • now simply bool is returned, whether periodic fixing _would_ be necessary.
  • the number of of periodic fixings is counted and printed in MoleculeListClass::OutputConfigForListOfFragments().
  • Property mode set to 100644
File size: 81.7 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 * molecule_fragmentation.cpp
10 *
11 * Created on: Oct 5, 2009
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 <cstring>
23
24#include "World.hpp"
25#include "atom.hpp"
26#include "bond.hpp"
27#include "config.hpp"
28#include "element.hpp"
29#include "Helpers/helpers.hpp"
30#include "lists.hpp"
31#include "CodePatterns/Verbose.hpp"
32#include "CodePatterns/Log.hpp"
33#include "molecule.hpp"
34#include "periodentafel.hpp"
35#include "World.hpp"
36#include "LinearAlgebra/RealSpaceMatrix.hpp"
37#include "Box.hpp"
38
39/************************************* Functions for class molecule *********************************/
40
41
42/** Estimates by educated guessing (using upper limit) the expected number of fragments.
43 * The upper limit is
44 * \f[
45 * n = N \cdot C^k
46 * \f]
47 * where \f$C=2^c\f$ and c is the maximum bond degree over N number of atoms.
48 * \param *out output stream for debugging
49 * \param order bond order k
50 * \return number n of fragments
51 */
52int molecule::GuesstimateFragmentCount(int order)
53{
54 size_t c = 0;
55 int FragmentCount;
56 // get maximum bond degree
57 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
58 c = ((*iter)->ListOfBonds.size() > c) ? (*iter)->ListOfBonds.size() : c;
59 }
60 FragmentCount = NoNonHydrogen*(1 << (c*order));
61 DoLog(1) && (Log() << Verbose(1) << "Upper limit for this subgraph is " << FragmentCount << " for " << NoNonHydrogen << " non-H atoms with maximum bond degree of " << c << "." << endl);
62 return FragmentCount;
63};
64
65/** Scans a single line for number and puts them into \a KeySet.
66 * \param *out output stream for debugging
67 * \param *buffer buffer to scan
68 * \param &CurrentSet filled KeySet on return
69 * \return true - at least one valid atom id parsed, false - CurrentSet is empty
70 */
71bool ScanBufferIntoKeySet(char *buffer, KeySet &CurrentSet)
72{
73 stringstream line;
74 int AtomNr;
75 int status = 0;
76
77 line.str(buffer);
78 while (!line.eof()) {
79 line >> AtomNr;
80 if (AtomNr >= 0) {
81 CurrentSet.insert(AtomNr); // insert at end, hence in same order as in file!
82 status++;
83 } // else it's "-1" or else and thus must not be added
84 }
85 DoLog(1) && (Log() << Verbose(1) << "The scanned KeySet is ");
86 for(KeySet::iterator runner = CurrentSet.begin(); runner != CurrentSet.end(); runner++) {
87 DoLog(0) && (Log() << Verbose(0) << (*runner) << "\t");
88 }
89 DoLog(0) && (Log() << Verbose(0) << endl);
90 return (status != 0);
91};
92
93/** Parses the KeySet file and fills \a *FragmentList from the known molecule structure.
94 * Does two-pass scanning:
95 * -# Scans the keyset file and initialises a temporary graph
96 * -# Scans TEFactors file and sets the TEFactor of each key set in the temporary graph accordingly
97 * Finally, the temporary graph is inserted into the given \a FragmentList for return.
98 * \param &path path to file
99 * \param *FragmentList empty, filled on return
100 * \return true - parsing successfully, false - failure on parsing (FragmentList will be NULL)
101 */
102bool ParseKeySetFile(std::string &path, Graph *&FragmentList)
103{
104 bool status = true;
105 ifstream InputFile;
106 stringstream line;
107 GraphTestPair testGraphInsert;
108 int NumberOfFragments = 0;
109 string filename;
110
111 if (FragmentList == NULL) { // check list pointer
112 FragmentList = new Graph;
113 }
114
115 // 1st pass: open file and read
116 DoLog(1) && (Log() << Verbose(1) << "Parsing the KeySet file ... " << endl);
117 filename = path + KEYSETFILE;
118 InputFile.open(filename.c_str());
119 if (InputFile.good()) {
120 // each line represents a new fragment
121 char buffer[MAXSTRINGSIZE];
122 // 1. parse keysets and insert into temp. graph
123 while (!InputFile.eof()) {
124 InputFile.getline(buffer, MAXSTRINGSIZE);
125 KeySet CurrentSet;
126 if ((strlen(buffer) > 0) && (ScanBufferIntoKeySet(buffer, CurrentSet))) { // if at least one valid atom was added, write config
127 testGraphInsert = FragmentList->insert(GraphPair (CurrentSet,pair<int,double>(NumberOfFragments++,1))); // store fragment number and current factor
128 if (!testGraphInsert.second) {
129 DoeLog(0) && (eLog()<< Verbose(0) << "KeySet file must be corrupt as there are two equal key sets therein!" << endl);
130 performCriticalExit();
131 }
132 }
133 }
134 // 2. Free and done
135 InputFile.close();
136 InputFile.clear();
137 DoLog(1) && (Log() << Verbose(1) << "\t ... done." << endl);
138 } else {
139 DoLog(1) && (Log() << Verbose(1) << "\t ... File " << filename << " not found." << endl);
140 status = false;
141 }
142
143 return status;
144};
145
146/** Parses the TE factors file and fills \a *FragmentList from the known molecule structure.
147 * -# Scans TEFactors file and sets the TEFactor of each key set in the temporary graph accordingly
148 * \param *out output stream for debugging
149 * \param *path path to file
150 * \param *FragmentList graph whose nodes's TE factors are set on return
151 * \return true - parsing successfully, false - failure on parsing
152 */
153bool ParseTEFactorsFile(char *path, Graph *FragmentList)
154{
155 bool status = true;
156 ifstream InputFile;
157 stringstream line;
158 GraphTestPair testGraphInsert;
159 int NumberOfFragments = 0;
160 double TEFactor;
161 char filename[MAXSTRINGSIZE];
162
163 if (FragmentList == NULL) { // check list pointer
164 FragmentList = new Graph;
165 }
166
167 // 2nd pass: open TEFactors file and read
168 DoLog(1) && (Log() << Verbose(1) << "Parsing the TEFactors file ... " << endl);
169 sprintf(filename, "%s/%s%s", path, FRAGMENTPREFIX, TEFACTORSFILE);
170 InputFile.open(filename);
171 if (InputFile != NULL) {
172 // 3. add found TEFactors to each keyset
173 NumberOfFragments = 0;
174 for(Graph::iterator runner = FragmentList->begin();runner != FragmentList->end(); runner++) {
175 if (!InputFile.eof()) {
176 InputFile >> TEFactor;
177 (*runner).second.second = TEFactor;
178 DoLog(2) && (Log() << Verbose(2) << "Setting " << ++NumberOfFragments << " fragment's TEFactor to " << (*runner).second.second << "." << endl);
179 } else {
180 status = false;
181 break;
182 }
183 }
184 // 4. Free and done
185 InputFile.close();
186 DoLog(1) && (Log() << Verbose(1) << "done." << endl);
187 } else {
188 DoLog(1) && (Log() << Verbose(1) << "File " << filename << " not found." << endl);
189 status = false;
190 }
191
192 return status;
193};
194
195/** Stores key sets to file.
196 * \param KeySetList Graph with Keysets
197 * \param &path path to file
198 * \return true - file written successfully, false - writing failed
199 */
200bool StoreKeySetFile(Graph &KeySetList, std::string &path)
201{
202 bool status = true;
203 string line = path + KEYSETFILE;
204 ofstream output(line.c_str());
205
206 // open KeySet file
207 DoLog(1) && (Log() << Verbose(1) << "Saving key sets of the total graph ... ");
208 if(output.good()) {
209 for(Graph::iterator runner = KeySetList.begin(); runner != KeySetList.end(); runner++) {
210 for (KeySet::iterator sprinter = (*runner).first.begin();sprinter != (*runner).first.end(); sprinter++) {
211 if (sprinter != (*runner).first.begin())
212 output << "\t";
213 output << *sprinter;
214 }
215 output << endl;
216 }
217 DoLog(0) && (Log() << Verbose(0) << "done." << endl);
218 } else {
219 DoeLog(0) && (eLog()<< Verbose(0) << "Unable to open " << line << " for writing keysets!" << endl);
220 performCriticalExit();
221 status = false;
222 }
223 output.close();
224 output.clear();
225
226 return status;
227};
228
229
230/** Stores TEFactors to file.
231 * \param *out output stream for debugging
232 * \param KeySetList Graph with factors
233 * \param *path path to file
234 * \return true - file written successfully, false - writing failed
235 */
236bool StoreTEFactorsFile(Graph &KeySetList, char *path)
237{
238 ofstream output;
239 bool status = true;
240 string line;
241
242 // open TEFactors file
243 line = path;
244 line.append("/");
245 line += FRAGMENTPREFIX;
246 line += TEFACTORSFILE;
247 output.open(line.c_str(), ios::out);
248 DoLog(1) && (Log() << Verbose(1) << "Saving TEFactors of the total graph ... ");
249 if(output != NULL) {
250 for(Graph::iterator runner = KeySetList.begin(); runner != KeySetList.end(); runner++)
251 output << (*runner).second.second << endl;
252 DoLog(1) && (Log() << Verbose(1) << "done." << endl);
253 } else {
254 DoLog(1) && (Log() << Verbose(1) << "failed to open " << line << "." << endl);
255 status = false;
256 }
257 output.close();
258
259 return status;
260};
261
262/** For a given graph, sorts KeySets into a (index, keyset) map.
263 * \param *GlobalKeySetList list of keysets with global ids (valid in "this" molecule) needed for adaptive increase
264 * \return map from index to keyset
265 */
266map<int,KeySet> * GraphToIndexedKeySet(Graph *GlobalKeySetList)
267{
268 map<int,KeySet> *IndexKeySetList = new map<int,KeySet>;
269 for(Graph::iterator runner = GlobalKeySetList->begin(); runner != GlobalKeySetList->end(); runner++) {
270 IndexKeySetList->insert( pair<int,KeySet>(runner->second.first,runner->first) );
271 }
272 return IndexKeySetList;
273};
274
275/** Inserts a (\a No, \a value) pair into the list, overwriting present one.
276 * Note if values are equal, No will decided on which is first
277 * \param *out output stream for debugging
278 * \param &AdaptiveCriteriaList list to insert into
279 * \param &IndexedKeySetList list to find key set for a given index \a No
280 * \param FragOrder current bond order of fragment
281 * \param No index of keyset
282 * \param value energy value
283 */
284void InsertIntoAdaptiveCriteriaList(map<int, pair<double,int> > *AdaptiveCriteriaList, map<int,KeySet> &IndexKeySetList, int FragOrder, int No, double Value)
285{
286 map<int,KeySet>::iterator marker = IndexKeySetList.find(No); // find keyset to Frag No.
287 if (marker != IndexKeySetList.end()) { // if found
288 Value *= 1 + MYEPSILON*(*((*marker).second.begin())); // in case of equal energies this makes them not equal without changing anything actually
289 // as the smallest number in each set has always been the root (we use global id to keep the doubles away), seek smallest and insert into AtomMask
290 pair <map<int, pair<double,int> >::iterator, bool> InsertedElement = AdaptiveCriteriaList->insert( make_pair(*((*marker).second.begin()), pair<double,int>( fabs(Value), FragOrder) ));
291 map<int, pair<double,int> >::iterator PresentItem = InsertedElement.first;
292 if (!InsertedElement.second) { // this root is already present
293 if ((*PresentItem).second.second < FragOrder) // if order there is lower, update entry with higher-order term
294 //if ((*PresentItem).second.first < (*runner).first) // as higher-order terms are not always better, we skip this part (which would always include this site into adaptive increase)
295 { // if value is smaller, update value and order
296 (*PresentItem).second.first = fabs(Value);
297 (*PresentItem).second.second = FragOrder;
298 DoLog(2) && (Log() << Verbose(2) << "Updated element (" << (*PresentItem).first << ",[" << (*PresentItem).second.first << "," << (*PresentItem).second.second << "])." << endl);
299 } else {
300 DoLog(2) && (Log() << Verbose(2) << "Did not update element " << (*PresentItem).first << " as " << FragOrder << " is less than or equal to " << (*PresentItem).second.second << "." << endl);
301 }
302 } else {
303 DoLog(2) && (Log() << Verbose(2) << "Inserted element (" << (*PresentItem).first << ",[" << (*PresentItem).second.first << "," << (*PresentItem).second.second << "])." << endl);
304 }
305 } else {
306 DoLog(1) && (Log() << Verbose(1) << "No Fragment under No. " << No << "found." << endl);
307 }
308};
309
310/** Counts lines in file.
311 * Note we are scanning lines from current position, not from beginning.
312 * \param InputFile file to be scanned.
313 */
314int CountLinesinFile(ifstream &InputFile)
315{
316 char *buffer = new char[MAXSTRINGSIZE];
317 int lines=0;
318
319 int PositionMarker = InputFile.tellg(); // not needed as Inputfile is copied, given by value, not by ref
320 // count the number of lines, i.e. the number of fragments
321 InputFile.getline(buffer, MAXSTRINGSIZE); // skip comment lines
322 InputFile.getline(buffer, MAXSTRINGSIZE);
323 while(!InputFile.eof()) {
324 InputFile.getline(buffer, MAXSTRINGSIZE);
325 lines++;
326 }
327 InputFile.seekg(PositionMarker, ios::beg);
328 delete[](buffer);
329 return lines;
330};
331
332
333/** Scans the adaptive order file and insert (index, value) into map.
334 * \param &path path to ENERGYPERFRAGMENT file (may be NULL if Order is non-negative)
335 * \param &IndexedKeySetList list to find key set for a given index \a No
336 * \return adaptive criteria list from file
337 */
338map<int, pair<double,int> > * ScanAdaptiveFileIntoMap(std::string &path, map<int,KeySet> &IndexKeySetList)
339{
340 map<int, pair<double,int> > *AdaptiveCriteriaList = new map<int, pair<double,int> >;
341 int No = 0, FragOrder = 0;
342 double Value = 0.;
343 char buffer[MAXSTRINGSIZE];
344 string filename = path + ENERGYPERFRAGMENT;
345 ifstream InputFile(filename.c_str());
346
347 if (InputFile.fail()) {
348 DoeLog(1) && (eLog() << Verbose(1) << "Cannot find file " << filename << "." << endl);
349 return AdaptiveCriteriaList;
350 }
351
352 if (CountLinesinFile(InputFile) > 0) {
353 // each line represents a fragment root (Atom::nr) id and its energy contribution
354 InputFile.getline(buffer, MAXSTRINGSIZE); // skip comment lines
355 InputFile.getline(buffer, MAXSTRINGSIZE);
356 while(!InputFile.eof()) {
357 InputFile.getline(buffer, MAXSTRINGSIZE);
358 if (strlen(buffer) > 2) {
359 //Log() << Verbose(2) << "Scanning: " << buffer << endl;
360 stringstream line(buffer);
361 line >> FragOrder;
362 line >> ws >> No;
363 line >> ws >> Value; // skip time entry
364 line >> ws >> Value;
365 No -= 1; // indices start at 1 in file, not 0
366 //Log() << Verbose(2) << " - yields (" << No << "," << Value << ", " << FragOrder << ")" << endl;
367
368 // clean the list of those entries that have been superceded by higher order terms already
369 InsertIntoAdaptiveCriteriaList(AdaptiveCriteriaList, IndexKeySetList, FragOrder, No, Value);
370 }
371 }
372 // close and done
373 InputFile.close();
374 InputFile.clear();
375 }
376
377 return AdaptiveCriteriaList;
378};
379
380/** Maps adaptive criteria list back onto (Value, (Root Nr., Order))
381 * (i.e. sorted by value to pick the highest ones)
382 * \param *out output stream for debugging
383 * \param &AdaptiveCriteriaList list to insert into
384 * \param *mol molecule with atoms
385 * \return remapped list
386 */
387map<double, pair<int,int> > * ReMapAdaptiveCriteriaListToValue(map<int, pair<double,int> > *AdaptiveCriteriaList, molecule *mol)
388{
389 atom *Walker = NULL;
390 map<double, pair<int,int> > *FinalRootCandidates = new map<double, pair<int,int> > ;
391 DoLog(1) && (Log() << Verbose(1) << "Root candidate list is: " << endl);
392 for(map<int, pair<double,int> >::iterator runner = AdaptiveCriteriaList->begin(); runner != AdaptiveCriteriaList->end(); runner++) {
393 Walker = mol->FindAtom((*runner).first);
394 if (Walker != NULL) {
395 //if ((*runner).second.second >= Walker->AdaptiveOrder) { // only insert if this is an "active" root site for the current order
396 if (!Walker->MaxOrder) {
397 DoLog(2) && (Log() << Verbose(2) << "(" << (*runner).first << ",[" << (*runner).second.first << "," << (*runner).second.second << "])" << endl);
398 FinalRootCandidates->insert( make_pair( (*runner).second.first, pair<int,int>((*runner).first, (*runner).second.second) ) );
399 } else {
400 DoLog(2) && (Log() << Verbose(2) << "Excluding (" << *Walker << ", " << (*runner).first << ",[" << (*runner).second.first << "," << (*runner).second.second << "]), as it has reached its maximum order." << endl);
401 }
402 } else {
403 DoeLog(0) && (eLog()<< Verbose(0) << "Atom No. " << (*runner).second.first << " was not found in this molecule." << endl);
404 performCriticalExit();
405 }
406 }
407 return FinalRootCandidates;
408};
409
410/** Marks all candidate sites for update if below adaptive threshold.
411 * Picks a given number of highest values and set *AtomMask to true.
412 * \param *out output stream for debugging
413 * \param *AtomMask defines true/false per global Atom::nr to mask in/out each nuclear site, used to activate given number of site to increment order adaptively
414 * \param FinalRootCandidates list candidates to check
415 * \param Order desired order
416 * \param *mol molecule with atoms
417 * \return true - if update is necessary, false - not
418 */
419bool MarkUpdateCandidates(bool *AtomMask, map<double, pair<int,int> > &FinalRootCandidates, int Order, molecule *mol)
420{
421 atom *Walker = NULL;
422 int No = -1;
423 bool status = false;
424 for(map<double, pair<int,int> >::iterator runner = FinalRootCandidates.upper_bound(pow(10.,Order)); runner != FinalRootCandidates.end(); runner++) {
425 No = (*runner).second.first;
426 Walker = mol->FindAtom(No);
427 //if (Walker->AdaptiveOrder < MinimumRingSize[Walker->nr]) {
428 DoLog(2) && (Log() << Verbose(2) << "Root " << No << " is still above threshold (10^{" << Order <<"}: " << runner->first << ", setting entry " << No << " of Atom mask to true." << endl);
429 AtomMask[No] = true;
430 status = true;
431 //} else
432 //Log() << Verbose(2) << "Root " << No << " is still above threshold (10^{" << Order <<"}: " << runner->first << ", however MinimumRingSize of " << MinimumRingSize[Walker->nr] << " does not allow further adaptive increase." << endl;
433 }
434 return status;
435};
436
437/** print atom mask for debugging.
438 * \param *out output stream for debugging
439 * \param *AtomMask defines true/false per global Atom::nr to mask in/out each nuclear site, used to activate given number of site to increment order adaptively
440 * \param AtomCount number of entries in \a *AtomMask
441 */
442void PrintAtomMask(bool *AtomMask, int AtomCount)
443{
444 DoLog(2) && (Log() << Verbose(2) << " ");
445 for(int i=0;i<AtomCount;i++)
446 DoLog(0) && (Log() << Verbose(0) << (i % 10));
447 DoLog(0) && (Log() << Verbose(0) << endl);
448 DoLog(2) && (Log() << Verbose(2) << "Atom mask is: ");
449 for(int i=0;i<AtomCount;i++)
450 DoLog(0) && (Log() << Verbose(0) << (AtomMask[i] ? "t" : "f"));
451 DoLog(0) && (Log() << Verbose(0) << endl);
452};
453
454/** Checks whether the OrderAtSite is still below \a Order at some site.
455 * \param *AtomMask defines true/false per global Atom::nr to mask in/out each nuclear site, used to activate given number of site to increment order adaptively
456 * \param *GlobalKeySetList list of keysets with global ids (valid in "this" molecule) needed for adaptive increase
457 * \param Order desired Order if positive, desired exponent in threshold criteria if negative (0 is single-step)
458 * \param *MinimumRingSize array of max. possible order to avoid loops
459 * \param path path to ENERGYPERFRAGMENT file (may be NULL if Order is non-negative)
460 * \return true - needs further fragmentation, false - does not need fragmentation
461 */
462bool molecule::CheckOrderAtSite(bool *AtomMask, Graph *GlobalKeySetList, int Order, int *MinimumRingSize, std::string path)
463{
464 bool status = false;
465
466 // initialize mask list
467 for(int i=getAtomCount();i--;)
468 AtomMask[i] = false;
469
470 if (Order < 0) { // adaptive increase of BondOrder per site
471 if (AtomMask[getAtomCount()] == true) // break after one step
472 return false;
473
474 // transmorph graph keyset list into indexed KeySetList
475 if (GlobalKeySetList == NULL) {
476 DoeLog(1) && (eLog()<< Verbose(1) << "Given global key set list (graph) is NULL!" << endl);
477 return false;
478 }
479 map<int,KeySet> *IndexKeySetList = GraphToIndexedKeySet(GlobalKeySetList);
480
481 // parse the EnergyPerFragment file
482 map<int, pair<double,int> > *AdaptiveCriteriaList = ScanAdaptiveFileIntoMap(path, *IndexKeySetList); // (Root No., (Value, Order)) !
483 if (AdaptiveCriteriaList->empty()) {
484 DoeLog(2) && (eLog()<< Verbose(2) << "Unable to parse file, incrementing all." << endl);
485 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
486 #ifdef ADDHYDROGEN
487 if ((*iter)->getType()->getAtomicNumber() != 1) // skip hydrogen
488 #endif
489 {
490 AtomMask[(*iter)->nr] = true; // include all (non-hydrogen) atoms
491 status = true;
492 }
493 }
494 }
495 // then map back onto (Value, (Root Nr., Order)) (i.e. sorted by value to pick the highest ones)
496 map<double, pair<int,int> > *FinalRootCandidates = ReMapAdaptiveCriteriaListToValue(AdaptiveCriteriaList, this);
497
498 // pick the ones still below threshold and mark as to be adaptively updated
499 MarkUpdateCandidates(AtomMask, *FinalRootCandidates, Order, this);
500
501 delete[](IndexKeySetList);
502 delete[](AdaptiveCriteriaList);
503 delete[](FinalRootCandidates);
504 } else { // global increase of Bond Order
505 for(molecule::const_iterator iter = begin(); iter != end(); ++iter) {
506 #ifdef ADDHYDROGEN
507 if ((*iter)->getType()->getAtomicNumber() != 1) // skip hydrogen
508 #endif
509 {
510 AtomMask[(*iter)->nr] = true; // include all (non-hydrogen) atoms
511 if ((Order != 0) && ((*iter)->AdaptiveOrder < Order)) // && ((*iter)->AdaptiveOrder < MinimumRingSize[(*iter)->nr]))
512 status = true;
513 }
514 }
515 if ((!Order) && (!AtomMask[getAtomCount()])) // single stepping, just check
516 status = true;
517
518 if (!status) {
519 if (Order == 0)
520 DoLog(1) && (Log() << Verbose(1) << "Single stepping done." << endl);
521 else
522 DoLog(1) && (Log() << Verbose(1) << "Order at every site is already equal or above desired order " << Order << "." << endl);
523 }
524 }
525
526 PrintAtomMask(AtomMask, getAtomCount()); // for debugging
527
528 return status;
529};
530
531/** Create a SortIndex to map from atomic labels to the sequence in which the atoms are given in the config file.
532 * \param *out output stream for debugging
533 * \param *&SortIndex Mapping array of size molecule::AtomCount
534 * \return true - success, false - failure of SortIndex alloc
535 */
536bool molecule::CreateMappingLabelsToConfigSequence(int *&SortIndex)
537{
538 if (SortIndex != NULL) {
539 DoLog(1) && (Log() << Verbose(1) << "SortIndex is " << SortIndex << " and not NULL as expected." << endl);
540 return false;
541 }
542 SortIndex = new int[getAtomCount()];
543 for(int i=getAtomCount();i--;)
544 SortIndex[i] = -1;
545
546 int AtomNo = 0;
547 for(internal_iterator iter=atoms.begin();iter!=atoms.end();++iter){
548 ASSERT(SortIndex[(*iter)->nr]==-1,"Same SortIndex set twice");
549 SortIndex[(*iter)->nr] = AtomNo++;
550 }
551
552 return true;
553};
554
555
556
557/** Creates a lookup table for true father's Atom::Nr -> atom ptr.
558 * \param *start begin of list (STL iterator, i.e. first item)
559 * \paran *end end of list (STL iterator, i.e. one past last item)
560 * \param **Lookuptable pointer to return allocated lookup table (should be NULL on start)
561 * \param count optional predetermined size for table (otherwise we set the count to highest true father id)
562 * \return true - success, false - failure
563 */
564bool molecule::CreateFatherLookupTable(atom **&LookupTable, int count)
565{
566 bool status = true;
567 int AtomNo;
568
569 if (LookupTable != NULL) {
570 Log() << Verbose(0) << "Pointer for Lookup table is not NULL! Aborting ..." <<endl;
571 return false;
572 }
573
574 // count them
575 if (count == 0) {
576 for (molecule::iterator iter = begin(); iter != end(); ++iter) { // create a lookup table (Atom::nr -> atom) used as a marker table lateron
577 count = (count < (*iter)->GetTrueFather()->nr) ? (*iter)->GetTrueFather()->nr : count;
578 }
579 }
580 if (count <= 0) {
581 Log() << Verbose(0) << "Count of lookup list is 0 or less." << endl;
582 return false;
583 }
584
585 // allocate and fill
586 LookupTable = new atom *[count];
587 if (LookupTable == NULL) {
588 eLog() << Verbose(0) << "LookupTable memory allocation failed!" << endl;
589 performCriticalExit();
590 status = false;
591 } else {
592 for (int i=0;i<count;i++)
593 LookupTable[i] = NULL;
594 for (molecule::iterator iter = begin(); iter != end(); ++iter) {
595 AtomNo = (*iter)->GetTrueFather()->nr;
596 if ((AtomNo >= 0) && (AtomNo < count)) {
597 //*out << "Setting LookupTable[" << AtomNo << "] to " << *(*iter) << endl;
598 LookupTable[AtomNo] = (*iter);
599 } else {
600 Log() << Verbose(0) << "Walker " << *(*iter) << " exceeded range of nuclear ids [0, " << count << ")." << endl;
601 status = false;
602 break;
603 }
604 }
605 }
606
607 return status;
608};
609
610/** Performs a many-body bond order analysis for a given bond order.
611 * -# parses adjacency, keysets and orderatsite files
612 * -# performs DFS to find connected subgraphs (to leave this in was a design decision: might be useful later)
613 * -# RootStack is created for every subgraph (here, later we implement the "update 10 sites with highest energ
614y contribution", and that's why this consciously not done in the following loop)
615 * -# in a loop over all subgraphs
616 * -# calls FragmentBOSSANOVA with this RootStack and within the subgraph molecule structure
617 * -# creates molecule (fragment)s from the returned keysets (StoreFragmentFromKeySet)
618 * -# combines the generated molecule lists from all subgraphs
619 * -# saves to disk: fragment configs, adjacency, orderatsite, keyset files
620 * Note that as we split "this" molecule up into a list of subgraphs, i.e. a MoleculeListClass, we have two sets
621 * of vertex indices: Global always means the index in "this" molecule, whereas local refers to the molecule or
622 * subgraph in the MoleculeListClass.
623 * \param Order up to how many neighbouring bonds a fragment contains in BondOrderScheme::BottumUp scheme
624 * \param &prefix path and prefix of the bond order configs to be written
625 * \return 1 - continue, 2 - stop (no fragmentation occured)
626 */
627int molecule::FragmentMolecule(int Order, std::string &prefix)
628{
629 MoleculeListClass *BondFragments = NULL;
630 int *MinimumRingSize = new int[getAtomCount()];
631 int FragmentCounter;
632 MoleculeLeafClass *MolecularWalker = NULL;
633 MoleculeLeafClass *Subgraphs = NULL; // list of subgraphs from DFS analysis
634 fstream File;
635 bool FragmentationToDo = true;
636 std::deque<bond *> *BackEdgeStack = NULL, *LocalBackEdgeStack = NULL;
637 bool CheckOrder = false;
638 Graph **FragmentList = NULL;
639 Graph *ParsedFragmentList = NULL;
640 Graph TotalGraph; // graph with all keysets however local numbers
641 int TotalNumberOfKeySets = 0;
642 atom **ListOfAtoms = NULL;
643 atom ***ListOfLocalAtoms = NULL;
644 bool *AtomMask = NULL;
645
646 DoLog(0) && (Log() << Verbose(0) << endl);
647#ifdef ADDHYDROGEN
648 DoLog(0) && (Log() << Verbose(0) << "I will treat hydrogen special and saturate dangling bonds with it." << endl);
649#else
650 DoLog(0) && (Log() << Verbose(0) << "Hydrogen is treated just like the rest of the lot." << endl);
651#endif
652
653 // ++++++++++++++++++++++++++++ INITIAL STUFF: Bond structure analysis, file parsing, ... ++++++++++++++++++++++++++++++++++++++++++
654
655 // ===== 1. Check whether bond structure is same as stored in files ====
656
657 // create lookup table for Atom::nr
658 FragmentationToDo = FragmentationToDo && CreateFatherLookupTable(ListOfAtoms, getAtomCount());
659
660 // === compare it with adjacency file ===
661 FragmentationToDo = FragmentationToDo && CheckAdjacencyFileAgainstMolecule(prefix, ListOfAtoms);
662 delete[](ListOfAtoms);
663
664 // ===== 2. perform a DFS analysis to gather info on cyclic structure and a list of disconnected subgraphs =====
665 Subgraphs = DepthFirstSearchAnalysis(BackEdgeStack);
666
667 // analysis of the cycles (print rings, get minimum cycle length) for each subgraph
668 for(int i=getAtomCount();i--;)
669 MinimumRingSize[i] = getAtomCount();
670 MolecularWalker = Subgraphs;
671 const int LeafCount = Subgraphs->next->Count();
672 FragmentCounter = 0;
673 while (MolecularWalker->next != NULL) {
674 MolecularWalker = MolecularWalker->next;
675 // fill the bond structure of the individually stored subgraphs
676 ListOfAtoms = NULL;
677 MolecularWalker->FillBondStructureFromReference(this, ListOfAtoms, false); // we want to keep the created ListOfLocalAtoms
678 DoLog(0) && (Log() << Verbose(0) << "Analysing the cycles of subgraph " << MolecularWalker->Leaf << " with nr. " << FragmentCounter << "." << endl);
679 LocalBackEdgeStack = new std::deque<bond *>; // (MolecularWalker->Leaf->BondCount);
680// // check the list of local atoms for debugging
681// Log() << Verbose(0) << "ListOfLocalAtoms for this subgraph is:" << endl;
682// for (int i=0;i<getAtomCount();i++)
683// if (ListOfLocalAtoms[FragmentCounter][i] == NULL)
684// Log() << Verbose(0) << "\tNULL";
685// else
686// Log() << Verbose(0) << "\t" << ListOfLocalAtoms[FragmentCounter][i]->Name;
687 DoLog(0) && (Log() << Verbose(0) << "Gathering local back edges for subgraph " << MolecularWalker->Leaf << " with nr. " << FragmentCounter << "." << endl);
688 MolecularWalker->Leaf->PickLocalBackEdges(ListOfAtoms, BackEdgeStack, LocalBackEdgeStack);
689 DoLog(0) && (Log() << Verbose(0) << "Analysing the cycles of subgraph " << MolecularWalker->Leaf << " with nr. " << FragmentCounter << "." << endl);
690 MolecularWalker->Leaf->CyclicStructureAnalysis(LocalBackEdgeStack, MinimumRingSize);
691 DoLog(0) && (Log() << Verbose(0) << "Done with Analysing the cycles of subgraph " << MolecularWalker->Leaf << " with nr. " << FragmentCounter << "." << endl);
692 delete(LocalBackEdgeStack);
693 delete(ListOfAtoms);
694 FragmentCounter++;
695 }
696 delete(BackEdgeStack);
697
698 // ===== 3. if structure still valid, parse key set file and others =====
699 FragmentationToDo = FragmentationToDo && ParseKeySetFile(prefix, ParsedFragmentList);
700
701 // ===== 4. check globally whether there's something to do actually (first adaptivity check)
702 FragmentationToDo = FragmentationToDo && ParseOrderAtSiteFromFile(prefix);
703
704 // =================================== Begin of FRAGMENTATION ===============================
705 // ===== 6a. assign each keyset to its respective subgraph =====
706 ListOfLocalAtoms = new atom **[LeafCount];
707 for (int i=0;i<LeafCount;i++)
708 ListOfLocalAtoms[i] = NULL;
709 FragmentCounter = 0;
710 Subgraphs->next->AssignKeySetsToFragment(this, ParsedFragmentList, ListOfLocalAtoms, FragmentList, FragmentCounter, true);
711 delete[](ListOfLocalAtoms);
712
713 // ===== 6b. prepare and go into the adaptive (Order<0), single-step (Order==0) or incremental (Order>0) cycle
714 KeyStack *RootStack = new KeyStack[Subgraphs->next->Count()];
715 AtomMask = new bool[getAtomCount()+1];
716 AtomMask[getAtomCount()] = false;
717 FragmentationToDo = false; // if CheckOrderAtSite just ones recommends fragmentation, we will save fragments afterwards
718 while ((CheckOrder = CheckOrderAtSite(AtomMask, ParsedFragmentList, Order, MinimumRingSize, prefix))) {
719 FragmentationToDo = FragmentationToDo || CheckOrder;
720 AtomMask[getAtomCount()] = true; // last plus one entry is used as marker that we have been through this loop once already in CheckOrderAtSite()
721 // ===== 6b. fill RootStack for each subgraph (second adaptivity check) =====
722 Subgraphs->next->FillRootStackForSubgraphs(RootStack, AtomMask, (FragmentCounter = 0));
723
724 // ===== 7. fill the bond fragment list =====
725 FragmentCounter = 0;
726 MolecularWalker = Subgraphs;
727 while (MolecularWalker->next != NULL) {
728 MolecularWalker = MolecularWalker->next;
729 DoLog(1) && (Log() << Verbose(1) << "Fragmenting subgraph " << MolecularWalker << "." << endl);
730 //MolecularWalker->Leaf->OutputListOfBonds(out); // output atom::ListOfBonds for debugging
731 if (MolecularWalker->Leaf->hasBondStructure()) {
732 // call BOSSANOVA method
733 DoLog(0) && (Log() << Verbose(0) << endl << " ========== BOND ENERGY of subgraph " << FragmentCounter << " ========================= " << endl);
734 MolecularWalker->Leaf->FragmentBOSSANOVA(FragmentList[FragmentCounter], RootStack[FragmentCounter], MinimumRingSize);
735 } else {
736 DoeLog(1) && (eLog()<< Verbose(1) << "Subgraph " << MolecularWalker << " has no atoms!" << endl);
737 }
738 FragmentCounter++; // next fragment list
739 }
740 }
741 DoLog(2) && (Log() << Verbose(2) << "CheckOrder is " << CheckOrder << "." << endl);
742 delete[](RootStack);
743 delete[](AtomMask);
744 delete(ParsedFragmentList);
745 delete[](MinimumRingSize);
746
747 // ==================================== End of FRAGMENTATION ============================================
748
749 // ===== 8a. translate list into global numbers (i.e. ones that are valid in "this" molecule, not in MolecularWalker->Leaf)
750 Subgraphs->next->TranslateIndicesToGlobalIDs(FragmentList, (FragmentCounter = 0), TotalNumberOfKeySets, TotalGraph);
751
752 // free subgraph memory again
753 FragmentCounter = 0;
754 while (Subgraphs != NULL) {
755 // remove entry in fragment list
756 // remove subgraph fragment
757 MolecularWalker = Subgraphs->next;
758 delete(Subgraphs);
759 Subgraphs = MolecularWalker;
760 }
761 // free fragment list
762 for (int i=0; i< FragmentCounter; ++i )
763 delete(FragmentList[i]);
764 delete[](FragmentList);
765
766 DoLog(0) && (Log() << Verbose(0) << FragmentCounter-1 << " subgraph fragments have been removed." << std::endl);
767
768 // ===== 8b. gather keyset lists (graphs) from all subgraphs and transform into MoleculeListClass =====
769 //if (FragmentationToDo) { // we should always store the fragments again as coordination might have changed slightly without changing bond structure
770 // allocate memory for the pointer array and transmorph graphs into full molecular fragments
771 BondFragments = new MoleculeListClass(World::getPointer());
772 int k=0;
773 for(Graph::iterator runner = TotalGraph.begin(); runner != TotalGraph.end(); runner++) {
774 KeySet test = (*runner).first;
775 DoLog(0) && (Log() << Verbose(0) << "Fragment No." << (*runner).second.first << " with TEFactor " << (*runner).second.second << "." << endl);
776 BondFragments->insert(StoreFragmentFromKeySet(test, World::getInstance().getConfig()));
777 k++;
778 }
779 DoLog(0) && (Log() << Verbose(0) << k << "/" << BondFragments->ListOfMolecules.size() << " fragments generated from the keysets." << endl);
780
781 // ===== 9. Save fragments' configuration and keyset files et al to disk ===
782 if (BondFragments->ListOfMolecules.size() != 0) {
783 // create the SortIndex from BFS labels to order in the config file
784 int *SortIndex = NULL;
785 CreateMappingLabelsToConfigSequence(SortIndex);
786
787 DoLog(1) && (Log() << Verbose(1) << "Writing " << BondFragments->ListOfMolecules.size() << " possible bond fragmentation configs" << endl);
788 if (BondFragments->OutputConfigForListOfFragments(prefix, SortIndex))
789 DoLog(1) && (Log() << Verbose(1) << "All configs written." << endl);
790 else
791 DoLog(1) && (Log() << Verbose(1) << "Some config writing failed." << endl);
792
793 // store force index reference file
794 BondFragments->StoreForcesFile(prefix, SortIndex);
795
796 // store keysets file
797 StoreKeySetFile(TotalGraph, prefix);
798
799 {
800 // store Adjacency file
801 std::string filename = prefix + ADJACENCYFILE;
802 StoreAdjacencyToFile(filename);
803 }
804
805 // store Hydrogen saturation correction file
806 BondFragments->AddHydrogenCorrection(prefix);
807
808 // store adaptive orders into file
809 StoreOrderAtSiteFile(prefix);
810
811 // restore orbital and Stop values
812 //CalculateOrbitals(*configuration);
813
814 // free memory for bond part
815 DoLog(1) && (Log() << Verbose(1) << "Freeing bond memory" << endl);
816 delete[](SortIndex);
817 } else {
818 DoLog(1) && (Log() << Verbose(1) << "FragmentList is zero on return, splitting failed." << endl);
819 }
820 // remove all create molecules again from the World including their atoms
821 for (MoleculeList::iterator iter = BondFragments->ListOfMolecules.begin();
822 !BondFragments->ListOfMolecules.empty();
823 iter = BondFragments->ListOfMolecules.begin()) {
824 // remove copied atoms and molecule again
825 molecule *mol = *iter;
826 mol->removeAtomsinMolecule();
827 World::getInstance().destroyMolecule(mol);
828 BondFragments->ListOfMolecules.erase(iter);
829 }
830 delete(BondFragments);
831 DoLog(0) && (Log() << Verbose(0) << "End of bond fragmentation." << endl);
832
833 return ((int)(!FragmentationToDo)+1); // 1 - continue, 2 - stop (no fragmentation occured)
834};
835
836
837/** Stores pairs (Atom::nr, Atom::AdaptiveOrder) into file.
838 * Atoms not present in the file get "-1".
839 * \param &path path to file ORDERATSITEFILE
840 * \return true - file writable, false - not writable
841 */
842bool molecule::StoreOrderAtSiteFile(std::string &path)
843{
844 string line;
845 ofstream file;
846
847 line = path + ORDERATSITEFILE;
848 file.open(line.c_str());
849 DoLog(1) && (Log() << Verbose(1) << "Writing OrderAtSite " << ORDERATSITEFILE << " ... " << endl);
850 if (file.good()) {
851 for_each(atoms.begin(),atoms.end(),bind2nd(mem_fun(&atom::OutputOrder), &file));
852 file.close();
853 DoLog(1) && (Log() << Verbose(1) << "done." << endl);
854 return true;
855 } else {
856 DoLog(1) && (Log() << Verbose(1) << "failed to open file " << line << "." << endl);
857 return false;
858 }
859};
860
861/** Parses pairs(Atom::nr, Atom::AdaptiveOrder) from file and stores in molecule's Atom's.
862 * Atoms not present in the file get "0".
863 * \param &path path to file ORDERATSITEFILEe
864 * \return true - file found and scanned, false - file not found
865 * \sa ParseKeySetFile() and CheckAdjacencyFileAgainstMolecule() as this is meant to be used in conjunction with the two
866 */
867bool molecule::ParseOrderAtSiteFromFile(std::string &path)
868{
869 unsigned char *OrderArray = new unsigned char[getAtomCount()];
870 bool *MaxArray = new bool[getAtomCount()];
871 bool status;
872 int AtomNr, value;
873 string line;
874 ifstream file;
875
876 for(int i=0;i<getAtomCount();i++) {
877 OrderArray[i] = 0;
878 MaxArray[i] = false;
879 }
880
881 DoLog(1) && (Log() << Verbose(1) << "Begin of ParseOrderAtSiteFromFile" << endl);
882 line = path + ORDERATSITEFILE;
883 file.open(line.c_str());
884 if (file.good()) {
885 while (!file.eof()) { // parse from file
886 AtomNr = -1;
887 file >> AtomNr;
888 if (AtomNr != -1) { // test whether we really parsed something (this is necessary, otherwise last atom is set twice and to 0 on second time)
889 file >> value;
890 OrderArray[AtomNr] = value;
891 file >> value;
892 MaxArray[AtomNr] = value;
893 //Log() << Verbose(2) << "AtomNr " << AtomNr << " with order " << (int)OrderArray[AtomNr] << " and max order set to " << (int)MaxArray[AtomNr] << "." << endl;
894 }
895 }
896 file.close();
897
898 // set atom values
899 for(internal_iterator iter=atoms.begin();iter!=atoms.end();++iter){
900 (*iter)->AdaptiveOrder = OrderArray[(*iter)->nr];
901 (*iter)->MaxOrder = MaxArray[(*iter)->nr];
902 }
903 //SetAtomValueToIndexedArray( OrderArray, &atom::nr, &atom::AdaptiveOrder );
904 //SetAtomValueToIndexedArray( MaxArray, &atom::nr, &atom::MaxOrder );
905
906 DoLog(1) && (Log() << Verbose(1) << "\t ... done." << endl);
907 status = true;
908 } else {
909 DoLog(1) && (Log() << Verbose(1) << "\t ... failed to open file " << line << "." << endl);
910 status = false;
911 }
912 delete[](OrderArray);
913 delete[](MaxArray);
914
915 DoLog(1) && (Log() << Verbose(1) << "End of ParseOrderAtSiteFromFile" << endl);
916 return status;
917};
918
919
920
921/** Looks through a std::deque<atom *> and returns the likeliest removal candiate.
922 * \param *out output stream for debugging messages
923 * \param *&Leaf KeySet to look through
924 * \param *&ShortestPathList list of the shortest path to decide which atom to suggest as removal candidate in the end
925 * \param index of the atom suggested for removal
926 */
927int molecule::LookForRemovalCandidate(KeySet *&Leaf, int *&ShortestPathList)
928{
929 atom *Runner = NULL;
930 int SP, Removal;
931
932 DoLog(2) && (Log() << Verbose(2) << "Looking for removal candidate." << endl);
933 SP = -1; //0; // not -1, so that Root is never removed
934 Removal = -1;
935 for (KeySet::iterator runner = Leaf->begin(); runner != Leaf->end(); runner++) {
936 Runner = FindAtom((*runner));
937 if (Runner->getType()->getAtomicNumber() != 1) { // skip all those added hydrogens when re-filling snake stack
938 if (ShortestPathList[(*runner)] > SP) { // remove the oldest one with longest shortest path
939 SP = ShortestPathList[(*runner)];
940 Removal = (*runner);
941 }
942 }
943 }
944 return Removal;
945};
946
947/** Initializes some value for putting fragment of \a *mol into \a *Leaf.
948 * \param *mol total molecule
949 * \param *Leaf fragment molecule
950 * \param &Leaflet pointer to KeySet structure
951 * \param **SonList calloc'd list which atom of \a *Leaf is a son of which atom in \a *mol
952 * \return number of atoms in fragment
953 */
954int StoreFragmentFromKeySet_Init(molecule *mol, molecule *Leaf, KeySet &Leaflet, atom **SonList)
955{
956 atom *FatherOfRunner = NULL;
957
958 Leaf->BondDistance = mol->BondDistance;
959
960 // first create the minimal set of atoms from the KeySet
961 int size = 0;
962 for(KeySet::iterator runner = Leaflet.begin(); runner != Leaflet.end(); runner++) {
963 FatherOfRunner = mol->FindAtom((*runner)); // find the id
964 SonList[FatherOfRunner->nr] = Leaf->AddCopyAtom(FatherOfRunner);
965 size++;
966 }
967 return size;
968};
969
970/** Creates an induced subgraph out of a fragmental key set, adding bonds and hydrogens (if treated specially).
971 * \param *out output stream for debugging messages
972 * \param *mol total molecule
973 * \param *Leaf fragment molecule
974 * \param IsAngstroem whether we have Ansgtroem or bohrradius
975 * \param **SonList list which atom of \a *Leaf is a son of which atom in \a *mol
976 */
977void CreateInducedSubgraphOfFragment(molecule *mol, molecule *Leaf, atom **SonList, bool IsAngstroem)
978{
979 bool LonelyFlag = false;
980 atom *OtherFather = NULL;
981 atom *FatherOfRunner = NULL;
982
983#ifdef ADDHYDROGEN
984 molecule::const_iterator runner;
985#endif
986 // we increment the iter just before skipping the hydrogen
987 for (molecule::const_iterator iter = Leaf->begin(); iter != Leaf->end();) {
988 LonelyFlag = true;
989 FatherOfRunner = (*iter)->father;
990 ASSERT(FatherOfRunner,"Atom without father found");
991 if (SonList[FatherOfRunner->nr] != NULL) { // check if this, our father, is present in list
992 // create all bonds
993 for (BondList::const_iterator BondRunner = FatherOfRunner->ListOfBonds.begin(); BondRunner != FatherOfRunner->ListOfBonds.end(); (++BondRunner)) {
994 OtherFather = (*BondRunner)->GetOtherAtom(FatherOfRunner);
995// Log() << Verbose(2) << "Father " << *FatherOfRunner << " of son " << *SonList[FatherOfRunner->nr] << " is bound to " << *OtherFather;
996 if (SonList[OtherFather->nr] != NULL) {
997// Log() << Verbose(0) << ", whose son is " << *SonList[OtherFather->nr] << "." << endl;
998 if (OtherFather->nr > FatherOfRunner->nr) { // add bond (nr check is for adding only one of both variants: ab, ba)
999// Log() << Verbose(3) << "Adding Bond: ";
1000// Log() << Verbose(0) <<
1001 Leaf->AddBond((*iter), SonList[OtherFather->nr], (*BondRunner)->BondDegree);
1002// Log() << Verbose(0) << "." << endl;
1003 //NumBonds[(*iter)->nr]++;
1004 } else {
1005// Log() << Verbose(3) << "Not adding bond, labels in wrong order." << endl;
1006 }
1007 LonelyFlag = false;
1008 } else {
1009// Log() << Verbose(0) << ", who has no son in this fragment molecule." << endl;
1010#ifdef ADDHYDROGEN
1011 //Log() << Verbose(3) << "Adding Hydrogen to " << (*iter)->Name << " and a bond in between." << endl;
1012 if(!Leaf->AddHydrogenReplacementAtom((*BondRunner), (*iter), FatherOfRunner, OtherFather, IsAngstroem))
1013 exit(1);
1014#endif
1015 //NumBonds[(*iter)->nr] += Binder->BondDegree;
1016 }
1017 }
1018 } else {
1019 DoeLog(1) && (eLog()<< Verbose(1) << "Son " << (*iter)->getName() << " has father " << FatherOfRunner->getName() << " but its entry in SonList is " << SonList[FatherOfRunner->nr] << "!" << endl);
1020 }
1021 if ((LonelyFlag) && (Leaf->getAtomCount() > 1)) {
1022 DoLog(0) && (Log() << Verbose(0) << **iter << "has got bonds only to hydrogens!" << endl);
1023 }
1024 ++iter;
1025#ifdef ADDHYDROGEN
1026 while ((iter != Leaf->end()) && ((*iter)->getType()->getAtomicNumber() == 1)){ // skip added hydrogen
1027 iter++;
1028 }
1029#endif
1030 }
1031};
1032
1033/** Stores a fragment from \a KeySet into \a molecule.
1034 * First creates the minimal set of atoms from the KeySet, then creates the bond structure from the complete
1035 * molecule and adds missing hydrogen where bonds were cut.
1036 * \param *out output stream for debugging messages
1037 * \param &Leaflet pointer to KeySet structure
1038 * \param IsAngstroem whether we have Ansgtroem or bohrradius
1039 * \return pointer to constructed molecule
1040 */
1041molecule * molecule::StoreFragmentFromKeySet(KeySet &Leaflet, bool IsAngstroem)
1042{
1043 atom **SonList = new atom*[getAtomCount()];
1044 molecule *Leaf = World::getInstance().createMolecule();
1045
1046 for(int i=0;i<getAtomCount();i++)
1047 SonList[i] = NULL;
1048
1049// Log() << Verbose(1) << "Begin of StoreFragmentFromKeyset." << endl;
1050 StoreFragmentFromKeySet_Init(this, Leaf, Leaflet, SonList);
1051 // create the bonds between all: Make it an induced subgraph and add hydrogen
1052// Log() << Verbose(2) << "Creating bonds from father graph (i.e. induced subgraph creation)." << endl;
1053 CreateInducedSubgraphOfFragment(this, Leaf, SonList, IsAngstroem);
1054
1055 //Leaflet->Leaf->ScanForPeriodicCorrection(out);
1056 delete[](SonList);
1057// Log() << Verbose(1) << "End of StoreFragmentFromKeyset." << endl;
1058 return Leaf;
1059};
1060
1061
1062/** Clears the touched list
1063 * \param *out output stream for debugging
1064 * \param verbosity verbosity level
1065 * \param *&TouchedList touched list
1066 * \param SubOrder current suborder
1067 * \param TouchedIndex currently touched
1068 */
1069void SPFragmentGenerator_ClearingTouched(int verbosity, int *&TouchedList, int SubOrder, int &TouchedIndex)
1070{
1071 Log() << Verbose(1+verbosity) << "Clearing touched list." << endl;
1072 for (TouchedIndex=SubOrder+1;TouchedIndex--;) // empty touched list
1073 TouchedList[TouchedIndex] = -1;
1074 TouchedIndex = 0;
1075
1076}
1077
1078/** Adds the current combination of the power set to the snake stack.
1079 * \param *out output stream for debugging
1080 * \param verbosity verbosity level
1081 * \param CurrentCombination
1082 * \param SetDimension maximum number of bits in power set
1083 * \param *FragmentSet snake stack to remove from
1084 * \param *&TouchedList touched list
1085 * \param TouchedIndex currently touched
1086 * \return number of set bits
1087 */
1088int AddPowersetToSnakeStack(int verbosity, int CurrentCombination, int SetDimension, KeySet *FragmentSet, bond **BondsSet, int *&TouchedList, int &TouchedIndex)
1089{
1090 atom *OtherWalker = NULL;
1091 bool bit = false;
1092 KeySetTestPair TestKeySetInsert;
1093
1094 int Added = 0;
1095 for (int j=0;j<SetDimension;j++) { // pull out every bit by shifting
1096 bit = ((CurrentCombination & (1 << j)) != 0); // mask the bit for the j-th bond
1097 if (bit) { // if bit is set, we add this bond partner
1098 OtherWalker = BondsSet[j]->rightatom; // rightatom is always the one more distant, i.e. the one to add
1099 //Log() << Verbose(1+verbosity) << "Current Bond is " << BondsSet[j] << ", checking on " << *OtherWalker << "." << endl;
1100 Log() << Verbose(2+verbosity) << "Adding " << *OtherWalker << " with nr " << OtherWalker->nr << "." << endl;
1101 TestKeySetInsert = FragmentSet->insert(OtherWalker->nr);
1102 if (TestKeySetInsert.second) {
1103 TouchedList[TouchedIndex++] = OtherWalker->nr; // note as added
1104 Added++;
1105 } else {
1106 Log() << Verbose(2+verbosity) << "This was item was already present in the keyset." << endl;
1107 }
1108 } else {
1109 Log() << Verbose(2+verbosity) << "Not adding." << endl;
1110 }
1111 }
1112 return Added;
1113};
1114
1115/** Counts the number of elements in a power set.
1116 * \param *SetFirst
1117 * \param *SetLast
1118 * \param *&TouchedList touched list
1119 * \param TouchedIndex currently touched
1120 * \return number of elements
1121 */
1122int CountSetMembers(bond *SetFirst, bond *SetLast, int *&TouchedList, int TouchedIndex)
1123{
1124 int SetDimension = 0;
1125 bond *Binder = SetFirst; // start node for this level
1126 while (Binder->next != SetLast) { // compare to end node of this level
1127 Binder = Binder->next;
1128 for (int k=TouchedIndex;k--;) {
1129 if (Binder->Contains(TouchedList[k])) // if we added this very endpiece
1130 SetDimension++;
1131 }
1132 }
1133 return SetDimension;
1134};
1135
1136/** Counts the number of elements in a power set.
1137 * \param *BondsList bonds list to fill
1138 * \param *SetFirst
1139 * \param *SetLast
1140 * \param *&TouchedList touched list
1141 * \param TouchedIndex currently touched
1142 * \return number of elements
1143 */
1144int FillBondsList(bond **BondsList, bond *SetFirst, bond *SetLast, int *&TouchedList, int TouchedIndex)
1145{
1146 int SetDimension = 0;
1147 bond *Binder = SetFirst; // start node for this level
1148 while (Binder->next != SetLast) { // compare to end node of this level
1149 Binder = Binder->next;
1150 for (int k=0;k<TouchedIndex;k++) {
1151 if (Binder->leftatom->nr == TouchedList[k]) // leftatom is always the close one
1152 BondsList[SetDimension++] = Binder;
1153 }
1154 }
1155 return SetDimension;
1156};
1157
1158/** Remove all items that were added on this SP level.
1159 * \param *out output stream for debugging
1160 * \param verbosity verbosity level
1161 * \param *FragmentSet snake stack to remove from
1162 * \param *&TouchedList touched list
1163 * \param TouchedIndex currently touched
1164 */
1165void RemoveAllTouchedFromSnakeStack(int verbosity, KeySet *FragmentSet, int *&TouchedList, int &TouchedIndex)
1166{
1167 int Removal = 0;
1168 for(int j=0;j<TouchedIndex;j++) {
1169 Removal = TouchedList[j];
1170 Log() << Verbose(2+verbosity) << "Removing item nr. " << Removal << " from snake stack." << endl;
1171 FragmentSet->erase(Removal);
1172 TouchedList[j] = -1;
1173 }
1174 DoLog(2) && (Log() << Verbose(2) << "Remaining local nr.s on snake stack are: ");
1175 for(KeySet::iterator runner = FragmentSet->begin(); runner != FragmentSet->end(); runner++)
1176 DoLog(0) && (Log() << Verbose(0) << (*runner) << " ");
1177 DoLog(0) && (Log() << Verbose(0) << endl);
1178 TouchedIndex = 0; // set Index to 0 for list of atoms added on this level
1179};
1180
1181/** From a given set of Bond sorted by Shortest Path distance, create all possible fragments of size \a SetDimension.
1182 * -# loops over every possible combination (2^dimension of edge set)
1183 * -# inserts current set, if there's still space left
1184 * -# yes: calls SPFragmentGenerator with structure, created new edge list and size respective to root dist
1185ance+1
1186 * -# no: stores fragment into keyset list by calling InsertFragmentIntoGraph
1187 * -# removes all items added into the snake stack (in UniqueFragments structure) added during level (root
1188distance) and current set
1189 * \param *out output stream for debugging
1190 * \param FragmentSearch UniqueFragments structure with all values needed
1191 * \param RootDistance current shortest path level, whose set of edges is represented by **BondsSet
1192 * \param SetDimension Number of possible bonds on this level (i.e. size of the array BondsSet[])
1193 * \param SubOrder remaining number of allowed vertices to add
1194 */
1195void molecule::SPFragmentGenerator(struct UniqueFragments *FragmentSearch, int RootDistance, bond **BondsSet, int SetDimension, int SubOrder)
1196{
1197 int verbosity = 0; //FragmentSearch->ANOVAOrder-SubOrder;
1198 int NumCombinations;
1199 int bits, TouchedIndex, SubSetDimension, SP, Added;
1200 int SpaceLeft;
1201 int *TouchedList = new int[SubOrder + 1];
1202 KeySetTestPair TestKeySetInsert;
1203
1204 NumCombinations = 1 << SetDimension;
1205
1206 // here for all bonds of Walker all combinations of end pieces (from the bonds)
1207 // have to be added and for the remaining ANOVA order GraphCrawler be called
1208 // recursively for the next level
1209
1210 Log() << Verbose(1+verbosity) << "Begin of SPFragmentGenerator." << endl;
1211 Log() << Verbose(1+verbosity) << "We are " << RootDistance << " away from Root, which is " << *FragmentSearch->Root << ", SubOrder is " << SubOrder << ", SetDimension is " << SetDimension << " and this means " << NumCombinations-1 << " combination(s)." << endl;
1212
1213 // initialised touched list (stores added atoms on this level)
1214 SPFragmentGenerator_ClearingTouched(verbosity, TouchedList, SubOrder, TouchedIndex);
1215
1216 // create every possible combination of the endpieces
1217 Log() << Verbose(1+verbosity) << "Going through all combinations of the power set." << endl;
1218 for (int i=1;i<NumCombinations;i++) { // sweep through all power set combinations (skip empty set!)
1219 // count the set bit of i
1220 bits = 0;
1221 for (int j=SetDimension;j--;)
1222 bits += (i & (1 << j)) >> j;
1223
1224 Log() << Verbose(1+verbosity) << "Current set is " << Binary(i | (1 << SetDimension)) << ", number of bits is " << bits << "." << endl;
1225 if (bits <= SubOrder) { // if not greater than additional atoms allowed on stack, continue
1226 // --1-- add this set of the power set of bond partners to the snake stack
1227 Added = AddPowersetToSnakeStack(verbosity, i, SetDimension, FragmentSearch->FragmentSet, BondsSet, TouchedList, TouchedIndex);
1228
1229 SpaceLeft = SubOrder - Added ;// SubOrder - bits; // due to item's maybe being already present, this does not work anymore
1230 if (SpaceLeft > 0) {
1231 Log() << Verbose(1+verbosity) << "There's still some space left on stack: " << SpaceLeft << "." << endl;
1232 if (SubOrder > 1) { // Due to Added above we have to check extra whether we're not already reaching beyond the desired Order
1233 // --2-- look at all added end pieces of this combination, construct bond subsets and sweep through a power set of these by recursion
1234 SP = RootDistance+1; // this is the next level
1235
1236 // first count the members in the subset
1237 SubSetDimension = CountSetMembers(FragmentSearch->BondsPerSPList[2*SP], FragmentSearch->BondsPerSPList[2*SP+1], TouchedList, TouchedIndex);
1238
1239 // then allocate and fill the list
1240 bond *BondsList[SubSetDimension];
1241 SubSetDimension = FillBondsList(BondsList, FragmentSearch->BondsPerSPList[2*SP], FragmentSearch->BondsPerSPList[2*SP+1], TouchedList, TouchedIndex);
1242
1243 // then iterate
1244 Log() << Verbose(2+verbosity) << "Calling subset generator " << SP << " away from root " << *FragmentSearch->Root << " with sub set dimension " << SubSetDimension << "." << endl;
1245 SPFragmentGenerator(FragmentSearch, SP, BondsList, SubSetDimension, SubOrder-bits);
1246 }
1247 } else {
1248 // --2-- otherwise store the complete fragment
1249 Log() << Verbose(1+verbosity) << "Enough items on stack for a fragment!" << endl;
1250 // store fragment as a KeySet
1251 DoLog(2) && (Log() << Verbose(2) << "Found a new fragment[" << FragmentSearch->FragmentCounter << "], local nr.s are: ");
1252 for(KeySet::iterator runner = FragmentSearch->FragmentSet->begin(); runner != FragmentSearch->FragmentSet->end(); runner++)
1253 DoLog(0) && (Log() << Verbose(0) << (*runner) << " ");
1254 DoLog(0) && (Log() << Verbose(0) << endl);
1255 //if (!CheckForConnectedSubgraph(FragmentSearch->FragmentSet))
1256 //DoeLog(1) && (eLog()<< Verbose(1) << "The found fragment is not a connected subgraph!" << endl);
1257 InsertFragmentIntoGraph(FragmentSearch);
1258 }
1259
1260 // --3-- remove all added items in this level from snake stack
1261 Log() << Verbose(1+verbosity) << "Removing all items that were added on this SP level " << RootDistance << "." << endl;
1262 RemoveAllTouchedFromSnakeStack(verbosity, FragmentSearch->FragmentSet, TouchedList, TouchedIndex);
1263 } else {
1264 Log() << Verbose(2+verbosity) << "More atoms to add for this set (" << bits << ") than space left on stack " << SubOrder << ", skipping this set." << endl;
1265 }
1266 }
1267 delete[](TouchedList);
1268 Log() << Verbose(1+verbosity) << "End of SPFragmentGenerator, " << RootDistance << " away from Root " << *FragmentSearch->Root << " and SubOrder is " << SubOrder << "." << endl;
1269};
1270
1271/** Allocates memory for UniqueFragments::BondsPerSPList.
1272 * \param *out output stream
1273 * \param Order bond order (limits BFS exploration and "number of digits" in power set generation
1274 * \param FragmentSearch UniqueFragments
1275 * \sa FreeSPList()
1276 */
1277void InitialiseSPList(int Order, struct UniqueFragments &FragmentSearch)
1278{
1279 FragmentSearch.BondsPerSPList = new bond* [Order * 2];
1280 FragmentSearch.BondsPerSPCount = new int[Order];
1281 for (int i=Order;i--;) {
1282 FragmentSearch.BondsPerSPList[2*i] = new bond(); // start node
1283 FragmentSearch.BondsPerSPList[2*i+1] = new bond(); // end node
1284 FragmentSearch.BondsPerSPList[2*i]->next = FragmentSearch.BondsPerSPList[2*i+1]; // intertwine these two
1285 FragmentSearch.BondsPerSPList[2*i+1]->previous = FragmentSearch.BondsPerSPList[2*i];
1286 FragmentSearch.BondsPerSPCount[i] = 0;
1287 }
1288};
1289
1290/** Free's memory for for UniqueFragments::BondsPerSPList.
1291 * \param *out output stream
1292 * \param Order bond order (limits BFS exploration and "number of digits" in power set generation
1293 * \param FragmentSearch UniqueFragments\
1294 * \sa InitialiseSPList()
1295 */
1296void FreeSPList(int Order, struct UniqueFragments &FragmentSearch)
1297{
1298 delete[](FragmentSearch.BondsPerSPCount);
1299 for (int i=Order;i--;) {
1300 delete(FragmentSearch.BondsPerSPList[2*i]);
1301 delete(FragmentSearch.BondsPerSPList[2*i+1]);
1302 }
1303 delete[](FragmentSearch.BondsPerSPList);
1304};
1305
1306/** Sets FragmenSearch to initial value.
1307 * Sets UniqueFragments::ShortestPathList entries to zero, UniqueFragments::BondsPerSPCount to zero (except zero level to 1) and
1308 * adds initial bond UniqueFragments::Root to UniqueFragments::Root to UniqueFragments::BondsPerSPList
1309 * \param *out output stream
1310 * \param Order bond order (limits BFS exploration and "number of digits" in power set generation
1311 * \param FragmentSearch UniqueFragments
1312 * \sa FreeSPList()
1313 */
1314void SetSPList(int Order, struct UniqueFragments &FragmentSearch)
1315{
1316 // prepare Label and SP arrays of the BFS search
1317 FragmentSearch.ShortestPathList[FragmentSearch.Root->nr] = 0;
1318
1319 // prepare root level (SP = 0) and a loop bond denoting Root
1320 for (int i=Order;i--;)
1321 FragmentSearch.BondsPerSPCount[i] = 0;
1322 FragmentSearch.BondsPerSPCount[0] = 1;
1323 bond *Binder = new bond(FragmentSearch.Root, FragmentSearch.Root);
1324 add(Binder, FragmentSearch.BondsPerSPList[1]);
1325};
1326
1327/** Resets UniqueFragments::ShortestPathList and cleans bonds from UniqueFragments::BondsPerSPList.
1328 * \param *out output stream
1329 * \param Order bond order (limits BFS exploration and "number of digits" in power set generation
1330 * \param FragmentSearch UniqueFragments
1331 * \sa InitialiseSPList()
1332 */
1333void ResetSPList(int Order, struct UniqueFragments &FragmentSearch)
1334{
1335 bond *Binder = NULL;
1336 DoLog(0) && (Log() << Verbose(0) << "Free'ing all found lists. and resetting index lists" << endl);
1337 for(int i=Order;i--;) {
1338 DoLog(1) && (Log() << Verbose(1) << "Current SP level is " << i << ": ");
1339 Binder = FragmentSearch.BondsPerSPList[2*i];
1340 while (Binder->next != FragmentSearch.BondsPerSPList[2*i+1]) {
1341 Binder = Binder->next;
1342 // Log() << Verbose(0) << "Removing atom " << Binder->leftatom->nr << " and " << Binder->rightatom->nr << "." << endl; // make sure numbers are local
1343 FragmentSearch.ShortestPathList[Binder->leftatom->nr] = -1;
1344 FragmentSearch.ShortestPathList[Binder->rightatom->nr] = -1;
1345 }
1346 // delete added bonds
1347 cleanup(FragmentSearch.BondsPerSPList[2*i], FragmentSearch.BondsPerSPList[2*i+1]);
1348 // also start and end node
1349 DoLog(0) && (Log() << Verbose(0) << "cleaned." << endl);
1350 }
1351};
1352
1353
1354/** Fills the Bonds per Shortest Path List and set the vertex labels.
1355 * \param *out output stream
1356 * \param Order bond order (limits BFS exploration and "number of digits" in power set generation
1357 * \param FragmentSearch UniqueFragments
1358 * \param *mol molecule with atoms and bonds
1359 * \param RestrictedKeySet Restricted vertex set to use in context of molecule
1360 */
1361void FillSPListandLabelVertices(int Order, struct UniqueFragments &FragmentSearch, molecule *mol, KeySet RestrictedKeySet)
1362{
1363 // Actually, we should construct a spanning tree vom the root atom and select all edges therefrom and put them into
1364 // according shortest path lists. However, we don't. Rather we fill these lists right away, as they do form a spanning
1365 // tree already sorted into various SP levels. That's why we just do loops over the depth (CurrentSP) and breadth
1366 // (EdgeinSPLevel) of this tree ...
1367 // In another picture, the bonds always contain a direction by rightatom being the one more distant from root and hence
1368 // naturally leftatom forming its predecessor, preventing the BFS"seeker" from continuing in the wrong direction.
1369 int AtomKeyNr = -1;
1370 atom *Walker = NULL;
1371 atom *OtherWalker = NULL;
1372 atom *Predecessor = NULL;
1373 bond *CurrentEdge = NULL;
1374 bond *Binder = NULL;
1375 int RootKeyNr = FragmentSearch.Root->GetTrueFather()->nr;
1376 int RemainingWalkers = -1;
1377 int SP = -1;
1378
1379 DoLog(0) && (Log() << Verbose(0) << "Starting BFS analysis ..." << endl);
1380 for (SP = 0; SP < (Order-1); SP++) {
1381 DoLog(1) && (Log() << Verbose(1) << "New SP level reached: " << SP << ", creating new SP list with " << FragmentSearch.BondsPerSPCount[SP] << " item(s)");
1382 if (SP > 0) {
1383 DoLog(0) && (Log() << Verbose(0) << ", old level closed with " << FragmentSearch.BondsPerSPCount[SP-1] << " item(s)." << endl);
1384 FragmentSearch.BondsPerSPCount[SP] = 0;
1385 } else
1386 DoLog(0) && (Log() << Verbose(0) << "." << endl);
1387
1388 RemainingWalkers = FragmentSearch.BondsPerSPCount[SP];
1389 CurrentEdge = FragmentSearch.BondsPerSPList[2*SP]; /// start of this SP level's list
1390 while (CurrentEdge->next != FragmentSearch.BondsPerSPList[2*SP+1]) { /// end of this SP level's list
1391 CurrentEdge = CurrentEdge->next;
1392 RemainingWalkers--;
1393 Walker = CurrentEdge->rightatom; // rightatom is always the one more distant
1394 Predecessor = CurrentEdge->leftatom; // ... and leftatom is predecessor
1395 AtomKeyNr = Walker->nr;
1396 DoLog(0) && (Log() << Verbose(0) << "Current Walker is: " << *Walker << " with nr " << Walker->nr << " and SP of " << SP << ", with " << RemainingWalkers << " remaining walkers on this level." << endl);
1397 // check for new sp level
1398 // go through all its bonds
1399 DoLog(1) && (Log() << Verbose(1) << "Going through all bonds of Walker." << endl);
1400 for (BondList::const_iterator Runner = Walker->ListOfBonds.begin(); Runner != Walker->ListOfBonds.end(); (++Runner)) {
1401 OtherWalker = (*Runner)->GetOtherAtom(Walker);
1402 if ((RestrictedKeySet.find(OtherWalker->nr) != RestrictedKeySet.end())
1403 #ifdef ADDHYDROGEN
1404 && (OtherWalker->getType()->getAtomicNumber() != 1)
1405 #endif
1406 ) { // skip hydrogens and restrict to fragment
1407 DoLog(2) && (Log() << Verbose(2) << "Current partner is " << *OtherWalker << " with nr " << OtherWalker->nr << " in bond " << *(*Runner) << "." << endl);
1408 // set the label if not set (and push on root stack as well)
1409 if ((OtherWalker != Predecessor) && (OtherWalker->GetTrueFather()->nr > RootKeyNr)) { // only pass through those with label bigger than Root's
1410 FragmentSearch.ShortestPathList[OtherWalker->nr] = SP+1;
1411 DoLog(3) && (Log() << Verbose(3) << "Set Shortest Path to " << FragmentSearch.ShortestPathList[OtherWalker->nr] << "." << endl);
1412 // add the bond in between to the SP list
1413 Binder = new bond(Walker, OtherWalker); // create a new bond in such a manner, that bond::rightatom is always the one more distant
1414 add(Binder, FragmentSearch.BondsPerSPList[2*(SP+1)+1]);
1415 FragmentSearch.BondsPerSPCount[SP+1]++;
1416 DoLog(3) && (Log() << Verbose(3) << "Added its bond to SP list, having now " << FragmentSearch.BondsPerSPCount[SP+1] << " item(s)." << endl);
1417 } else {
1418 if (OtherWalker != Predecessor)
1419 DoLog(3) && (Log() << Verbose(3) << "Not passing on, as index of " << *OtherWalker << " " << OtherWalker->GetTrueFather()->nr << " is smaller than that of Root " << RootKeyNr << "." << endl);
1420 else
1421 DoLog(3) && (Log() << Verbose(3) << "This is my predecessor " << *Predecessor << "." << endl);
1422 }
1423 } else Log() << Verbose(2) << "Is not in the restricted keyset or skipping hydrogen " << *OtherWalker << "." << endl;
1424 }
1425 }
1426 }
1427};
1428
1429/** prints the Bonds per Shortest Path list in UniqueFragments.
1430 * \param *out output stream
1431 * \param Order bond order (limits BFS exploration and "number of digits" in power set generation
1432 * \param FragmentSearch UniqueFragments
1433 */
1434void OutputSPList(int Order, struct UniqueFragments &FragmentSearch)
1435{
1436 bond *Binder = NULL;
1437 DoLog(0) && (Log() << Verbose(0) << "Printing all found lists." << endl);
1438 for(int i=1;i<Order;i++) { // skip the root edge in the printing
1439 Binder = FragmentSearch.BondsPerSPList[2*i];
1440 DoLog(1) && (Log() << Verbose(1) << "Current SP level is " << i << "." << endl);
1441 while (Binder->next != FragmentSearch.BondsPerSPList[2*i+1]) {
1442 Binder = Binder->next;
1443 DoLog(2) && (Log() << Verbose(2) << *Binder << endl);
1444 }
1445 }
1446};
1447
1448/** Simply counts all bonds in all UniqueFragments::BondsPerSPList lists.
1449 * \param *out output stream
1450 * \param Order bond order (limits BFS exploration and "number of digits" in power set generation
1451 * \param FragmentSearch UniqueFragments
1452 */
1453int CountNumbersInBondsList(int Order, struct UniqueFragments &FragmentSearch)
1454{
1455 bond *Binder = NULL;
1456 int SP = -1; // the Root <-> Root edge must be subtracted!
1457 for(int i=Order;i--;) { // sum up all found edges
1458 Binder = FragmentSearch.BondsPerSPList[2*i];
1459 while (Binder->next != FragmentSearch.BondsPerSPList[2*i+1]) {
1460 Binder = Binder->next;
1461 SP++;
1462 }
1463 }
1464 return SP;
1465};
1466
1467/** Creates a list of all unique fragments of certain vertex size from a given graph \a Fragment for a given root vertex in the context of \a this molecule.
1468 * -# initialises UniqueFragments structure
1469 * -# fills edge list via BFS
1470 * -# creates the fragment by calling recursive function SPFragmentGenerator with UniqueFragments structure, 0 as
1471 root distance, the edge set, its dimension and the current suborder
1472 * -# Free'ing structure
1473 * Note that we may use the fact that the atoms are SP-ordered on the atomstack. I.e. when popping always the last, we first get all
1474 * with SP of 2, then those with SP of 3, then those with SP of 4 and so on.
1475 * \param *out output stream for debugging
1476 * \param Order bond order (limits BFS exploration and "number of digits" in power set generation
1477 * \param FragmentSearch UniqueFragments structure containing TEFactor, root atom and so on
1478 * \param RestrictedKeySet Restricted vertex set to use in context of molecule
1479 * \return number of inserted fragments
1480 * \note ShortestPathList in FragmentSearch structure is probably due to NumberOfAtomsSPLevel and SP not needed anymore
1481 */
1482int molecule::PowerSetGenerator(int Order, struct UniqueFragments &FragmentSearch, KeySet RestrictedKeySet)
1483{
1484 int Counter = FragmentSearch.FragmentCounter; // mark current value of counter
1485
1486 DoLog(0) && (Log() << Verbose(0) << endl);
1487 DoLog(0) && (Log() << Verbose(0) << "Begin of PowerSetGenerator with order " << Order << " at Root " << *FragmentSearch.Root << "." << endl);
1488
1489 SetSPList(Order, FragmentSearch);
1490
1491 // do a BFS search to fill the SP lists and label the found vertices
1492 FillSPListandLabelVertices(Order, FragmentSearch, this, RestrictedKeySet);
1493
1494 // outputting all list for debugging
1495 OutputSPList(Order, FragmentSearch);
1496
1497 // creating fragments with the found edge sets (may be done in reverse order, faster)
1498 int SP = CountNumbersInBondsList(Order, FragmentSearch);
1499 DoLog(0) && (Log() << Verbose(0) << "Total number of edges is " << SP << "." << endl);
1500 if (SP >= (Order-1)) {
1501 // start with root (push on fragment stack)
1502 DoLog(0) && (Log() << Verbose(0) << "Starting fragment generation with " << *FragmentSearch.Root << ", local nr is " << FragmentSearch.Root->nr << "." << endl);
1503 FragmentSearch.FragmentSet->clear();
1504 DoLog(0) && (Log() << Verbose(0) << "Preparing subset for this root and calling generator." << endl);
1505
1506 // prepare the subset and call the generator
1507 bond* BondsList[FragmentSearch.BondsPerSPCount[0]];
1508 for(int i=0;i<FragmentSearch.BondsPerSPCount[0];i++)
1509 BondsList[i] = NULL;
1510 BondsList[0] = FragmentSearch.BondsPerSPList[0]->next; // on SP level 0 there's only the root bond
1511
1512 SPFragmentGenerator(&FragmentSearch, 0, BondsList, FragmentSearch.BondsPerSPCount[0], Order);
1513 } else {
1514 DoLog(0) && (Log() << Verbose(0) << "Not enough total number of edges to build " << Order << "-body fragments." << endl);
1515 }
1516
1517 // as FragmentSearch structure is used only once, we don't have to clean it anymore
1518 // remove root from stack
1519 DoLog(0) && (Log() << Verbose(0) << "Removing root again from stack." << endl);
1520 FragmentSearch.FragmentSet->erase(FragmentSearch.Root->nr);
1521
1522 // free'ing the bonds lists
1523 ResetSPList(Order, FragmentSearch);
1524
1525 // return list
1526 DoLog(0) && (Log() << Verbose(0) << "End of PowerSetGenerator." << endl);
1527 return (FragmentSearch.FragmentCounter - Counter);
1528};
1529
1530bool KeyCompare::operator() (const KeySet SubgraphA, const KeySet SubgraphB) const
1531{
1532 //Log() << Verbose(0) << "my check is used." << endl;
1533 if (SubgraphA.size() < SubgraphB.size()) {
1534 return true;
1535 } else {
1536 if (SubgraphA.size() > SubgraphB.size()) {
1537 return false;
1538 } else {
1539 KeySet::iterator IteratorA = SubgraphA.begin();
1540 KeySet::iterator IteratorB = SubgraphB.begin();
1541 while ((IteratorA != SubgraphA.end()) && (IteratorB != SubgraphB.end())) {
1542 if ((*IteratorA) < (*IteratorB))
1543 return true;
1544 else if ((*IteratorA) > (*IteratorB)) {
1545 return false;
1546 } // else, go on to next index
1547 IteratorA++;
1548 IteratorB++;
1549 } // end of while loop
1550 }// end of check in case of equal sizes
1551 }
1552 return false; // if we reach this point, they are equal
1553};
1554
1555
1556/** Combines all KeySets from all orders into single ones (with just unique entries).
1557 * \param *out output stream for debugging
1558 * \param *&FragmentList list to fill
1559 * \param ***FragmentLowerOrdersList
1560 * \param &RootStack stack with all root candidates (unequal to each atom in complete molecule if adaptive scheme is applied)
1561 * \param *mol molecule with atoms and bonds
1562 */
1563int CombineAllOrderListIntoOne(Graph *&FragmentList, Graph ***FragmentLowerOrdersList, KeyStack &RootStack, molecule *mol)
1564{
1565 int RootNr = 0;
1566 int RootKeyNr = 0;
1567 int StartNr = 0;
1568 int counter = 0;
1569 int NumLevels = 0;
1570 atom *Walker = NULL;
1571
1572 DoLog(0) && (Log() << Verbose(0) << "Combining the lists of all orders per order and finally into a single one." << endl);
1573 if (FragmentList == NULL) {
1574 FragmentList = new Graph;
1575 counter = 0;
1576 } else {
1577 counter = FragmentList->size();
1578 }
1579
1580 StartNr = RootStack.back();
1581 do {
1582 RootKeyNr = RootStack.front();
1583 RootStack.pop_front();
1584 Walker = mol->FindAtom(RootKeyNr);
1585 NumLevels = 1 << (Walker->AdaptiveOrder - 1);
1586 for(int i=0;i<NumLevels;i++) {
1587 if (FragmentLowerOrdersList[RootNr][i] != NULL) {
1588 InsertGraphIntoGraph(*FragmentList, (*FragmentLowerOrdersList[RootNr][i]), &counter);
1589 }
1590 }
1591 RootStack.push_back(Walker->nr);
1592 RootNr++;
1593 } while (RootKeyNr != StartNr);
1594 return counter;
1595};
1596
1597/** Free's memory allocated for all KeySets from all orders.
1598 * \param *out output stream for debugging
1599 * \param ***FragmentLowerOrdersList
1600 * \param &RootStack stack with all root candidates (unequal to each atom in complete molecule if adaptive scheme is applied)
1601 * \param *mol molecule with atoms and bonds
1602 */
1603void FreeAllOrdersList(Graph ***FragmentLowerOrdersList, KeyStack &RootStack, molecule *mol)
1604{
1605 DoLog(1) && (Log() << Verbose(1) << "Free'ing the lists of all orders per order." << endl);
1606 int RootNr = 0;
1607 int RootKeyNr = 0;
1608 int NumLevels = 0;
1609 atom *Walker = NULL;
1610 while (!RootStack.empty()) {
1611 RootKeyNr = RootStack.front();
1612 RootStack.pop_front();
1613 Walker = mol->FindAtom(RootKeyNr);
1614 NumLevels = 1 << (Walker->AdaptiveOrder - 1);
1615 for(int i=0;i<NumLevels;i++) {
1616 if (FragmentLowerOrdersList[RootNr][i] != NULL) {
1617 delete(FragmentLowerOrdersList[RootNr][i]);
1618 }
1619 }
1620 delete[](FragmentLowerOrdersList[RootNr]);
1621 RootNr++;
1622 }
1623 delete[](FragmentLowerOrdersList);
1624};
1625
1626
1627/** Performs BOSSANOVA decomposition at selected sites, increasing the cutoff by one at these sites.
1628 * -# constructs a complete keyset of the molecule
1629 * -# In a loop over all possible roots from the given rootstack
1630 * -# increases order of root site
1631 * -# calls PowerSetGenerator with this order, the complete keyset and the rootkeynr
1632 * -# for all consecutive lower levels PowerSetGenerator is called with the suborder, the higher order keyset
1633as the restricted one and each site in the set as the root)
1634 * -# these are merged into a fragment list of keysets
1635 * -# All fragment lists (for all orders, i.e. from all destination fields) are merged into one list for return
1636 * Important only is that we create all fragments, it is not important if we create them more than once
1637 * as these copies are filtered out via use of the hash table (KeySet).
1638 * \param *out output stream for debugging
1639 * \param Fragment&*List list of already present keystacks (adaptive scheme) or empty list
1640 * \param &RootStack stack with all root candidates (unequal to each atom in complete molecule if adaptive scheme is applied)
1641 * \param *MinimumRingSize minimum ring size for each atom (molecule::Atomcount)
1642 * \return pointer to Graph list
1643 */
1644void molecule::FragmentBOSSANOVA(Graph *&FragmentList, KeyStack &RootStack, int *MinimumRingSize)
1645{
1646 Graph ***FragmentLowerOrdersList = NULL;
1647 int NumLevels = 0;
1648 int NumMolecules = 0;
1649 int TotalNumMolecules = 0;
1650 int *NumMoleculesOfOrder = NULL;
1651 int Order = 0;
1652 int UpgradeCount = RootStack.size();
1653 KeyStack FragmentRootStack;
1654 int RootKeyNr = 0;
1655 int RootNr = 0;
1656 struct UniqueFragments FragmentSearch;
1657
1658 DoLog(0) && (Log() << Verbose(0) << "Begin of FragmentBOSSANOVA." << endl);
1659
1660 // FragmentLowerOrdersList is a 2D-array of pointer to MoleculeListClass objects, one dimension represents the ANOVA expansion of a single order (i.e. 5)
1661 // with all needed lower orders that are subtracted, the other dimension is the BondOrder (i.e. from 1 to 5)
1662 NumMoleculesOfOrder = new int[UpgradeCount];
1663 FragmentLowerOrdersList = new Graph**[UpgradeCount];
1664
1665 for(int i=0;i<UpgradeCount;i++) {
1666 NumMoleculesOfOrder[i] = 0;
1667 FragmentLowerOrdersList[i] = NULL;
1668 }
1669
1670 // initialise the fragments structure
1671 FragmentSearch.FragmentCounter = 0;
1672 FragmentSearch.FragmentSet = new KeySet;
1673 FragmentSearch.Root = FindAtom(RootKeyNr);
1674 FragmentSearch.ShortestPathList = new int[getAtomCount()];
1675 for (int i=getAtomCount();i--;) {
1676 FragmentSearch.ShortestPathList[i] = -1;
1677 }
1678
1679 // Construct the complete KeySet which we need for topmost level only (but for all Roots)
1680 KeySet CompleteMolecule;
1681 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) {
1682 CompleteMolecule.insert((*iter)->GetTrueFather()->nr);
1683 }
1684
1685 // this can easily be seen: if Order is 5, then the number of levels for each lower order is the total sum of the number of levels above, as
1686 // each has to be split up. E.g. for the second level we have one from 5th, one from 4th, two from 3th (which in turn is one from 5th, one from 4th),
1687 // hence we have overall four 2th order levels for splitting. This also allows for putting all into a single array (FragmentLowerOrdersList[])
1688 // with the order along the cells as this: 5433222211111111 for BondOrder 5 needing 16=pow(2,5-1) cells (only we use bit-shifting which is faster)
1689 RootNr = 0; // counts through the roots in RootStack
1690 while ((RootNr < UpgradeCount) && (!RootStack.empty())) {
1691 RootKeyNr = RootStack.front();
1692 RootStack.pop_front();
1693 atom *Walker = FindAtom(RootKeyNr);
1694 // check cyclic lengths
1695 //if ((MinimumRingSize[Walker->GetTrueFather()->nr] != -1) && (Walker->GetTrueFather()->AdaptiveOrder+1 > MinimumRingSize[Walker->GetTrueFather()->nr])) {
1696 // Log() << Verbose(0) << "Bond order " << Walker->GetTrueFather()->AdaptiveOrder << " of Root " << *Walker << " greater than or equal to Minimum Ring size of " << MinimumRingSize << " found is not allowed." << endl;
1697 //} else
1698 {
1699 // increase adaptive order by one
1700 Walker->GetTrueFather()->AdaptiveOrder++;
1701 Order = Walker->AdaptiveOrder = Walker->GetTrueFather()->AdaptiveOrder;
1702
1703 // initialise Order-dependent entries of UniqueFragments structure
1704 InitialiseSPList(Order, FragmentSearch);
1705
1706 // allocate memory for all lower level orders in this 1D-array of ptrs
1707 NumLevels = 1 << (Order-1); // (int)pow(2,Order);
1708 FragmentLowerOrdersList[RootNr] = new Graph*[NumLevels];
1709 for (int i=0;i<NumLevels;i++)
1710 FragmentLowerOrdersList[RootNr][i] = NULL;
1711
1712 // create top order where nothing is reduced
1713 DoLog(0) && (Log() << Verbose(0) << "==============================================================================================================" << endl);
1714 DoLog(0) && (Log() << Verbose(0) << "Creating KeySets of Bond Order " << Order << " for " << *Walker << ", " << (RootStack.size()-RootNr) << " Roots remaining." << endl); // , NumLevels is " << NumLevels << "
1715
1716 // Create list of Graphs of current Bond Order (i.e. F_{ij})
1717 FragmentLowerOrdersList[RootNr][0] = new Graph;
1718 FragmentSearch.TEFactor = 1.;
1719 FragmentSearch.Leaflet = FragmentLowerOrdersList[RootNr][0]; // set to insertion graph
1720 FragmentSearch.Root = Walker;
1721 NumMoleculesOfOrder[RootNr] = PowerSetGenerator(Walker->AdaptiveOrder, FragmentSearch, CompleteMolecule);
1722
1723 // output resulting number
1724 DoLog(1) && (Log() << Verbose(1) << "Number of resulting KeySets is: " << NumMoleculesOfOrder[RootNr] << "." << endl);
1725 if (NumMoleculesOfOrder[RootNr] != 0) {
1726 NumMolecules = 0;
1727 } else {
1728 Walker->GetTrueFather()->MaxOrder = true;
1729 }
1730 // now, we have completely filled each cell of FragmentLowerOrdersList[] for the current Walker->AdaptiveOrder
1731 //NumMoleculesOfOrder[Walker->AdaptiveOrder-1] = NumMolecules;
1732 TotalNumMolecules += NumMoleculesOfOrder[RootNr];
1733// Log() << Verbose(1) << "Number of resulting molecules for Order " << (int)Walker->GetTrueFather()->AdaptiveOrder << " is: " << NumMoleculesOfOrder[RootNr] << "." << endl;
1734 RootStack.push_back(RootKeyNr); // put back on stack
1735 RootNr++;
1736
1737 // free Order-dependent entries of UniqueFragments structure for next loop cycle
1738 FreeSPList(Order, FragmentSearch);
1739 }
1740 }
1741 DoLog(0) && (Log() << Verbose(0) << "==============================================================================================================" << endl);
1742 DoLog(1) && (Log() << Verbose(1) << "Total number of resulting molecules is: " << TotalNumMolecules << "." << endl);
1743 DoLog(0) && (Log() << Verbose(0) << "==============================================================================================================" << endl);
1744
1745 // cleanup FragmentSearch structure
1746 delete[](FragmentSearch.ShortestPathList);
1747 delete(FragmentSearch.FragmentSet);
1748
1749 // now, FragmentLowerOrdersList is complete, it looks - for BondOrder 5 - as this (number is the ANOVA Order of the terms therein)
1750 // 5433222211111111
1751 // 43221111
1752 // 3211
1753 // 21
1754 // 1
1755
1756 // Subsequently, we combine all into a single list (FragmentList)
1757 CombineAllOrderListIntoOne(FragmentList, FragmentLowerOrdersList, RootStack, this);
1758 FreeAllOrdersList(FragmentLowerOrdersList, RootStack, this);
1759 delete[](NumMoleculesOfOrder);
1760
1761 DoLog(0) && (Log() << Verbose(0) << "End of FragmentBOSSANOVA." << endl);
1762};
1763
1764/** Corrects the nuclei position if the fragment was created over the cell borders.
1765 * Scans all bonds, checks the distance, if greater than typical, we have a candidate for the correction.
1766 * We remove the bond whereafter the graph probably separates. Then, we translate the one component periodically
1767 * and re-add the bond. Looping on the distance check.
1768 * \param *out ofstream for debugging messages
1769 */
1770bool molecule::ScanForPeriodicCorrection()
1771{
1772 bond *Binder = NULL;
1773 bond *OtherBinder = NULL;
1774 atom *Walker = NULL;
1775 atom *OtherWalker = NULL;
1776 RealSpaceMatrix matrix = World::getInstance().getDomain().getM();
1777 enum Shading *ColorList = NULL;
1778 double tmp;
1779 bool LastBond = true; // only needed to due list construct
1780 Vector Translationvector;
1781 //std::deque<atom *> *CompStack = NULL;
1782 std::deque<atom *> *AtomStack = new std::deque<atom *>; // (getAtomCount());
1783 bool flag = true;
1784
1785 DoLog(2) && (Log() << Verbose(2) << "Begin of ScanForPeriodicCorrection." << endl);
1786
1787 ColorList = new enum Shading[getAtomCount()];
1788 for (int i=0;i<getAtomCount();i++)
1789 ColorList[i] = (enum Shading)0;
1790 if (flag) {
1791 // remove bonds that are beyond bonddistance
1792 Translationvector.Zero();
1793 // scan all bonds
1794 flag = false;
1795 for(molecule::iterator AtomRunner = begin(); (!flag) && (AtomRunner != end()); ++AtomRunner)
1796 for(BondList::iterator BondRunner = (*AtomRunner)->ListOfBonds.begin(); (!flag) && (BondRunner != (*AtomRunner)->ListOfBonds.end()); ++BondRunner) {
1797 Binder = (*BondRunner);
1798 for (int i=NDIM;i--;) {
1799 tmp = fabs(Binder->leftatom->at(i) - Binder->rightatom->at(i));
1800 //Log() << Verbose(3) << "Checking " << i << "th distance of " << *Binder->leftatom << " to " << *Binder->rightatom << ": " << tmp << "." << endl;
1801 if (tmp > BondDistance) {
1802// OtherBinder = Binder->next; // note down binding partner for later re-insertion
1803// if (OtherBinder != NULL) {
1804// LastBond = false;
1805// } else {
1806// OtherBinder = Binder->previous;
1807// LastBond = true;
1808// }
1809// unlink(Binder); // unlink bond
1810 DoLog(2) && (Log() << Verbose(2) << "Correcting at bond " << *Binder << "." << endl);
1811 flag = true;
1812 break;
1813 }
1814 }
1815 }
1816 //if (flag) {
1817 if (0) {
1818 // create translation vector from their periodically modified distance
1819 for (int i=NDIM;i--;) {
1820 tmp = Binder->leftatom->at(i) - Binder->rightatom->at(i);
1821 if (fabs(tmp) > BondDistance)
1822 Translationvector[i] = (tmp < 0) ? +1. : -1.;
1823 }
1824 Translationvector *= matrix;
1825 //Log() << Verbose(3) << "Translation vector is ";
1826 Log() << Verbose(0) << Translationvector << endl;
1827 // apply to all atoms of first component via BFS
1828 for (int i=getAtomCount();i--;)
1829 ColorList[i] = white;
1830 AtomStack->push_front(Binder->leftatom);
1831 while (!AtomStack->empty()) {
1832 Walker = AtomStack->front();
1833 AtomStack->pop_front();
1834 //Log() << Verbose (3) << "Current Walker is: " << *Walker << "." << endl;
1835 ColorList[Walker->nr] = black; // mark as explored
1836 *Walker += Translationvector; // translate
1837 for (BondList::const_iterator Runner = Walker->ListOfBonds.begin(); Runner != Walker->ListOfBonds.end(); (++Runner)) {
1838 if ((*Runner) != Binder) {
1839 OtherWalker = (*Runner)->GetOtherAtom(Walker);
1840 if (ColorList[OtherWalker->nr] == white) {
1841 AtomStack->push_front(OtherWalker); // push if yet unexplored
1842 }
1843 }
1844 }
1845 }
1846 // re-add bond
1847 if (OtherBinder == NULL) { // is the only bond?
1848 //Do nothing
1849 } else {
1850 if (!LastBond) {
1851 link(Binder, OtherBinder);
1852 } else {
1853 link(OtherBinder, Binder);
1854 }
1855 }
1856 } else {
1857 DoLog(3) && (Log() << Verbose(3) << "No corrections for this fragment." << endl);
1858 }
1859 //delete(CompStack);
1860 }
1861 // free allocated space from ReturnFullMatrixforSymmetric()
1862 delete(AtomStack);
1863 delete[](ColorList);
1864 DoLog(2) && (Log() << Verbose(2) << "End of ScanForPeriodicCorrection." << endl);
1865
1866 return flag;
1867};
Note: See TracBrowser for help on using the repository browser.