source: src/Atom/atom.cpp@ 8b58ac

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 8b58ac was 94d5ac6, checked in by Frederik Heber <heber@…>, 12 years ago

FIX: As we use GSL internally, we are as of now required to use GPL v2 license.

  • GNU Scientific Library is used at every place in the code, especially the sub-package LinearAlgebra is based on it which in turn is used really everywhere in the remainder of MoleCuilder. Hence, we have to use the GPL license for the whole of MoleCuilder. In effect, GPL's COPYING was present all along and stated the terms of the GPL v2 license.
  • Hence, I added the default GPL v2 disclaimer to every source file and removed the note about a (actually missing) LICENSE file.
  • also, I added a help-redistribute action which again gives the disclaimer of the GPL v2.
  • also, I changed in the disclaimer that is printed at every program start in builder_init.cpp.
  • TEST: Added check on GPL statement present in every module to test CodeChecks project-disclaimer.
  • Property mode set to 100644
File size: 7.5 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::IsInShape(const Shape& shape) const
135{
136 return shape.isInside(getPosition());
137};
138
139bool atom::OutputIndexed(ofstream * const out, const int ElementNo, const int AtomNo, const char *comment) const
140{
141 if (out != NULL) {
142 *out << "Ion_Type" << ElementNo << "_" << AtomNo << "\t" << fixed << setprecision(9) << showpoint;
143 *out << at(0) << "\t" << at(1) << "\t" << at(2);
144 *out << "\t" << (int)(getFixedIon());
145 if (getAtomicVelocity().Norm() > MYEPSILON)
146 *out << "\t" << scientific << setprecision(6) << getAtomicVelocity()[0] << "\t" << getAtomicVelocity()[1] << "\t" << getAtomicVelocity()[2] << "\t";
147 if (comment != NULL)
148 *out << " # " << comment << endl;
149 else
150 *out << " # molecule nr " << getNr() << endl;
151 return true;
152 } else
153 return false;
154};
155
156bool atom::OutputArrayIndexed(ostream * const out,const enumeration<const element*> &elementLookup, int *AtomNo, const char *comment) const
157{
158 AtomNo[getType()->getAtomicNumber()]++; // increment number
159 if (out != NULL) {
160 const element *elemental = getType();
161 ASSERT(elementLookup.there.find(elemental)!=elementLookup.there.end(),"Type of this atom was not in the formula upon enumeration");
162 *out << "Ion_Type" << elementLookup.there.find(elemental)->second << "_" << AtomNo[elemental->getAtomicNumber()] << "\t" << fixed << setprecision(9) << showpoint;
163 *out << at(0) << "\t" << at(1) << "\t" << at(2);
164 *out << "\t" << getFixedIon();
165 if (getAtomicVelocity().Norm() > MYEPSILON)
166 *out << "\t" << scientific << setprecision(6) << getAtomicVelocity()[0] << "\t" << getAtomicVelocity()[1] << "\t" << getAtomicVelocity()[2] << "\t";
167 if (comment != NULL)
168 *out << " # " << comment << endl;
169 else
170 *out << " # molecule nr " << getNr() << endl;
171 return true;
172 } else
173 return false;
174};
175
176bool atom::Compare(const atom &ptr) const
177{
178 if (getNr() < ptr.getNr())
179 return true;
180 else
181 return false;
182};
183
184double atom::DistanceSquaredToVector(const Vector &origin) const
185{
186 return DistanceSquared(origin);
187};
188
189double atom::DistanceToVector(const Vector &origin) const
190{
191 return distance(origin);
192};
193
194void atom::InitComponentNr()
195{
196 if (ComponentNr != NULL)
197 delete[](ComponentNr);
198 const BondList& ListOfBonds = getListOfBonds();
199 ComponentNr = new int[ListOfBonds.size()+1];
200 for (int i=ListOfBonds.size()+1;i--;)
201 ComponentNr[i] = -1;
202};
203
204void atom::resetGraphNr(){
205 GraphNr=-1;
206}
207
208std::ostream & atom::operator << (std::ostream &ost) const
209{
210 ParticleInfo::operator<<(ost);
211 ost << "," << getPosition();
212 return ost;
213}
214
215std::ostream & operator << (std::ostream &ost, const atom &a)
216{
217 a.ParticleInfo::operator<<(ost);
218 ost << "," << a.getPosition();
219 return ost;
220}
221
222bool operator < (atom &a, atom &b)
223{
224 return a.Compare(b);
225};
226
227World *atom::getWorld(){
228 return world;
229}
230
231void atom::setWorld(World* _world){
232 world = _world;
233}
234
235bool atom::changeId(atomId_t newId){
236 // first we move ourselves in the world
237 // the world lets us know if that succeeded
238 if(world->changeAtomId(id,newId,this)){
239 OBSERVE;
240 id = newId;
241 NOTIFY(IndexChanged);
242 return true;
243 }
244 else{
245 return false;
246 }
247}
248
249void atom::setId(atomId_t _id) {
250 id=_id;
251}
252
253atomId_t atom::getId() const {
254 return id;
255}
256
257void atom::setMolecule(molecule *_mol){
258 // take this atom from the old molecule
259 removeFromMolecule();
260 mol = _mol;
261 if ((mol) && (!mol->containsAtom(this)))
262 mol->insert(this);
263}
264
265void atom::unsetMolecule()
266{
267 // take this atom from the old molecule
268 ASSERT(!mol->containsAtom(this),
269 "atom::unsetMolecule() - old molecule "+toString(mol)+" still contains us!");
270 mol = NULL;
271}
272
273molecule* atom::getMolecule() const {
274 return mol;
275}
276
277void atom::removeFromMolecule(){
278 if(mol){
279 if(mol->containsAtom(this)){
280 mol->erase(this);
281 }
282 mol=0;
283 }
284}
285
286bool atom::changeNr(const int newNr)
287{
288 if ((mol) && (mol->changeAtomNr(getNr(),newNr,this))) {
289 return true;
290 } else{
291 return false;
292 }
293}
294
295int atom::getNr() const{
296 return ParticleInfo::getNr();
297}
298
299atom* NewAtom(atomId_t _id){
300 atom * res =new atom();
301 res->setId(_id);
302 return res;
303}
304
305void DeleteAtom(atom* atom){
306 delete atom;
307}
308
309bool compareAtomElements(atom* atom1,atom* atom2){
310 return atom1->getType()->getAtomicNumber() < atom2->getType()->getAtomicNumber();
311}
Note: See TracBrowser for help on using the repository browser.