source: src/Fragmentation/Exporters/ExportGraph.cpp@ a7aebd

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

World removes empty molecules.

  • on destroyAtom() of molecule's last atom, destroyMolecule() is called.
  • FIX: destroyMolecule(molecule *) did use OBSERVE unncessarily. This caused seg'fault.
  • extracted removeAtomsinMolecule from molecule class. This is necessary since World will automatically remove empty molecules.
  • Property mode set to 100644
File size: 9.8 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2011 University of Bonn. All rights reserved.
5 * Copyright (C) 2013 Frederik Heber. All rights reserved.
6 *
7 *
8 * This file is part of MoleCuilder.
9 *
10 * MoleCuilder is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * MoleCuilder is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24/*
25 * ExportGraph.cpp
26 *
27 * Created on: 08.03.2012
28 * Author: heber
29 */
30
31// include config.h
32#ifdef HAVE_CONFIG_H
33#include <config.h>
34#endif
35
36#include "CodePatterns/MemDebug.hpp"
37
38#include "ExportGraph.hpp"
39
40#include "CodePatterns/Info.hpp"
41#include "CodePatterns/Log.hpp"
42
43#include "Bond/bond.hpp"
44#include "Element/element.hpp"
45#include "Fragmentation/Graph.hpp"
46#include "Fragmentation/KeySet.hpp"
47#include "Fragmentation/SortIndex.hpp"
48#include "Graph/ListOfLocalAtoms.hpp"
49#include "molecule.hpp"
50#include "MoleculeListClass.hpp"
51#include "World.hpp"
52
53/** Constructor for class ExportGraph.
54 *
55 * @param _graph
56 */
57ExportGraph::ExportGraph(
58 const Graph &_graph,
59 const enum HydrogenTreatment _treatment,
60 const enum HydrogenSaturation _saturation,
61 const SaturatedFragment::GlobalSaturationPositions_t &_globalsaturationpositions) :
62 TotalGraph(_graph),
63 BondFragments(World::getPointer()),
64 treatment(_treatment),
65 saturation(_saturation),
66 globalsaturationpositions(_globalsaturationpositions),
67 CurrentKeySet(TotalGraph.begin())
68{
69}
70
71/** Destructor for class ExportGraph.
72 *
73 */
74ExportGraph::~ExportGraph()
75{
76 // remove all create molecules again from the World including their atoms
77 for (MoleculeList::iterator iter = BondFragments.ListOfMolecules.begin();
78 !BondFragments.ListOfMolecules.empty();
79 iter = BondFragments.ListOfMolecules.begin()) {
80 // remove copied atoms and molecule again
81 molecule *mol = *iter;
82 BondFragments.ListOfMolecules.erase(iter);
83 removeAtomsinMolecule(mol);
84 }
85}
86
87void ExportGraph::reset()
88{
89 CurrentKeySet = TotalGraph.begin();
90}
91
92ExportGraph::SaturatedFragment_ptr ExportGraph::getNextFragment()
93{
94 // if a fragment is still leased, return zero ptr.
95 if (!KeySetsInUse.empty()) {
96 ELOG(1, "Leasing KeySet while old one is not returned.");
97 return SaturatedFragment_ptr();
98 }
99
100 // else return current fragment or indicate end
101 if (CurrentKeySet != TotalGraph.end()) {
102 const KeySet &set = (CurrentKeySet++)->first;
103 return leaseFragment(set);
104 } else {
105 return leaseFragment(EmptySet);
106 }
107}
108
109ExportGraph::SaturatedFragment_ptr ExportGraph::leaseFragment(const KeySet &_set)
110{
111 // create the saturation which adds itself to KeySetsInUse
112 SaturatedFragment_ptr _ptr(
113 new SaturatedFragment(
114 _set,
115 KeySetsInUse,
116 hydrogens,
117 treatment,
118 saturation,
119 globalsaturationpositions)
120 );
121 // and return
122 return _ptr;
123}
124
125void ExportGraph::releaseFragment(SaturatedFragment_ptr &_ptr)
126{
127 ASSERT(_ptr != NULL,
128 "ExportGraph::releaseFragment() - pointer is NULL.");
129 SaturatedFragment::KeySetsInUse_t::iterator iter = KeySetsInUse.find(_ptr->getKeySet());
130 if (iter == KeySetsInUse.end()) {
131 ASSERT(0,
132 "ExportGraph::releaseFragment() - returning unknown set "
133 +toString(_ptr->getKeySet())+".");
134 return;
135 } else {
136 // release instance which removes itself in KeySetsInUse
137 _ptr.reset();
138 }
139}
140
141///** Internal helper to create from each keyset a molecule
142// *
143// */
144//void ExportGraph::prepareMolecule()
145//{
146// size_t count = 0;
147// for(Graph::const_iterator runner = TotalGraph.begin(); runner != TotalGraph.end(); runner++) {
148// KeySet test = (*runner).first;
149// LOG(2, "DEBUG: Fragment No." << (*runner).second.first << " with TEFactor "
150// << (*runner).second.second << ".");
151// BondFragments.insert(StoreFragmentFromKeySet(test, World::getInstance().getConfig()));
152// ++count;
153// }
154// LOG(1, "INFO: " << count << "/" << BondFragments.ListOfMolecules.size()
155// << " fragments generated from the keysets.");
156//}
157//
158///** Stores a fragment from \a KeySet into \a molecule.
159// * First creates the minimal set of atoms from the KeySet, then creates the bond structure from the complete
160// * molecule and adds missing hydrogen where bonds were cut.
161// * \param &Leaflet pointer to KeySet structure
162// * \param IsAngstroem whether we have Ansgtroem or bohrradius
163// * \return pointer to constructed molecule
164// */
165//molecule * ExportGraph::StoreFragmentFromKeySet(KeySet &Leaflet, bool IsAngstroem)
166//{
167// Info info(__func__);
168// ListOfLocalAtoms_t SonList;
169// molecule *Leaf = World::getInstance().createMolecule();
170//
171// StoreFragmentFromKeySet_Init(Leaf, Leaflet, SonList);
172// // create the bonds between all: Make it an induced subgraph and add hydrogen
173//// LOG(2, "Creating bonds from father graph (i.e. induced subgraph creation).");
174// CreateInducedSubgraphOfFragment(Leaf, SonList, IsAngstroem);
175//
176// //Leaflet->Leaf->ScanForPeriodicCorrection(out);
177// return Leaf;
178//}
179//
180///** Initializes some value for putting fragment of \a *mol into \a *Leaf.
181// * \param *Leaf fragment molecule
182// * \param &Leaflet pointer to KeySet structure
183// * \param SonList calloc'd list which atom of \a *Leaf is a son of which atom in \a *mol
184// * \return number of atoms in fragment
185// */
186//int ExportGraph::StoreFragmentFromKeySet_Init(molecule *Leaf, KeySet &Leaflet, ListOfLocalAtoms_t &SonList)
187//{
188// atom *FatherOfRunner = NULL;
189//
190// // first create the minimal set of atoms from the KeySet
191// World &world = World::getInstance();
192// int size = 0;
193// for(KeySet::const_iterator runner = Leaflet.begin(); runner != Leaflet.end(); runner++) {
194// FatherOfRunner = world.getAtom(AtomById(*runner)); // find the id
195// SonList.insert( std::make_pair(FatherOfRunner->getNr(), Leaf->AddCopyAtom(FatherOfRunner) ) );
196// size++;
197// }
198// return size;
199//}
200//
201///** Creates an induced subgraph out of a fragmental key set, adding bonds and hydrogens (if treated specially).
202// * \param *Leaf fragment molecule
203// * \param IsAngstroem whether we have Ansgtroem or bohrradius
204// * \param SonList list which atom of \a *Leaf is another atom's son
205// */
206//void ExportGraph::CreateInducedSubgraphOfFragment(molecule *Leaf, ListOfLocalAtoms_t &SonList, bool IsAngstroem)
207//{
208// bool LonelyFlag = false;
209// atom *OtherFather = NULL;
210// atom *FatherOfRunner = NULL;
211//
212// // we increment the iter just before skipping the hydrogen
213// // as we use AddBond, we cannot have a const_iterator here
214// for (molecule::iterator iter = Leaf->begin(); iter != Leaf->end();) {
215// LonelyFlag = true;
216// FatherOfRunner = (*iter)->father;
217// ASSERT(FatherOfRunner,"Atom without father found");
218// if (SonList.find(FatherOfRunner->getNr()) != SonList.end()) { // check if this, our father, is present in list
219// // create all bonds
220// const BondList& ListOfBonds = FatherOfRunner->getListOfBonds();
221// for (BondList::const_iterator BondRunner = ListOfBonds.begin();
222// BondRunner != ListOfBonds.end();
223// ++BondRunner) {
224// OtherFather = (*BondRunner)->GetOtherAtom(FatherOfRunner);
225// if (SonList.find(OtherFather->getNr()) != SonList.end()) {
226//// LOG(2, "INFO: Father " << *FatherOfRunner << " of son " << *SonList[FatherOfRunner->getNr()]
227//// << " is bound to " << *OtherFather << ", whose son is "
228//// << *SonList[OtherFather->getNr()] << ".");
229// if (OtherFather->getNr() > FatherOfRunner->getNr()) { // add bond (Nr check is for adding only one of both variants: ab, ba)
230// std::stringstream output;
231//// output << "ACCEPT: Adding Bond: "
232// output << Leaf->AddBond((*iter), SonList[OtherFather->getNr()], (*BondRunner)->getDegree());
233//// LOG(3, output.str());
234// //NumBonds[(*iter)->getNr()]++;
235// } else {
236//// LOG(3, "REJECY: Not adding bond, labels in wrong order.");
237// }
238// LonelyFlag = false;
239// } else {
240//// LOG(2, "INFO: Father " << *FatherOfRunner << " of son " << *SonList[FatherOfRunner->getNr()]
241//// << " is bound to " << *OtherFather << ", who has no son in this fragment molecule.");
242// if (saturation == DoSaturate) {
243//// LOG(3, "ACCEPT: Adding Hydrogen to " << (*iter)->Name << " and a bond in between.");
244// if (!Leaf->AddHydrogenReplacementAtom((*BondRunner), (*iter), FatherOfRunner, OtherFather, IsAngstroem))
245// exit(1);
246// } else if ((treatment == ExcludeHydrogen) && (OtherFather->getElementNo() == (atomicNumber_t)1)) {
247// // just copy the atom if it's a hydrogen
248// atom * const OtherWalker = Leaf->AddCopyAtom(OtherFather);
249// Leaf->AddBond((*iter), OtherWalker, (*BondRunner)->getDegree());
250// }
251// //NumBonds[(*iter)->getNr()] += Binder->getDegree();
252// }
253// }
254// } else {
255// ELOG(1, "Son " << (*iter)->getName() << " has father " << FatherOfRunner->getName() << " but its entry in SonList is " << SonList[FatherOfRunner->getNr()] << "!");
256// }
257// if ((LonelyFlag) && (Leaf->getAtomCount() > 1)) {
258// LOG(0, **iter << "has got bonds only to hydrogens!");
259// }
260// ++iter;
261// if (saturation == DoSaturate) {
262// while ((iter != Leaf->end()) && ((*iter)->getType()->getAtomicNumber() == 1)){ // skip added hydrogen
263// iter++;
264// }
265// }
266// }
267//}
Note: See TracBrowser for help on using the repository browser.