source: src/atom.cpp@ 2d292d

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 2d292d was 8f4df1, checked in by Frederik Heber <heber@…>, 15 years ago

Merge branch 'AtomicPositionEncapsulation' into stable

Conflicts:

src/Actions/AtomAction/ChangeElementAction.cpp
src/Actions/WorldAction/RemoveSphereOfAtomsAction.cpp
src/Makefile.am
src/UIElements/TextUI/TextDialog.cpp
src/analysis_correlation.hpp
src/atom.cpp
src/atom_atominfo.hpp
src/bond.cpp
src/boundary.cpp
src/molecule_geometry.cpp
src/tesselation.cpp
src/tesselationhelpers.cpp
src/triangleintersectionlist.cpp
src/unittests/Makefile.am

  • fixed #includes due to moves to Helpers and LinearAlgebra
  • moved VectorInterface.* and vector_ops.* to LinearAlgebra
  • no more direct access of atom::node, remapped to set/getPosition()
  • no more direct access to atom::type, remapped to set/getType() (also in atom due to derivation and atominfo::AtomicElement is private not protected).
  • Property mode set to 100644
File size: 10.8 KB
RevLine 
[14de469]1/** \file atom.cpp
[1907a7]2 *
[14de469]3 * Function implementations for the class atom.
[1907a7]4 *
[14de469]5 */
6
[112b09]7#include "Helpers/MemDebug.hpp"
8
[357fba]9#include "atom.hpp"
[e41951]10#include "bond.hpp"
[4a7776a]11#include "config.hpp"
[f66195]12#include "element.hpp"
[266237]13#include "lists.hpp"
[ccd9f5]14#include "parser.hpp"
[57f243]15#include "LinearAlgebra/Vector.hpp"
[d346b6]16#include "World.hpp"
[6cfa36]17#include "molecule.hpp"
[c550dd]18#include "Shapes/Shape.hpp"
[1907a7]19
[36166d]20#include <iomanip>
[0ba410]21#include <iostream>
[36166d]22
[14de469]23/************************************* Functions for class atom *************************************/
24
[70ff32]25
[14de469]26/** Constructor of class atom.
27 */
[46d958]28atom::atom() :
[6cfa36]29 father(this), sort(&nr), mol(0)
[d74077]30{};
[14de469]31
[2319ed]32/** Constructor of class atom.
33 */
[46d958]34atom::atom(atom *pointer) :
[6cfa36]35 ParticleInfo(pointer),father(pointer), sort(&nr)
[2319ed]36{
[d74077]37 setType(pointer->getType()); // copy element of atom
38 setPosition(pointer->getPosition()); // copy coordination
39 AtomicVelocity = pointer->AtomicVelocity; // copy velocity
[2319ed]40 FixedIon = pointer->FixedIon;
[6cfa36]41 mol = 0;
[b453f9]42};
[2319ed]43
[46d958]44atom *atom::clone(){
[68f03d]45 atom *res = new atom(this);
[46d958]46 res->father = this;
[5f612ee]47 res->sort = &res->nr;
[d74077]48 res->setType(getType());
49 res->setPosition(this->getPosition());
50 res->AtomicVelocity = this->AtomicVelocity;
[46d958]51 res->FixedIon = FixedIon;
[6cfa36]52 res->mol = 0;
[23b547]53 World::getInstance().registerAtom(res);
[46d958]54 return res;
55}
56
[2319ed]57
[14de469]58/** Destructor of class atom.
59 */
[1907a7]60atom::~atom()
[14de469]61{
[6cfa36]62 removeFromMolecule();
[a80241]63 for(BondList::iterator iter=ListOfBonds.begin(); iter!=ListOfBonds.end();){
64 // deleting the bond will invalidate the iterator !!!
65 bond *bond =*(iter++);
66 delete(bond);
67 }
[14de469]68};
69
70
71/** Climbs up the father list until NULL, last is returned.
72 * \return true father, i.e. whose father points to itself, NULL if it could not be found or has none (added hydrogen)
73 */
74atom *atom::GetTrueFather()
75{
[215df0]76 if(father == this){ // top most father is the one that points on itself
77 return this;
78 }
79 else if(!father) {
80 return 0;
81 }
82 else {
83 return father->GetTrueFather();
84 }
[14de469]85};
86
[e65246]87/** Sets father to itself or its father in case of copying a molecule.
88 */
89void atom::CorrectFather()
90{
91 if (father->father == father) // same atom in copy's father points to itself
92 father = this; // set father to itself (copy of a whole molecule)
93 else
94 father = father->father; // set father to original's father
95
96};
97
98/** Check whether father is equal to given atom.
99 * \param *ptr atom to compare father to
100 * \param **res return value (only set if atom::father is equal to \a *ptr)
101 */
[b453f9]102void atom::EqualsFather ( const atom *ptr, const atom **res ) const
[e65246]103{
104 if ( ptr == father )
105 *res = this;
106};
107
[00abfc]108bool atom::isFather(const atom *ptr){
109 return ptr==father;
110}
111
[e9f8f9]112/** Checks whether atom is within the given box.
113 * \param offset offset to box origin
114 * \param *parallelepiped box matrix
115 * \return true - is inside, false - is not
116 */
[c550dd]117bool atom::IsInShape(const Shape& shape) const
[e9f8f9]118{
[d74077]119 return shape.isInside(getPosition());
[e9f8f9]120};
121
[266237]122/** Counts the number of bonds weighted by bond::BondDegree.
123 * \param bonds times bond::BondDegree
124 */
[4455f4]125int BondedParticle::CountBonds() const
[266237]126{
127 int NoBonds = 0;
128 for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); (++Runner))
129 NoBonds += (*Runner)->BondDegree;
130 return NoBonds;
131};
132
[b453f9]133/** Output of a single atom with given numbering.
[14de469]134 * \param ElementNo cardinal number of the element
135 * \param AtomNo cardinal number among these atoms of the same element
136 * \param *out stream to output to
[1907a7]137 * \param *comment commentary after '#' sign
[e41951]138 * \return true - \a *out present, false - \a *out is NULL
[14de469]139 */
[e138de]140bool atom::OutputIndexed(ofstream * const out, const int ElementNo, const int AtomNo, const char *comment) const
[14de469]141{
142 if (out != NULL) {
143 *out << "Ion_Type" << ElementNo << "_" << AtomNo << "\t" << fixed << setprecision(9) << showpoint;
[d74077]144 *out << at(0) << "\t" << at(1) << "\t" << at(2);
[943d02]145 *out << "\t" << FixedIon;
[d74077]146 if (AtomicVelocity.Norm() > MYEPSILON)
147 *out << "\t" << scientific << setprecision(6) << AtomicVelocity[0] << "\t" << AtomicVelocity[1] << "\t" << AtomicVelocity[2] << "\t";
[437922]148 if (comment != NULL)
149 *out << " # " << comment << endl;
[e9f8f9]150 else
151 *out << " # molecule nr " << nr << endl;
152 return true;
153 } else
154 return false;
155};
[b453f9]156
157/** Output of a single atom with numbering from array according to atom::type.
158 * \param *ElementNo cardinal number of the element
159 * \param *AtomNo cardinal number among these atoms of the same element
160 * \param *out stream to output to
161 * \param *comment commentary after '#' sign
162 * \return true - \a *out present, false - \a *out is NULL
163 */
[0ba410]164bool atom::OutputArrayIndexed(ostream * const out,const enumeration<const element*> &elementLookup, int *AtomNo, const char *comment) const
[e9f8f9]165{
[d74077]166 AtomNo[getType()->Z]++; // increment number
[e9f8f9]167 if (out != NULL) {
[8f4df1]168 const element *elemental = getType();
169 cout << "Looking for atom with element " << *elemental << endl;
170 ASSERT(elementLookup.there.find(elemental)!=elementLookup.there.end(),"Type of this atom was not in the formula upon enumeration");
171 *out << "Ion_Type" << elementLookup.there.find(elemental)->second << "_" << AtomNo[elemental->Z] << "\t" << fixed << setprecision(9) << showpoint;
[d74077]172 *out << at(0) << "\t" << at(1) << "\t" << at(2);
[e9f8f9]173 *out << "\t" << FixedIon;
[d74077]174 if (AtomicVelocity.Norm() > MYEPSILON)
175 *out << "\t" << scientific << setprecision(6) << AtomicVelocity[0] << "\t" << AtomicVelocity[1] << "\t" << AtomicVelocity[2] << "\t";
[e9f8f9]176 if (comment != NULL)
177 *out << " # " << comment << endl;
[437922]178 else
179 *out << " # molecule nr " << nr << endl;
[14de469]180 return true;
181 } else
182 return false;
183};
184
185/** Output of a single atom as one lin in xyz file.
186 * \param *out stream to output to
[e41951]187 * \return true - \a *out present, false - \a *out is NULL
[14de469]188 */
189bool atom::OutputXYZLine(ofstream *out) const
190{
191 if (out != NULL) {
[d74077]192 *out << getType()->symbol << "\t" << at(0) << "\t" << at(1) << "\t" << at(2) << "\t" << endl;
[14de469]193 return true;
194 } else
195 return false;
196};
197
[fcd7b6]198/** Output of a single atom as one lin in xyz file.
199 * \param *out stream to output to
[e41951]200 * \param *ElementNo array with ion type number in the config file this atom's element shall have
201 * \param *AtomNo array with atom number in the config file this atom shall have, is increase by one automatically
202 * \param step Trajectory time step to output
203 * \return true - \a *out present, false - \a *out is NULL
[fcd7b6]204 */
[e138de]205bool atom::OutputTrajectory(ofstream * const out, const int *ElementNo, int *AtomNo, const int step) const
[fcd7b6]206{
[d74077]207 AtomNo[getType()->Z]++;
[fcd7b6]208 if (out != NULL) {
[d74077]209 *out << "Ion_Type" << ElementNo[getType()->Z] << "_" << AtomNo[getType()->Z] << "\t" << fixed << setprecision(9) << showpoint;
[0a4f7f]210 *out << Trajectory.R.at(step)[0] << "\t" << Trajectory.R.at(step)[1] << "\t" << Trajectory.R.at(step)[2];
[fcd7b6]211 *out << "\t" << FixedIon;
212 if (Trajectory.U.at(step).Norm() > MYEPSILON)
[0a4f7f]213 *out << "\t" << scientific << setprecision(6) << Trajectory.U.at(step)[0] << "\t" << Trajectory.U.at(step)[1] << "\t" << Trajectory.U.at(step)[2] << "\t";
[fcd7b6]214 if (Trajectory.F.at(step).Norm() > MYEPSILON)
[0a4f7f]215 *out << "\t" << scientific << setprecision(6) << Trajectory.F.at(step)[0] << "\t" << Trajectory.F.at(step)[1] << "\t" << Trajectory.F.at(step)[2] << "\t";
[fcd7b6]216 *out << "\t# Number in molecule " << nr << endl;
217 return true;
218 } else
219 return false;
220};
221
[681a8a]222/** Output of a single atom as one lin in xyz file.
223 * \param *out stream to output to
[e41951]224 * \param step Trajectory time step to output
225 * \return true - \a *out present, false - \a *out is NULL
[681a8a]226 */
[e138de]227bool atom::OutputTrajectoryXYZ(ofstream * const out, const int step) const
[681a8a]228{
229 if (out != NULL) {
[d74077]230 *out << getType()->symbol << "\t";
[0a4f7f]231 *out << Trajectory.R.at(step)[0] << "\t";
232 *out << Trajectory.R.at(step)[1] << "\t";
233 *out << Trajectory.R.at(step)[2] << endl;
[681a8a]234 return true;
235 } else
236 return false;
237};
238
[4455f4]239/** Outputs the MPQC configuration line for this atom.
240 * \param *out output stream
241 * \param *center center of molecule subtracted from position
242 * \param *AtomNo pointer to atom counter that is increased by one
243 */
[1b2d30]244void atom::OutputMPQCLine(ostream * const out, const Vector *center, int *AtomNo = NULL) const
[4455f4]245{
[d74077]246 Vector recentered(getPosition());
247 recentered -= *center;
248 *out << "\t\t" << getType()->symbol << " [ " << recentered[0] << "\t" << recentered[1] << "\t" << recentered[2] << " ]" << endl;
[4455f4]249 if (AtomNo != NULL)
250 *AtomNo++;
251};
252
253/** Compares the indices of \a this atom with a given \a ptr.
254 * \param ptr atom to compare index against
255 * \return true - this one's is smaller, false - not
256 */
[b453f9]257bool atom::Compare(const atom &ptr) const
[4455f4]258{
259 if (nr < ptr.nr)
260 return true;
261 else
262 return false;
263};
264
265/** Returns squared distance to a given vector.
266 * \param origin vector to calculate distance to
267 * \return distance squared
268 */
[b453f9]269double atom::DistanceSquaredToVector(const Vector &origin) const
[4455f4]270{
[d74077]271 return DistanceSquared(origin);
[4455f4]272};
273
274/** Returns distance to a given vector.
275 * \param origin vector to calculate distance to
276 * \return distance
277 */
[b453f9]278double atom::DistanceToVector(const Vector &origin) const
[4455f4]279{
[d74077]280 return distance(origin);
[4455f4]281};
282
283/** Initialises the component number array.
284 * Size is set to atom::ListOfBonds.size()+1 (last is th encode end by -1)
285 */
286void atom::InitComponentNr()
287{
288 if (ComponentNr != NULL)
[920c70]289 delete[](ComponentNr);
290 ComponentNr = new int[ListOfBonds.size()+1];
[4455f4]291 for (int i=ListOfBonds.size()+1;i--;)
292 ComponentNr[i] = -1;
293};
294
[d74077]295std::ostream & atom::operator << (std::ostream &ost) const
296{
297 ParticleInfo::operator<<(ost);
298 ost << "," << getPosition();
299 return ost;
300}
301
302std::ostream & operator << (std::ostream &ost, const atom &a)
303{
304 a.ParticleInfo::operator<<(ost);
305 ost << "," << a.getPosition();
306 return ost;
307}
[4455f4]308
309bool operator < (atom &a, atom &b)
310{
311 return a.Compare(b);
312};
313
[46d958]314World *atom::getWorld(){
315 return world;
316}
317
318void atom::setWorld(World* _world){
319 world = _world;
320}
321
[88d586]322bool atom::changeId(atomId_t newId){
323 // first we move ourselves in the world
324 // the world lets us know if that succeeded
325 if(world->changeAtomId(id,newId,this)){
326 id = newId;
327 return true;
328 }
329 else{
330 return false;
331 }
332}
333
334void atom::setId(atomId_t _id) {
[46d958]335 id=_id;
336}
337
[ad2b411]338atomId_t atom::getId() const {
[46d958]339 return id;
340}
341
[6cfa36]342void atom::setMolecule(molecule *_mol){
343 // take this atom from the old molecule
344 removeFromMolecule();
345 mol = _mol;
346 if(!mol->containsAtom(this)){
[dddbfe]347 mol->insert(this);
[6cfa36]348 }
349}
350
[c084cc]351molecule* atom::getMolecule(){
352 return mol;
353}
354
[6cfa36]355void atom::removeFromMolecule(){
356 if(mol){
357 if(mol->containsAtom(this)){
358 mol->erase(this);
359 }
360 mol=0;
361 }
362}
363
364
[88d586]365atom* NewAtom(atomId_t _id){
366 atom * res =new atom();
367 res->setId(_id);
368 return res;
[46d958]369}
370
[88d586]371void DeleteAtom(atom* atom){
[46d958]372 delete atom;
373}
Note: See TracBrowser for help on using the repository browser.