source: src/Atom/atom.cpp@ d649b7

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 d649b7 was 11f0fa, checked in by Frederik Heber <heber@…>, 12 years ago

FIX: Newly created atoms must have trajectories reaching out till CurrentTime.

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