source: src/bondgraph.cpp@ b21a64

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

BondGraph is parsed if command line switch '-g' is given.

  • builder.cpp: case 'g' which gives a bond length table file which is parsed after the configuration and before other command line options.
  • BondGraph::BondLengthMatrixMinMaxDistance() falls back to CovalentMinMaxDistance() if no table parsed.
  • Bond Length Table was changed to have first row _and_ column each enlist all the elements and does not have a "#" in front anymore.
  • The unit test has been changed accordingly.

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

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