source: src/Bond/bond.cpp@ 49c059

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 49c059 was 1a4d4fe, checked in by Frederik Heber <heber@…>, 14 years ago

FIX: bond::~bond() checks whether the bond is a ring circle, leftatom == rightatom.

  • Unregistering the same atom again leads to seg'fault.
  • Property mode set to 100644
File size: 3.4 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/** \file Bond.cpp
9 *
10 * Function implementations for the classes BondLeaf, BondTree and bond.
11 *
12 */
13
14// include config.h
15#ifdef HAVE_CONFIG_H
16#include <config.h>
17#endif
18
19#include "CodePatterns/MemDebug.hpp"
20
21#include "CodePatterns/Log.hpp"
22#include "CodePatterns/Verbose.hpp"
23#include "atom.hpp"
24#include "Bond/bond.hpp"
25#include "element.hpp"
26
27
28/***************************************** Functions for class bond ********************************/
29
30/** Empty Constructor for class bond.
31 */
32bond::bond() :
33 leftatom(NULL),
34 rightatom(NULL),
35 HydrogenBond(0),
36 BondDegree(0),
37 nr(-1)
38{};
39
40/** Constructor for class bond, taking right and left bond partner
41 * \param *left left atom
42 * \param *right right atom
43 * \param degree bond degree
44 * \param number increasing index
45 */
46bond::bond(atom *left, atom *right, const int degree, const int number) :
47 leftatom(left),
48 rightatom(right),
49 HydrogenBond(0),
50 BondDegree(degree),
51 nr(number)
52{
53 if ((left != NULL) && (right != NULL)) {
54 if ((left->getType() != NULL) && (left->getType()->getAtomicNumber() == 1))
55 HydrogenBond++;
56 if ((right->getType() != NULL) && (right->getType()->getAtomicNumber() == 1))
57 HydrogenBond++;
58 }
59};
60
61/** Empty Destructor for class bond.
62 */
63bond::~bond()
64{
65 // remove this node from the list structure
66 if (leftatom != NULL)
67 leftatom->UnregisterBond(this);
68 // there might be self-bonds
69 if ((leftatom != rightatom) && (rightatom != NULL))
70 rightatom->UnregisterBond(this);
71};
72
73ostream & operator << (ostream &ost, const bond &b)
74{
75 ost << "[" << b.leftatom->getName() << " <" << b.BondDegree << "(H" << b.HydrogenBond << ")>" << b.rightatom->getName() << "]";
76 return ost;
77};
78
79/** Get the other atom in a bond if one is specified.
80 * \param *Atom the pointer to the one atom
81 * \return pointer to the other atom in the bond, NULL if no match (indicates something's wrong with the bond)
82 */
83atom * bond::GetOtherAtom(const ParticleInfo * const Atom) const
84{
85 if(leftatom == Atom)
86 return rightatom;
87 if(rightatom == Atom)
88 return leftatom;
89 DoeLog(1) && (eLog()<< Verbose(1) << "Bond " << *this << " does not contain atom " << *Atom << "!" << endl);
90 return NULL;
91};
92
93
94/** Checks if an atom exists in a bond.
95 * \param *ptr pointer to atom
96 * \return true if it is either bond::leftatom or bond::rightatom, false otherwise
97 */
98bool bond::Contains(const ParticleInfo * const ptr)
99{
100 return ((leftatom == ptr) || (rightatom == ptr));
101};
102
103/** Checks if an atom exists in a bond.
104 * \param Nr index of atom
105 * \return true if it is either bond::leftatom or bond::rightatom, false otherwise
106 */
107bool bond::Contains(const int number)
108{
109 return ((leftatom->getNr() == number) || (rightatom->getNr() == number));
110};
111
112/** Calculates the bond length.
113 * \return |a - b| with a = bond::leftatom and b = bond::rightatom.
114 */
115double bond::GetDistance() const
116{
117 return (leftatom->distance(*rightatom));
118};
119
120/** Calculates the bond length.
121 * \return |a - b|^2 with a = bond::leftatom and b = bond::rightatom.
122 */
123double bond::GetDistanceSquared() const
124{
125 return (leftatom->DistanceSquared(*rightatom));
126};
Note: See TracBrowser for help on using the repository browser.