source: src/Atom/atom.cpp@ 0c72e2

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 0c72e2 was 7e51e1, checked in by Frederik Heber <heber@…>, 11 years ago

Extended UndoRedoHelpers.

  • added removeLastStep(), addNewStep().
  • FIX: some UndoRedoHelper functions did not have const arguments as they should.
  • FIX: AtomicInfo did not set/store force vector of atom.
  • added AtomInfo::removeTrajectoryStep() and BondedParticleInfo::...() to allow for removal of a time step in the course of undoing. Enhanced AtomInfo, atom, and TesselPoint by removeSteps(), similar to UpdateSteps().
  • Property mode set to 100644
File size: 8.2 KB
RevLine 
[bcf653]1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
[0aa122]4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
[5aaa43]5 * Copyright (C) 2013 Frederik Heber. All rights reserved.
[94d5ac6]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/>.
[bcf653]22 */
23
[14de469]24/** \file atom.cpp
[1907a7]25 *
[14de469]26 * Function implementations for the class atom.
[1907a7]27 *
[14de469]28 */
29
[bf3817]30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
[ad011c]35#include "CodePatterns/MemDebug.hpp"
[112b09]36
[357fba]37#include "atom.hpp"
[708277]38#include "AtomObserver.hpp"
[129204]39#include "Bond/bond.hpp"
[e2373df]40#include "CodePatterns/Log.hpp"
[4a7776a]41#include "config.hpp"
[3bdb6d]42#include "Element/element.hpp"
[57f243]43#include "LinearAlgebra/Vector.hpp"
[d346b6]44#include "World.hpp"
[11f0fa]45#include "WorldTime.hpp"
[6cfa36]46#include "molecule.hpp"
[c550dd]47#include "Shapes/Shape.hpp"
[a0064e]48
[36166d]49#include <iomanip>
[0ba410]50#include <iostream>
[36166d]51
[14de469]52/************************************* Functions for class atom *************************************/
53
[70ff32]54
[46d958]55atom::atom() :
[97b825]56 father(this),
[5309ba]57 sort(&Nr),
[97b825]58 mol(0)
[708277]59{
60 // sign on to global atom change tracker
61 AtomObserver::getInstance().AtomInserted(this);
62}
[14de469]63
[ea0c8b]64atom::atom(atom *pointer) :
65 ParticleInfo(*pointer),
[c742fe]66 AtomInfo(*pointer),
[97b825]67 father(pointer),
[5309ba]68 sort(&Nr),
[9df680]69 mol(0)
[2319ed]70{
[443547]71 AtomicPosition = pointer->AtomicPosition; // copy trajectory of coordination
72 AtomicVelocity = pointer->AtomicVelocity; // copy trajectory of velocity
73 AtomicForce = pointer->AtomicForce;
[708277]74 // sign on to global atom change tracker
75 AtomObserver::getInstance().AtomInserted(this);
[b453f9]76};
[2319ed]77
[46d958]78atom *atom::clone(){
[68f03d]79 atom *res = new atom(this);
[23b547]80 World::getInstance().registerAtom(res);
[46d958]81 return res;
82}
83
[2319ed]84
[14de469]85/** Destructor of class atom.
86 */
[1907a7]87atom::~atom()
[14de469]88{
[6cfa36]89 removeFromMolecule();
[708277]90 // sign off from global atom change tracker
91 AtomObserver::getInstance().AtomRemoved(this);
92}
[e2373df]93
94
95void atom::UpdateSteps()
96{
97 LOG(4,"atom::UpdateSteps() called.");
98 // append to position, velocity and force vector
99 AtomInfo::AppendTrajectoryStep();
[1e6249]100 // append to ListOfBonds vector
101 BondedParticleInfo::AppendTrajectoryStep();
[e2373df]102}
103
[7e51e1]104void atom::removeSteps()
105{
106 LOG(4,"atom::removeSteps() called.");
107 // append to position, velocity and force vector
108 AtomInfo::removeTrajectoryStep();
109 // append to ListOfBonds vector
110 BondedParticleInfo::removeTrajectoryStep();
111}
112
[59fff1]113atom *atom::GetTrueFather()
114{
115 const atom *father = const_cast<const atom *>(this)->GetTrueFather();
116 return const_cast<atom *>(father);
117}
118
119const atom *atom::GetTrueFather() const
[14de469]120{
[215df0]121 if(father == this){ // top most father is the one that points on itself
122 return this;
123 }
124 else if(!father) {
125 return 0;
126 }
127 else {
128 return father->GetTrueFather();
129 }
[14de469]130};
131
[e65246]132/** Sets father to itself or its father in case of copying a molecule.
133 */
134void atom::CorrectFather()
135{
[2e352f]136 if (father->father != father) // same atom in copy's father points to itself
137// father = this; // set father to itself (copy of a whole molecule)
138// else
[e65246]139 father = father->father; // set father to original's father
140
141};
142
[b453f9]143void atom::EqualsFather ( const atom *ptr, const atom **res ) const
[e65246]144{
145 if ( ptr == father )
146 *res = this;
147};
148
[00abfc]149bool atom::isFather(const atom *ptr){
150 return ptr==father;
151}
152
[e138de]153bool atom::OutputIndexed(ofstream * const out, const int ElementNo, const int AtomNo, const char *comment) const
[14de469]154{
155 if (out != NULL) {
156 *out << "Ion_Type" << ElementNo << "_" << AtomNo << "\t" << fixed << setprecision(9) << showpoint;
[d74077]157 *out << at(0) << "\t" << at(1) << "\t" << at(2);
[6625c3]158 *out << "\t" << (int)(getFixedIon());
[bce72c]159 if (getAtomicVelocity().Norm() > MYEPSILON)
160 *out << "\t" << scientific << setprecision(6) << getAtomicVelocity()[0] << "\t" << getAtomicVelocity()[1] << "\t" << getAtomicVelocity()[2] << "\t";
[437922]161 if (comment != NULL)
162 *out << " # " << comment << endl;
[e9f8f9]163 else
[735b1c]164 *out << " # molecule nr " << getNr() << endl;
[e9f8f9]165 return true;
166 } else
167 return false;
168};
[b453f9]169
[0ba410]170bool atom::OutputArrayIndexed(ostream * const out,const enumeration<const element*> &elementLookup, int *AtomNo, const char *comment) const
[e9f8f9]171{
[83f176]172 AtomNo[getType()->getAtomicNumber()]++; // increment number
[e9f8f9]173 if (out != NULL) {
[8f4df1]174 const element *elemental = getType();
175 ASSERT(elementLookup.there.find(elemental)!=elementLookup.there.end(),"Type of this atom was not in the formula upon enumeration");
[83f176]176 *out << "Ion_Type" << elementLookup.there.find(elemental)->second << "_" << AtomNo[elemental->getAtomicNumber()] << "\t" << fixed << setprecision(9) << showpoint;
[d74077]177 *out << at(0) << "\t" << at(1) << "\t" << at(2);
[6625c3]178 *out << "\t" << getFixedIon();
[bce72c]179 if (getAtomicVelocity().Norm() > MYEPSILON)
180 *out << "\t" << scientific << setprecision(6) << getAtomicVelocity()[0] << "\t" << getAtomicVelocity()[1] << "\t" << getAtomicVelocity()[2] << "\t";
[e9f8f9]181 if (comment != NULL)
182 *out << " # " << comment << endl;
[437922]183 else
[735b1c]184 *out << " # molecule nr " << getNr() << endl;
[14de469]185 return true;
186 } else
187 return false;
188};
189
[b453f9]190bool atom::Compare(const atom &ptr) const
[4455f4]191{
[735b1c]192 if (getNr() < ptr.getNr())
[4455f4]193 return true;
194 else
195 return false;
196};
197
[b453f9]198double atom::DistanceSquaredToVector(const Vector &origin) const
[4455f4]199{
[d74077]200 return DistanceSquared(origin);
[4455f4]201};
202
[b453f9]203double atom::DistanceToVector(const Vector &origin) const
[4455f4]204{
[d74077]205 return distance(origin);
[4455f4]206};
207
208void atom::InitComponentNr()
209{
210 if (ComponentNr != NULL)
[920c70]211 delete[](ComponentNr);
[9d83b6]212 const BondList& ListOfBonds = getListOfBonds();
[920c70]213 ComponentNr = new int[ListOfBonds.size()+1];
[4455f4]214 for (int i=ListOfBonds.size()+1;i--;)
215 ComponentNr[i] = -1;
[14b65e]216};
217
218void atom::resetGraphNr(){
219 GraphNr=-1;
220}
[4455f4]221
[d74077]222std::ostream & atom::operator << (std::ostream &ost) const
223{
224 ParticleInfo::operator<<(ost);
225 ost << "," << getPosition();
226 return ost;
227}
228
229std::ostream & operator << (std::ostream &ost, const atom &a)
230{
231 a.ParticleInfo::operator<<(ost);
232 ost << "," << a.getPosition();
233 return ost;
234}
[4455f4]235
236bool operator < (atom &a, atom &b)
237{
238 return a.Compare(b);
239};
240
[46d958]241World *atom::getWorld(){
242 return world;
243}
244
245void atom::setWorld(World* _world){
246 world = _world;
247}
248
[88d586]249bool atom::changeId(atomId_t newId){
250 // first we move ourselves in the world
251 // the world lets us know if that succeeded
[4f7f0bf]252 if(world->changeAtomId(id,newId,this)){
253 OBSERVE;
254 id = newId;
255 NOTIFY(IndexChanged);
[88d586]256 return true;
257 }
258 else{
259 return false;
260 }
261}
262
263void atom::setId(atomId_t _id) {
[46d958]264 id=_id;
265}
266
[ad2b411]267atomId_t atom::getId() const {
[46d958]268 return id;
269}
270
[6cfa36]271void atom::setMolecule(molecule *_mol){
272 // take this atom from the old molecule
273 removeFromMolecule();
[3867a7]274 mol = _mol;
275 if ((mol) && (!mol->containsAtom(this)))
[dddbfe]276 mol->insert(this);
[6cfa36]277}
278
[0d9546]279void atom::unsetMolecule()
280{
281 // take this atom from the old molecule
282 ASSERT(!mol->containsAtom(this),
283 "atom::unsetMolecule() - old molecule "+toString(mol)+" still contains us!");
284 mol = NULL;
285}
286
[e41c48]287molecule* atom::getMolecule() const {
[c084cc]288 return mol;
289}
290
[6cfa36]291void atom::removeFromMolecule(){
292 if(mol){
293 if(mol->containsAtom(this)){
294 mol->erase(this);
295 }
296 mol=0;
297 }
[1f8337]298}
299
[560bbe]300bool atom::changeNr(const int newNr)
301{
302 if ((mol) && (mol->changeAtomNr(getNr(),newNr,this))) {
303 return true;
304 } else{
305 return false;
306 }
307}
308
[e8a21f]309int atom::getNr() const{
[735b1c]310 return ParticleInfo::getNr();
[e8a21f]311}
[6cfa36]312
[88d586]313atom* NewAtom(atomId_t _id){
[11f0fa]314 atom * res = new atom();
315 // extent trajectory to current time step
316 const size_t CurrentTime = WorldTime::getTime();
317 for (size_t step = res->getTrajectorySize(); step <= CurrentTime; ++step)
318 res->UpdateSteps();
[88d586]319 res->setId(_id);
320 return res;
[46d958]321}
322
[88d586]323void DeleteAtom(atom* atom){
[46d958]324 delete atom;
[e5f64de]325}
326
327bool compareAtomElements(atom* atom1,atom* atom2){
[ed26ae]328 return atom1->getType()->getAtomicNumber() < atom2->getType()->getAtomicNumber();
[46d958]329}
Note: See TracBrowser for help on using the repository browser.