source: src/atom_bondedparticle.cpp@ 1a6bda

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

CodePatterns places all includes now in subfolder CodePatterns/.

  • change all includes accordingly.
  • this was necessary as Helpers and Patterns are not very distinctive names for include folders. Already now, we had a conflict between Helpers from CodePatterns and Helpers from this project.
  • changed compilation test in ax_codepatterns.m4 when changing CodePatterns includes.
  • Property mode set to 100644
File size: 6.6 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/*
9 * atom_bondedparticle.cpp
10 *
11 * Created on: Oct 19, 2009
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "CodePatterns/MemDebug.hpp"
21
22#include "atom.hpp"
23#include "atom_bondedparticle.hpp"
24#include "bond.hpp"
25#include "element.hpp"
26#include "lists.hpp"
27#include "CodePatterns/Log.hpp"
28#include "CodePatterns/Verbose.hpp"
29
30/** Constructor of class BondedParticle.
31 */
32BondedParticle::BondedParticle()
33{
34};
35
36/** Destructor of class BondedParticle.
37 */
38BondedParticle::~BondedParticle()
39{
40 BondList::const_iterator Runner;
41 while (!ListOfBonds.empty()) {
42 Runner = ListOfBonds.begin();
43 removewithoutcheck(*Runner);
44 }
45};
46
47/** Outputs the current atom::AdaptiveOrder and atom::MaxOrder to \a *file.
48 * \param *file output stream
49 */
50void BondedParticle::OutputOrder(ofstream *file) const
51{
52 *file << nr << "\t" << (int)AdaptiveOrder << "\t" << (int)MaxOrder << endl;
53 //Log() << Verbose(2) << "Storing: " << nr << "\t" << (int)AdaptiveOrder << "\t" << (int)MaxOrder << "." << endl;
54};
55
56/** Prints all bonds of this atom with total degree.
57 */
58void BondedParticle::OutputBondOfAtom() const
59{
60 DoLog(4) && (Log() << Verbose(4) << "Atom " << getName() << "/" << nr << " with " << ListOfBonds.size() << " bonds: " << endl);
61 int TotalDegree = 0;
62 for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); ++Runner) {
63 DoLog(4) && (Log() << Verbose(4) << **Runner << endl);
64 TotalDegree += (*Runner)->BondDegree;
65 }
66 DoLog(4) && (Log() << Verbose(4) << " -- TotalDegree: " << TotalDegree << endl);
67};
68
69/** Output of atom::nr along with all bond partners.
70 * \param *AdjacencyFile output stream
71 */
72void BondedParticle::OutputAdjacency(ofstream * const AdjacencyFile) const
73{
74 *AdjacencyFile << nr << "\t";
75 for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); (++Runner))
76 *AdjacencyFile << (*Runner)->GetOtherAtom(this)->nr << "\t";
77 *AdjacencyFile << endl;
78};
79
80/** Output of atom::nr along each bond partner per line.
81 * Only bonds are printed where atom::nr is smaller than the one of the bond partner.
82 * \param *AdjacencyFile output stream
83 */
84void BondedParticle::OutputBonds(ofstream * const BondFile) const
85{
86 for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); (++Runner))
87 if (nr < (*Runner)->GetOtherAtom(this)->nr)
88 *BondFile << nr << "\t" << (*Runner)->GetOtherAtom(this)->nr << "\n";
89};
90
91/**
92 * Adds a bond between this bonded particle and another. Does nothing if this
93 * bond already exists.
94 *
95 * \param bonding partner
96 */
97void BondedParticle::addBond(BondedParticle* Partner) {
98 if (IsBondedTo(Partner)) {
99 return;
100 }
101
102 bond* newBond = new bond((atom*) this, (atom*) Partner, 1, 0);
103 RegisterBond(newBond);
104 Partner->RegisterBond(newBond);
105}
106
107/** Puts a given bond into atom::ListOfBonds.
108 * \param *Binder bond to insert
109 */
110bool BondedParticle::RegisterBond(bond *Binder)
111{
112 bool status = false;
113 if (Binder != NULL) {
114 if (Binder->Contains(this)) {
115 ListOfBonds.push_back(Binder);
116 status = true;
117 } else {
118 DoeLog(1) && (eLog()<< Verbose(1) << *Binder << " does not contain " << *this << "." << endl);
119 }
120 } else {
121 DoeLog(1) && (eLog()<< Verbose(1) << "Binder is " << Binder << "." << endl);
122 }
123 return status;
124};
125
126/** Removes a given bond from atom::ListOfBonds.
127 * \param *Binder bond to remove
128 */
129bool BondedParticle::UnregisterBond(bond *Binder)
130{
131 bool status = false;
132 if (Binder != NULL) {
133 if (Binder->Contains(this)) {
134 ListOfBonds.remove(Binder);
135 status = true;
136 } else {
137 DoeLog(1) && (eLog()<< Verbose(1) << *Binder << " does not contain " << *this << "." << endl);
138 }
139 } else {
140 DoeLog(1) && (eLog()<< Verbose(1) << "Binder is " << Binder << "." << endl);
141 }
142 return status;
143};
144
145/** Removes all bonds from atom::ListOfBonds.
146 * \note Does not do any memory de-allocation.
147 */
148void BondedParticle::UnregisterAllBond()
149{
150 ListOfBonds.clear();
151};
152
153/** Corrects the bond degree by one at most if necessary.
154 * \param *out output stream for debugging
155 */
156int BondedParticle::CorrectBondDegree()
157{
158 int NoBonds = 0;
159 int OtherNoBonds = 0;
160 int FalseBondDegree = 0;
161 atom *OtherWalker = NULL;
162 bond *CandidateBond = NULL;
163
164 NoBonds = CountBonds();
165 //Log() << Verbose(3) << "Walker " << *this << ": " << (int)this->type->NoValenceOrbitals << " > " << NoBonds << "?" << endl;
166 if ((int)(getType()->getNoValenceOrbitals()) > NoBonds) { // we have a mismatch, check all bonding partners for mismatch
167 for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); (++Runner)) {
168 OtherWalker = (*Runner)->GetOtherAtom(this);
169 OtherNoBonds = OtherWalker->CountBonds();
170 //Log() << Verbose(3) << "OtherWalker " << *OtherWalker << ": " << (int)OtherWalker->type->NoValenceOrbitals << " > " << OtherNoBonds << "?" << endl;
171 if ((int)(OtherWalker->getType()->getNoValenceOrbitals()) > OtherNoBonds) { // check if possible candidate
172 if ((CandidateBond == NULL) || (ListOfBonds.size() > OtherWalker->ListOfBonds.size())) { // pick the one with fewer number of bonds first
173 CandidateBond = (*Runner);
174 //Log() << Verbose(3) << "New candidate is " << *CandidateBond << "." << endl;
175 }
176 }
177 }
178 if ((CandidateBond != NULL)) {
179 CandidateBond->BondDegree++;
180 //Log() << Verbose(2) << "Increased bond degree for bond " << *CandidateBond << "." << endl;
181 } else {
182 DoeLog(2) && (eLog()<< Verbose(2) << "Could not find correct degree for atom " << *this << "." << endl);
183 FalseBondDegree++;
184 }
185 }
186 return FalseBondDegree;
187};
188
189/** Checks whether there is a bond between \a this atom and the given \a *BondPartner.
190 * \param *BondPartner atom to check for
191 * \return true - bond exists, false - bond does not exist
192 */
193bool BondedParticle::IsBondedTo(BondedParticle * const BondPartner)
194{
195 bool status = false;
196
197 for (BondList::iterator runner = ListOfBonds.begin(); runner != ListOfBonds.end(); runner++) {
198 status = status || ((*runner)->Contains(BondPartner));
199 }
200 return status;
201};
202
203std::ostream & BondedParticle::operator << (std::ostream &ost) const
204{
205 ParticleInfo::operator<<(ost);
206 ost << "," << getPosition();
207 return ost;
208}
209
210std::ostream & operator << (std::ostream &ost, const BondedParticle &a)
211{
212 a.ParticleInfo::operator<<(ost);
213 ost << "," << a.getPosition();
214 return ost;
215}
216
Note: See TracBrowser for help on using the repository browser.