source: src/atom_bondedparticle.cpp@ 831a14

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

Refactored atom.cpp into multiple files.

After the class atom was refactored into multiple base classes that are inherited, these base classes are also all put into separate files. This is basically a preparatory step for the like-wise refactoring of class molecule into inherited base classes and splitting up (that is there done already). Finally, we will also separate the relations, i.e. not have "atom.hpp" included everywhere and use class atom, but rather the subclasses such as TrajectoryParticle and its header files only.
Signed-off-by: Frederik Heber <heber@…>

  • Property mode set to 100644
File size: 4.6 KB
Line 
1/*
2 * atom_bondedparticle.cpp
3 *
4 * Created on: Oct 19, 2009
5 * Author: heber
6 */
7
8#include "atom.hpp"
9#include "atom_bondedparticle.hpp"
10#include "bond.hpp"
11#include "element.hpp"
12#include "lists.hpp"
13#include "verbose.hpp"
14
15/** Constructor of class BondedParticle.
16 */
17BondedParticle::BondedParticle(){};
18
19/** Destructor of class BondedParticle.
20 */
21BondedParticle::~BondedParticle()
22{
23 BondList::const_iterator Runner;
24 while (!ListOfBonds.empty()) {
25 Runner = ListOfBonds.begin();
26 removewithoutcheck(*Runner);
27 }
28};
29
30/** Outputs the current atom::AdaptiveOrder and atom::MaxOrder to \a *file.
31 * \param *file output stream
32 */
33void BondedParticle::OutputOrder(ofstream *file)
34{
35 *file << nr << "\t" << (int)AdaptiveOrder << "\t" << (int)MaxOrder << endl;
36 //cout << Verbose(2) << "Storing: " << nr << "\t" << (int)AdaptiveOrder << "\t" << (int)MaxOrder << "." << endl;
37};
38
39/** Prints all bonds of this atom with total degree.
40 * \param *out stream to output to
41 * \return true - \a *out present, false - \a *out is NULL
42 */
43bool BondedParticle::OutputBondOfAtom(ofstream *out) const
44{
45 if (out != NULL) {
46 *out << Verbose(4) << "Atom " << Name << "/" << nr << " with " << ListOfBonds.size() << " bonds: ";
47 int TotalDegree = 0;
48 for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); ++Runner) {
49 *out << **Runner << "\t";
50 TotalDegree += (*Runner)->BondDegree;
51 }
52 *out << " -- TotalDegree: " << TotalDegree << endl;
53 return true;
54 } else
55 return false;
56};
57
58/** Output of atom::nr along with all bond partners.
59 * \param *AdjacencyFile output stream
60 */
61void BondedParticle::OutputAdjacency(ofstream *AdjacencyFile) const
62{
63 *AdjacencyFile << nr << "\t";
64 for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); (++Runner))
65 *AdjacencyFile << (*Runner)->GetOtherAtom(this)->nr << "\t";
66 *AdjacencyFile << endl;
67};
68
69/** Puts a given bond into atom::ListOfBonds.
70 * \param *Binder bond to insert
71 */
72bool BondedParticle::RegisterBond(bond *Binder)
73{
74 bool status = false;
75 if (Binder != NULL) {
76 if (Binder->Contains(this)) {
77 ListOfBonds.push_back(Binder);
78 status = true;
79 } else {
80 cout << Verbose(1) << "ERROR: " << *Binder << " does not contain " << *this << "." << endl;
81 }
82 } else {
83 cout << Verbose(1) << "ERROR: Binder is " << Binder << "." << endl;
84 }
85 return status;
86};
87
88/** Removes a given bond from atom::ListOfBonds.
89 * \param *Binder bond to remove
90 */
91bool BondedParticle::UnregisterBond(bond *Binder)
92{
93 bool status = false;
94 if (Binder != NULL) {
95 if (Binder->Contains(this)) {
96 ListOfBonds.remove(Binder);
97 status = true;
98 } else {
99 cout << Verbose(1) << "ERROR: " << *Binder << " does not contain " << *this << "." << endl;
100 }
101 } else {
102 cout << Verbose(1) << "ERROR: Binder is " << Binder << "." << endl;
103 }
104 return status;
105};
106
107/** Removes all bonds from atom::ListOfBonds.
108 * \note Does not do any memory de-allocation.
109 */
110void BondedParticle::UnregisterAllBond()
111{
112 ListOfBonds.clear();
113};
114
115/** Corrects the bond degree by one at most if necessary.
116 * \param *out output stream for debugging
117 */
118int BondedParticle::CorrectBondDegree(ofstream *out)
119{
120 int NoBonds = 0;
121 int OtherNoBonds = 0;
122 int FalseBondDegree = 0;
123 atom *OtherWalker = NULL;
124 bond *CandidateBond = NULL;
125
126 *out << Verbose(3) << "Walker " << *this << ": " << (int)this->type->NoValenceOrbitals << " > " << NoBonds << "?" << endl;
127 NoBonds = CountBonds();
128 if ((int)(type->NoValenceOrbitals) > NoBonds) { // we have a mismatch, check all bonding partners for mismatch
129 for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); (++Runner)) {
130 OtherWalker = (*Runner)->GetOtherAtom(this);
131 OtherNoBonds = OtherWalker->CountBonds();
132 *out << Verbose(3) << "OtherWalker " << *OtherWalker << ": " << (int)OtherWalker->type->NoValenceOrbitals << " > " << NoBonds << "?" << endl;
133 if ((int)(OtherWalker->type->NoValenceOrbitals) > NoBonds) { // check if possible candidate
134 if ((CandidateBond == NULL) || (ListOfBonds.size() > OtherWalker->ListOfBonds.size())) { // pick the one with fewer number of bonds first
135 CandidateBond = (*Runner);
136 *out << Verbose(3) << "New candidate is " << *CandidateBond << "." << endl;
137 }
138 }
139 }
140 if ((CandidateBond != NULL)) {
141 CandidateBond->BondDegree++;
142 *out << Verbose(2) << "Increased bond degree for bond " << *CandidateBond << "." << endl;
143 } else {
144 *out << Verbose(2) << "Could not find correct degree for atom " << *this << "." << endl;
145 FalseBondDegree++;
146 }
147 }
148 return FalseBondDegree;
149};
150
Note: See TracBrowser for help on using the repository browser.