source: src/Atom/atom.cpp@ 708277

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 708277 was 708277, checked in by Frederik Heber <heber@…>, 12 years ago

FIX: Using fixed Observer in CodePatterns 1.2.6.

  • we now require CodePatterns 1.2.6.
  • Notifications now use subjectKilled() when the Observable they are associated with is destroyed. This allows Observers that are just sign on to a single channel safely sign off.
  • also, derived Observable classes must not remove their Channels and Notifications by themselves. This is done by the Observable base class. Otherwise, subjectKilled() is not called.
  • changed AtomObserver: Is directly connected to the atom class, AtomInserted and AtomRemoved called in its cstor and dstor. The World has nothing to do with it. However, we have to make sure AtomObserver is purged after World.
  • Fixed also some faulty uses of ObserverLog and we always insert into NotificationChannels with static_cast to Observable for clarity.
  • 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-2012 University of Bonn. All rights reserved.
5 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/** \file atom.cpp
24 *
25 * Function implementations for the class atom.
26 *
27 */
28
29// include config.h
30#ifdef HAVE_CONFIG_H
31#include <config.h>
32#endif
33
34#include "CodePatterns/MemDebug.hpp"
35
36#include "atom.hpp"
37#include "AtomObserver.hpp"
38#include "Bond/bond.hpp"
39#include "CodePatterns/Log.hpp"
40#include "config.hpp"
41#include "Element/element.hpp"
42#include "LinearAlgebra/Vector.hpp"
43#include "World.hpp"
44#include "molecule.hpp"
45#include "Shapes/Shape.hpp"
46
47#include <iomanip>
48#include <iostream>
49
50/************************************* Functions for class atom *************************************/
51
52
53atom::atom() :
54 father(this),
55 sort(&Nr),
56 mol(0)
57{
58 // sign on to global atom change tracker
59 AtomObserver::getInstance().AtomInserted(this);
60}
61
62atom::atom(atom *pointer) :
63 ParticleInfo(*pointer),
64 AtomInfo(*pointer),
65 father(pointer),
66 sort(&Nr),
67 mol(0)
68{
69 AtomicPosition = pointer->AtomicPosition; // copy trajectory of coordination
70 AtomicVelocity = pointer->AtomicVelocity; // copy trajectory of velocity
71 AtomicForce = pointer->AtomicForce;
72 // sign on to global atom change tracker
73 AtomObserver::getInstance().AtomInserted(this);
74};
75
76atom *atom::clone(){
77 atom *res = new atom(this);
78 World::getInstance().registerAtom(res);
79 return res;
80}
81
82
83/** Destructor of class atom.
84 */
85atom::~atom()
86{
87 removeFromMolecule();
88 // sign off from global atom change tracker
89 AtomObserver::getInstance().AtomRemoved(this);
90}
91
92
93void atom::UpdateSteps()
94{
95 LOG(4,"atom::UpdateSteps() called.");
96 // append to position, velocity and force vector
97 AtomInfo::AppendTrajectoryStep();
98 // append to ListOfBonds vector
99 BondedParticleInfo::AppendTrajectoryStep();
100}
101
102atom *atom::GetTrueFather()
103{
104 const atom *father = const_cast<const atom *>(this)->GetTrueFather();
105 return const_cast<atom *>(father);
106}
107
108const atom *atom::GetTrueFather() const
109{
110 if(father == this){ // top most father is the one that points on itself
111 return this;
112 }
113 else if(!father) {
114 return 0;
115 }
116 else {
117 return father->GetTrueFather();
118 }
119};
120
121/** Sets father to itself or its father in case of copying a molecule.
122 */
123void atom::CorrectFather()
124{
125 if (father->father != father) // same atom in copy's father points to itself
126// father = this; // set father to itself (copy of a whole molecule)
127// else
128 father = father->father; // set father to original's father
129
130};
131
132void atom::EqualsFather ( const atom *ptr, const atom **res ) const
133{
134 if ( ptr == father )
135 *res = this;
136};
137
138bool atom::isFather(const atom *ptr){
139 return ptr==father;
140}
141
142bool atom::OutputIndexed(ofstream * const out, const int ElementNo, const int AtomNo, const char *comment) const
143{
144 if (out != NULL) {
145 *out << "Ion_Type" << ElementNo << "_" << AtomNo << "\t" << fixed << setprecision(9) << showpoint;
146 *out << at(0) << "\t" << at(1) << "\t" << at(2);
147 *out << "\t" << (int)(getFixedIon());
148 if (getAtomicVelocity().Norm() > MYEPSILON)
149 *out << "\t" << scientific << setprecision(6) << getAtomicVelocity()[0] << "\t" << getAtomicVelocity()[1] << "\t" << getAtomicVelocity()[2] << "\t";
150 if (comment != NULL)
151 *out << " # " << comment << endl;
152 else
153 *out << " # molecule nr " << getNr() << endl;
154 return true;
155 } else
156 return false;
157};
158
159bool atom::OutputArrayIndexed(ostream * const out,const enumeration<const element*> &elementLookup, int *AtomNo, const char *comment) const
160{
161 AtomNo[getType()->getAtomicNumber()]++; // increment number
162 if (out != NULL) {
163 const element *elemental = getType();
164 ASSERT(elementLookup.there.find(elemental)!=elementLookup.there.end(),"Type of this atom was not in the formula upon enumeration");
165 *out << "Ion_Type" << elementLookup.there.find(elemental)->second << "_" << AtomNo[elemental->getAtomicNumber()] << "\t" << fixed << setprecision(9) << showpoint;
166 *out << at(0) << "\t" << at(1) << "\t" << at(2);
167 *out << "\t" << getFixedIon();
168 if (getAtomicVelocity().Norm() > MYEPSILON)
169 *out << "\t" << scientific << setprecision(6) << getAtomicVelocity()[0] << "\t" << getAtomicVelocity()[1] << "\t" << getAtomicVelocity()[2] << "\t";
170 if (comment != NULL)
171 *out << " # " << comment << endl;
172 else
173 *out << " # molecule nr " << getNr() << endl;
174 return true;
175 } else
176 return false;
177};
178
179bool atom::Compare(const atom &ptr) const
180{
181 if (getNr() < ptr.getNr())
182 return true;
183 else
184 return false;
185};
186
187double atom::DistanceSquaredToVector(const Vector &origin) const
188{
189 return DistanceSquared(origin);
190};
191
192double atom::DistanceToVector(const Vector &origin) const
193{
194 return distance(origin);
195};
196
197void atom::InitComponentNr()
198{
199 if (ComponentNr != NULL)
200 delete[](ComponentNr);
201 const BondList& ListOfBonds = getListOfBonds();
202 ComponentNr = new int[ListOfBonds.size()+1];
203 for (int i=ListOfBonds.size()+1;i--;)
204 ComponentNr[i] = -1;
205};
206
207void atom::resetGraphNr(){
208 GraphNr=-1;
209}
210
211std::ostream & atom::operator << (std::ostream &ost) const
212{
213 ParticleInfo::operator<<(ost);
214 ost << "," << getPosition();
215 return ost;
216}
217
218std::ostream & operator << (std::ostream &ost, const atom &a)
219{
220 a.ParticleInfo::operator<<(ost);
221 ost << "," << a.getPosition();
222 return ost;
223}
224
225bool operator < (atom &a, atom &b)
226{
227 return a.Compare(b);
228};
229
230World *atom::getWorld(){
231 return world;
232}
233
234void atom::setWorld(World* _world){
235 world = _world;
236}
237
238bool atom::changeId(atomId_t newId){
239 // first we move ourselves in the world
240 // the world lets us know if that succeeded
241 if(world->changeAtomId(id,newId,this)){
242 OBSERVE;
243 id = newId;
244 NOTIFY(IndexChanged);
245 return true;
246 }
247 else{
248 return false;
249 }
250}
251
252void atom::setId(atomId_t _id) {
253 id=_id;
254}
255
256atomId_t atom::getId() const {
257 return id;
258}
259
260void atom::setMolecule(molecule *_mol){
261 // take this atom from the old molecule
262 removeFromMolecule();
263 mol = _mol;
264 if ((mol) && (!mol->containsAtom(this)))
265 mol->insert(this);
266}
267
268void atom::unsetMolecule()
269{
270 // take this atom from the old molecule
271 ASSERT(!mol->containsAtom(this),
272 "atom::unsetMolecule() - old molecule "+toString(mol)+" still contains us!");
273 mol = NULL;
274}
275
276molecule* atom::getMolecule() const {
277 return mol;
278}
279
280void atom::removeFromMolecule(){
281 if(mol){
282 if(mol->containsAtom(this)){
283 mol->erase(this);
284 }
285 mol=0;
286 }
287}
288
289bool atom::changeNr(const int newNr)
290{
291 if ((mol) && (mol->changeAtomNr(getNr(),newNr,this))) {
292 return true;
293 } else{
294 return false;
295 }
296}
297
298int atom::getNr() const{
299 return ParticleInfo::getNr();
300}
301
302atom* NewAtom(atomId_t _id){
303 atom * res =new atom();
304 res->setId(_id);
305 return res;
306}
307
308void DeleteAtom(atom* atom){
309 delete atom;
310}
311
312bool compareAtomElements(atom* atom1,atom* atom2){
313 return atom1->getType()->getAtomicNumber() < atom2->getType()->getAtomicNumber();
314}
Note: See TracBrowser for help on using the repository browser.