source: src/atom_bondedparticle.cpp@ 9a3a53

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 Candidate_v1.7.0 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 9a3a53 was a2bdbe, checked in by Frederik Heber <heber@…>, 15 years ago

BondedParticle::UnregisterAllBond with new parameter step.

  • Property mode set to 100644
File size: 7.7 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#include "WorldTime.hpp"
30
31/** Constructor of class BondedParticle.
32 */
33BondedParticle::BondedParticle()
34{
35 ListOfBonds.push_back(BondList());
36};
37
38/** Destructor of class BondedParticle.
39 */
40BondedParticle::~BondedParticle()
41{
42 BondList::iterator Runner;
43 for (std::vector<BondList>::iterator iter = ListOfBonds.begin();
44 !ListOfBonds.empty();
45 iter = ListOfBonds.begin()) {
46 while (!(*iter).empty()) {
47 Runner = (*iter).begin();
48 removewithoutcheck(*Runner);
49 }
50 ListOfBonds.erase(iter);
51 }
52};
53
54/** Outputs the current atom::AdaptiveOrder and atom::MaxOrder to \a *file.
55 * \param *file output stream
56 */
57void BondedParticle::OutputOrder(ofstream *file) const
58{
59 *file << nr << "\t" << (int)AdaptiveOrder << "\t" << (int)MaxOrder << endl;
60 //Log() << Verbose(2) << "Storing: " << nr << "\t" << (int)AdaptiveOrder << "\t" << (int)MaxOrder << "." << endl;
61};
62
63/** Prints all bonds of this atom with total degree.
64 */
65void BondedParticle::OutputBondOfAtom() const
66{
67 const BondList& ListOfBonds = getListOfBonds();
68 DoLog(4) && (Log() << Verbose(4) << "Atom " << getName() << "/" << nr << " with " << ListOfBonds.size() << " bonds: " << endl);
69 int TotalDegree = 0;
70 for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); ++Runner) {
71 DoLog(4) && (Log() << Verbose(4) << **Runner << endl);
72 TotalDegree += (*Runner)->BondDegree;
73 }
74 DoLog(4) && (Log() << Verbose(4) << " -- TotalDegree: " << TotalDegree << endl);
75};
76
77/** Output of atom::nr along with all bond partners.
78 * \param *AdjacencyFile output stream
79 */
80void BondedParticle::OutputAdjacency(ofstream * const AdjacencyFile) const
81{
82 const BondList& ListOfBonds = getListOfBonds();
83 *AdjacencyFile << nr << "\t";
84 for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); (++Runner))
85 *AdjacencyFile << (*Runner)->GetOtherAtom(this)->nr << "\t";
86 *AdjacencyFile << endl;
87};
88
89/** Output of atom::nr along each bond partner per line.
90 * Only bonds are printed where atom::nr is smaller than the one of the bond partner.
91 * \param *AdjacencyFile output stream
92 */
93void BondedParticle::OutputBonds(ofstream * const BondFile) const
94{
95 const BondList& ListOfBonds = getListOfBonds();
96 for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); (++Runner))
97 if (nr < (*Runner)->GetOtherAtom(this)->nr)
98 *BondFile << nr << "\t" << (*Runner)->GetOtherAtom(this)->nr << "\n";
99};
100
101/**
102 * Adds a bond between this bonded particle and another. Does nothing if this
103 * bond already exists.
104 *
105 * \param bonding partner
106 */
107void BondedParticle::addBond(BondedParticle* Partner) {
108 if (IsBondedTo(Partner)) {
109 return;
110 }
111
112 bond* newBond = new bond((atom*) this, (atom*) Partner, 1, 0);
113 RegisterBond(newBond);
114 Partner->RegisterBond(newBond);
115}
116
117/** Puts a given bond into atom::ListOfBonds.
118 * \param *Binder bond to insert
119 */
120bool BondedParticle::RegisterBond(bond *Binder)
121{
122 bool status = false;
123 if (Binder != NULL) {
124 if (Binder->Contains(this)) {
125 BondList& ListOfBonds = getListOfBonds();
126 ListOfBonds.push_back(Binder);
127 status = true;
128 } else {
129 DoeLog(1) && (eLog()<< Verbose(1) << *Binder << " does not contain " << *this << "." << endl);
130 }
131 } else {
132 DoeLog(1) && (eLog()<< Verbose(1) << "Binder is " << Binder << "." << endl);
133 }
134 return status;
135};
136
137/** Removes a given bond from atom::ListOfBonds.
138 * @param _step time step to access
139 * \param *Binder bond to remove
140 */
141bool BondedParticle::UnregisterBond(bond *Binder)
142{
143 bool status = false;
144 if (Binder != NULL) {
145 if (Binder->Contains(this)) {
146 BondList& ListOfBonds = getListOfBonds();
147 ListOfBonds.remove(Binder);
148 status = true;
149 } else {
150 DoeLog(1) && (eLog()<< Verbose(1) << *Binder << " does not contain " << *this << "." << endl);
151 }
152 } else {
153 DoeLog(1) && (eLog()<< Verbose(1) << "Binder is " << Binder << "." << endl);
154 }
155 return status;
156};
157
158/** Removes all bonds from atom::ListOfBonds.
159 * \note Does not do any memory de-allocation.
160 */
161void BondedParticle::UnregisterAllBond(const unsigned int _step)
162{
163 BondList& ListOfBonds = getListOfBondsAtStep(_step);
164 ListOfBonds.clear();
165};
166
167/** Corrects the bond degree by one at most if necessary.
168 * \param *out output stream for debugging
169 */
170int BondedParticle::CorrectBondDegree()
171{
172 int NoBonds = 0;
173 int OtherNoBonds = 0;
174 int FalseBondDegree = 0;
175 atom *OtherWalker = NULL;
176 bond *CandidateBond = NULL;
177
178 NoBonds = CountBonds();
179 //Log() << Verbose(3) << "Walker " << *this << ": " << (int)this->type->NoValenceOrbitals << " > " << NoBonds << "?" << endl;
180 if ((int)(getType()->getNoValenceOrbitals()) > NoBonds) { // we have a mismatch, check all bonding partners for mismatch
181 const BondList& ListOfBonds = getListOfBonds();
182 for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); (++Runner)) {
183 OtherWalker = (*Runner)->GetOtherAtom(this);
184 OtherNoBonds = OtherWalker->CountBonds();
185 //Log() << Verbose(3) << "OtherWalker " << *OtherWalker << ": " << (int)OtherWalker->type->NoValenceOrbitals << " > " << OtherNoBonds << "?" << endl;
186 if ((int)(OtherWalker->getType()->getNoValenceOrbitals()) > OtherNoBonds) { // check if possible candidate
187 const BondList& OtherListOfBonds = OtherWalker->getListOfBonds();
188 if ((CandidateBond == NULL) || (ListOfBonds.size() > OtherListOfBonds.size())) { // pick the one with fewer number of bonds first
189 CandidateBond = (*Runner);
190 //Log() << Verbose(3) << "New candidate is " << *CandidateBond << "." << endl;
191 }
192 }
193 }
194 if ((CandidateBond != NULL)) {
195 CandidateBond->BondDegree++;
196 //Log() << Verbose(2) << "Increased bond degree for bond " << *CandidateBond << "." << endl;
197 } else {
198 DoeLog(2) && (eLog()<< Verbose(2) << "Could not find correct degree for atom " << *this << "." << endl);
199 FalseBondDegree++;
200 }
201 }
202 return FalseBondDegree;
203};
204
205/** Counts the number of bonds weighted by bond::BondDegree.
206 * @param _step time step to access
207 * \param bonds times bond::BondDegree
208 */
209int BondedParticle::CountBonds() const
210{
211 int NoBonds = 0;
212 const BondList& ListOfBonds = getListOfBonds();
213 for (BondList::const_iterator Runner = ListOfBonds.begin();
214 Runner != ListOfBonds.end();
215 (++Runner))
216 NoBonds += (*Runner)->BondDegree;
217 return NoBonds;
218};
219
220/** Checks whether there is a bond between \a this atom and the given \a *BondPartner.
221 * \param *BondPartner atom to check for
222 * \return true - bond exists, false - bond does not exist
223 */
224bool BondedParticle::IsBondedTo(BondedParticle * const BondPartner)
225{
226 bool status = false;
227
228 const BondList& ListOfBonds = getListOfBonds();
229 for (BondList::const_iterator runner = ListOfBonds.begin(); runner != ListOfBonds.end(); runner++) {
230 status = status || ((*runner)->Contains(BondPartner));
231 }
232 return status;
233};
234
235std::ostream & BondedParticle::operator << (std::ostream &ost) const
236{
237 ParticleInfo::operator<<(ost);
238 ost << "," << getPosition();
239 return ost;
240}
241
242std::ostream & operator << (std::ostream &ost, const BondedParticle &a)
243{
244 a.ParticleInfo::operator<<(ost);
245 ost << "," << a.getPosition();
246 return ost;
247}
248
Note: See TracBrowser for help on using the repository browser.