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

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 v1.3.14
Last change on this file since a676f9 was ac9ca4, checked in by Frederik Heber <heber@…>, 12 years ago

FragmentAction creates FragmentJobs if no output-types are given.

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