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

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

Moved all stuff related to elements into own subfolder and has its own convenience library.

  • this induced massive changes in includes in other files.
  • we adapted PeriodentafelUnitTest to not get instance from world, but we create it ourselves.
  • also moved all .db files related to elements into subfolder Element/.
  • Property mode set to 100644
File size: 3.1 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010 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 "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
39static QGLSceneNode *createBond(QObject *parent, double distance)
40{
41 QGLBuilder builder;
42 QGLCylinder cylinder(.25,.25,.25);
43 cylinder.setHeight(distance);
44 builder << cylinder;
45 QGLSceneNode *n = builder.finalizedSceneNode();
46 n->setParent(parent);
47 return n;
48}
49
50GLMoleculeObject_bond::GLMoleculeObject_bond(QObject *parent, const bond *bondref, double distance, enum SideOfBond side) :
51 GLMoleculeObject(createBond(parent, distance), parent), _bond(bondref)
52{
53 Vector Position;
54 Vector OtherPosition;
55 size_t elementno = 0;
56 switch (side) {
57 case left:
58 Position = _bond->leftatom->getPosition();
59 OtherPosition = _bond->rightatom->getPosition();
60 if (_bond->leftatom->getType() != NULL) {
61 elementno = _bond->leftatom->getType()->getNumber();
62 } else { // if not element yet set, set to hydrogen
63 elementno = 1;
64 }
65 break;
66 case right:
67 Position = _bond->rightatom->getPosition();
68 OtherPosition = _bond->leftatom->getPosition();
69 if (_bond->rightatom->getType() != NULL) {
70 elementno = _bond->rightatom->getType()->getNumber();
71 } else { // if not element yet set, set to hydrogen
72 elementno = 1;
73 }
74
75 break;
76 default:
77 ASSERT(0,
78 "GLMoleculeObject_bond::GLMoleculeObject_bond() - side is not a valid argument: "+toString(side)+".");
79 break;
80 }
81
82 QGLMaterial *elementmaterial = getMaterial(elementno);
83 setMaterial(elementmaterial);
84
85 // calculate position
86 Vector Z(0.,0.,1.);
87 Vector zeroVec(0.,0.,0.);
88 Vector a,b;
89 Vector OtherAxis;
90 double alpha;
91 a = Position - OtherPosition;
92 // construct rotation axis
93 b = a;
94 b.VectorProduct(Z);
95 Line axis(zeroVec, b);
96 // calculate rotation angle
97 alpha = a.Angle(Z);
98 // construct other axis to check right-hand rule
99 OtherAxis = b;
100 OtherAxis.VectorProduct(Z);
101 // assure right-hand rule for the rotation
102 if (a.ScalarProduct(OtherAxis) < MYEPSILON)
103 alpha = M_PI-alpha;
104 // check
105 Vector a_rotated = axis.rotateVector(a, alpha);
106 std::cout << "Created cylinder from "// << Position << " to " << OtherPosition
107 << a << " to " << a_rotated << " around " << b << " by " << alpha/M_PI*180. << ", respectively." << endl;
108
109 // set position
110 setPosition(QVector3D(Position[0], Position[1], Position[2]));
111 setRotationVector(QVector3D(b[0], b[1], b[2]));
112 setRotationAngle(alpha/M_PI*180.);
113}
Note: See TracBrowser for help on using the repository browser.