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

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 b1b413 was 856d05, checked in by Frederik Heber <heber@…>, 12 years ago

MEMFIX: Added WorldTime and ObserverLog ::purgeInstance() calls.

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