source: src/bondgraph.cpp@ a0064e

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

LinkedCell constructor rewritten.

  • had to introduce getValue(iterator) to: molecule, tesselation, LinkedCell::LinkedNodes
  • LinkedCell::LinkedNodes is not a typedef anymore
  • new class LinkedCell::LinkedNodes derived from stl::list<TesselPoint *> to add getValue(iterator).
  • LinkedCell constructors changed:
    • use template for all classes that have begin(), end() and ... sigh ... getValue()
    • Argh! STL containers do all have begin() and end() but no consistent operator* (maps return pair<> ...)
    • specialized version for PointCloud derivatives
    • various functions had to be changed due to changed signature of LinkedCell constructor
  • Property mode set to 100644
File size: 6.7 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 "Helpers/MemDebug.hpp"
21
22#include <iostream>
23
24#include "atom.hpp"
25#include "bond.hpp"
26#include "bondgraph.hpp"
27#include "element.hpp"
28#include "Helpers/Info.hpp"
29#include "Helpers/Verbose.hpp"
30#include "Helpers/Log.hpp"
31#include "molecule.hpp"
32#include "parser.hpp"
33#include "periodentafel.hpp"
34#include "LinearAlgebra/Vector.hpp"
35
36const 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
37
38/** Constructor of class BondGraph.
39 * This classes contains typical bond lengths and thus may be used to construct a bond graph for a given molecule.
40 */
41BondGraph::BondGraph(bool IsA) :
42 BondLengthMatrix(NULL),
43 max_distance(0),
44 IsAngstroem(IsA)
45{};
46
47/** Destructor of class BondGraph.
48 */
49BondGraph::~BondGraph()
50{
51 if (BondLengthMatrix != NULL) {
52 delete(BondLengthMatrix);
53 }
54};
55
56/** Parses the bond lengths in a given file and puts them int a matrix form.
57 * Allocates \a MatrixContainer for BondGraph::BondLengthMatrix, using MatrixContainer::ParseMatrix(),
58 * but only if parsing is successful. Otherwise variable is left as NULL.
59 * \param *out output stream for debugging
60 * \param filename file with bond lengths to parse
61 * \return true - success in parsing file, false - failed to parse the file
62 */
63bool BondGraph::LoadBondLengthTable(const string &filename)
64{
65 Info FunctionInfo(__func__);
66 bool status = true;
67 MatrixContainer *TempContainer = NULL;
68
69 // allocate MatrixContainer
70 if (BondLengthMatrix != NULL) {
71 DoLog(1) && (Log() << Verbose(1) << "MatrixContainer for Bond length already present, removing." << endl);
72 delete(BondLengthMatrix);
73 }
74 TempContainer = new MatrixContainer;
75
76 // parse in matrix
77 if ((status = TempContainer->ParseMatrix(filename.c_str(), 0, 1, 0))) {
78 DoLog(1) && (Log() << Verbose(1) << "Parsing bond length matrix successful." << endl);
79 } else {
80 DoeLog(1) && (eLog()<< Verbose(1) << "Parsing bond length matrix failed." << endl);
81 }
82
83 // find greatest distance
84 max_distance=0;
85 if (status) {
86 for(int i=0;i<TempContainer->RowCounter[0];i++)
87 for(int j=i;j<TempContainer->ColumnCounter[0];j++)
88 if (TempContainer->Matrix[0][i][j] > max_distance)
89 max_distance = TempContainer->Matrix[0][i][j];
90 }
91 max_distance += BondThreshold;
92
93 if (status) // set to not NULL only if matrix was parsed
94 BondLengthMatrix = TempContainer;
95 else {
96 BondLengthMatrix = NULL;
97 delete(TempContainer);
98 }
99 return status;
100};
101
102/** Parses the bond lengths in a given file and puts them int a matrix form.
103 * \param *out output stream for debugging
104 * \param *mol molecule with atoms
105 * \return true - success, false - failed to construct bond structure
106 */
107bool BondGraph::ConstructBondGraph(molecule * const mol)
108{
109 Info FunctionInfo(__func__);
110 bool status = true;
111
112 if (mol->empty()) // only construct if molecule is not empty
113 return false;
114
115 if (BondLengthMatrix == NULL) { // no bond length matrix parsed?
116 SetMaxDistanceToMaxOfCovalentRadii(mol);
117 mol->CreateAdjacencyList(max_distance, IsAngstroem, &BondGraph::CovalentMinMaxDistance, this);
118 } else
119 mol->CreateAdjacencyList(max_distance, IsAngstroem, &BondGraph::BondLengthMatrixMinMaxDistance, this);
120
121 return status;
122};
123
124/** Returns the entry for a given index pair.
125 * \param firstelement index/atom number of first element (row index)
126 * \param secondelement index/atom number of second element (column index)
127 * \note matrix is of course symmetric.
128 */
129double BondGraph::GetBondLength(int firstZ, int secondZ)
130{
131 if (BondLengthMatrix == NULL)
132 return( -1. );
133 else
134 return (BondLengthMatrix->Matrix[0][firstZ][secondZ]);
135};
136
137/** Determines the maximum of all element::CovalentRadius for elements present in \a *mol.
138 * \param *out output stream for debugging
139 * \param *mol molecule with all atoms and their respective elements.
140 */
141double BondGraph::SetMaxDistanceToMaxOfCovalentRadii(const molecule * const mol)
142{
143 Info FunctionInfo(__func__);
144 max_distance = 0.;
145
146 for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
147 if ((*iter)->getType()->getCovalentRadius() > max_distance)
148 max_distance = (*iter)->getType()->getCovalentRadius();
149 }
150 max_distance *= 2.;
151 max_distance += BondThreshold;
152
153 return max_distance;
154};
155
156/** Returns the maximum distance (e.g. necessary for LinkedCell).
157 * \return BondGraph::max_distance
158 */
159double BondGraph::getMaxDistance() const
160{
161 return max_distance;
162}
163
164
165/** Returns bond criterion for given pair based on covalent radius.
166 * \param *Walker first BondedParticle
167 * \param *OtherWalker second BondedParticle
168 * \param &MinDistance lower bond bound on return
169 * \param &MaxDistance upper bond bound on return
170 * \param IsAngstroem whether units are in angstroem or bohr radii
171 */
172void BondGraph::CovalentMinMaxDistance(BondedParticle * const Walker, BondedParticle * const OtherWalker, double &MinDistance, double &MaxDistance, bool IsAngstroem)
173{
174 MinDistance = OtherWalker->getType()->getCovalentRadius() + Walker->getType()->getCovalentRadius();
175 MinDistance *= (IsAngstroem) ? 1. : 1. / AtomicLengthToAngstroem;
176 MaxDistance = MinDistance + BondThreshold;
177 MinDistance -= BondThreshold;
178};
179
180/** Returns bond criterion for given pair based on a bond length matrix.
181 * The matrix should be contained in \a this BondGraph and contain an element-
182 * to-element length.
183 * \param *Walker first BondedParticle
184 * \param *OtherWalker second BondedParticle
185 * \param &MinDistance lower bond bound on return
186 * \param &MaxDistance upper bond bound on return
187 * \param IsAngstroem whether units are in angstroem or bohr radii
188 */
189void BondGraph::BondLengthMatrixMinMaxDistance(BondedParticle * const Walker, BondedParticle * const OtherWalker, double &MinDistance, double &MaxDistance, bool IsAngstroem)
190{
191 if (BondLengthMatrix == NULL) {// safety measure if no matrix has been parsed yet
192 DoeLog(2) && (eLog()<< Verbose(2) << "BondLengthMatrixMinMaxDistance() called without having parsed the bond length matrix yet!" << endl);
193 CovalentMinMaxDistance(Walker, OtherWalker, MinDistance, MaxDistance, IsAngstroem);
194 } else {
195 MinDistance = GetBondLength(Walker->getType()->getAtomicNumber()-1, OtherWalker->getType()->getAtomicNumber()-1);
196 MinDistance *= (IsAngstroem) ? 1. : 1. / AtomicLengthToAngstroem;
197 MaxDistance = MinDistance + BondThreshold;
198 MinDistance -= BondThreshold;
199 }
200};
Note: See TracBrowser for help on using the repository browser.