source: src/Fragmentation/Interfragmenter.cpp@ d1831e

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

atom::getMolecule() now returns ptr to const molecule.

  • changed some places where getMolecule() was used. Most of them required only const access anyway. World is allowed to const'cast the constness away as it commands over molecules anyway.
  • Property mode set to 100644
File size: 6.9 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2013 Frederik Heber. 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 * Interfragmenter.cpp
25 *
26 * Created on: Jul 5, 2013
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 "Interfragmenter.hpp"
38
39#include <list>
40#include <map>
41
42#include "CodePatterns/Assert.hpp"
43#include "CodePatterns/Log.hpp"
44
45#include "LinearAlgebra/Vector.hpp"
46
47#include "AtomIdSet.hpp"
48#include "Element/element.hpp"
49#include "Fragmentation/Graph.hpp"
50#include "Fragmentation/KeySet.hpp"
51#include "LinkedCell/LinkedCell_View.hpp"
52#include "LinkedCell/types.hpp"
53#include "World.hpp"
54
55void Interfragmenter::operator()(
56 size_t MaxOrder,
57 double Rcut,
58 const enum HydrogenTreatment treatment)
59{
60 /// create a map of atom to keyset (below equal MaxOrder)
61 typedef std::list<const KeySet *> keysets_t;
62 typedef std::map<const atom *, keysets_t > atomkeyset_t;
63 atomkeyset_t atomkeyset;
64 LOG(1, "INFO: Placing all atoms and their keysets into a map.");
65 for (Graph::const_iterator keysetiter = TotalGraph.begin();
66 keysetiter != TotalGraph.end(); ++keysetiter) {
67 const KeySet &keyset = keysetiter->first;
68 LOG(2, "DEBUG: Current keyset is " << keyset);
69 const AtomIdSet atoms(keyset);
70 const size_t atoms_size = atoms.getAtomIds().size();
71 if ((atoms_size > MaxOrder) || (atoms_size == 0))
72 continue;
73 for (AtomIdSet::const_iterator atomiter = atoms.begin();
74 atomiter != atoms.end(); ++atomiter) {
75 // either create new list ...
76 std::pair<atomkeyset_t::iterator, bool> inserter =
77 atomkeyset.insert( std::make_pair(*atomiter, keysets_t(1, &keyset) ));
78 // ... or push to end
79 if (inserter.second) {
80 LOG(3, "DEBUG: Created new entry in map.");
81 } else {
82 LOG(3, "DEBUG: Added keyset to present entry.");
83 inserter.first->second.push_back(&keyset);
84 }
85 }
86 }
87 LOG(2, "DEBUG: There are " << atomkeyset.size() << " entries in lookup.");
88
89 Graph InterFragments;
90 int counter = TotalGraph.size();
91
92 /// go through all fragments up to MaxOrder
93 LOG(1, "INFO: Creating inter-fragments.");
94 for (Graph::const_iterator keysetiter = TotalGraph.begin();
95 keysetiter != TotalGraph.end(); ++keysetiter) {
96 const KeySet &keyset = keysetiter->first;
97 LOG(2, "DEBUG: Current keyset is " << keyset);
98 const AtomIdSet atoms(keyset);
99 const size_t atoms_size = atoms.getAtomIds().size();
100 if ((atoms_size > MaxOrder) || (atoms_size == 0))
101 continue;
102
103 /// go through linked cell and get all neighboring atoms up to Rcut
104 Vector center;
105 const molecule *_mol = (*atoms.begin())->getMolecule();
106 for (AtomIdSet::const_iterator iter = atoms.begin();
107 iter != atoms.end(); ++iter) {
108 center += (*iter)->getPosition();
109 ASSERT ( _mol == (*iter)->getMolecule(),
110 "Interfragmenter::operator() - ids in same keyset belong to different molecule.");
111 }
112 center *= 1./(double)atoms_size;
113 LinkedCell::LinkedCell_View view = World::getInstance().getLinkedCell(Rcut);
114 LinkedCell::LinkedList neighbors = view.getAllNeighbors(Rcut, center);
115 LOG(4, "DEBUG: Obtained " << neighbors.size() << " neighbors in distance of "
116 << Rcut << " around " << center << ".");
117
118 /// remove all atoms that belong to same molecule as does one of the
119 /// fragment's atoms
120 typedef std::vector<const atom *> candidates_t;
121 candidates_t candidates;
122 candidates.reserve(neighbors.size());
123 for (LinkedCell::LinkedList::const_iterator iter = neighbors.begin();
124 iter != neighbors.end(); ++iter) {
125 const atom * const _atom = static_cast<const atom * const >(*iter);
126 ASSERT( _atom != NULL,
127 "Interfragmenter::operator() - a neighbor is not actually an atom?");
128 if ((_atom->getMolecule() != _mol)
129 && (_atom->getPosition().DistanceSquared(center) < Rcut*Rcut)
130 && ((treatment == IncludeHydrogen) || (_atom->getType()->getAtomicNumber() != 1))) {
131 candidates.push_back(_atom);
132 }
133 }
134 LOG(3, "DEBUG: There remain " << candidates.size() << " candidates.");
135
136 // create a lookup specific to this fragment
137 atomkeyset_t fragmentmap;
138 for (candidates_t::const_iterator candidateiter = candidates.begin();
139 candidateiter != candidates.end(); ++candidateiter) {
140 const atom * _atom = *candidateiter;
141 atomkeyset_t::const_iterator iter = atomkeyset.find(_atom);
142 ASSERT( iter != atomkeyset.end(),
143 "Interfragmenter::operator() - could not find atom "
144 +toString(_atom->getId())+" in lookup.");
145 fragmentmap.insert( std::make_pair( _atom, iter->second) );
146 }
147 LOG(4, "DEBUG: Copied part of lookup map contains " << fragmentmap.size() << " keys.");
148
149 /// combine each remaining fragment with current fragment to a new fragment
150 /// if keyset is less
151 for (candidates_t::const_iterator candidateiter = candidates.begin();
152 candidateiter != candidates.end(); ++candidateiter) {
153 const atom *_atom = *candidateiter;
154 LOG(3, "DEBUG: Current candidate is " << *_atom << ".");
155 atomkeyset_t::iterator finditer = fragmentmap.find(_atom);
156 ASSERT( finditer != fragmentmap.end(),
157 "Interfragmenter::operator() - could not find atom "
158 +toString(_atom->getId())+" in fragment specific lookup.");
159 keysets_t &othersets = finditer->second;
160 keysets_t::iterator otheriter = othersets.begin();
161 while (otheriter != othersets.end()) {
162 const KeySet &otherset = **otheriter;
163 LOG(3, "DEBUG: Current keyset is " << otherset << ".");
164 // only add them one way round and not the other
165 if (otherset < keyset) {
166 ++otheriter;
167 continue;
168 }
169 KeySet newset(otherset);
170 newset.insert(keyset.begin(), keyset.end());
171 LOG(3, "DEBUG: Inserting new combined set " << newset << ".");
172 InterFragments.insert( std::make_pair(newset, std::make_pair(++counter, 1.)));
173 // finally, remove the set such that no other combination exists
174 otheriter = othersets.erase(otheriter);
175 }
176 }
177 }
178
179 /// eventually, add all new fragments to the Graph
180 counter = TotalGraph.size();
181 TotalGraph.InsertGraph(InterFragments, counter);
182}
Note: See TracBrowser for help on using the repository browser.