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

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

Replaced MoleculeListClass in ExportGraph by vector of molecules.

  • Property mode set to 100644
File size: 9.7 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 treatment(_treatment),
64 saturation(_saturation),
65 globalsaturationpositions(_globalsaturationpositions),
66 CurrentKeySet(TotalGraph.begin())
67{
68}
69
70/** Destructor for class ExportGraph.
71 *
72 */
73ExportGraph::~ExportGraph()
74{
75 // remove all create molecules again from the World including their atoms
76 for (std::vector<molecule *>::iterator iter = BondFragments.begin();
77 !BondFragments.empty();
78 iter = BondFragments.begin()) {
79 // remove copied atoms and molecule again
80 molecule *mol = *iter;
81 BondFragments.erase(iter);
82 removeAtomsinMolecule(mol);
83 }
84}
85
86void ExportGraph::reset()
87{
88 CurrentKeySet = TotalGraph.begin();
89}
90
91ExportGraph::SaturatedFragment_ptr ExportGraph::getNextFragment()
92{
93 // if a fragment is still leased, return zero ptr.
94 if (!KeySetsInUse.empty()) {
95 ELOG(1, "Leasing KeySet while old one is not returned.");
96 return SaturatedFragment_ptr();
97 }
98
99 // else return current fragment or indicate end
100 if (CurrentKeySet != TotalGraph.end()) {
101 const KeySet &set = (CurrentKeySet++)->first;
102 return leaseFragment(set);
103 } else {
104 return leaseFragment(EmptySet);
105 }
106}
107
108ExportGraph::SaturatedFragment_ptr ExportGraph::leaseFragment(const KeySet &_set)
109{
110 // create the saturation which adds itself to KeySetsInUse
111 SaturatedFragment_ptr _ptr(
112 new SaturatedFragment(
113 _set,
114 KeySetsInUse,
115 hydrogens,
116 treatment,
117 saturation,
118 globalsaturationpositions)
119 );
120 // and return
121 return _ptr;
122}
123
124void ExportGraph::releaseFragment(SaturatedFragment_ptr &_ptr)
125{
126 ASSERT(_ptr != NULL,
127 "ExportGraph::releaseFragment() - pointer is NULL.");
128 SaturatedFragment::KeySetsInUse_t::iterator iter = KeySetsInUse.find(_ptr->getKeySet());
129 if (iter == KeySetsInUse.end()) {
130 ASSERT(0,
131 "ExportGraph::releaseFragment() - returning unknown set "
132 +toString(_ptr->getKeySet())+".");
133 return;
134 } else {
135 // release instance which removes itself in KeySetsInUse
136 _ptr.reset();
137 }
138}
139
140///** Internal helper to create from each keyset a molecule
141// *
142// */
143//void ExportGraph::prepareMolecule()
144//{
145// size_t count = 0;
146// for(Graph::const_iterator runner = TotalGraph.begin(); runner != TotalGraph.end(); runner++) {
147// KeySet test = (*runner).first;
148// LOG(2, "DEBUG: Fragment No." << (*runner).second.first << " with TEFactor "
149// << (*runner).second.second << ".");
150// BondFragments.insert(StoreFragmentFromKeySet(test, World::getInstance().getConfig()));
151// ++count;
152// }
153// LOG(1, "INFO: " << count << "/" << BondFragments.ListOfMolecules.size()
154// << " fragments generated from the keysets.");
155//}
156//
157///** Stores a fragment from \a KeySet into \a molecule.
158// * First creates the minimal set of atoms from the KeySet, then creates the bond structure from the complete
159// * molecule and adds missing hydrogen where bonds were cut.
160// * \param &Leaflet pointer to KeySet structure
161// * \param IsAngstroem whether we have Ansgtroem or bohrradius
162// * \return pointer to constructed molecule
163// */
164//molecule * ExportGraph::StoreFragmentFromKeySet(KeySet &Leaflet, bool IsAngstroem)
165//{
166// Info info(__func__);
167// ListOfLocalAtoms_t SonList;
168// molecule *Leaf = World::getInstance().createMolecule();
169//
170// StoreFragmentFromKeySet_Init(Leaf, Leaflet, SonList);
171// // create the bonds between all: Make it an induced subgraph and add hydrogen
172//// LOG(2, "Creating bonds from father graph (i.e. induced subgraph creation).");
173// CreateInducedSubgraphOfFragment(Leaf, SonList, IsAngstroem);
174//
175// //Leaflet->Leaf->ScanForPeriodicCorrection(out);
176// return Leaf;
177//}
178//
179///** Initializes some value for putting fragment of \a *mol into \a *Leaf.
180// * \param *Leaf fragment molecule
181// * \param &Leaflet pointer to KeySet structure
182// * \param SonList calloc'd list which atom of \a *Leaf is a son of which atom in \a *mol
183// * \return number of atoms in fragment
184// */
185//int ExportGraph::StoreFragmentFromKeySet_Init(molecule *Leaf, KeySet &Leaflet, ListOfLocalAtoms_t &SonList)
186//{
187// atom *FatherOfRunner = NULL;
188//
189// // first create the minimal set of atoms from the KeySet
190// World &world = World::getInstance();
191// int size = 0;
192// for(KeySet::const_iterator runner = Leaflet.begin(); runner != Leaflet.end(); runner++) {
193// FatherOfRunner = world.getAtom(AtomById(*runner)); // find the id
194// SonList.insert( std::make_pair(FatherOfRunner->getNr(), Leaf->AddCopyAtom(FatherOfRunner) ) );
195// size++;
196// }
197// return size;
198//}
199//
200///** Creates an induced subgraph out of a fragmental key set, adding bonds and hydrogens (if treated specially).
201// * \param *Leaf fragment molecule
202// * \param IsAngstroem whether we have Ansgtroem or bohrradius
203// * \param SonList list which atom of \a *Leaf is another atom's son
204// */
205//void ExportGraph::CreateInducedSubgraphOfFragment(molecule *Leaf, ListOfLocalAtoms_t &SonList, bool IsAngstroem)
206//{
207// bool LonelyFlag = false;
208// atom *OtherFather = NULL;
209// atom *FatherOfRunner = NULL;
210//
211// // we increment the iter just before skipping the hydrogen
212// // as we use AddBond, we cannot have a const_iterator here
213// for (molecule::iterator iter = Leaf->begin(); iter != Leaf->end();) {
214// LonelyFlag = true;
215// FatherOfRunner = (*iter)->father;
216// ASSERT(FatherOfRunner,"Atom without father found");
217// if (SonList.find(FatherOfRunner->getNr()) != SonList.end()) { // check if this, our father, is present in list
218// // create all bonds
219// const BondList& ListOfBonds = FatherOfRunner->getListOfBonds();
220// for (BondList::const_iterator BondRunner = ListOfBonds.begin();
221// BondRunner != ListOfBonds.end();
222// ++BondRunner) {
223// OtherFather = (*BondRunner)->GetOtherAtom(FatherOfRunner);
224// if (SonList.find(OtherFather->getNr()) != SonList.end()) {
225//// LOG(2, "INFO: Father " << *FatherOfRunner << " of son " << *SonList[FatherOfRunner->getNr()]
226//// << " is bound to " << *OtherFather << ", whose son is "
227//// << *SonList[OtherFather->getNr()] << ".");
228// if (OtherFather->getNr() > FatherOfRunner->getNr()) { // add bond (Nr check is for adding only one of both variants: ab, ba)
229// std::stringstream output;
230//// output << "ACCEPT: Adding Bond: "
231// output << Leaf->AddBond((*iter), SonList[OtherFather->getNr()], (*BondRunner)->getDegree());
232//// LOG(3, output.str());
233// //NumBonds[(*iter)->getNr()]++;
234// } else {
235//// LOG(3, "REJECY: Not adding bond, labels in wrong order.");
236// }
237// LonelyFlag = false;
238// } else {
239//// LOG(2, "INFO: Father " << *FatherOfRunner << " of son " << *SonList[FatherOfRunner->getNr()]
240//// << " is bound to " << *OtherFather << ", who has no son in this fragment molecule.");
241// if (saturation == DoSaturate) {
242//// LOG(3, "ACCEPT: Adding Hydrogen to " << (*iter)->Name << " and a bond in between.");
243// if (!Leaf->AddHydrogenReplacementAtom((*BondRunner), (*iter), FatherOfRunner, OtherFather, IsAngstroem))
244// exit(1);
245// } else if ((treatment == ExcludeHydrogen) && (OtherFather->getElementNo() == (atomicNumber_t)1)) {
246// // just copy the atom if it's a hydrogen
247// atom * const OtherWalker = Leaf->AddCopyAtom(OtherFather);
248// Leaf->AddBond((*iter), OtherWalker, (*BondRunner)->getDegree());
249// }
250// //NumBonds[(*iter)->getNr()] += Binder->getDegree();
251// }
252// }
253// } else {
254// ELOG(1, "Son " << (*iter)->getName() << " has father " << FatherOfRunner->getName() << " but its entry in SonList is " << SonList[FatherOfRunner->getNr()] << "!");
255// }
256// if ((LonelyFlag) && (Leaf->getAtomCount() > 1)) {
257// LOG(0, **iter << "has got bonds only to hydrogens!");
258// }
259// ++iter;
260// if (saturation == DoSaturate) {
261// while ((iter != Leaf->end()) && ((*iter)->getType()->getAtomicNumber() == 1)){ // skip added hydrogen
262// iter++;
263// }
264// }
265// }
266//}
Note: See TracBrowser for help on using the repository browser.