source: src/Graph/BondGraph.cpp@ 5d41b3f

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 5d41b3f was 44f53e, checked in by Frederik Heber <heber@…>, 13 years ago

Made various verbosities a lot less annoying.

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