| 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 | FatherId(_atom.father->getId()), | 
|---|
| 64 | MolId(0), | 
|---|
| 65 | Id(_atom.getId()), | 
|---|
| 66 | Nr(_atom.getNr()) | 
|---|
| 67 | { | 
|---|
| 68 | const molecule * const mol = _atom.getMolecule(); | 
|---|
| 69 | ASSERT(mol != NULL, | 
|---|
| 70 | "Atom "+toString(_atom.getId())+" is not associated with any molecule."); | 
|---|
| 71 | MolId = mol->getId(); | 
|---|
| 72 | } | 
|---|
| 73 |  | 
|---|
| 74 | AtomicInfo::~AtomicInfo() | 
|---|
| 75 | {} | 
|---|
| 76 |  | 
|---|
| 77 |  | 
|---|
| 78 | bool AtomicInfo::setAtom(atom &_atom) const | 
|---|
| 79 | { | 
|---|
| 80 | _atom.setPosition(Position); | 
|---|
| 81 | _atom.setType(Type); | 
|---|
| 82 | _atom.setCharge(charge); | 
|---|
| 83 | _atom.setAtomicVelocity(Velocity); | 
|---|
| 84 |  | 
|---|
| 85 | // set old id | 
|---|
| 86 | bool status = true; | 
|---|
| 87 | if (_atom.getId() != Id) | 
|---|
| 88 | status = _atom.changeId(Id); | 
|---|
| 89 |  | 
|---|
| 90 | // set its father | 
|---|
| 91 | atom * const _father = World::getInstance().getAtom(AtomById(FatherId)); | 
|---|
| 92 | if (_father == NULL) | 
|---|
| 93 | _atom.father = &_atom; | 
|---|
| 94 | else | 
|---|
| 95 | _atom.father = _father; | 
|---|
| 96 |  | 
|---|
| 97 | // setting molecule | 
|---|
| 98 | molecule * const _mol = World::getInstance().getMolecule(MoleculeById(MolId)); | 
|---|
| 99 | if (_mol != NULL) | 
|---|
| 100 | _atom.setMolecule(_mol); // this is ok, mol is const within AtomicInfo, but not outside (atoms need to register) | 
|---|
| 101 | _atom.changeNr(Nr); | 
|---|
| 102 |  | 
|---|
| 103 | return status; | 
|---|
| 104 | } | 
|---|
| 105 |  | 
|---|
| 106 | atomId_t AtomicInfo::getId() const { | 
|---|
| 107 | return Id; | 
|---|
| 108 | } | 
|---|
| 109 |  | 
|---|
| 110 | AtomicInfo& AtomicInfo::operator=(const AtomicInfo& AI) | 
|---|
| 111 | { | 
|---|
| 112 | if (&AI == this)  // check self-assignment | 
|---|
| 113 | return *this; | 
|---|
| 114 | Position = AI.Position; | 
|---|
| 115 | Type = AI.Type; | 
|---|
| 116 | FatherId = AI.FatherId; | 
|---|
| 117 | MolId = AI.MolId; | 
|---|
| 118 | Velocity = AI.Velocity; | 
|---|
| 119 | Id = AI.Id; | 
|---|
| 120 | Nr = AI.Nr; | 
|---|
| 121 | return *this; | 
|---|
| 122 | } | 
|---|
| 123 |  | 
|---|