source: src/bondgraph.cpp@ 5be0eb

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 5be0eb was 244a84, checked in by Frederik Heber <heber@…>, 15 years ago

GetDistanceToSurface() separated, filling now with water instead of boron, DissectMoleculeIntoConnectedSubgraphs() now working on list of molecules instead of single one.

Signed-off-by: Frederik Heber <heber@…>

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