source: src/bondgraph.cpp@ bbbad5

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

Shortened constructors [Meyers, "Effective C++" item 12]

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