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

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 ed26ae was ed26ae, checked in by Frederik Heber <heber@…>, 13 years ago

Renamed calls to element::getNumber() -> ::getAtomicNumber().

  • dropped element::getNumber() as getAtomicNumber has same functionality.
  • Property mode set to 100644
File size: 5.5 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/qglbuilder.h>
23#include <Qt3D/qglcylinder.h>
24#include <Qt3D/qglmaterial.h>
25#include <Qt3D/qglscenenode.h>
26
27#include "CodePatterns/MemDebug.hpp"
28
29#include <cmath>
30
31#include "CodePatterns/Assert.hpp"
32#include "CodePatterns/Log.hpp"
33#include "CodePatterns/Observer/Notification.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
41static QGLSceneNode *createBond(QObject *parent, double distance)
42{
43 QGLBuilder builder;
44 QGLCylinder cylinder(.25,.25,.25);
45 cylinder.setHeight(distance);
46 builder << cylinder;
47 QGLSceneNode *n = builder.finalizedSceneNode();
48 n->setParent(parent);
49 return n;
50}
51
52GLMoleculeObject_bond::GLMoleculeObject_bond(QObject *parent, const bond *bondref, const double distance, const enum SideOfBond side) :
53 GLMoleculeObject(createBond(parent, distance), parent),
54 Observer(std::string("GLMoleculeObject_bond")
55 +toString(bondref->leftatom->getId())
56 +std::string("-")
57 +toString(bondref->rightatom->getId())),
58 _bond(bondref),
59 BondSide(side)
60{
61 // sign on as observer (obtain non-const instance before)
62 _bond->signOn(this, BondObservable::BondRemoved);
63
64 Vector Position;
65 Vector OtherPosition;
66 size_t elementno = 0;
67 switch (BondSide) {
68 case left:
69 Position = _bond->leftatom->getPosition();
70 OtherPosition = _bond->rightatom->getPosition();
71 if (_bond->leftatom->getType() != NULL) {
72 elementno = _bond->leftatom->getType()->getAtomicNumber();
73 } else { // if not element yet set, set to hydrogen
74 elementno = 1;
75 }
76 break;
77 case right:
78 Position = _bond->rightatom->getPosition();
79 OtherPosition = _bond->leftatom->getPosition();
80 if (_bond->rightatom->getType() != NULL) {
81 elementno = _bond->rightatom->getType()->getAtomicNumber();
82 } else { // if not element yet set, set to hydrogen
83 elementno = 1;
84 }
85
86 break;
87 default:
88 ASSERT(0,
89 "GLMoleculeObject_bond::GLMoleculeObject_bond() - side is not a valid argument: "+toString(BondSide)+".");
90 break;
91 }
92
93 QGLMaterial *elementmaterial = getMaterial(elementno);
94 setMaterial(elementmaterial);
95
96 // calculate position
97 Vector Z(0.,0.,1.);
98 Vector zeroVec(0.,0.,0.);
99 Vector a,b;
100 Vector OtherAxis;
101 double alpha;
102 a = Position - OtherPosition;
103 // construct rotation axis
104 b = a;
105 b.VectorProduct(Z);
106 Line axis(zeroVec, b);
107 // calculate rotation angle
108 alpha = a.Angle(Z);
109 // construct other axis to check right-hand rule
110 OtherAxis = b;
111 OtherAxis.VectorProduct(Z);
112 // assure right-hand rule for the rotation
113 if (a.ScalarProduct(OtherAxis) < MYEPSILON)
114 alpha = M_PI-alpha;
115 // check
116 Vector a_rotated = axis.rotateVector(a, alpha);
117 LOG(3, "INFO: Created cylinder from "// << Position << " to " << OtherPosition
118 << a << " to " << a_rotated << " around " << b << " by " << alpha/M_PI*180. << ", respectively.");
119
120 // set position
121 setPosition(QVector3D(Position[0], Position[1], Position[2]));
122 setRotationVector(QVector3D(b[0], b[1], b[2]));
123 setRotationAngle(alpha/M_PI*180.);
124}
125
126GLMoleculeObject_bond::~GLMoleculeObject_bond()
127{
128 // sign on as observer (obtain non-const instance before)
129 _bond->signOff(this, BondObservable::BondRemoved);
130
131 LOG(2, "INFO: Destroying GLMoleculeObject_bond to bond " << *_bond << " and side " << BondSide << ".");
132}
133
134void GLMoleculeObject_bond::update(Observable *publisher)
135{
136#ifdef LOG_OBSERVER
137 observerLog().addMessage() << "++ Update of Observer " << observerLog().getName(this) << " from bond " << *_bond << ".";
138#endif
139}
140
141void GLMoleculeObject_bond::subjectKilled(Observable *publisher)
142{
143 LOG(2, "INFO: Received subjectKilled from " << *_bond << ".");
144 switch (BondSide) {
145 case left:
146 emit BondRemoved(_bond->leftatom->getId(), _bond->rightatom->getId());
147 break;
148 case right:
149 emit BondRemoved(_bond->rightatom->getId(), _bond->leftatom->getId());
150 break;
151 default:
152 ASSERT(0,
153 "GLMoleculeObject_bond::subjectKilled() - side is not a valid argument: "+toString(BondSide)+".");
154 break;
155 }
156 delete this;
157}
158
159void GLMoleculeObject_bond::recieveNotification(Observable *publisher, Notification_ptr notification)
160{
161#ifdef LOG_OBSERVER
162 observerLog().addMessage() << "++ Update of Observer "<< observerLog().getName(this)
163 << " received notification from bond " << *_bond << " for channel "
164 << notification->getChannelNo() << ".";
165#endif
166 switch (notification->getChannelNo()) {
167 case BondObservable::BondRemoved:
168 LOG(2, "INFO: Received notification of BondRemoved from " << *_bond << ".");
169 switch (BondSide) {
170 case left:
171 emit BondRemoved(_bond->leftatom->getId(), _bond->rightatom->getId());
172 break;
173 case right:
174 emit BondRemoved(_bond->rightatom->getId(), _bond->leftatom->getId());
175 break;
176 default:
177 ASSERT(0,
178 "GLMoleculeObject_bond::recieveNotification() - side is not a valid argument: "+toString(BondSide)+".");
179 break;
180 }
181 delete this;
182 break;
183 default:
184 break;
185 }
186}
Note: See TracBrowser for help on using the repository browser.