source: src/bondgraph.cpp@ 111f4a

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 Candidate_v1.7.0 Candidate_v1.7.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 111f4a was 111f4a, checked in by Frederik Heber <heber@…>, 15 years ago

Const-ness and cosmetic fixes to class BondGraph.

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