source: src/atom.cpp@ 1363de

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

DOCUFIX: atom - Moved all doxygen documentation to header file.

  • Property mode set to 100644
File size: 8.5 KB
RevLine 
[bcf653]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
[14de469]8/** \file atom.cpp
[1907a7]9 *
[14de469]10 * Function implementations for the class atom.
[1907a7]11 *
[14de469]12 */
13
[bf3817]14// include config.h
15#ifdef HAVE_CONFIG_H
16#include <config.h>
17#endif
18
[ad011c]19#include "CodePatterns/MemDebug.hpp"
[112b09]20
[357fba]21#include "atom.hpp"
[129204]22#include "Bond/bond.hpp"
[e2373df]23#include "CodePatterns/Log.hpp"
[4a7776a]24#include "config.hpp"
[f66195]25#include "element.hpp"
[ccd9f5]26#include "parser.hpp"
[57f243]27#include "LinearAlgebra/Vector.hpp"
[d346b6]28#include "World.hpp"
[6cfa36]29#include "molecule.hpp"
[c550dd]30#include "Shapes/Shape.hpp"
[a0064e]31
[36166d]32#include <iomanip>
[0ba410]33#include <iostream>
[36166d]34
[14de469]35/************************************* Functions for class atom *************************************/
36
[70ff32]37
[46d958]38atom::atom() :
[97b825]39 father(this),
[5309ba]40 sort(&Nr),
[97b825]41 mol(0)
[d74077]42{};
[14de469]43
[46d958]44atom::atom(atom *pointer) :
[97b825]45 ParticleInfo(pointer),
46 father(pointer),
[5309ba]47 sort(&Nr),
[9df680]48 mol(0)
[2319ed]49{
[443547]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;
[6625c3]54 setFixedIon(pointer->getFixedIon());
[b453f9]55};
[2319ed]56
[46d958]57atom *atom::clone(){
[68f03d]58 atom *res = new atom(this);
[23b547]59 World::getInstance().registerAtom(res);
[46d958]60 return res;
61}
62
[2319ed]63
[14de469]64/** Destructor of class atom.
65 */
[1907a7]66atom::~atom()
[14de469]67{
[6cfa36]68 removeFromMolecule();
[14de469]69};
[e2373df]70
71
72void atom::UpdateSteps()
73{
74 LOG(4,"atom::UpdateSteps() called.");
75 // append to position, velocity and force vector
76 AtomInfo::AppendTrajectoryStep();
[1e6249]77 // append to ListOfBonds vector
78 BondedParticleInfo::AppendTrajectoryStep();
[e2373df]79}
80
[14de469]81atom *atom::GetTrueFather()
82{
[215df0]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 }
[14de469]92};
93
[e65246]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
[b453f9]105void atom::EqualsFather ( const atom *ptr, const atom **res ) const
[e65246]106{
107 if ( ptr == father )
108 *res = this;
109};
110
[00abfc]111bool atom::isFather(const atom *ptr){
112 return ptr==father;
113}
114
[c550dd]115bool atom::IsInShape(const Shape& shape) const
[e9f8f9]116{
[d74077]117 return shape.isInside(getPosition());
[e9f8f9]118};
119
[e138de]120bool atom::OutputIndexed(ofstream * const out, const int ElementNo, const int AtomNo, const char *comment) const
[14de469]121{
122 if (out != NULL) {
123 *out << "Ion_Type" << ElementNo << "_" << AtomNo << "\t" << fixed << setprecision(9) << showpoint;
[d74077]124 *out << at(0) << "\t" << at(1) << "\t" << at(2);
[6625c3]125 *out << "\t" << (int)(getFixedIon());
[bce72c]126 if (getAtomicVelocity().Norm() > MYEPSILON)
127 *out << "\t" << scientific << setprecision(6) << getAtomicVelocity()[0] << "\t" << getAtomicVelocity()[1] << "\t" << getAtomicVelocity()[2] << "\t";
[437922]128 if (comment != NULL)
129 *out << " # " << comment << endl;
[e9f8f9]130 else
[735b1c]131 *out << " # molecule nr " << getNr() << endl;
[e9f8f9]132 return true;
133 } else
134 return false;
135};
[b453f9]136
[0ba410]137bool atom::OutputArrayIndexed(ostream * const out,const enumeration<const element*> &elementLookup, int *AtomNo, const char *comment) const
[e9f8f9]138{
[83f176]139 AtomNo[getType()->getAtomicNumber()]++; // increment number
[e9f8f9]140 if (out != NULL) {
[8f4df1]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");
[83f176]143 *out << "Ion_Type" << elementLookup.there.find(elemental)->second << "_" << AtomNo[elemental->getAtomicNumber()] << "\t" << fixed << setprecision(9) << showpoint;
[d74077]144 *out << at(0) << "\t" << at(1) << "\t" << at(2);
[6625c3]145 *out << "\t" << getFixedIon();
[bce72c]146 if (getAtomicVelocity().Norm() > MYEPSILON)
147 *out << "\t" << scientific << setprecision(6) << getAtomicVelocity()[0] << "\t" << getAtomicVelocity()[1] << "\t" << getAtomicVelocity()[2] << "\t";
[e9f8f9]148 if (comment != NULL)
149 *out << " # " << comment << endl;
[437922]150 else
[735b1c]151 *out << " # molecule nr " << getNr() << endl;
[14de469]152 return true;
153 } else
154 return false;
155};
156
157bool atom::OutputXYZLine(ofstream *out) const
158{
159 if (out != NULL) {
[b5c53d]160 *out << getType()->getSymbol() << "\t" << at(0) << "\t" << at(1) << "\t" << at(2) << "\t" << endl;
[14de469]161 return true;
162 } else
163 return false;
164};
165
[882a8a]166bool atom::OutputTrajectory(ofstream * const out, const enumeration<const element*> &elementLookup, int *AtomNo, const int step) const
[fcd7b6]167{
[83f176]168 AtomNo[getType()->getAtomicNumber()]++;
[882a8a]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;
[056e70]173 *out << getPositionAtStep(step)[0] << "\t" << getPositionAtStep(step)[1] << "\t" << getPositionAtStep(step)[2];
[6625c3]174 *out << "\t" << (int)(getFixedIon());
[056e70]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";
[735b1c]179 *out << "\t# Number in molecule " << getNr() << endl;
[fcd7b6]180 return true;
181 } else
182 return false;
183};
184
[e138de]185bool atom::OutputTrajectoryXYZ(ofstream * const out, const int step) const
[681a8a]186{
187 if (out != NULL) {
[b5c53d]188 *out << getType()->getSymbol() << "\t";
[056e70]189 *out << getPositionAtStep(step)[0] << "\t";
190 *out << getPositionAtStep(step)[1] << "\t";
191 *out << getPositionAtStep(step)[2] << endl;
[681a8a]192 return true;
193 } else
194 return false;
195};
196
[0dc86e2]197void atom::OutputMPQCLine(ostream * const out, const Vector *center) const
[4455f4]198{
[d74077]199 Vector recentered(getPosition());
200 recentered -= *center;
[b5c53d]201 *out << "\t\t" << getType()->getSymbol() << " [ " << recentered[0] << "\t" << recentered[1] << "\t" << recentered[2] << " ]" << endl;
[4455f4]202};
203
[b453f9]204bool atom::Compare(const atom &ptr) const
[4455f4]205{
[735b1c]206 if (getNr() < ptr.getNr())
[4455f4]207 return true;
208 else
209 return false;
210};
211
[b453f9]212double atom::DistanceSquaredToVector(const Vector &origin) const
[4455f4]213{
[d74077]214 return DistanceSquared(origin);
[4455f4]215};
216
[b453f9]217double atom::DistanceToVector(const Vector &origin) const
[4455f4]218{
[d74077]219 return distance(origin);
[4455f4]220};
221
222void atom::InitComponentNr()
223{
224 if (ComponentNr != NULL)
[920c70]225 delete[](ComponentNr);
[9d83b6]226 const BondList& ListOfBonds = getListOfBonds();
[920c70]227 ComponentNr = new int[ListOfBonds.size()+1];
[4455f4]228 for (int i=ListOfBonds.size()+1;i--;)
229 ComponentNr[i] = -1;
[14b65e]230};
231
232void atom::resetGraphNr(){
233 GraphNr=-1;
234}
[4455f4]235
[d74077]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}
[4455f4]249
250bool operator < (atom &a, atom &b)
251{
252 return a.Compare(b);
253};
254
[46d958]255World *atom::getWorld(){
256 return world;
257}
258
259void atom::setWorld(World* _world){
260 world = _world;
261}
262
[88d586]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) {
[46d958]276 id=_id;
277}
278
[ad2b411]279atomId_t atom::getId() const {
[46d958]280 return id;
281}
282
[6cfa36]283void atom::setMolecule(molecule *_mol){
284 // take this atom from the old molecule
285 removeFromMolecule();
286 mol = _mol;
287 if(!mol->containsAtom(this)){
[dddbfe]288 mol->insert(this);
[6cfa36]289 }
290}
291
[e41c48]292molecule* atom::getMolecule() const {
[c084cc]293 return mol;
294}
295
[6cfa36]296void atom::removeFromMolecule(){
297 if(mol){
298 if(mol->containsAtom(this)){
299 mol->erase(this);
300 }
301 mol=0;
302 }
[1f8337]303}
304
[e8a21f]305int atom::getNr() const{
[735b1c]306 return ParticleInfo::getNr();
[e8a21f]307}
[6cfa36]308
[88d586]309atom* NewAtom(atomId_t _id){
310 atom * res =new atom();
311 res->setId(_id);
312 return res;
[46d958]313}
314
[88d586]315void DeleteAtom(atom* atom){
[46d958]316 delete atom;
[e5f64de]317}
318
319bool compareAtomElements(atom* atom1,atom* atom2){
320 return atom1->getType()->getNumber() < atom2->getType()->getNumber();
[46d958]321}
Note: See TracBrowser for help on using the repository browser.