source: src/atom.cpp@ 50e4e5

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 50e4e5 was 360c8b, checked in by Frederik Heber <heber@…>, 13 years ago

Merge branch 'Adding_Psi3Parser' into stable

Conflicts:

src/Parser/FormatParser.hpp
src/Parser/unittests/ParserTremoloUnitTest.cpp

Issues:

  • Element and periodentafel have been moved to folder src/Element.
  • Property mode set to 100644
File size: 9.0 KB
Line 
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
8/** \file atom.cpp
9 *
10 * Function implementations for the class atom.
11 *
12 */
13
14// include config.h
15#ifdef HAVE_CONFIG_H
16#include <config.h>
17#endif
18
19#include "CodePatterns/MemDebug.hpp"
20
21#include "atom.hpp"
22#include "Bond/bond.hpp"
23#include "CodePatterns/Log.hpp"
24#include "config.hpp"
25#include "Element/element.hpp"
26#include "LinearAlgebra/Vector.hpp"
27#include "World.hpp"
28#include "molecule.hpp"
29#include "Shapes/Shape.hpp"
30
31#include <iomanip>
32#include <iostream>
33
34/************************************* Functions for class atom *************************************/
35
36
37atom::atom() :
38 father(this),
39 sort(&Nr),
40 mol(0)
41{};
42
43atom::atom(atom *pointer) :
44 ParticleInfo(pointer),
45 father(pointer),
46 sort(&Nr),
47 mol(0)
48{
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;
53 setFixedIon(pointer->getFixedIon());
54};
55
56atom *atom::clone(){
57 atom *res = new atom(this);
58 World::getInstance().registerAtom(res);
59 return res;
60}
61
62
63/** Destructor of class atom.
64 */
65atom::~atom()
66{
67 removeFromMolecule();
68};
69
70
71void atom::UpdateSteps()
72{
73 LOG(4,"atom::UpdateSteps() called.");
74 // append to position, velocity and force vector
75 AtomInfo::AppendTrajectoryStep();
76 // append to ListOfBonds vector
77 BondedParticleInfo::AppendTrajectoryStep();
78}
79
80atom *atom::GetTrueFather()
81{
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 }
91};
92
93/** Sets father to itself or its father in case of copying a molecule.
94 */
95void atom::CorrectFather()
96{
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
100 father = father->father; // set father to original's father
101
102};
103
104void atom::EqualsFather ( const atom *ptr, const atom **res ) const
105{
106 if ( ptr == father )
107 *res = this;
108};
109
110bool atom::isFather(const atom *ptr){
111 return ptr==father;
112}
113
114bool atom::IsInShape(const Shape& shape) const
115{
116 return shape.isInside(getPosition());
117};
118
119bool atom::OutputIndexed(ofstream * const out, const int ElementNo, const int AtomNo, const char *comment) const
120{
121 if (out != NULL) {
122 *out << "Ion_Type" << ElementNo << "_" << AtomNo << "\t" << fixed << setprecision(9) << showpoint;
123 *out << at(0) << "\t" << at(1) << "\t" << at(2);
124 *out << "\t" << (int)(getFixedIon());
125 if (getAtomicVelocity().Norm() > MYEPSILON)
126 *out << "\t" << scientific << setprecision(6) << getAtomicVelocity()[0] << "\t" << getAtomicVelocity()[1] << "\t" << getAtomicVelocity()[2] << "\t";
127 if (comment != NULL)
128 *out << " # " << comment << endl;
129 else
130 *out << " # molecule nr " << getNr() << endl;
131 return true;
132 } else
133 return false;
134};
135
136bool atom::OutputArrayIndexed(ostream * const out,const enumeration<const element*> &elementLookup, int *AtomNo, const char *comment) const
137{
138 AtomNo[getType()->getAtomicNumber()]++; // increment number
139 if (out != NULL) {
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");
142 *out << "Ion_Type" << elementLookup.there.find(elemental)->second << "_" << AtomNo[elemental->getAtomicNumber()] << "\t" << fixed << setprecision(9) << showpoint;
143 *out << at(0) << "\t" << at(1) << "\t" << at(2);
144 *out << "\t" << 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::OutputXYZLine(ofstream *out) const
157{
158 if (out != NULL) {
159 *out << getType()->getSymbol() << "\t" << at(0) << "\t" << at(1) << "\t" << at(2) << "\t" << endl;
160 return true;
161 } else
162 return false;
163};
164
165bool atom::OutputTrajectory(ofstream * const out, const enumeration<const element*> &elementLookup, int *AtomNo, const int step) const
166{
167 AtomNo[getType()->getAtomicNumber()]++;
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;
172 *out << getPositionAtStep(step)[0] << "\t" << getPositionAtStep(step)[1] << "\t" << getPositionAtStep(step)[2];
173 *out << "\t" << (int)(getFixedIon());
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";
178 *out << "\t# Number in molecule " << getNr() << endl;
179 return true;
180 } else
181 return false;
182};
183
184bool atom::OutputTrajectoryXYZ(ofstream * const out, const int step) const
185{
186 if (out != NULL) {
187 *out << getType()->getSymbol() << "\t";
188 *out << getPositionAtStep(step)[0] << "\t";
189 *out << getPositionAtStep(step)[1] << "\t";
190 *out << getPositionAtStep(step)[2] << endl;
191 return true;
192 } else
193 return false;
194};
195
196void atom::OutputMPQCLine(ostream * const out, const Vector *center) const
197{
198 Vector recentered(getPosition());
199 recentered -= *center;
200 *out << "\t\t" << getType()->getSymbol() << " [ " << recentered[0] << "\t" << recentered[1] << "\t" << recentered[2] << " ]" << endl;
201};
202
203void atom::OutputPsi3Line(ostream * const out, const Vector *center) const
204{
205 Vector recentered(getPosition());
206 recentered -= *center;
207 *out << "\t( " << getType()->getSymbol() << "\t" << recentered[0] << "\t" << recentered[1] << "\t" << recentered[2] << " )" << endl;
208};
209
210bool atom::Compare(const atom &ptr) const
211{
212 if (getNr() < ptr.getNr())
213 return true;
214 else
215 return false;
216};
217
218double atom::DistanceSquaredToVector(const Vector &origin) const
219{
220 return DistanceSquared(origin);
221};
222
223double atom::DistanceToVector(const Vector &origin) const
224{
225 return distance(origin);
226};
227
228void atom::InitComponentNr()
229{
230 if (ComponentNr != NULL)
231 delete[](ComponentNr);
232 const BondList& ListOfBonds = getListOfBonds();
233 ComponentNr = new int[ListOfBonds.size()+1];
234 for (int i=ListOfBonds.size()+1;i--;)
235 ComponentNr[i] = -1;
236};
237
238void atom::resetGraphNr(){
239 GraphNr=-1;
240}
241
242std::ostream & atom::operator << (std::ostream &ost) const
243{
244 ParticleInfo::operator<<(ost);
245 ost << "," << getPosition();
246 return ost;
247}
248
249std::ostream & operator << (std::ostream &ost, const atom &a)
250{
251 a.ParticleInfo::operator<<(ost);
252 ost << "," << a.getPosition();
253 return ost;
254}
255
256bool operator < (atom &a, atom &b)
257{
258 return a.Compare(b);
259};
260
261World *atom::getWorld(){
262 return world;
263}
264
265void atom::setWorld(World* _world){
266 world = _world;
267}
268
269bool atom::changeId(atomId_t newId){
270 // first we move ourselves in the world
271 // the world lets us know if that succeeded
272 if(world->changeAtomId(id,newId,this)){
273 id = newId;
274 return true;
275 }
276 else{
277 return false;
278 }
279}
280
281void atom::setId(atomId_t _id) {
282 id=_id;
283}
284
285atomId_t atom::getId() const {
286 return id;
287}
288
289void atom::setMolecule(molecule *_mol){
290 // take this atom from the old molecule
291 removeFromMolecule();
292 mol = _mol;
293 if(!mol->containsAtom(this)){
294 mol->insert(this);
295 }
296}
297
298void atom::unsetMolecule()
299{
300 // take this atom from the old molecule
301 ASSERT(!mol->containsAtom(this),
302 "atom::unsetMolecule() - old molecule "+toString(mol)+" still contains us!");
303 mol = NULL;
304}
305
306molecule* atom::getMolecule() const {
307 return mol;
308}
309
310void atom::removeFromMolecule(){
311 if(mol){
312 if(mol->containsAtom(this)){
313 mol->erase(this);
314 }
315 mol=0;
316 }
317}
318
319int atom::getNr() const{
320 return ParticleInfo::getNr();
321}
322
323atom* NewAtom(atomId_t _id){
324 atom * res =new atom();
325 res->setId(_id);
326 return res;
327}
328
329void DeleteAtom(atom* atom){
330 delete atom;
331}
332
333bool compareAtomElements(atom* atom1,atom* atom2){
334 return atom1->getType()->getNumber() < atom2->getType()->getNumber();
335}
Note: See TracBrowser for help on using the repository browser.