source: src/Actions/FragmentationAction/CreateAdjacencyAction.cpp@ 300220

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

BondGraph::..MinMaxDistance() changed to use range<double>.

  • Property mode set to 100644
File size: 8.5 KB
Line 
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 * CreateAdjacencyAction.cpp
10 *
11 * Created on: May 9, 2010
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 "Descriptors/AtomIdDescriptor.hpp"
23#include "Descriptors/MoleculeDescriptor.hpp"
24
25#include "atom.hpp"
26#include "bond.hpp"
27#include "bondgraph.hpp"
28#include "CodePatterns/Log.hpp"
29#include "CodePatterns/Range.hpp"
30#include "CodePatterns/Verbose.hpp"
31#include "config.hpp"
32#include "linkedcell.hpp"
33#include "molecule.hpp"
34#include "PointCloudAdaptor.hpp"
35#include "World.hpp"
36#include "WorldTime.hpp"
37
38#include <iostream>
39#include <list>
40#include <string>
41
42typedef std::map< moleculeId_t, std::vector<atomId_t> > MolAtomList;
43
44using namespace std;
45
46#include "Actions/FragmentationAction/CreateAdjacencyAction.hpp"
47
48// and construct the stuff
49#include "CreateAdjacencyAction.def"
50#include "Action_impl_pre.hpp"
51/** =========== define the function ====================== */
52Action::state_ptr FragmentationCreateAdjacencyAction::performCall() {
53 // obtain information
54 getParametersfromValueStorage();
55
56 DoLog(1) && (Log() << Verbose(1) << "Constructing bond graph for selected atoms ... " << endl);
57
58 config *configuration = World::getInstance().getConfig();
59 BondGraph *BG = World::getInstance().getBondGraph();
60 ASSERT(BG != NULL, "FragmentationCreateAdjacencyAction: BondGraph is NULL.");
61 BG->SetMaxDistanceToMaxOfCovalentRadii(AtomSetMixin<std::vector<atom *> >(World::getInstance().getSelectedAtoms()));
62 double BondDistance = BG->getMaxDistance();
63 bool IsAngstroem = configuration->GetIsAngstroem();
64
65 atom *Walker = NULL;
66 atom *OtherWalker = NULL;
67 int n[NDIM];
68 LinkedCell *LC = NULL;
69 Box &domain = World::getInstance().getDomain();
70
71 // remove every bond from the selected atoms' list
72 int AtomCount = 0;
73 for (World::AtomSelectionIterator AtomRunner = World::getInstance().beginAtomSelection();
74 AtomRunner != World::getInstance().endAtomSelection();
75 ++AtomRunner) {
76 AtomCount++;
77 BondList& ListOfBonds = (AtomRunner->second)->getListOfBonds();
78 for(BondList::iterator BondRunner = ListOfBonds.begin();
79 !ListOfBonds.empty();
80 BondRunner = ListOfBonds.begin())
81 if ((*BondRunner)->leftatom == AtomRunner->second)
82 delete((*BondRunner));
83 }
84 int BondCount = 0;
85
86 // count atoms in molecule = dimension of matrix (also give each unique name and continuous numbering)
87 DoLog(1) && (Log() << Verbose(1) << "AtomCount " << AtomCount << " and bonddistance is " << BondDistance << "." << endl);
88
89 if ((AtomCount > 1) && (BondDistance > 1.)) {
90 DoLog(2) && (Log() << Verbose(2) << "Creating Linked Cell structure ... " << endl);
91 TesselPointSTLList list;
92 for (World::AtomSelectionIterator AtomRunner = World::getInstance().beginAtomSelection();
93 AtomRunner != World::getInstance().endAtomSelection();
94 ++AtomRunner) {
95 list.push_back(AtomRunner->second);
96 }
97 PointCloudAdaptor< TesselPointSTLList > cloud(&list, "AtomSelection");
98 LC = new LinkedCell(cloud, BondDistance);
99
100 // create a list to map Tesselpoint::Nr to atom *
101 DoLog(2) && (Log() << Verbose(2) << "Creating TesselPoint to atom map ... " << endl);
102
103 // set numbers for atoms that can later be used
104 std::map<TesselPoint *, int> AtomIds;
105 int i=0;
106 for (World::AtomSelectionIterator AtomRunner = World::getInstance().beginAtomSelection();
107 AtomRunner != World::getInstance().endAtomSelection();
108 ++AtomRunner) {
109 AtomIds.insert(pair<TesselPoint *, int> (AtomRunner->second, i++) );
110 }
111
112 // 3a. go through every cell
113 DoLog(2) && (Log() << Verbose(2) << "Celling ... " << endl);
114 for (LC->n[0] = 0; LC->n[0] < LC->N[0]; LC->n[0]++)
115 for (LC->n[1] = 0; LC->n[1] < LC->N[1]; LC->n[1]++)
116 for (LC->n[2] = 0; LC->n[2] < LC->N[2]; LC->n[2]++) {
117 const TesselPointSTLList *List = LC->GetCurrentCell();
118// Log() << Verbose(2) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << " containing " << List->size() << " points." << endl;
119 if (List != NULL) {
120 for (TesselPointSTLList::const_iterator Runner = List->begin();
121 Runner != List->end();
122 Runner++) {
123 Walker = dynamic_cast<atom*>(*Runner);
124 ASSERT(Walker,"Tesselpoint that was not an atom retrieved from LinkedNode");
125 //Log() << Verbose(0) << "Current Atom is " << *Walker << "." << endl;
126 // 3c. check for possible bond between each atom in this and every one in the 27 cells
127 for (n[0] = -1; n[0] <= 1; n[0]++)
128 for (n[1] = -1; n[1] <= 1; n[1]++)
129 for (n[2] = -1; n[2] <= 1; n[2]++) {
130 const TesselPointSTLList *OtherList = LC->GetRelativeToCurrentCell(n);
131// Log() << Verbose(2) << "Current relative cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << " containing " << List->size() << " points." << endl;
132 if (OtherList != NULL) {
133 for (TesselPointSTLList::const_iterator OtherRunner = OtherList->begin(); OtherRunner != OtherList->end(); OtherRunner++) {
134 if (AtomIds.find(*OtherRunner)->second > AtomIds.find(Walker)->second) {
135 OtherWalker = dynamic_cast<atom*>(*OtherRunner);
136 ASSERT(OtherWalker,"TesselPoint that was not an atom retrieved from LinkedNode");
137 //Log() << Verbose(1) << "Checking distance " << OtherWalker->x.PeriodicDistanceSquared(&(Walker->x), cell_size) << " against typical bond length of " << bonddistance*bonddistance << "." << endl;
138 range<double> MinMaxDistanceSquared(0.,0.);
139 BG->getMinMaxDistanceSquared(Walker, OtherWalker, MinMaxDistanceSquared, IsAngstroem);
140 const double distance = domain.periodicDistanceSquared(OtherWalker->getPosition(),Walker->getPosition());
141 const bool status = MinMaxDistanceSquared.isInRange(distance);
142// LOG3, "INFO: MinMaxDistanceSquared interval is " << MinMaxDistanceSquared << ".");
143 if (AtomIds[OtherWalker->father] > AtomIds[Walker->father]) {
144 if (status) { // create bond if distance is smaller
145// Log() << Verbose(1) << "Adding Bond between " << *Walker << " and " << *OtherWalker << " in distance " << sqrt(distance) << "." << endl;
146 bond * const Binder = new bond(Walker->father, OtherWalker->father, 1, BondCount++);
147 Walker->father->RegisterBond(WorldTime::getTime(),Binder);
148 OtherWalker->father->RegisterBond(WorldTime::getTime(),Binder);
149 } else {
150// Log() << Verbose(1) << "Not Adding: distance too great." << endl;
151 }
152 } else {
153// Log() << Verbose(1) << "Not Adding: Wrong order of labels." << endl;
154 }
155 }
156 }
157 }
158 }
159 }
160 }
161 }
162 delete (LC);
163 DoLog(1) && (Log() << Verbose(1) << "I detected " << BondCount << " bonds in the molecule with distance " << BondDistance << "." << endl);
164
165 // correct bond degree by comparing valence and bond degree
166 DoLog(2) && (Log() << Verbose(2) << "Correcting bond degree ... " << endl);
167 //CorrectBondDegree();
168
169 } else
170 DoLog(1) && (Log() << Verbose(1) << "AtomCount is " << AtomCount << ", thus no bonds, no connections!." << endl);
171 DoLog(0) && (Log() << Verbose(0) << "End of CreateAdjacencyList." << endl);
172
173 return Action::success;
174}
175
176Action::state_ptr FragmentationCreateAdjacencyAction::performUndo(Action::state_ptr _state) {
177// FragmentationCreateAdjacencyState *state = assert_cast<FragmentationCreateAdjacencyState*>(_state.get());
178
179 return Action::success;
180}
181
182Action::state_ptr FragmentationCreateAdjacencyAction::performRedo(Action::state_ptr _state){
183 return Action::success;
184}
185
186bool FragmentationCreateAdjacencyAction::canUndo() {
187 return false;
188}
189
190bool FragmentationCreateAdjacencyAction::shouldUndo() {
191 return false;
192}
193/** =========== end of function ====================== */
Note: See TracBrowser for help on using the repository browser.