source: src/atom.cpp@ 5f61dde

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

Moved all stuff related to elements into own subfolder and has its own convenience library.

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