| 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 | /*
 | 
|---|
| 24 |  * AtomicInfo.cpp
 | 
|---|
| 25 |  *
 | 
|---|
| 26 |  *  Created on: Aug 10, 2010
 | 
|---|
| 27 |  *      Author: heber
 | 
|---|
| 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 "AtomicInfo.hpp"
 | 
|---|
| 39 | #include "CodePatterns/Assert.hpp"
 | 
|---|
| 40 | #include "Descriptors/AtomIdDescriptor.hpp"
 | 
|---|
| 41 | #include "Descriptors/MoleculeIdDescriptor.hpp"
 | 
|---|
| 42 | #include "Element/element.hpp"
 | 
|---|
| 43 | #include "LinearAlgebra/Vector.hpp"
 | 
|---|
| 44 | #include "molecule.hpp"
 | 
|---|
| 45 | #include "World.hpp"
 | 
|---|
| 46 | 
 | 
|---|
| 47 | /********************************** Functions for class AtomicInfo **********************************/
 | 
|---|
| 48 | 
 | 
|---|
| 49 | AtomicInfo::AtomicInfo() :
 | 
|---|
| 50 |     Type(NULL),
 | 
|---|
| 51 |     charge(0.),
 | 
|---|
| 52 |     FatherId(0),
 | 
|---|
| 53 |     MolId(0),
 | 
|---|
| 54 |     Id(0),
 | 
|---|
| 55 |     Nr(0)
 | 
|---|
| 56 | {}
 | 
|---|
| 57 | 
 | 
|---|
| 58 | AtomicInfo::AtomicInfo(const atom &_atom) :
 | 
|---|
| 59 |     Position(_atom.getPosition()),
 | 
|---|
| 60 |     Type(_atom.getType()),
 | 
|---|
| 61 |     charge(_atom.getCharge()),
 | 
|---|
| 62 |     Velocity(_atom.getAtomicVelocity()),
 | 
|---|
| 63 |     Force(_atom.getAtomicForce()),
 | 
|---|
| 64 |     FatherId(_atom.father->getId()),
 | 
|---|
| 65 |     MolId(0),
 | 
|---|
| 66 |     Id(_atom.getId()),
 | 
|---|
| 67 |     Nr(_atom.getNr())
 | 
|---|
| 68 | {
 | 
|---|
| 69 |   const molecule * const mol = _atom.getMolecule();
 | 
|---|
| 70 |   ASSERT(mol != NULL,
 | 
|---|
| 71 |       "Atom "+toString(_atom.getId())+" is not associated with any molecule.");
 | 
|---|
| 72 |   MolId = mol->getId();
 | 
|---|
| 73 | }
 | 
|---|
| 74 | 
 | 
|---|
| 75 | AtomicInfo::~AtomicInfo()
 | 
|---|
| 76 | {}
 | 
|---|
| 77 | 
 | 
|---|
| 78 | 
 | 
|---|
| 79 | bool AtomicInfo::setAtom(atom &_atom) const
 | 
|---|
| 80 | {
 | 
|---|
| 81 |   _atom.setPosition(Position);
 | 
|---|
| 82 |   _atom.setType(Type);
 | 
|---|
| 83 |   _atom.setCharge(charge);
 | 
|---|
| 84 |   _atom.setAtomicVelocity(Velocity);
 | 
|---|
| 85 |   _atom.setAtomicForce(Force);
 | 
|---|
| 86 | 
 | 
|---|
| 87 |   // set old id
 | 
|---|
| 88 |   bool status = true;
 | 
|---|
| 89 |   if (_atom.getId() != Id)
 | 
|---|
| 90 |     status = _atom.changeId(Id);
 | 
|---|
| 91 | 
 | 
|---|
| 92 |   // set its father
 | 
|---|
| 93 |   atom * const _father = World::getInstance().getAtom(AtomById(FatherId));
 | 
|---|
| 94 |   if (_father == NULL)
 | 
|---|
| 95 |     _atom.father = &_atom;
 | 
|---|
| 96 |   else
 | 
|---|
| 97 |     _atom.father = _father;
 | 
|---|
| 98 | 
 | 
|---|
| 99 |   // setting molecule
 | 
|---|
| 100 |   molecule * const _mol = World::getInstance().getMolecule(MoleculeById(MolId));
 | 
|---|
| 101 |   if (_mol != NULL)
 | 
|---|
| 102 |     _atom.setMolecule(_mol); // this is ok, mol is const within AtomicInfo, but not outside (atoms need to register)
 | 
|---|
| 103 |   _atom.changeNr(Nr);
 | 
|---|
| 104 | 
 | 
|---|
| 105 |   return status;
 | 
|---|
| 106 | }
 | 
|---|
| 107 | 
 | 
|---|
| 108 | atomId_t AtomicInfo::getId() const {
 | 
|---|
| 109 |   return Id;
 | 
|---|
| 110 | }
 | 
|---|
| 111 | 
 | 
|---|
| 112 | AtomicInfo& AtomicInfo::operator=(const AtomicInfo& AI)
 | 
|---|
| 113 | {
 | 
|---|
| 114 |   if (&AI == this)  // check self-assignment
 | 
|---|
| 115 |     return *this;
 | 
|---|
| 116 |   Position = AI.Position;
 | 
|---|
| 117 |   Type = AI.Type;
 | 
|---|
| 118 |   FatherId = AI.FatherId;
 | 
|---|
| 119 |   MolId = AI.MolId;
 | 
|---|
| 120 |   Velocity = AI.Velocity;
 | 
|---|
| 121 |   Force = AI.Force;
 | 
|---|
| 122 |   Id = AI.Id;
 | 
|---|
| 123 |   Nr = AI.Nr;
 | 
|---|
| 124 |   return *this;
 | 
|---|
| 125 | }
 | 
|---|
| 126 | 
 | 
|---|