source: src/bondgraph.cpp@ 2d292d

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 2d292d was 8f4df1, checked in by Frederik Heber <heber@…>, 14 years ago

Merge branch 'AtomicPositionEncapsulation' into stable

Conflicts:

src/Actions/AtomAction/ChangeElementAction.cpp
src/Actions/WorldAction/RemoveSphereOfAtomsAction.cpp
src/Makefile.am
src/UIElements/TextUI/TextDialog.cpp
src/analysis_correlation.hpp
src/atom.cpp
src/atom_atominfo.hpp
src/bond.cpp
src/boundary.cpp
src/molecule_geometry.cpp
src/tesselation.cpp
src/tesselationhelpers.cpp
src/triangleintersectionlist.cpp
src/unittests/Makefile.am

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