source: src/atom.cpp@ 2d5fee

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 2d5fee was a9b86d, checked in by Frederik Heber <heber@…>, 14 years ago

Split up modules parser.[ch]pp into one module per class.

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