source: src/atom.cpp@ 44de80

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 44de80 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
Line 
1/** \file atom.cpp
2 *
3 * Function implementations for the class atom.
4 *
5 */
6
7#include "Helpers/MemDebug.hpp"
8
9#include "atom.hpp"
10#include "bond.hpp"
11#include "config.hpp"
12#include "element.hpp"
13#include "lists.hpp"
14#include "parser.hpp"
15#include "LinearAlgebra/Vector.hpp"
16#include "World.hpp"
17#include "molecule.hpp"
18#include "Shapes/Shape.hpp"
19
20#include <iomanip>
21#include <iostream>
22
23/************************************* Functions for class atom *************************************/
24
25
26/** Constructor of class atom.
27 */
28atom::atom() :
29 father(this), sort(&nr), mol(0)
30{};
31
32/** Constructor of class atom.
33 */
34atom::atom(atom *pointer) :
35 ParticleInfo(pointer),father(pointer), sort(&nr)
36{
37 setType(pointer->getType()); // copy element of atom
38 setPosition(pointer->getPosition()); // copy coordination
39 AtomicVelocity = pointer->AtomicVelocity; // copy velocity
40 FixedIon = pointer->FixedIon;
41 mol = 0;
42};
43
44atom *atom::clone(){
45 atom *res = new atom(this);
46 res->father = this;
47 res->sort = &res->nr;
48 res->setType(getType());
49 res->setPosition(this->getPosition());
50 res->AtomicVelocity = this->AtomicVelocity;
51 res->FixedIon = FixedIon;
52 res->mol = 0;
53 World::getInstance().registerAtom(res);
54 return res;
55}
56
57
58/** Destructor of class atom.
59 */
60atom::~atom()
61{
62 removeFromMolecule();
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 }
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{
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 }
85};
86
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 */
102void atom::EqualsFather ( const atom *ptr, const atom **res ) const
103{
104 if ( ptr == father )
105 *res = this;
106};
107
108bool atom::isFather(const atom *ptr){
109 return ptr==father;
110}
111
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 */
117bool atom::IsInShape(const Shape& shape) const
118{
119 return shape.isInside(getPosition());
120};
121
122/** Counts the number of bonds weighted by bond::BondDegree.
123 * \param bonds times bond::BondDegree
124 */
125int BondedParticle::CountBonds() const
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
133/** Output of a single atom with given numbering.
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
137 * \param *comment commentary after '#' sign
138 * \return true - \a *out present, false - \a *out is NULL
139 */
140bool atom::OutputIndexed(ofstream * const out, const int ElementNo, const int AtomNo, const char *comment) const
141{
142 if (out != NULL) {
143 *out << "Ion_Type" << ElementNo << "_" << AtomNo << "\t" << fixed << setprecision(9) << showpoint;
144 *out << at(0) << "\t" << at(1) << "\t" << at(2);
145 *out << "\t" << FixedIon;
146 if (AtomicVelocity.Norm() > MYEPSILON)
147 *out << "\t" << scientific << setprecision(6) << AtomicVelocity[0] << "\t" << AtomicVelocity[1] << "\t" << AtomicVelocity[2] << "\t";
148 if (comment != NULL)
149 *out << " # " << comment << endl;
150 else
151 *out << " # molecule nr " << nr << endl;
152 return true;
153 } else
154 return false;
155};
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 */
164bool atom::OutputArrayIndexed(ostream * const out,const enumeration<const element*> &elementLookup, int *AtomNo, const char *comment) const
165{
166 AtomNo[getType()->Z]++; // increment number
167 if (out != NULL) {
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;
172 *out << at(0) << "\t" << at(1) << "\t" << at(2);
173 *out << "\t" << FixedIon;
174 if (AtomicVelocity.Norm() > MYEPSILON)
175 *out << "\t" << scientific << setprecision(6) << AtomicVelocity[0] << "\t" << AtomicVelocity[1] << "\t" << AtomicVelocity[2] << "\t";
176 if (comment != NULL)
177 *out << " # " << comment << endl;
178 else
179 *out << " # molecule nr " << nr << endl;
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
187 * \return true - \a *out present, false - \a *out is NULL
188 */
189bool atom::OutputXYZLine(ofstream *out) const
190{
191 if (out != NULL) {
192 *out << getType()->symbol << "\t" << at(0) << "\t" << at(1) << "\t" << at(2) << "\t" << endl;
193 return true;
194 } else
195 return false;
196};
197
198/** Output of a single atom as one lin in xyz file.
199 * \param *out stream to output to
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
204 */
205bool atom::OutputTrajectory(ofstream * const out, const int *ElementNo, int *AtomNo, const int step) const
206{
207 AtomNo[getType()->Z]++;
208 if (out != NULL) {
209 *out << "Ion_Type" << ElementNo[getType()->Z] << "_" << AtomNo[getType()->Z] << "\t" << fixed << setprecision(9) << showpoint;
210 *out << Trajectory.R.at(step)[0] << "\t" << Trajectory.R.at(step)[1] << "\t" << Trajectory.R.at(step)[2];
211 *out << "\t" << FixedIon;
212 if (Trajectory.U.at(step).Norm() > MYEPSILON)
213 *out << "\t" << scientific << setprecision(6) << Trajectory.U.at(step)[0] << "\t" << Trajectory.U.at(step)[1] << "\t" << Trajectory.U.at(step)[2] << "\t";
214 if (Trajectory.F.at(step).Norm() > MYEPSILON)
215 *out << "\t" << scientific << setprecision(6) << Trajectory.F.at(step)[0] << "\t" << Trajectory.F.at(step)[1] << "\t" << Trajectory.F.at(step)[2] << "\t";
216 *out << "\t# Number in molecule " << nr << endl;
217 return true;
218 } else
219 return false;
220};
221
222/** Output of a single atom as one lin in xyz file.
223 * \param *out stream to output to
224 * \param step Trajectory time step to output
225 * \return true - \a *out present, false - \a *out is NULL
226 */
227bool atom::OutputTrajectoryXYZ(ofstream * const out, const int step) const
228{
229 if (out != NULL) {
230 *out << getType()->symbol << "\t";
231 *out << Trajectory.R.at(step)[0] << "\t";
232 *out << Trajectory.R.at(step)[1] << "\t";
233 *out << Trajectory.R.at(step)[2] << endl;
234 return true;
235 } else
236 return false;
237};
238
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 */
244void atom::OutputMPQCLine(ostream * const out, const Vector *center, int *AtomNo = NULL) const
245{
246 Vector recentered(getPosition());
247 recentered -= *center;
248 *out << "\t\t" << getType()->symbol << " [ " << recentered[0] << "\t" << recentered[1] << "\t" << recentered[2] << " ]" << endl;
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 */
257bool atom::Compare(const atom &ptr) const
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 */
269double atom::DistanceSquaredToVector(const Vector &origin) const
270{
271 return DistanceSquared(origin);
272};
273
274/** Returns distance to a given vector.
275 * \param origin vector to calculate distance to
276 * \return distance
277 */
278double atom::DistanceToVector(const Vector &origin) const
279{
280 return distance(origin);
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)
289 delete[](ComponentNr);
290 ComponentNr = new int[ListOfBonds.size()+1];
291 for (int i=ListOfBonds.size()+1;i--;)
292 ComponentNr[i] = -1;
293};
294
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}
308
309bool operator < (atom &a, atom &b)
310{
311 return a.Compare(b);
312};
313
314World *atom::getWorld(){
315 return world;
316}
317
318void atom::setWorld(World* _world){
319 world = _world;
320}
321
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) {
335 id=_id;
336}
337
338atomId_t atom::getId() const {
339 return id;
340}
341
342void atom::setMolecule(molecule *_mol){
343 // take this atom from the old molecule
344 removeFromMolecule();
345 mol = _mol;
346 if(!mol->containsAtom(this)){
347 mol->insert(this);
348 }
349}
350
351molecule* atom::getMolecule(){
352 return mol;
353}
354
355void atom::removeFromMolecule(){
356 if(mol){
357 if(mol->containsAtom(this)){
358 mol->erase(this);
359 }
360 mol=0;
361 }
362}
363
364
365atom* NewAtom(atomId_t _id){
366 atom * res =new atom();
367 res->setId(_id);
368 return res;
369}
370
371void DeleteAtom(atom* atom){
372 delete atom;
373}
Note: See TracBrowser for help on using the repository browser.