source: src/Atom/atom.cpp@ ed26ae

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

Renamed calls to element::getNumber() -> ::getAtomicNumber().

  • dropped element::getNumber() as getAtomicNumber has same functionality.
  • Property mode set to 100644
File size: 6.9 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 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/** \file atom.cpp
9 *
10 * Function implementations for the class atom.
11 *
12 */
13
14// include config.h
15#ifdef HAVE_CONFIG_H
16#include <config.h>
17#endif
18
19#include "CodePatterns/MemDebug.hpp"
20
21#include "atom.hpp"
22#include "Bond/bond.hpp"
23#include "CodePatterns/Log.hpp"
24#include "config.hpp"
25#include "Element/element.hpp"
26#include "LinearAlgebra/Vector.hpp"
27#include "World.hpp"
28#include "molecule.hpp"
29#include "Shapes/Shape.hpp"
30
31#include <iomanip>
32#include <iostream>
33
34/************************************* Functions for class atom *************************************/
35
36
37atom::atom() :
38 father(this),
39 sort(&Nr),
40 mol(0)
41{};
42
43atom::atom(atom *pointer) :
44 ParticleInfo(*pointer),
45 AtomInfo(*pointer),
46 father(pointer),
47 sort(&Nr),
48 mol(0)
49{
50 AtomicPosition = pointer->AtomicPosition; // copy trajectory of coordination
51 AtomicVelocity = pointer->AtomicVelocity; // copy trajectory of velocity
52 AtomicForce = pointer->AtomicForce;
53};
54
55atom *atom::clone(){
56 atom *res = new atom(this);
57 World::getInstance().registerAtom(res);
58 return res;
59}
60
61
62/** Destructor of class atom.
63 */
64atom::~atom()
65{
66 removeFromMolecule();
67};
68
69
70void atom::UpdateSteps()
71{
72 LOG(4,"atom::UpdateSteps() called.");
73 // append to position, velocity and force vector
74 AtomInfo::AppendTrajectoryStep();
75 // append to ListOfBonds vector
76 BondedParticleInfo::AppendTrajectoryStep();
77}
78
79atom *atom::GetTrueFather()
80{
81 const atom *father = const_cast<const atom *>(this)->GetTrueFather();
82 return const_cast<atom *>(father);
83}
84
85const atom *atom::GetTrueFather() const
86{
87 if(father == this){ // top most father is the one that points on itself
88 return this;
89 }
90 else if(!father) {
91 return 0;
92 }
93 else {
94 return father->GetTrueFather();
95 }
96};
97
98/** Sets father to itself or its father in case of copying a molecule.
99 */
100void atom::CorrectFather()
101{
102 if (father->father != father) // same atom in copy's father points to itself
103// father = this; // set father to itself (copy of a whole molecule)
104// else
105 father = father->father; // set father to original's father
106
107};
108
109void atom::EqualsFather ( const atom *ptr, const atom **res ) const
110{
111 if ( ptr == father )
112 *res = this;
113};
114
115bool atom::isFather(const atom *ptr){
116 return ptr==father;
117}
118
119bool atom::IsInShape(const Shape& shape) const
120{
121 return shape.isInside(getPosition());
122};
123
124bool atom::OutputIndexed(ofstream * const out, const int ElementNo, const int AtomNo, const char *comment) const
125{
126 if (out != NULL) {
127 *out << "Ion_Type" << ElementNo << "_" << AtomNo << "\t" << fixed << setprecision(9) << showpoint;
128 *out << at(0) << "\t" << at(1) << "\t" << at(2);
129 *out << "\t" << (int)(getFixedIon());
130 if (getAtomicVelocity().Norm() > MYEPSILON)
131 *out << "\t" << scientific << setprecision(6) << getAtomicVelocity()[0] << "\t" << getAtomicVelocity()[1] << "\t" << getAtomicVelocity()[2] << "\t";
132 if (comment != NULL)
133 *out << " # " << comment << endl;
134 else
135 *out << " # molecule nr " << getNr() << endl;
136 return true;
137 } else
138 return false;
139};
140
141bool atom::OutputArrayIndexed(ostream * const out,const enumeration<const element*> &elementLookup, int *AtomNo, const char *comment) const
142{
143 AtomNo[getType()->getAtomicNumber()]++; // increment number
144 if (out != NULL) {
145 const element *elemental = getType();
146 ASSERT(elementLookup.there.find(elemental)!=elementLookup.there.end(),"Type of this atom was not in the formula upon enumeration");
147 *out << "Ion_Type" << elementLookup.there.find(elemental)->second << "_" << AtomNo[elemental->getAtomicNumber()] << "\t" << fixed << setprecision(9) << showpoint;
148 *out << at(0) << "\t" << at(1) << "\t" << at(2);
149 *out << "\t" << getFixedIon();
150 if (getAtomicVelocity().Norm() > MYEPSILON)
151 *out << "\t" << scientific << setprecision(6) << getAtomicVelocity()[0] << "\t" << getAtomicVelocity()[1] << "\t" << getAtomicVelocity()[2] << "\t";
152 if (comment != NULL)
153 *out << " # " << comment << endl;
154 else
155 *out << " # molecule nr " << getNr() << endl;
156 return true;
157 } else
158 return false;
159};
160
161bool atom::Compare(const atom &ptr) const
162{
163 if (getNr() < ptr.getNr())
164 return true;
165 else
166 return false;
167};
168
169double atom::DistanceSquaredToVector(const Vector &origin) const
170{
171 return DistanceSquared(origin);
172};
173
174double atom::DistanceToVector(const Vector &origin) const
175{
176 return distance(origin);
177};
178
179void atom::InitComponentNr()
180{
181 if (ComponentNr != NULL)
182 delete[](ComponentNr);
183 const BondList& ListOfBonds = getListOfBonds();
184 ComponentNr = new int[ListOfBonds.size()+1];
185 for (int i=ListOfBonds.size()+1;i--;)
186 ComponentNr[i] = -1;
187};
188
189void atom::resetGraphNr(){
190 GraphNr=-1;
191}
192
193std::ostream & atom::operator << (std::ostream &ost) const
194{
195 ParticleInfo::operator<<(ost);
196 ost << "," << getPosition();
197 return ost;
198}
199
200std::ostream & operator << (std::ostream &ost, const atom &a)
201{
202 a.ParticleInfo::operator<<(ost);
203 ost << "," << a.getPosition();
204 return ost;
205}
206
207bool operator < (atom &a, atom &b)
208{
209 return a.Compare(b);
210};
211
212World *atom::getWorld(){
213 return world;
214}
215
216void atom::setWorld(World* _world){
217 world = _world;
218}
219
220bool atom::changeId(atomId_t newId){
221 // first we move ourselves in the world
222 // the world lets us know if that succeeded
223 if(world->changeAtomId(id,newId,this)){
224 id = newId;
225 return true;
226 }
227 else{
228 return false;
229 }
230}
231
232void atom::setId(atomId_t _id) {
233 id=_id;
234}
235
236atomId_t atom::getId() const {
237 return id;
238}
239
240void atom::setMolecule(molecule *_mol){
241 // take this atom from the old molecule
242 removeFromMolecule();
243 mol = _mol;
244 if ((mol) && (!mol->containsAtom(this)))
245 mol->insert(this);
246}
247
248void atom::unsetMolecule()
249{
250 // take this atom from the old molecule
251 ASSERT(!mol->containsAtom(this),
252 "atom::unsetMolecule() - old molecule "+toString(mol)+" still contains us!");
253 mol = NULL;
254}
255
256molecule* atom::getMolecule() const {
257 return mol;
258}
259
260void atom::removeFromMolecule(){
261 if(mol){
262 if(mol->containsAtom(this)){
263 mol->erase(this);
264 }
265 mol=0;
266 }
267}
268
269bool atom::changeNr(const int newNr)
270{
271 if ((mol) && (mol->changeAtomNr(getNr(),newNr,this))) {
272 return true;
273 } else{
274 return false;
275 }
276}
277
278int atom::getNr() const{
279 return ParticleInfo::getNr();
280}
281
282atom* NewAtom(atomId_t _id){
283 atom * res =new atom();
284 res->setId(_id);
285 return res;
286}
287
288void DeleteAtom(atom* atom){
289 delete atom;
290}
291
292bool compareAtomElements(atom* atom1,atom* atom2){
293 return atom1->getType()->getAtomicNumber() < atom2->getType()->getAtomicNumber();
294}
Note: See TracBrowser for help on using the repository browser.