source: src/atom_bondedparticle.cpp@ 435065

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 435065 was 4b5cf8, checked in by Frederik Heber <heber@…>, 14 years ago

BondedParticle::OutputBondOfAtom() now takes stream to print to.

  • Property mode set to 100644
File size: 9.1 KB
RevLine 
[bcf653]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
[6b919f8]8/*
9 * atom_bondedparticle.cpp
10 *
11 * Created on: Oct 19, 2009
12 * Author: heber
13 */
14
[bf3817]15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
[ad011c]20#include "CodePatterns/MemDebug.hpp"
[112b09]21
[6b919f8]22#include "atom.hpp"
23#include "atom_bondedparticle.hpp"
24#include "bond.hpp"
[d557374]25#include "CodePatterns/Assert.hpp"
[ad011c]26#include "CodePatterns/Log.hpp"
27#include "CodePatterns/Verbose.hpp"
[d557374]28#include "element.hpp"
[6b919f8]29
30/** Constructor of class BondedParticle.
31 */
[70ff32]32BondedParticle::BondedParticle()
33{
[9d83b6]34 ListOfBonds.push_back(BondList());
[70ff32]35};
[6b919f8]36
37/** Destructor of class BondedParticle.
38 */
39BondedParticle::~BondedParticle()
40{
[03c77c]41 const size_t max = ListOfBonds.size();
42 for (size_t i = 0; i < max; ++i) {
43 ClearBondsAtStep(i);
[6b919f8]44 }
45};
46
47/** Outputs the current atom::AdaptiveOrder and atom::MaxOrder to \a *file.
48 * \param *file output stream
49 */
[b453f9]50void BondedParticle::OutputOrder(ofstream *file) const
[6b919f8]51{
[735b1c]52 *file << getNr() << "\t" << (int)AdaptiveOrder << "\t" << (int)MaxOrder << endl;
53 //Log() << Verbose(2) << "Storing: " << getNr() << "\t" << (int)AdaptiveOrder << "\t" << (int)MaxOrder << "." << endl;
[6b919f8]54};
55
56/** Prints all bonds of this atom with total degree.
57 */
[4b5cf8]58void BondedParticle::OutputBondOfAtom(std::ostream &ost) const
[6b919f8]59{
[9d83b6]60 const BondList& ListOfBonds = getListOfBonds();
[4b5cf8]61 ost << "Atom " << getName() << "/" << getNr() << " with " << ListOfBonds.size() << " bonds: ";
[e138de]62 int TotalDegree = 0;
63 for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); ++Runner) {
[4b5cf8]64 ost << **Runner << "\t";
[e138de]65 TotalDegree += (*Runner)->BondDegree;
66 }
[4b5cf8]67 ost << " -- TotalDegree: " << TotalDegree;
[6b919f8]68};
69
[5309ba]70/** Output of atom::Nr along with all bond partners.
[6b919f8]71 * \param *AdjacencyFile output stream
72 */
[1f1b23]73void BondedParticle::OutputAdjacency(ofstream * const AdjacencyFile) const
[6b919f8]74{
[9d83b6]75 const BondList& ListOfBonds = getListOfBonds();
[735b1c]76 *AdjacencyFile << getNr() << "\t";
[6b919f8]77 for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); (++Runner))
[735b1c]78 *AdjacencyFile << (*Runner)->GetOtherAtom(this)->getNr() << "\t";
[6b919f8]79 *AdjacencyFile << endl;
80};
81
[5309ba]82/** Output of atom::Nr along each bond partner per line.
83 * Only bonds are printed where atom::Nr is smaller than the one of the bond partner.
[1f1b23]84 * \param *AdjacencyFile output stream
85 */
86void BondedParticle::OutputBonds(ofstream * const BondFile) const
87{
[9d83b6]88 const BondList& ListOfBonds = getListOfBonds();
[1f1b23]89 for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); (++Runner))
[735b1c]90 if (getNr() < (*Runner)->GetOtherAtom(this)->getNr())
91 *BondFile << getNr() << "\t" << (*Runner)->GetOtherAtom(this)->getNr() << "\n";
[1f1b23]92};
93
[b8d4a3]94/**
95 * Adds a bond between this bonded particle and another. Does nothing if this
96 * bond already exists.
97 *
[073a9e4]98 * @param _step time step to access
[b8d4a3]99 * \param bonding partner
100 */
[073a9e4]101void BondedParticle::addBond(const unsigned int _step, BondedParticle* Partner) {
102 if (IsBondedTo(_step, Partner)) {
[b8d4a3]103 return;
104 }
105
106 bond* newBond = new bond((atom*) this, (atom*) Partner, 1, 0);
[073a9e4]107 RegisterBond(_step, newBond);
108 Partner->RegisterBond(_step, newBond);
[b8d4a3]109}
110
[6b919f8]111/** Puts a given bond into atom::ListOfBonds.
[073a9e4]112 * @param _step time step to access
[6b919f8]113 * \param *Binder bond to insert
114 */
[073a9e4]115bool BondedParticle::RegisterBond(const unsigned int _step, bond *Binder)
[6b919f8]116{
117 bool status = false;
118 if (Binder != NULL) {
119 if (Binder->Contains(this)) {
[d557374]120 //LOG(3,"INFO: Registering bond "<< *Binder << " with atom " << *this << " at step " << _step);
[073a9e4]121 BondList& ListOfBonds = getListOfBondsAtStep(_step);
[6b919f8]122 ListOfBonds.push_back(Binder);
123 status = true;
124 } else {
[58ed4a]125 DoeLog(1) && (eLog()<< Verbose(1) << *Binder << " does not contain " << *this << "." << endl);
[6b919f8]126 }
127 } else {
[58ed4a]128 DoeLog(1) && (eLog()<< Verbose(1) << "Binder is " << Binder << "." << endl);
[6b919f8]129 }
130 return status;
131};
132
133/** Removes a given bond from atom::ListOfBonds.
[9d83b6]134 * @param _step time step to access
[6b919f8]135 * \param *Binder bond to remove
136 */
137bool BondedParticle::UnregisterBond(bond *Binder)
138{
139 bool status = false;
[d557374]140 ASSERT(Binder != NULL, "BondedParticle::UnregisterBond() - Binder is NULL.");
141 const int step = ContainsBondAtStep(Binder);
142 if (step != -1) {
143 //LOG(3,"INFO: Unregistering bond "<< *Binder << " from list " << &ListOfBonds << " of atom " << *this << " at step " << step);
144 ListOfBonds[step].remove(Binder);
145 status = true;
[6b919f8]146 } else {
[d557374]147 DoeLog(1) && (eLog()<< Verbose(1) << *Binder << " does not contain " << *this << "." << endl);
[6b919f8]148 }
149 return status;
150};
151
152/** Removes all bonds from atom::ListOfBonds.
153 * \note Does not do any memory de-allocation.
154 */
[a2bdbe]155void BondedParticle::UnregisterAllBond(const unsigned int _step)
[6b919f8]156{
[af897f]157 ListOfBonds[_step].clear();
158}
[6b919f8]159
[583081]160/** Removes all bonds of given \a _step with freeing memory.
161 *
162 * @param _step time step whose bonds to free
163 */
164void BondedParticle::ClearBondsAtStep(const unsigned int _step)
165{
166 //LOG(3,"INFO: Clearing all bonds of " << *this << ": " << ListOfBonds[_step]);
167 for (BondList::iterator iter = (ListOfBonds[_step]).begin();
168 !(ListOfBonds[_step]).empty();
169 iter = (ListOfBonds[_step]).begin()) {
170 //LOG(3,"INFO: Clearing bond (" << *iter << ") " << *(*iter) << " of list " << &ListOfBonds);
171 delete((*iter)); // will also unregister with us and remove from list
172 }
173}
174
[93c6e9]175/** Searches for the time step where the given bond \a *Binder is a bond of this particle.
176 *
177 * @param Binder bond to check
178 * @return >=0 - first time step where bond appears, -1 - bond not present in lists
179 */
180int BondedParticle::ContainsBondAtStep(bond *Binder)
181{
182 int step = -1;
183 int tempstep = 0;
184 for(std::vector<BondList>::const_iterator iter = ListOfBonds.begin();
185 iter != ListOfBonds.end();
186 ++iter,++tempstep) {
187 for (BondList::const_iterator bonditer = iter->begin();
188 bonditer != iter->end();
189 ++bonditer) {
190 if ((*bonditer) == Binder) {
191 step = tempstep;
192 break;
193 }
194 }
195 if (step != -1)
196 break;
197 }
198
199 return step;
200}
201
[6b919f8]202/** Corrects the bond degree by one at most if necessary.
[93c6e9]203 * \return number of corrections done
[6b919f8]204 */
[e138de]205int BondedParticle::CorrectBondDegree()
[6b919f8]206{
207 int NoBonds = 0;
208 int OtherNoBonds = 0;
209 int FalseBondDegree = 0;
210 atom *OtherWalker = NULL;
211 bond *CandidateBond = NULL;
212
213 NoBonds = CountBonds();
[791138]214 //Log() << Verbose(3) << "Walker " << *this << ": " << (int)this->type->NoValenceOrbitals << " > " << NoBonds << "?" << endl;
[83f176]215 if ((int)(getType()->getNoValenceOrbitals()) > NoBonds) { // we have a mismatch, check all bonding partners for mismatch
[9d83b6]216 const BondList& ListOfBonds = getListOfBonds();
[6b919f8]217 for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); (++Runner)) {
218 OtherWalker = (*Runner)->GetOtherAtom(this);
219 OtherNoBonds = OtherWalker->CountBonds();
[791138]220 //Log() << Verbose(3) << "OtherWalker " << *OtherWalker << ": " << (int)OtherWalker->type->NoValenceOrbitals << " > " << OtherNoBonds << "?" << endl;
[83f176]221 if ((int)(OtherWalker->getType()->getNoValenceOrbitals()) > OtherNoBonds) { // check if possible candidate
[9d83b6]222 const BondList& OtherListOfBonds = OtherWalker->getListOfBonds();
223 if ((CandidateBond == NULL) || (ListOfBonds.size() > OtherListOfBonds.size())) { // pick the one with fewer number of bonds first
[6b919f8]224 CandidateBond = (*Runner);
[e138de]225 //Log() << Verbose(3) << "New candidate is " << *CandidateBond << "." << endl;
[6b919f8]226 }
227 }
228 }
229 if ((CandidateBond != NULL)) {
230 CandidateBond->BondDegree++;
[791138]231 //Log() << Verbose(2) << "Increased bond degree for bond " << *CandidateBond << "." << endl;
[6b919f8]232 } else {
[58ed4a]233 DoeLog(2) && (eLog()<< Verbose(2) << "Could not find correct degree for atom " << *this << "." << endl);
[6b919f8]234 FalseBondDegree++;
235 }
236 }
237 return FalseBondDegree;
238};
239
[c0d9eb]240/** Counts the number of bonds weighted by bond::BondDegree.
241 * @param _step time step to access
242 * \param bonds times bond::BondDegree
243 */
244int BondedParticle::CountBonds() const
245{
246 int NoBonds = 0;
[9d83b6]247 const BondList& ListOfBonds = getListOfBonds();
[c0d9eb]248 for (BondList::const_iterator Runner = ListOfBonds.begin();
249 Runner != ListOfBonds.end();
250 (++Runner))
251 NoBonds += (*Runner)->BondDegree;
252 return NoBonds;
253};
254
[b70721]255/** Checks whether there is a bond between \a this atom and the given \a *BondPartner.
[073a9e4]256 * @param _step time step to access
[b70721]257 * \param *BondPartner atom to check for
258 * \return true - bond exists, false - bond does not exist
259 */
[073a9e4]260bool BondedParticle::IsBondedTo(const unsigned int _step, BondedParticle * const BondPartner) const
[b70721]261{
262 bool status = false;
263
[073a9e4]264 const BondList& ListOfBonds = getListOfBondsAtStep(_step);
265 for (BondList::const_iterator runner = ListOfBonds.begin();
266 runner != ListOfBonds.end();
267 runner++) {
[b70721]268 status = status || ((*runner)->Contains(BondPartner));
269 }
270 return status;
271};
272
[d74077]273std::ostream & BondedParticle::operator << (std::ostream &ost) const
274{
275 ParticleInfo::operator<<(ost);
276 ost << "," << getPosition();
277 return ost;
278}
279
280std::ostream & operator << (std::ostream &ost, const BondedParticle &a)
281{
282 a.ParticleInfo::operator<<(ost);
283 ost << "," << a.getPosition();
284 return ost;
285}
286
Note: See TracBrowser for help on using the repository browser.