source: src/Atom/atom.cpp@ 50eff3

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 50eff3 was 4e904b, checked in by Frederik Heber <heber@…>, 12 years ago

Removed atom::IsInShape().

  • this makes libMolecuilderAtom not depend on ..Shapes.
  • Property mode set to 100644
File size: 7.4 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
5 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/** \file atom.cpp
24 *
25 * Function implementations for the class atom.
26 *
27 */
28
29// include config.h
30#ifdef HAVE_CONFIG_H
31#include <config.h>
32#endif
33
34#include "CodePatterns/MemDebug.hpp"
35
36#include "atom.hpp"
37#include "Bond/bond.hpp"
38#include "CodePatterns/Log.hpp"
39#include "config.hpp"
40#include "Element/element.hpp"
41#include "LinearAlgebra/Vector.hpp"
42#include "World.hpp"
43#include "molecule.hpp"
44#include "Shapes/Shape.hpp"
45
46#include <iomanip>
47#include <iostream>
48
49/************************************* Functions for class atom *************************************/
50
51
52atom::atom() :
53 father(this),
54 sort(&Nr),
55 mol(0)
56{};
57
58atom::atom(atom *pointer) :
59 ParticleInfo(*pointer),
60 AtomInfo(*pointer),
61 father(pointer),
62 sort(&Nr),
63 mol(0)
64{
65 AtomicPosition = pointer->AtomicPosition; // copy trajectory of coordination
66 AtomicVelocity = pointer->AtomicVelocity; // copy trajectory of velocity
67 AtomicForce = pointer->AtomicForce;
68};
69
70atom *atom::clone(){
71 atom *res = new atom(this);
72 World::getInstance().registerAtom(res);
73 return res;
74}
75
76
77/** Destructor of class atom.
78 */
79atom::~atom()
80{
81 removeFromMolecule();
82};
83
84
85void atom::UpdateSteps()
86{
87 LOG(4,"atom::UpdateSteps() called.");
88 // append to position, velocity and force vector
89 AtomInfo::AppendTrajectoryStep();
90 // append to ListOfBonds vector
91 BondedParticleInfo::AppendTrajectoryStep();
92}
93
94atom *atom::GetTrueFather()
95{
96 const atom *father = const_cast<const atom *>(this)->GetTrueFather();
97 return const_cast<atom *>(father);
98}
99
100const atom *atom::GetTrueFather() const
101{
102 if(father == this){ // top most father is the one that points on itself
103 return this;
104 }
105 else if(!father) {
106 return 0;
107 }
108 else {
109 return father->GetTrueFather();
110 }
111};
112
113/** Sets father to itself or its father in case of copying a molecule.
114 */
115void atom::CorrectFather()
116{
117 if (father->father != father) // same atom in copy's father points to itself
118// father = this; // set father to itself (copy of a whole molecule)
119// else
120 father = father->father; // set father to original's father
121
122};
123
124void atom::EqualsFather ( const atom *ptr, const atom **res ) const
125{
126 if ( ptr == father )
127 *res = this;
128};
129
130bool atom::isFather(const atom *ptr){
131 return ptr==father;
132}
133
134bool atom::OutputIndexed(ofstream * const out, const int ElementNo, const int AtomNo, const char *comment) const
135{
136 if (out != NULL) {
137 *out << "Ion_Type" << ElementNo << "_" << AtomNo << "\t" << fixed << setprecision(9) << showpoint;
138 *out << at(0) << "\t" << at(1) << "\t" << at(2);
139 *out << "\t" << (int)(getFixedIon());
140 if (getAtomicVelocity().Norm() > MYEPSILON)
141 *out << "\t" << scientific << setprecision(6) << getAtomicVelocity()[0] << "\t" << getAtomicVelocity()[1] << "\t" << getAtomicVelocity()[2] << "\t";
142 if (comment != NULL)
143 *out << " # " << comment << endl;
144 else
145 *out << " # molecule nr " << getNr() << endl;
146 return true;
147 } else
148 return false;
149};
150
151bool atom::OutputArrayIndexed(ostream * const out,const enumeration<const element*> &elementLookup, int *AtomNo, const char *comment) const
152{
153 AtomNo[getType()->getAtomicNumber()]++; // increment number
154 if (out != NULL) {
155 const element *elemental = getType();
156 ASSERT(elementLookup.there.find(elemental)!=elementLookup.there.end(),"Type of this atom was not in the formula upon enumeration");
157 *out << "Ion_Type" << elementLookup.there.find(elemental)->second << "_" << AtomNo[elemental->getAtomicNumber()] << "\t" << fixed << setprecision(9) << showpoint;
158 *out << at(0) << "\t" << at(1) << "\t" << at(2);
159 *out << "\t" << getFixedIon();
160 if (getAtomicVelocity().Norm() > MYEPSILON)
161 *out << "\t" << scientific << setprecision(6) << getAtomicVelocity()[0] << "\t" << getAtomicVelocity()[1] << "\t" << getAtomicVelocity()[2] << "\t";
162 if (comment != NULL)
163 *out << " # " << comment << endl;
164 else
165 *out << " # molecule nr " << getNr() << endl;
166 return true;
167 } else
168 return false;
169};
170
171bool atom::Compare(const atom &ptr) const
172{
173 if (getNr() < ptr.getNr())
174 return true;
175 else
176 return false;
177};
178
179double atom::DistanceSquaredToVector(const Vector &origin) const
180{
181 return DistanceSquared(origin);
182};
183
184double atom::DistanceToVector(const Vector &origin) const
185{
186 return distance(origin);
187};
188
189void atom::InitComponentNr()
190{
191 if (ComponentNr != NULL)
192 delete[](ComponentNr);
193 const BondList& ListOfBonds = getListOfBonds();
194 ComponentNr = new int[ListOfBonds.size()+1];
195 for (int i=ListOfBonds.size()+1;i--;)
196 ComponentNr[i] = -1;
197};
198
199void atom::resetGraphNr(){
200 GraphNr=-1;
201}
202
203std::ostream & atom::operator << (std::ostream &ost) const
204{
205 ParticleInfo::operator<<(ost);
206 ost << "," << getPosition();
207 return ost;
208}
209
210std::ostream & operator << (std::ostream &ost, const atom &a)
211{
212 a.ParticleInfo::operator<<(ost);
213 ost << "," << a.getPosition();
214 return ost;
215}
216
217bool operator < (atom &a, atom &b)
218{
219 return a.Compare(b);
220};
221
222World *atom::getWorld(){
223 return world;
224}
225
226void atom::setWorld(World* _world){
227 world = _world;
228}
229
230bool atom::changeId(atomId_t newId){
231 // first we move ourselves in the world
232 // the world lets us know if that succeeded
233 if(world->changeAtomId(id,newId,this)){
234 OBSERVE;
235 id = newId;
236 NOTIFY(IndexChanged);
237 return true;
238 }
239 else{
240 return false;
241 }
242}
243
244void atom::setId(atomId_t _id) {
245 id=_id;
246}
247
248atomId_t atom::getId() const {
249 return id;
250}
251
252void atom::setMolecule(molecule *_mol){
253 // take this atom from the old molecule
254 removeFromMolecule();
255 mol = _mol;
256 if ((mol) && (!mol->containsAtom(this)))
257 mol->insert(this);
258}
259
260void atom::unsetMolecule()
261{
262 // take this atom from the old molecule
263 ASSERT(!mol->containsAtom(this),
264 "atom::unsetMolecule() - old molecule "+toString(mol)+" still contains us!");
265 mol = NULL;
266}
267
268molecule* atom::getMolecule() const {
269 return mol;
270}
271
272void atom::removeFromMolecule(){
273 if(mol){
274 if(mol->containsAtom(this)){
275 mol->erase(this);
276 }
277 mol=0;
278 }
279}
280
281bool atom::changeNr(const int newNr)
282{
283 if ((mol) && (mol->changeAtomNr(getNr(),newNr,this))) {
284 return true;
285 } else{
286 return false;
287 }
288}
289
290int atom::getNr() const{
291 return ParticleInfo::getNr();
292}
293
294atom* NewAtom(atomId_t _id){
295 atom * res =new atom();
296 res->setId(_id);
297 return res;
298}
299
300void DeleteAtom(atom* atom){
301 delete atom;
302}
303
304bool compareAtomElements(atom* atom1,atom* atom2){
305 return atom1->getType()->getAtomicNumber() < atom2->getType()->getAtomicNumber();
306}
Note: See TracBrowser for help on using the repository browser.