source: src/bondgraph.cpp@ 315164

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

Fix attempts of the Tesselation.

One problem still remains:

  • degenerated triangles are created more than two times.

The following has been changed:

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