source: src/atom.cpp@ b5c53d

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

Merge branch 'StructureRefactoring' into stable

Conflicts:

src/Actions/AtomAction/AddAction.cpp
src/Actions/AtomAction/ChangeElementAction.cpp
src/Parser/XyzParser.cpp
src/analysis_correlation.cpp
src/atom.cpp
src/config.cpp
src/molecule.cpp

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