source: src/MoleculeLeafClass.cpp@ 41a467

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 41a467 was 47d041, checked in by Frederik Heber <heber@…>, 13 years ago

HUGE: Removed all calls to Log(), eLog(), replaced by LOG() and ELOG().

  • Replaced DoLog(.) && (Log() << Verbose(.) << ... << std::endl) by Log(., ...).
  • Replaced Log() << Verbose(.) << .. << by Log(., ...)
  • on multiline used stringstream to generate and message which was finally used in LOG(., output.str())
  • there should be no more occurence of Log(). LOG() and ELOG() must be used instead.
  • Eventually, this will allow for storing all errors and re-printing them on program exit which would be very helpful to ascertain error-free runs for the user.
  • Property mode set to 100644
File size: 9.3 KB
RevLine 
[d3abb1]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 * MoleculeLeafClass.cpp
10 *
11 * Created on: Oct 20, 2011
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "CodePatterns/MemDebug.hpp"
21
22#include "MoleculeLeafClass.hpp"
23
24#include "CodePatterns/Log.hpp"
25
26#include "atom.hpp"
27#include "Element/element.hpp"
28#include "Fragmentation/Graph.hpp"
29#include "Fragmentation/KeySet.hpp"
30#include "molecule.hpp"
31
32/** Constructor for MoleculeLeafClass root leaf.
33 * \param *Up Leaf on upper level
34 * \param *PreviousLeaf NULL - We are the first leaf on this level, otherwise points to previous in list
35 */
36//MoleculeLeafClass::MoleculeLeafClass(MoleculeLeafClass *Up = NULL, MoleculeLeafClass *Previous = NULL)
37MoleculeLeafClass::MoleculeLeafClass(MoleculeLeafClass *PreviousLeaf = NULL) :
38 Leaf(NULL),
39 previous(PreviousLeaf)
40{
41 // if (Up != NULL)
42 // if (Up->DownLeaf == NULL) // are we the first down leaf for the upper leaf?
43 // Up->DownLeaf = this;
44 // UpLeaf = Up;
45 // DownLeaf = NULL;
46 if (previous != NULL) {
47 MoleculeLeafClass *Walker = previous->next;
48 previous->next = this;
49 next = Walker;
50 } else {
51 next = NULL;
52 }
53};
54
55/** Destructor for MoleculeLeafClass.
56 */
57MoleculeLeafClass::~MoleculeLeafClass()
58{
59 // if (DownLeaf != NULL) {// drop leaves further down
60 // MoleculeLeafClass *Walker = DownLeaf;
61 // MoleculeLeafClass *Next;
62 // do {
63 // Next = Walker->NextLeaf;
64 // delete(Walker);
65 // Walker = Next;
66 // } while (Walker != NULL);
67 // // Last Walker sets DownLeaf automatically to NULL
68 // }
69 // remove the leaf itself
70 if (Leaf != NULL) {
71 Leaf->removeAtomsinMolecule();
72 World::getInstance().destroyMolecule(Leaf);
73 Leaf = NULL;
74 }
75 // remove this Leaf from level list
76 if (previous != NULL)
77 previous->next = next;
78 // } else { // we are first in list (connects to UpLeaf->DownLeaf)
79 // if ((NextLeaf != NULL) && (NextLeaf->UpLeaf == NULL))
80 // NextLeaf->UpLeaf = UpLeaf; // either null as we are top level or the upleaf of the first node
81 // if (UpLeaf != NULL)
82 // UpLeaf->DownLeaf = NextLeaf; // either null as we are only leaf or NextLeaf if we are just the first
83 // }
84 // UpLeaf = NULL;
85 if (next != NULL) // are we last in list
86 next->previous = previous;
87 next = NULL;
88 previous = NULL;
89};
90
91/** Adds \a molecule leaf to the tree.
92 * \param *ptr ptr to molecule to be added
93 * \param *Previous previous MoleculeLeafClass referencing level and which on the level
94 * \return true - success, false - something went wrong
95 */
96bool MoleculeLeafClass::AddLeaf(molecule *ptr, MoleculeLeafClass *Previous)
97{
98 return false;
99};
100
101/** Fills the root stack for sites to be used as root in fragmentation depending on order or adaptivity criteria
102 * Again, as in \sa FillBondStructureFromReference steps recursively through each Leaf in this chain list of molecule's.
103 * \param *out output stream for debugging
104 * \param *&RootStack stack to be filled
105 * \param *AtomMask defines true/false per global Atom::Nr to mask in/out each nuclear site
106 * \param &FragmentCounter counts through the fragments in this MoleculeLeafClass
[07a47e]107 * \param saturation whether to treat hydrogen special or not
[d3abb1]108 * \return true - stack is non-empty, fragmentation necessary, false - stack is empty, no more sites to update
109 */
[07a47e]110bool MoleculeLeafClass::FillRootStackForSubgraphs(KeyStack *&RootStack, bool *AtomMask, int &FragmentCounter, const enum HydrogenSaturation saturation)
[d3abb1]111{
112 atom *Father = NULL;
113
114 if (RootStack != NULL) {
115 // find first root candidates
116 if (&(RootStack[FragmentCounter]) != NULL) {
117 RootStack[FragmentCounter].clear();
118 for(molecule::const_iterator iter = Leaf->begin(); iter != Leaf->end(); ++iter) {
119 Father = (*iter)->GetTrueFather();
120 if (AtomMask[Father->getNr()]) // apply mask
[07a47e]121 if ((saturation == DontSaturate) || ((*iter)->getType()->getAtomicNumber() != 1)) // skip hydrogen
122 RootStack[FragmentCounter].push_front((*iter)->getNr());
[d3abb1]123 }
124 if (next != NULL)
[07a47e]125 next->FillRootStackForSubgraphs(RootStack, AtomMask, ++FragmentCounter, saturation);
[d3abb1]126 } else {
[47d041]127 LOG(1, "Rootstack[" << FragmentCounter << "] is NULL.");
[d3abb1]128 return false;
129 }
130 FragmentCounter--;
131 return true;
132 } else {
[47d041]133 LOG(1, "Rootstack is NULL.");
[d3abb1]134 return false;
135 }
136};
137
138/** The indices per keyset are compared to the respective father's Atom::Nr in each subgraph and thus put into \a **&FragmentList.
139 * \param *out output stream fro debugging
140 * \param *reference reference molecule with the bond structure to be copied
141 * \param *KeySetList list with all keysets
142 * \param ***ListOfLocalAtoms Lookup table for each subgraph and index of each atom in global molecule, may be NULL on start, then it is filled
143 * \param **&FragmentList list to be allocated and returned
144 * \param &FragmentCounter counts the fragments as we move along the list
145 * \param FreeList true - ***ListOfLocalAtoms is free'd before return, false - it is not
146 * \retuen true - success, false - failure
147 */
148bool MoleculeLeafClass::AssignKeySetsToFragment(molecule *reference, Graph *KeySetList, atom ***&ListOfLocalAtoms, Graph **&FragmentList, int &FragmentCounter, bool FreeList)
149{
150 bool status = true;
151 int KeySetCounter = 0;
152
[47d041]153 LOG(1, "Begin of AssignKeySetsToFragment.");
[d3abb1]154 // fill ListOfLocalAtoms if NULL was given
155 if (!Leaf->FillListOfLocalAtoms(ListOfLocalAtoms[FragmentCounter], reference->getAtomCount())) {
[47d041]156 LOG(1, "Filling of ListOfLocalAtoms failed.");
[d3abb1]157 return false;
158 }
159
160 // allocate fragment list
161 if (FragmentList == NULL) {
162 KeySetCounter = Count();
163 FragmentList = new Graph*[KeySetCounter];
164 for (int i=0;i<KeySetCounter;i++)
165 FragmentList[i] = NULL;
166 KeySetCounter = 0;
167 }
168
169 if ((KeySetList != NULL) && (KeySetList->size() != 0)) { // if there are some scanned keysets at all
170 // assign scanned keysets
171 if (FragmentList[FragmentCounter] == NULL)
172 FragmentList[FragmentCounter] = new Graph;
173 KeySet *TempSet = new KeySet;
174 for (Graph::iterator runner = KeySetList->begin(); runner != KeySetList->end(); runner++) { // key sets contain global numbers!
175 if (ListOfLocalAtoms[FragmentCounter][reference->FindAtom(*((*runner).first.begin()))->getNr()] != NULL) {// as we may assume that that bond structure is unchanged, we only test the first key in each set
176 // translate keyset to local numbers
177 for (KeySet::iterator sprinter = (*runner).first.begin(); sprinter != (*runner).first.end(); sprinter++)
178 TempSet->insert(ListOfLocalAtoms[FragmentCounter][reference->FindAtom(*sprinter)->getNr()]->getNr());
179 // insert into FragmentList
180 FragmentList[FragmentCounter]->insert(GraphPair(*TempSet, pair<int, double> (KeySetCounter++, (*runner).second.second)));
181 }
182 TempSet->clear();
183 }
184 delete (TempSet);
185 if (KeySetCounter == 0) {// if there are no keysets, delete the list
[47d041]186 LOG(1, "KeySetCounter is zero, deleting FragmentList.");
[d3abb1]187 delete (FragmentList[FragmentCounter]);
188 } else
[47d041]189 LOG(1, KeySetCounter << " keysets were assigned to subgraph " << FragmentCounter << ".");
[d3abb1]190 FragmentCounter++;
191 if (next != NULL)
192 next->AssignKeySetsToFragment(reference, KeySetList, ListOfLocalAtoms, FragmentList, FragmentCounter, FreeList);
193 FragmentCounter--;
194 } else
[47d041]195 LOG(1, "KeySetList is NULL or empty.");
[d3abb1]196
197 if ((FreeList) && (ListOfLocalAtoms != NULL)) {
198 // free the index lookup list
199 delete[](ListOfLocalAtoms[FragmentCounter]);
200 }
[47d041]201 LOG(1, "End of AssignKeySetsToFragment.");
[d3abb1]202 return status;
203};
204
205/** Translate list into global numbers (i.e. ones that are valid in "this" molecule, not in MolecularWalker->Leaf)
206 * \param *out output stream for debugging
207 * \param **FragmentList Graph with local numbers per fragment
208 * \param &FragmentCounter counts the fragments as we move along the list
209 * \param &TotalNumberOfKeySets global key set counter
210 * \param &TotalGraph Graph to be filled with global numbers
211 */
212void MoleculeLeafClass::TranslateIndicesToGlobalIDs(Graph **FragmentList, int &FragmentCounter, int &TotalNumberOfKeySets, Graph &TotalGraph)
213{
[47d041]214 LOG(1, "Begin of TranslateIndicesToGlobalIDs.");
[d3abb1]215 KeySet *TempSet = new KeySet;
216 if (FragmentList[FragmentCounter] != NULL) {
217 for (Graph::iterator runner = FragmentList[FragmentCounter]->begin(); runner != FragmentList[FragmentCounter]->end(); runner++) {
218 for (KeySet::iterator sprinter = (*runner).first.begin(); sprinter != (*runner).first.end(); sprinter++)
219 TempSet->insert((Leaf->FindAtom(*sprinter))->GetTrueFather()->getNr());
220 TotalGraph.insert(GraphPair(*TempSet, pair<int, double> (TotalNumberOfKeySets++, (*runner).second.second)));
221 TempSet->clear();
222 }
223 delete (TempSet);
224 } else {
[47d041]225 LOG(1, "FragmentList is NULL.");
[d3abb1]226 }
227 if (next != NULL)
228 next->TranslateIndicesToGlobalIDs(FragmentList, ++FragmentCounter, TotalNumberOfKeySets, TotalGraph);
229 FragmentCounter--;
[47d041]230 LOG(1, "End of TranslateIndicesToGlobalIDs.");
[d3abb1]231};
232
233/** Simply counts the number of items in the list, from given MoleculeLeafClass.
234 * \return number of items
235 */
236int MoleculeLeafClass::Count() const
237{
238 if (next != NULL)
239 return next->Count() + 1;
240 else
241 return 1;
242};
243
Note: See TracBrowser for help on using the repository browser.