source: src/Graph/BondGraph.cpp@ 1ac24b

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 1ac24b was f007a1, checked in by Frederik Heber <heber@…>, 13 years ago

Added serialization capability to class BondGraph.

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