source: src/Atom/atom.cpp@ b49de6

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

FIX: ParticleInfo did use ptr instead of const ref in copy cstor.

  • is only used for atom's copy cstor.
  • Property mode set to 100644
File size: 9.2 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::OutputXYZLine(ofstream *out) const
162{
163 if (out != NULL) {
164 *out << getType()->getSymbol() << "\t" << at(0) << "\t" << at(1) << "\t" << at(2) << "\t" << endl;
165 return true;
166 } else
167 return false;
168};
169
170bool atom::OutputTrajectory(ofstream * const out, const enumeration<const element*> &elementLookup, int *AtomNo, const int step) const
171{
172 AtomNo[getType()->getAtomicNumber()]++;
173 if (out != NULL) {
174 const element *elemental = getType();
175 ASSERT(elementLookup.there.find(elemental)!=elementLookup.there.end(),"Type of this atom was not in the formula upon enumeration");
176 *out << "Ion_Type" << elementLookup.there.find(elemental)->second << "_" << AtomNo[getType()->getAtomicNumber()] << "\t" << fixed << setprecision(9) << showpoint;
177 *out << getPositionAtStep(step)[0] << "\t" << getPositionAtStep(step)[1] << "\t" << getPositionAtStep(step)[2];
178 *out << "\t" << (int)(getFixedIon());
179 if (getAtomicVelocityAtStep(step).Norm() > MYEPSILON)
180 *out << "\t" << scientific << setprecision(6) << getAtomicVelocityAtStep(step)[0] << "\t" << getAtomicVelocityAtStep(step)[1] << "\t" << getAtomicVelocityAtStep(step)[2] << "\t";
181 if (getAtomicForceAtStep(step).Norm() > MYEPSILON)
182 *out << "\t" << scientific << setprecision(6) << getAtomicForceAtStep(step)[0] << "\t" << getAtomicForceAtStep(step)[1] << "\t" << getAtomicForceAtStep(step)[2] << "\t";
183 *out << "\t# Number in molecule " << getNr() << endl;
184 return true;
185 } else
186 return false;
187};
188
189bool atom::OutputTrajectoryXYZ(ofstream * const out, const int step) const
190{
191 if (out != NULL) {
192 *out << getType()->getSymbol() << "\t";
193 *out << getPositionAtStep(step)[0] << "\t";
194 *out << getPositionAtStep(step)[1] << "\t";
195 *out << getPositionAtStep(step)[2] << endl;
196 return true;
197 } else
198 return false;
199};
200
201void atom::OutputMPQCLine(ostream * const out, const Vector *center) const
202{
203 Vector recentered(getPosition());
204 recentered -= *center;
205 *out << "\t\t" << getType()->getSymbol() << " [ " << recentered[0] << "\t" << recentered[1] << "\t" << recentered[2] << " ]" << endl;
206};
207
208void atom::OutputPsi3Line(ostream * const out, const Vector *center) const
209{
210 Vector recentered(getPosition());
211 recentered -= *center;
212 *out << "\t( " << getType()->getSymbol() << "\t" << recentered[0] << "\t" << recentered[1] << "\t" << recentered[2] << " )" << endl;
213};
214
215bool atom::Compare(const atom &ptr) const
216{
217 if (getNr() < ptr.getNr())
218 return true;
219 else
220 return false;
221};
222
223double atom::DistanceSquaredToVector(const Vector &origin) const
224{
225 return DistanceSquared(origin);
226};
227
228double atom::DistanceToVector(const Vector &origin) const
229{
230 return distance(origin);
231};
232
233void atom::InitComponentNr()
234{
235 if (ComponentNr != NULL)
236 delete[](ComponentNr);
237 const BondList& ListOfBonds = getListOfBonds();
238 ComponentNr = new int[ListOfBonds.size()+1];
239 for (int i=ListOfBonds.size()+1;i--;)
240 ComponentNr[i] = -1;
241};
242
243void atom::resetGraphNr(){
244 GraphNr=-1;
245}
246
247std::ostream & atom::operator << (std::ostream &ost) const
248{
249 ParticleInfo::operator<<(ost);
250 ost << "," << getPosition();
251 return ost;
252}
253
254std::ostream & operator << (std::ostream &ost, const atom &a)
255{
256 a.ParticleInfo::operator<<(ost);
257 ost << "," << a.getPosition();
258 return ost;
259}
260
261bool operator < (atom &a, atom &b)
262{
263 return a.Compare(b);
264};
265
266World *atom::getWorld(){
267 return world;
268}
269
270void atom::setWorld(World* _world){
271 world = _world;
272}
273
274bool atom::changeId(atomId_t newId){
275 // first we move ourselves in the world
276 // the world lets us know if that succeeded
277 if(world->changeAtomId(id,newId,this)){
278 id = newId;
279 return true;
280 }
281 else{
282 return false;
283 }
284}
285
286void atom::setId(atomId_t _id) {
287 id=_id;
288}
289
290atomId_t atom::getId() const {
291 return id;
292}
293
294void atom::setMolecule(molecule *_mol){
295 // take this atom from the old molecule
296 removeFromMolecule();
297 mol = _mol;
298 if ((mol) && (!mol->containsAtom(this)))
299 mol->insert(this);
300}
301
302void atom::unsetMolecule()
303{
304 // take this atom from the old molecule
305 ASSERT(!mol->containsAtom(this),
306 "atom::unsetMolecule() - old molecule "+toString(mol)+" still contains us!");
307 mol = NULL;
308}
309
310molecule* atom::getMolecule() const {
311 return mol;
312}
313
314void atom::removeFromMolecule(){
315 if(mol){
316 if(mol->containsAtom(this)){
317 mol->erase(this);
318 }
319 mol=0;
320 }
321}
322
323bool atom::changeNr(const int newNr)
324{
325 if ((mol) && (mol->changeAtomNr(getNr(),newNr,this))) {
326 return true;
327 } else{
328 return false;
329 }
330}
331
332int atom::getNr() const{
333 return ParticleInfo::getNr();
334}
335
336atom* NewAtom(atomId_t _id){
337 atom * res =new atom();
338 res->setId(_id);
339 return res;
340}
341
342void DeleteAtom(atom* atom){
343 delete atom;
344}
345
346bool compareAtomElements(atom* atom1,atom* atom2){
347 return atom1->getType()->getNumber() < atom2->getType()->getNumber();
348}
Note: See TracBrowser for help on using the repository browser.