source: src/bondgraph.cpp@ ff58f1

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 ff58f1 was bf3817, checked in by Frederik Heber <heber@…>, 15 years ago

Added ifdef HAVE_CONFIG and config.h include to each and every cpp file.

  • is now topmost in front of MemDebug.hpp (and any other).
  • Property mode set to 100644
File size: 6.2 KB
Line 
1/*
2 * bondgraph.cpp
3 *
4 * Created on: Oct 29, 2009
5 * Author: heber
6 */
7
8// include config.h
9#ifdef HAVE_CONFIG_H
10#include <config.h>
11#endif
12
13#include "Helpers/MemDebug.hpp"
14
15#include <iostream>
16
17#include "atom.hpp"
18#include "bond.hpp"
19#include "bondgraph.hpp"
20#include "element.hpp"
21#include "Helpers/Info.hpp"
22#include "Helpers/Verbose.hpp"
23#include "Helpers/Log.hpp"
24#include "molecule.hpp"
25#include "parser.hpp"
26#include "periodentafel.hpp"
27#include "LinearAlgebra/Vector.hpp"
28
29const 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
30
31/** Constructor of class BondGraph.
32 * This classes contains typical bond lengths and thus may be used to construct a bond graph for a given molecule.
33 */
34BondGraph::BondGraph(bool IsA) :
35 BondLengthMatrix(NULL),
36 max_distance(0),
37 IsAngstroem(IsA)
38{};
39
40/** Destructor of class BondGraph.
41 */
42BondGraph::~BondGraph()
43{
44 if (BondLengthMatrix != NULL) {
45 delete(BondLengthMatrix);
46 }
47};
48
49/** Parses the bond lengths in a given file and puts them int a matrix form.
50 * Allocates \a MatrixContainer for BondGraph::BondLengthMatrix, using MatrixContainer::ParseMatrix(),
51 * but only if parsing is successful. Otherwise variable is left as NULL.
52 * \param *out output stream for debugging
53 * \param filename file with bond lengths to parse
54 * \return true - success in parsing file, false - failed to parse the file
55 */
56bool BondGraph::LoadBondLengthTable(const string &filename)
57{
58 Info FunctionInfo(__func__);
59 bool status = true;
60 MatrixContainer *TempContainer = NULL;
61
62 // allocate MatrixContainer
63 if (BondLengthMatrix != NULL) {
64 DoLog(1) && (Log() << Verbose(1) << "MatrixContainer for Bond length already present, removing." << endl);
65 delete(BondLengthMatrix);
66 }
67 TempContainer = new MatrixContainer;
68
69 // parse in matrix
70 if ((status = TempContainer->ParseMatrix(filename.c_str(), 0, 1, 0))) {
71 DoLog(1) && (Log() << Verbose(1) << "Parsing bond length matrix successful." << endl);
72 } else {
73 DoeLog(1) && (eLog()<< Verbose(1) << "Parsing bond length matrix failed." << endl);
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
85 if (status) // set to not NULL only if matrix was parsed
86 BondLengthMatrix = TempContainer;
87 else {
88 BondLengthMatrix = NULL;
89 delete(TempContainer);
90 }
91 return status;
92};
93
94/** Parses the bond lengths in a given file and puts them int a matrix form.
95 * \param *out output stream for debugging
96 * \param *mol molecule with atoms
97 * \return true - success, false - failed to construct bond structure
98 */
99bool BondGraph::ConstructBondGraph(molecule * const mol)
100{
101 Info FunctionInfo(__func__);
102 bool status = true;
103
104 if (mol->empty()) // only construct if molecule is not empty
105 return false;
106
107 if (BondLengthMatrix == NULL) { // no bond length matrix parsed?
108 SetMaxDistanceToMaxOfCovalentRadii(mol);
109 mol->CreateAdjacencyList(max_distance, IsAngstroem, &BondGraph::CovalentMinMaxDistance, this);
110 } else
111 mol->CreateAdjacencyList(max_distance, IsAngstroem, &BondGraph::BondLengthMatrixMinMaxDistance, this);
112
113 return status;
114};
115
116/** Returns the entry for a given index pair.
117 * \param firstelement index/atom number of first element (row index)
118 * \param secondelement index/atom number of second element (column index)
119 * \note matrix is of course symmetric.
120 */
121double BondGraph::GetBondLength(int firstZ, int secondZ)
122{
123 if (BondLengthMatrix == NULL)
124 return( -1. );
125 else
126 return (BondLengthMatrix->Matrix[0][firstZ][secondZ]);
127};
128
129/** Determines the maximum of all element::CovalentRadius for elements present in \a *mol.
130 * \param *out output stream for debugging
131 * \param *mol molecule with all atoms and their respective elements.
132 */
133double BondGraph::SetMaxDistanceToMaxOfCovalentRadii(const molecule * const mol)
134{
135 Info FunctionInfo(__func__);
136 max_distance = 0.;
137
138 for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
139 if ((*iter)->getType()->CovalentRadius > max_distance)
140 max_distance = (*iter)->getType()->CovalentRadius;
141 }
142 max_distance *= 2.;
143
144 return max_distance;
145};
146
147/** Returns bond criterion for given pair based on covalent radius.
148 * \param *Walker first BondedParticle
149 * \param *OtherWalker second BondedParticle
150 * \param &MinDistance lower bond bound on return
151 * \param &MaxDistance upper bond bound on return
152 * \param IsAngstroem whether units are in angstroem or bohr radii
153 */
154void BondGraph::CovalentMinMaxDistance(BondedParticle * const Walker, BondedParticle * const OtherWalker, double &MinDistance, double &MaxDistance, bool IsAngstroem)
155{
156 MinDistance = OtherWalker->getType()->CovalentRadius + Walker->getType()->CovalentRadius;
157 MinDistance *= (IsAngstroem) ? 1. : 1. / AtomicLengthToAngstroem;
158 MaxDistance = MinDistance + BondThreshold;
159 MinDistance -= BondThreshold;
160};
161
162/** Returns bond criterion for given pair based on a bond length matrix.
163 * The matrix should be contained in \a this BondGraph and contain an element-
164 * to-element length.
165 * \param *Walker first BondedParticle
166 * \param *OtherWalker second BondedParticle
167 * \param &MinDistance lower bond bound on return
168 * \param &MaxDistance upper bond bound on return
169 * \param IsAngstroem whether units are in angstroem or bohr radii
170 */
171void BondGraph::BondLengthMatrixMinMaxDistance(BondedParticle * const Walker, BondedParticle * const OtherWalker, double &MinDistance, double &MaxDistance, bool IsAngstroem)
172{
173 if (BondLengthMatrix == NULL) {// safety measure if no matrix has been parsed yet
174 DoeLog(2) && (eLog()<< Verbose(2) << "BondLengthMatrixMinMaxDistance() called without having parsed the bond length matrix yet!" << endl);
175 CovalentMinMaxDistance(Walker, OtherWalker, MinDistance, MaxDistance, IsAngstroem);
176 } else {
177 MinDistance = GetBondLength(Walker->getType()->Z-1, OtherWalker->getType()->Z-1);
178 MinDistance *= (IsAngstroem) ? 1. : 1. / AtomicLengthToAngstroem;
179 MaxDistance = MinDistance + BondThreshold;
180 MinDistance -= BondThreshold;
181 }
182};
Note: See TracBrowser for help on using the repository browser.