source: src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.cpp@ 25e08a

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 25e08a 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: 6.3 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/*
24 * GLMoleculeObject_atom.cpp
25 *
26 * Created on: Aug 17, 2011
27 * Author: heber
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35#include "GLMoleculeObject_atom.hpp"
36
37#include <Qt3D/qglscenenode.h>
38
39#include "CodePatterns/MemDebug.hpp"
40
41#include "CodePatterns/Assert.hpp"
42#include "CodePatterns/Log.hpp"
43#include "CodePatterns/Observer/Notification.hpp"
44
45#include "Atom/atom.hpp"
46#include "Bond/bond.hpp"
47#include "Descriptors/AtomIdDescriptor.hpp"
48#include "Element/element.hpp"
49#include "LinearAlgebra/Vector.hpp"
50#include "GLMoleculeObject_bond.hpp"
51#include "World.hpp"
52
53GLMoleculeObject_atom::GLMoleculeObject_atom(QGLSceneNode *mesh[], QObject *parent, const atom *atomref) :
54 GLMoleculeObject(mesh, parent),
55 Observer(std::string("GLMoleculeObject_atom")+toString(atomref->getId())),
56 _atom(atomref)
57{
58 // sign on as observer (obtain non-const instance before)
59 atomref->signOn(this, AtomObservable::IndexChanged);
60 atomref->signOn(this, AtomObservable::PositionChanged);
61 atomref->signOn(this, AtomObservable::ElementChanged);
62 atomref->signOn(this, AtomObservable::BondsAdded);
63 World::getInstance().signOn(this, World::SelectionChanged);
64
65 // set the object's id
66 resetProperties();
67
68 LOG(2, "INFO: Created sphere for atom " << _atom->getId() << ".");
69
70 connect( this, SIGNAL(clicked()), this, SLOT(wasClicked()));
71}
72
73GLMoleculeObject_atom::~GLMoleculeObject_atom()
74{
75 if (_atom){
76 _atom->signOff(this, AtomObservable::IndexChanged);
77 _atom->signOff(this, AtomObservable::PositionChanged);
78 _atom->signOff(this, AtomObservable::ElementChanged);
79 _atom->signOff(this, AtomObservable::BondsAdded);
80 }
81 World::getInstance().signOff(this, World::SelectionChanged);
82}
83
84void GLMoleculeObject_atom::update(Observable *publisher)
85{
86#ifdef LOG_OBSERVER
87 observerLog().addMessage() << "++ Update of Observer " << observerLog().getName(this) << " from atom "+toString(_atom->getId())+".";
88#endif
89 resetProperties();
90}
91
92void GLMoleculeObject_atom::resetPosition()
93{
94 const Vector Position = _atom->getPosition();
95 LOG(4, "INFO: GLMoleculeObject_atom::resetIndex() - new position is "+toString(Position)+".");
96 setPosition(QVector3D(Position[0], Position[1], Position[2]));
97}
98
99void GLMoleculeObject_atom::resetElement()
100{
101 size_t elementno = 0;
102 if (_atom->getType() != NULL) {
103 elementno = _atom->getType()->getAtomicNumber();
104 } else { // if no element yet, set to hydrogen
105 elementno = 1;
106 }
107 LOG(4, "INFO: GLMoleculeObject_atom::resetIndex() - new element number is "+toString(elementno)+".");
108
109 // set materials
110 QGLMaterial *elementmaterial = getMaterial(elementno);
111 ASSERT(elementmaterial != NULL,
112 "GLMoleculeObject_atom::GLMoleculeObject_atom() - QGLMaterial ref from getter function is NULL.");
113 setMaterial(elementmaterial);
114
115 // set scale
116 double radius = 0.;
117 if (_atom->getType() != NULL) {
118 radius = _atom->getType()->getVanDerWaalsRadius();
119 } else {
120 radius = 0.5;
121 }
122 setScale( radius / 4. );
123}
124
125void GLMoleculeObject_atom::resetIndex()
126{
127 int oldId = objectId();
128 const size_t atomno = _atom->getId();
129 LOG(4, "INFO: GLMoleculeObject_atom::resetIndex() - new index is "+toString(atomno)+".");
130 setObjectId(atomno);
131
132 emit indexChanged(this, oldId, atomno);
133}
134
135void GLMoleculeObject_atom::resetProperties()
136{
137 // set position
138 resetPosition();
139
140 // set element
141 resetElement();
142
143 // set the object's id
144 resetIndex();
145
146 // selected?
147 setSelected(World::getInstance().isSelected(_atom));
148}
149
150void GLMoleculeObject_atom::subjectKilled(Observable *publisher)
151{
152 _atom = NULL;
153}
154
155void GLMoleculeObject_atom::recieveNotification(Observable *publisher, Notification_ptr notification)
156{
157 if (publisher == dynamic_cast<const Observable*>(_atom)){
158 // notofication from atom
159#ifdef LOG_OBSERVER
160 observerLog().addMessage() << "++ Update of Observer "<< observerLog().getName(this)
161 << " received notification from atom " << _atom->getId() << " for channel "
162 << notification->getChannelNo() << ".";
163#endif
164 switch (notification->getChannelNo()) {
165 case AtomObservable::ElementChanged:
166 resetElement();
167 emit changed();
168 break;
169 case AtomObservable::IndexChanged:
170 resetIndex();
171 break;
172 case AtomObservable::PositionChanged:
173 resetPosition();
174 emit changed();
175 break;
176 case AtomObservable::BondsAdded:
177 {
178 ASSERT(!_atom->getListOfBonds().empty(),
179 "GLMoleculeObject_atom::recieveNotification() - received BondsAdded but ListOfBonds is empty.");
180 const bond * _bond = *(_atom->getListOfBonds().rbegin());
181 const GLMoleculeObject_bond::SideOfBond side = (_bond->leftatom == _atom) ?
182 GLMoleculeObject_bond::left : GLMoleculeObject_bond::right;
183 emit BondsInserted(_bond, side);
184 break;
185 }
186 default:
187 //setProperties();
188 break;
189 }
190 }else{
191 // notification from world
192#ifdef LOG_OBSERVER
193 observerLog().addMessage() << "++ Update of Observer "<< observerLog().getName(this)
194 << " received notification from world for channel "
195 << notification->getChannelNo() << ".";
196#endif
197 switch (notification->getChannelNo()) {
198 case World::SelectionChanged:
199 setSelected(World::getInstance().isSelected(_atom));
200 break;
201 default:
202 break;
203 }
204 }
205}
206
207void GLMoleculeObject_atom::wasClicked()
208{
209 LOG(4, "INFO: GLMoleculeObject_atom: atom " << _atom->getId() << " has been clicked");
210 emit clicked(_atom->getId());
211}
Note: See TracBrowser for help on using the repository browser.