| [bcf653] | 1 | /* | 
|---|
|  | 2 | * Project: MoleCuilder | 
|---|
|  | 3 | * Description: creates and alters molecular systems | 
|---|
| [0aa122] | 4 | * Copyright (C)  2010-2012 University of Bonn. All rights reserved. | 
|---|
| [94d5ac6] | 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/>. | 
|---|
| [bcf653] | 21 | */ | 
|---|
|  | 22 |  | 
|---|
| [e41c48] | 23 | /* | 
|---|
|  | 24 | * AtomicInfo.cpp | 
|---|
|  | 25 | * | 
|---|
|  | 26 | *  Created on: Aug 10, 2010 | 
|---|
|  | 27 | *      Author: heber | 
|---|
|  | 28 | */ | 
|---|
|  | 29 |  | 
|---|
| [d2b28f] | 30 | // include config.h | 
|---|
|  | 31 | #ifdef HAVE_CONFIG_H | 
|---|
|  | 32 | #include <config.h> | 
|---|
|  | 33 | #endif | 
|---|
|  | 34 |  | 
|---|
| [ad011c] | 35 | #include "CodePatterns/MemDebug.hpp" | 
|---|
| [d2b28f] | 36 |  | 
|---|
| [e41c48] | 37 | #include "atom.hpp" | 
|---|
|  | 38 | #include "AtomicInfo.hpp" | 
|---|
| [b3d687] | 39 | #include "CodePatterns/Assert.hpp" | 
|---|
| [3867a7] | 40 | #include "Descriptors/AtomIdDescriptor.hpp" | 
|---|
|  | 41 | #include "Descriptors/MoleculeIdDescriptor.hpp" | 
|---|
| [3bdb6d] | 42 | #include "Element/element.hpp" | 
|---|
| [e41c48] | 43 | #include "LinearAlgebra/Vector.hpp" | 
|---|
| [3867a7] | 44 | #include "molecule.hpp" | 
|---|
|  | 45 | #include "World.hpp" | 
|---|
| [e41c48] | 46 |  | 
|---|
|  | 47 | /********************************** Functions for class AtomicInfo **********************************/ | 
|---|
|  | 48 |  | 
|---|
|  | 49 | AtomicInfo::AtomicInfo() : | 
|---|
|  | 50 | Type(NULL), | 
|---|
| [2034f3] | 51 | charge(0.), | 
|---|
| [3867a7] | 52 | FatherId(0), | 
|---|
|  | 53 | MolId(0), | 
|---|
| [560bbe] | 54 | Id(0), | 
|---|
|  | 55 | Nr(0) | 
|---|
| [e41c48] | 56 | {} | 
|---|
| [06070b] | 57 |  | 
|---|
| [e41c48] | 58 | AtomicInfo::AtomicInfo(const atom &_atom) : | 
|---|
|  | 59 | Position(_atom.getPosition()), | 
|---|
|  | 60 | Type(_atom.getType()), | 
|---|
| [2034f3] | 61 | charge(_atom.getCharge()), | 
|---|
| [bce72c] | 62 | Velocity(_atom.getAtomicVelocity()), | 
|---|
| [3867a7] | 63 | FatherId(_atom.father->getId()), | 
|---|
| [b3d687] | 64 | MolId(0), | 
|---|
| [560bbe] | 65 | Id(_atom.getId()), | 
|---|
|  | 66 | Nr(_atom.getNr()) | 
|---|
| [b3d687] | 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 | } | 
|---|
| [e41c48] | 73 |  | 
|---|
|  | 74 | AtomicInfo::~AtomicInfo() | 
|---|
|  | 75 | {} | 
|---|
|  | 76 |  | 
|---|
|  | 77 |  | 
|---|
|  | 78 | bool AtomicInfo::setAtom(atom &_atom) const | 
|---|
|  | 79 | { | 
|---|
|  | 80 | _atom.setPosition(Position); | 
|---|
|  | 81 | _atom.setType(Type); | 
|---|
| [2034f3] | 82 | _atom.setCharge(charge); | 
|---|
| [bce72c] | 83 | _atom.setAtomicVelocity(Velocity); | 
|---|
| [3867a7] | 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; | 
|---|
| [e41c48] | 94 | else | 
|---|
| [3867a7] | 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) | 
|---|
| [560bbe] | 101 | _atom.changeNr(Nr); | 
|---|
| [3867a7] | 102 |  | 
|---|
|  | 103 | return status; | 
|---|
| [e41c48] | 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; | 
|---|
| [3867a7] | 116 | FatherId = AI.FatherId; | 
|---|
|  | 117 | MolId = AI.MolId; | 
|---|
| [e41c48] | 118 | Velocity = AI.Velocity; | 
|---|
|  | 119 | Id = AI.Id; | 
|---|
| [560bbe] | 120 | Nr = AI.Nr; | 
|---|
| [e41c48] | 121 | return *this; | 
|---|
|  | 122 | } | 
|---|
|  | 123 |  | 
|---|