source: src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.cpp@ bca99d

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 bca99d was bca99d, checked in by Michael Ankele <ankele@…>, 13 years ago

GL: shared meshes

  • Property mode set to 100644
File size: 6.2 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 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * GLMoleculeObject_bond.cpp
10 *
11 * Created on: Aug 17, 2011
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "GLMoleculeObject_bond.hpp"
21
22#include <Qt3D/qglmaterial.h>
23#include <Qt3D/qglscenenode.h>
24
25#include "CodePatterns/MemDebug.hpp"
26
27#include <cmath>
28
29#include "CodePatterns/Assert.hpp"
30#include "CodePatterns/Log.hpp"
31#include "CodePatterns/Observer/Notification.hpp"
32#include "Atom/atom.hpp"
33#include "Bond/bond.hpp"
34#include "Element/element.hpp"
35#include "Helpers/defs.hpp"
36#include "LinearAlgebra/Line.hpp"
37#include "LinearAlgebra/Vector.hpp"
38
39GLMoleculeObject_bond::GLMoleculeObject_bond(QGLSceneNode *mesh, QObject *parent, const bond *bondref, const enum SideOfBond side) :
40 GLMoleculeObject(mesh, parent),
41 Observer(std::string("GLMoleculeObject_bond")
42 +toString(bondref->leftatom->getId())
43 +std::string("-")
44 +toString(bondref->rightatom->getId())),
45 _bond(bondref),
46 BondSide(side)
47{
48 // sign on as observer (obtain non-const instance before)
49 _bond->signOn(this, BondObservable::BondRemoved);
50 _bond->leftatom->signOn(this, AtomObservable::PositionChanged);
51 _bond->rightatom->signOn(this, AtomObservable::PositionChanged);
52
53 size_t elementno = 0;
54 switch (BondSide) {
55 case left:
56 if (_bond->leftatom->getType() != NULL) {
57 elementno = _bond->leftatom->getType()->getAtomicNumber();
58 } else { // if not element yet set, set to hydrogen
59 elementno = 1;
60 }
61 break;
62 case right:
63 if (_bond->rightatom->getType() != NULL) {
64 elementno = _bond->rightatom->getType()->getAtomicNumber();
65 } else { // if not element yet set, set to hydrogen
66 elementno = 1;
67 }
68
69 break;
70 default:
71 ASSERT(0,
72 "GLMoleculeObject_bond::GLMoleculeObject_bond() - side is not a valid argument: "+toString(BondSide)+".");
73 break;
74 }
75
76 QGLMaterial *elementmaterial = getMaterial(elementno);
77 setMaterial(elementmaterial);
78
79 resetPosition();
80}
81
82GLMoleculeObject_bond::~GLMoleculeObject_bond()
83{
84 // sign on as observer (obtain non-const instance before)
85 _bond->signOff(this, BondObservable::BondRemoved);
86 _bond->leftatom->signOff(this, AtomObservable::PositionChanged);
87 _bond->rightatom->signOff(this, AtomObservable::PositionChanged);
88
89 LOG(2, "INFO: Destroying GLMoleculeObject_bond to bond " << *_bond << " and side " << BondSide << ".");
90}
91
92void GLMoleculeObject_bond::update(Observable *publisher)
93{
94#ifdef LOG_OBSERVER
95 observerLog().addMessage() << "++ Update of Observer " << observerLog().getName(this) << " from bond " << *_bond << ".";
96#endif
97}
98
99void GLMoleculeObject_bond::subjectKilled(Observable *publisher)
100{
101 LOG(2, "INFO: Received subjectKilled from " << *_bond << ".");
102 switch (BondSide) {
103 case left:
104 emit BondRemoved(_bond->leftatom->getId(), _bond->rightatom->getId());
105 break;
106 case right:
107 emit BondRemoved(_bond->rightatom->getId(), _bond->leftatom->getId());
108 break;
109 default:
110 ASSERT(0,
111 "GLMoleculeObject_bond::subjectKilled() - side is not a valid argument: "+toString(BondSide)+".");
112 break;
113 }
114 delete this;
115}
116
117void GLMoleculeObject_bond::recieveNotification(Observable *publisher, Notification_ptr notification)
118{
119#ifdef LOG_OBSERVER
120 observerLog().addMessage() << "++ Update of Observer "<< observerLog().getName(this)
121 << " received notification from bond " << *_bond << " for channel "
122 << notification->getChannelNo() << ".";
123#endif
124 if (publisher == dynamic_cast<const Observable*>(_bond)){
125 // from the bond
126 switch (notification->getChannelNo()) {
127 case BondObservable::BondRemoved:
128 LOG(2, "INFO: Received notification of BondRemoved from " << *_bond << ".");
129 switch (BondSide) {
130 case left:
131 emit BondRemoved(_bond->leftatom->getId(), _bond->rightatom->getId());
132 break;
133 case right:
134 emit BondRemoved(_bond->rightatom->getId(), _bond->leftatom->getId());
135 break;
136 default:
137 ASSERT(0,
138 "GLMoleculeObject_bond::recieveNotification() - side is not a valid argument: "+toString(BondSide)+".");
139 break;
140 }
141 delete this;
142 break;
143 default:
144 break;
145 }
146 }else{
147 // from an atom
148 switch (notification->getChannelNo()) {
149 case AtomObservable::PositionChanged:
150 LOG(2, "INFO: Received notification of PositionChanged.");
151 resetPosition();
152 emit changed();
153 }
154 }
155}
156
157void GLMoleculeObject_bond::resetPosition()
158{
159 Vector Position;
160 Vector OtherPosition;
161 switch (BondSide) {
162 case left:
163 Position = _bond->leftatom->getPosition();
164 OtherPosition = _bond->rightatom->getPosition();
165 break;
166 case right:
167 Position = _bond->rightatom->getPosition();
168 OtherPosition = _bond->leftatom->getPosition();
169 break;
170 default:
171 ASSERT(0,
172 "GLMoleculeObject_bond::resetPosition() - side is not a valid argument: "+toString(BondSide)+".");
173 break;
174 }
175 const double distance =
176 Position.distance(OtherPosition)/2.;
177 setScaleZ(distance);
178
179 // calculate position
180 Vector Z(0.,0.,1.);
181 Vector zeroVec(0.,0.,0.);
182 Vector a,b;
183 Vector OtherAxis;
184 double alpha;
185 a = Position - OtherPosition;
186 // construct rotation axis
187 b = a;
188 b.VectorProduct(Z);
189 Line axis(zeroVec, b);
190 // calculate rotation angle
191 alpha = a.Angle(Z);
192 // construct other axis to check right-hand rule
193 OtherAxis = b;
194 OtherAxis.VectorProduct(Z);
195 // assure right-hand rule for the rotation
196 if (a.ScalarProduct(OtherAxis) < MYEPSILON)
197 alpha = M_PI-alpha;
198 // check
199 Vector a_rotated = axis.rotateVector(a, alpha);
200 LOG(3, "INFO: Created cylinder from "// << Position << " to " << OtherPosition
201 << a << " to " << a_rotated << " around " << b << " by " << alpha/M_PI*180. << ", respectively.");
202
203 // set position
204 setPosition(QVector3D(Position[0], Position[1], Position[2]));
205 setRotationVector(QVector3D(b[0], b[1], b[2]));
206 setRotationAngle(alpha/M_PI*180.);
207}
Note: See TracBrowser for help on using the repository browser.