source: src/bondgraph.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: 9.1 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 * bondgraph.cpp
10 *
11 * Created on: Oct 29, 2009
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 <iostream>
23
24#include "atom.hpp"
25#include "bond.hpp"
26#include "bondgraph.hpp"
27#include "Box.hpp"
28#include "element.hpp"
29#include "CodePatterns/Info.hpp"
30#include "CodePatterns/Log.hpp"
31#include "CodePatterns/Range.hpp"
32#include "CodePatterns/Verbose.hpp"
33#include "molecule.hpp"
34#include "parser.hpp"
35#include "periodentafel.hpp"
36#include "LinearAlgebra/Vector.hpp"
37#include "World.hpp"
38#include "WorldTime.hpp"
39
40const double BondGraph::BondThreshold = 0.4; //!< CSD threshold in bond check which is the width of the interval whose center is the sum of the covalent radii
41
42BondGraph::BondGraph(bool IsA) :
43 BondLengthMatrix(NULL),
44 max_distance(0),
45 IsAngstroem(IsA)
46{}
47
48BondGraph::~BondGraph()
49{
50 if (BondLengthMatrix != NULL) {
51 delete(BondLengthMatrix);
52 }
53}
54
55bool BondGraph::LoadBondLengthTable(std::istream &input)
56{
57 Info FunctionInfo(__func__);
58 bool status = true;
59 MatrixContainer *TempContainer = NULL;
60
61 // allocate MatrixContainer
62 if (BondLengthMatrix != NULL) {
63 LOG(1, "MatrixContainer for Bond length already present, removing.");
64 delete(BondLengthMatrix);
65 }
66 TempContainer = new MatrixContainer;
67
68 // parse in matrix
69 if ((input.good()) && (status = TempContainer->ParseMatrix(input, 0, 1, 0))) {
70 LOG(1, "Parsing bond length matrix successful.");
71 } else {
72 DoeLog(1) && (eLog()<< Verbose(1) << "Parsing bond length matrix failed." << endl);
73 status = false;
74 }
75
76 // find greatest distance
77 max_distance=0;
78 if (status) {
79 for(int i=0;i<TempContainer->RowCounter[0];i++)
80 for(int j=i;j<TempContainer->ColumnCounter[0];j++)
81 if (TempContainer->Matrix[0][i][j] > max_distance)
82 max_distance = TempContainer->Matrix[0][i][j];
83 }
84 max_distance += BondThreshold;
85
86 if (status) // set to not NULL only if matrix was parsed
87 BondLengthMatrix = TempContainer;
88 else {
89 BondLengthMatrix = NULL;
90 delete(TempContainer);
91 }
92 return status;
93}
94
95double BondGraph::GetBondLength(
96 int firstZ,
97 int secondZ) const
98{
99 std::cout << "Request for length between " << firstZ << " and " << secondZ << ": ";
100 if (BondLengthMatrix == NULL) {
101 std::cout << "-1." << std::endl;
102 return( -1. );
103 } else {
104 std::cout << BondLengthMatrix->Matrix[0][firstZ][secondZ] << std::endl;
105 return (BondLengthMatrix->Matrix[0][firstZ][secondZ]);
106 }
107}
108
109double BondGraph::getMaxDistance() const
110{
111 return max_distance;
112}
113
114void BondGraph::CovalentMinMaxDistance(
115 const element * const Walker,
116 const element * const OtherWalker,
117 range<double> &MinMaxDistance,
118 bool IsAngstroem) const
119{
120 MinMaxDistance.first = OtherWalker->getCovalentRadius() + Walker->getCovalentRadius();
121 MinMaxDistance.first *= (IsAngstroem) ? 1. : 1. / AtomicLengthToAngstroem;
122 MinMaxDistance.last = MinMaxDistance.first + BondThreshold;
123 MinMaxDistance.first -= BondThreshold;
124}
125
126void BondGraph::BondLengthMatrixMinMaxDistance(
127 const element * const Walker,
128 const element * const OtherWalker,
129 range<double> &MinMaxDistance,
130 bool IsAngstroem) const
131{
132 ASSERT(BondLengthMatrix, "BondGraph::BondLengthMatrixMinMaxDistance() called without NULL BondLengthMatrix.");
133 ASSERT(Walker, "BondGraph::BondLengthMatrixMinMaxDistance() - illegal element given.");
134 ASSERT(OtherWalker, "BondGraph::BondLengthMatrixMinMaxDistance() - illegal other element given.");
135 MinMaxDistance.first = GetBondLength(Walker->getAtomicNumber()-1, OtherWalker->getAtomicNumber()-1);
136 MinMaxDistance.first *= (IsAngstroem) ? 1. : 1. / AtomicLengthToAngstroem;
137 MinMaxDistance.last = MinMaxDistance.first + BondThreshold;
138 MinMaxDistance.first -= BondThreshold;
139}
140
141void BondGraph::getMinMaxDistance(
142 const element * const Walker,
143 const element * const OtherWalker,
144 range<double> &MinMaxDistance,
145 bool IsAngstroem) const
146{
147 if (BondLengthMatrix == NULL) {// safety measure if no matrix has been parsed yet
148 LOG(2, "INFO: Using Covalent radii criterion for [min,max) distances.");
149 CovalentMinMaxDistance(Walker, OtherWalker, MinMaxDistance, IsAngstroem);
150 } else {
151 LOG(2, "INFO: Using Covalent radii criterion for [min,max) distances.");
152 BondLengthMatrixMinMaxDistance(Walker, OtherWalker, MinMaxDistance, IsAngstroem);
153 }
154}
155
156void BondGraph::getMinMaxDistance(
157 const BondedParticle * const Walker,
158 const BondedParticle * const OtherWalker,
159 range<double> &MinMaxDistance,
160 bool IsAngstroem) const
161{
162 getMinMaxDistance(Walker->getType(), OtherWalker->getType(),MinMaxDistance, IsAngstroem);
163}
164
165void BondGraph::getMinMaxDistanceSquared(
166 const BondedParticle * const Walker,
167 const BondedParticle * const OtherWalker,
168 range<double> &MinMaxDistance,
169 bool IsAngstroem) const
170{
171 // use non-squared version
172 getMinMaxDistance(Walker, OtherWalker,MinMaxDistance, IsAngstroem);
173 // and square
174 MinMaxDistance.first *= MinMaxDistance.first;
175 MinMaxDistance.last *= MinMaxDistance.last;
176}
177
178void BondGraph::CreateAdjacency(LinkedCell &LC)
179{
180 atom *Walker = NULL;
181 atom *OtherWalker = NULL;
182 int n[NDIM];
183 Box &domain = World::getInstance().getDomain();
184
185 unsigned int BondCount = 0;
186 // 3a. go through every cell
187 LOG(3, "INFO: Celling ... ");
188 for (LC.n[0] = 0; LC.n[0] < LC.N[0]; LC.n[0]++)
189 for (LC.n[1] = 0; LC.n[1] < LC.N[1]; LC.n[1]++)
190 for (LC.n[2] = 0; LC.n[2] < LC.N[2]; LC.n[2]++) {
191 const TesselPointSTLList *List = LC.GetCurrentCell();
192 LOG(2, "Current cell is " << LC.n[0] << ", " << LC.n[1] << ", " << LC.n[2] << " with No. " << LC.index << " containing " << List->size() << " points.");
193 if (List != NULL) {
194 for (TesselPointSTLList::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
195 Walker = dynamic_cast<atom*>(*Runner);
196 ASSERT(Walker != NULL,
197 "BondGraph::CreateAdjacency() - Tesselpoint that was not an atom retrieved from LinkedNode");
198 LOG(2, "INFO: Current Atom is " << *Walker << ".");
199 // 3c. check for possible bond between each atom in this and every one in the 27 cells
200 for (n[0] = -1; n[0] <= 1; n[0]++)
201 for (n[1] = -1; n[1] <= 1; n[1]++)
202 for (n[2] = -1; n[2] <= 1; n[2]++) {
203 const TesselPointSTLList *OtherList = LC.GetRelativeToCurrentCell(n);
204 if (OtherList != NULL) {
205 LOG(3, "INFO: Current relative cell is " << LC.n[0] << ", " << LC.n[1] << ", " << LC.n[2] << " with No. " << LC.index << " containing " << List->size() << " points.");
206 for (TesselPointSTLList::const_iterator OtherRunner = OtherList->begin(); OtherRunner != OtherList->end(); OtherRunner++) {
207 if ((*OtherRunner) > Walker) { // just to not add bonds from both sides
208 OtherWalker = dynamic_cast<atom*>(*OtherRunner);
209 ASSERT(OtherWalker != NULL,
210 "BondGraph::CreateAdjacency() - TesselPoint that was not an atom retrieved from LinkedNode");
211 range<double> MinMaxDistanceSquared(0.,0.);
212 getMinMaxDistanceSquared(Walker, OtherWalker, MinMaxDistanceSquared, IsAngstroem);
213 const double distance = domain.periodicDistanceSquared(OtherWalker->getPosition(),Walker->getPosition());
214 LOG(2, "INFO: Checking squared distance " << distance << " against typical bond length of " << MinMaxDistanceSquared << ".");
215 const bool status = MinMaxDistanceSquared.isInRange(distance);
216 if (OtherWalker->father > Walker->father ) { // just to not add bonds from both sides
217 if (status) { // create bond if distance is smaller
218 LOG(1, "ACCEPT: Adding Bond between " << *Walker << " and " << *OtherWalker << " in distance " << sqrt(distance) << ".");
219 bond * Binder = new bond(Walker->father, OtherWalker->father, 1);
220 Walker->father->RegisterBond(WorldTime::getTime(), Binder);
221 OtherWalker->father->RegisterBond(WorldTime::getTime(), Binder);
222 BondCount++;
223 } else {
224 LOG(1, "REJECT: Squared distance "
225 << distance << " is out of squared covalent bounds "
226 << MinMaxDistanceSquared << ".");
227 }
228 } else {
229 LOG(5, "REJECT: Not Adding: Wrong order of father's.");
230 }
231 } else {
232 LOG(5, "REJECT: Not Adding: Wrong order.");
233 }
234 }
235 }
236 }
237 }
238 }
239 }
240 LOG(1, "I detected " << BondCount << " bonds in the molecule.");
241}
242
Note: See TracBrowser for help on using the repository browser.