| 1 |
/****************************************************************************** |
| 2 |
This source file is part of the Avogadro project. |
| 3 |
This source code is released under the 3-Clause BSD License, (see "LICENSE"). |
| 4 |
******************************************************************************/ |
| 5 |
|
| 6 |
#include "qtaimengine.h" |
| 7 |
|
| 8 |
#include <avogadro/qtgui/molecule.h> |
| 9 |
|
| 10 |
#include <avogadro/rendering/cylindergeometry.h> |
| 11 |
#include <avogadro/rendering/geometrynode.h> |
| 12 |
#include <avogadro/rendering/groupnode.h> |
| 13 |
#include <avogadro/rendering/spheregeometry.h> |
| 14 |
|
| 15 |
#include <QDebug> |
| 16 |
#include <QtCore/QVariant> |
| 17 |
|
| 18 |
using namespace Avogadro; |
| 19 |
using namespace Avogadro::Rendering; |
| 20 |
|
| 21 |
namespace Avogadro::QtPlugins { |
| 22 |
|
| 23 |
QTAIMEngine::QTAIMEngine(QObject* aParent) |
| 24 |
: QtGui::ScenePlugin(aParent), m_enabled(false) |
| 25 |
{ |
| 26 |
m_layerManager = QtGui::PluginLayerManager(m_name); |
| 27 |
} |
| 28 |
|
| 29 |
void QTAIMEngine::process(const QtGui::Molecule& molecule, |
| 30 |
Rendering::GroupNode& node) |
| 31 |
{ |
| 32 |
// Create sphere/cylinder nodes. |
| 33 |
auto* geometry = new GeometryNode; |
| 34 |
node.addChild(geometry); |
| 35 |
auto* spheres = new SphereGeometry; |
| 36 |
geometry->addDrawable(spheres); |
| 37 |
auto* cylinders = new CylinderGeometry; |
| 38 |
geometry->addDrawable(cylinders); |
| 39 |
|
| 40 |
// Render the bond paths |
| 41 |
if (molecule.property("QTAIMFirstNCPIndexVariantList").isValid() && |
| 42 |
molecule.property("QTAIMSecondNCPIndexVariantList").isValid() && |
| 43 |
molecule.property("QTAIMLaplacianAtBondCriticalPoints").isValid() && |
| 44 |
molecule.property("QTAIMEllipticityAtBondCriticalPoints").isValid() && |
| 45 |
molecule.property("QTAIMBondPathSegmentStartIndex").isValid() && |
| 46 |
molecule.property("QTAIMBondPathSegmentEndIndex").isValid() && |
| 47 |
molecule.property("QTAIMXBondPaths").isValid() && |
| 48 |
molecule.property("QTAIMYBondPaths").isValid() && |
| 49 |
molecule.property("QTAIMZBondPaths").isValid()) { |
| 50 |
QVariant firstNCPIndexVariant = |
| 51 |
molecule.property("QTAIMFirstNCPIndexVariantList"); |
| 52 |
QVariant secondNCPIndexVariant = |
| 53 |
molecule.property("QTAIMSecondNCPIndexVariantList"); |
| 54 |
QVariant laplacianAtBondCriticalPointsVariant = |
| 55 |
molecule.property("QTAIMLaplacianAtBondCriticalPoints"); |
| 56 |
QVariant ellipticityAtBondCriticalPointsVariant = |
| 57 |
molecule.property("QTAIMEllipticityAtBondCriticalPoints"); |
| 58 |
QVariant bondPathSegmentStartIndexVariant = |
| 59 |
molecule.property("QTAIMBondPathSegmentStartIndex"); |
| 60 |
QVariant bondPathSegmentEndIndexVariant = |
| 61 |
molecule.property("QTAIMBondPathSegmentEndIndex"); |
| 62 |
QVariant xBondPathsVariant = molecule.property("QTAIMXBondPaths"); |
| 63 |
QVariant yBondPathsVariant = molecule.property("QTAIMYBondPaths"); |
| 64 |
QVariant zBondPathsVariant = molecule.property("QTAIMZBondPaths"); |
| 65 |
|
| 66 |
QVariantList firstNCPIndexVariantList = firstNCPIndexVariant.toList(); |
| 67 |
QVariantList secondNCPIndexVariantList = secondNCPIndexVariant.toList(); |
| 68 |
QVariantList laplacianAtBondCriticalPointsVariantList = |
| 69 |
laplacianAtBondCriticalPointsVariant.toList(); |
| 70 |
QVariantList ellipticityAtBondCriticalPointsVariantList = |
| 71 |
ellipticityAtBondCriticalPointsVariant.toList(); |
| 72 |
QVariantList bondPathSegmentStartIndexVariantList = |
| 73 |
bondPathSegmentStartIndexVariant.toList(); |
| 74 |
QVariantList bondPathSegmentEndIndexVariantList = |
| 75 |
bondPathSegmentEndIndexVariant.toList(); |
| 76 |
QVariantList xBondPathsVariantList = xBondPathsVariant.toList(); |
| 77 |
QVariantList yBondPathsVariantList = yBondPathsVariant.toList(); |
| 78 |
QVariantList zBondPathsVariantList = zBondPathsVariant.toList(); |
| 79 |
|
| 80 |
for (qint64 i = 0; i < firstNCPIndexVariantList.length(); ++i) { |
| 81 |
|
| 82 |
qint64 start = bondPathSegmentStartIndexVariantList.at(i).toLongLong(); |
| 83 |
qint64 end = bondPathSegmentEndIndexVariantList.at(i).toLongLong(); |
| 84 |
|
| 85 |
if (laplacianAtBondCriticalPointsVariantList.at(i).toReal() > 0.0) { |
| 86 |
|
| 87 |
const qint64 step = 4; |
| 88 |
|
| 89 |
Vector3f xyz; |
| 90 |
Vector3ub color(255, 255, 255); |
| 91 |
for (qint64 j = start; j < end - 1; j = j + step) { |
| 92 |
xyz << xBondPathsVariantList.at(j).toFloat(), |
| 93 |
yBondPathsVariantList.at(j).toFloat(), |
| 94 |
zBondPathsVariantList.at(j).toFloat(); |
| 95 |
spheres->addSphere(xyz, color, 0.025f); |
| 96 |
} |
| 97 |
} else { |
| 98 |
|
| 99 |
const qint64 step = 1; |
| 100 |
|
| 101 |
Vector3ub color(255, 255, 255); |
| 102 |
double radius = 0.025; |
| 103 |
|
| 104 |
Vector3f v1; |
| 105 |
Vector3f v2; |
| 106 |
Vector3f direction; |
| 107 |
for (qint64 j = start; j < end - 1; j = j + step) { |
| 108 |
|
| 109 |
v1 << xBondPathsVariantList.at(j).toFloat(), |
| 110 |
yBondPathsVariantList.at(j).toFloat(), |
| 111 |
zBondPathsVariantList.at(j).toFloat(); |
| 112 |
v2 << xBondPathsVariantList.at(j + 1).toFloat(), |
| 113 |
yBondPathsVariantList.at(j + 1).toFloat(), |
| 114 |
zBondPathsVariantList.at(j + 1).toFloat(); |
| 115 |
|
| 116 |
direction = v2 - v1; |
| 117 |
float length = direction.norm(); |
| 118 |
direction /= length; |
| 119 |
|
| 120 |
cylinders->addCylinder(v1, v2, radius, color); |
| 121 |
} |
| 122 |
} |
| 123 |
} // bond path |
| 124 |
} |
| 125 |
|
| 126 |
if (molecule.property("QTAIMXNuclearCriticalPoints").isValid() && |
| 127 |
molecule.property("QTAIMYNuclearCriticalPoints").isValid() && |
| 128 |
molecule.property("QTAIMZNuclearCriticalPoints").isValid()) { |
| 129 |
QVariant xNuclearCriticalPointsVariant = |
| 130 |
molecule.property("QTAIMXNuclearCriticalPoints"); |
| 131 |
QVariant yNuclearCriticalPointsVariant = |
| 132 |
molecule.property("QTAIMYNuclearCriticalPoints"); |
| 133 |
QVariant zNuclearCriticalPointsVariant = |
| 134 |
molecule.property("QTAIMZNuclearCriticalPoints"); |
| 135 |
QVariantList xNuclearCriticalPointsVariantList = |
| 136 |
xNuclearCriticalPointsVariant.toList(); |
| 137 |
QVariantList yNuclearCriticalPointsVariantList = |
| 138 |
yNuclearCriticalPointsVariant.toList(); |
| 139 |
QVariantList zNuclearCriticalPointsVariantList = |
| 140 |
zNuclearCriticalPointsVariant.toList(); |
| 141 |
if (xNuclearCriticalPointsVariantList.length() == |
| 142 |
yNuclearCriticalPointsVariantList.length() && |
| 143 |
xNuclearCriticalPointsVariantList.length() == |
| 144 |
zNuclearCriticalPointsVariantList.length()) { |
| 145 |
Vector3f xyz; |
| 146 |
Vector3ub color(255, 64, 255); |
| 147 |
for (qint64 i = 0; i < xNuclearCriticalPointsVariantList.length(); ++i) { |
| 148 |
xyz << xNuclearCriticalPointsVariantList.at(i).toFloat(), |
| 149 |
yNuclearCriticalPointsVariantList.at(i).toFloat(), |
| 150 |
zNuclearCriticalPointsVariantList.at(i).toFloat(); |
| 151 |
|
| 152 |
// map->setFromPrimitive(ncp); |
| 153 |
|
| 154 |
spheres->addSphere(xyz, color, 0.1f); |
| 155 |
} |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 159 |
if (molecule.property("QTAIMXBondCriticalPoints").isValid() && |
| 160 |
molecule.property("QTAIMYBondCriticalPoints").isValid() && |
| 161 |
molecule.property("QTAIMZBondCriticalPoints").isValid()) { |
| 162 |
QVariant xBondCriticalPointsVariant = |
| 163 |
molecule.property("QTAIMXBondCriticalPoints"); |
| 164 |
QVariant yBondCriticalPointsVariant = |
| 165 |
molecule.property("QTAIMYBondCriticalPoints"); |
| 166 |
QVariant zBondCriticalPointsVariant = |
| 167 |
molecule.property("QTAIMZBondCriticalPoints"); |
| 168 |
QVariantList xBondCriticalPointsVariantList = |
| 169 |
xBondCriticalPointsVariant.toList(); |
| 170 |
QVariantList yBondCriticalPointsVariantList = |
| 171 |
yBondCriticalPointsVariant.toList(); |
| 172 |
QVariantList zBondCriticalPointsVariantList = |
| 173 |
zBondCriticalPointsVariant.toList(); |
| 174 |
if (xBondCriticalPointsVariantList.length() == |
| 175 |
yBondCriticalPointsVariantList.length() && |
| 176 |
xBondCriticalPointsVariantList.length() == |
| 177 |
zBondCriticalPointsVariantList.length()) { |
| 178 |
Vector3ub color(255, 255, 32); |
| 179 |
Vector3f xyz; |
| 180 |
for (qint64 i = 0; i < xBondCriticalPointsVariantList.length(); ++i) { |
| 181 |
xyz << xBondCriticalPointsVariantList.at(i).toFloat(), |
| 182 |
yBondCriticalPointsVariantList.at(i).toFloat(), |
| 183 |
zBondCriticalPointsVariantList.at(i).toFloat(); |
| 184 |
|
| 185 |
// map->setFromPrimitive(ncp); |
| 186 |
|
| 187 |
spheres->addSphere(xyz, color, 0.1f); |
| 188 |
} |
| 189 |
} |
| 190 |
} |
| 191 |
|
| 192 |
if (molecule.property("QTAIMXElectronDensitySources").isValid() && |
| 193 |
molecule.property("QTAIMYElectronDensitySources").isValid() && |
| 194 |
molecule.property("QTAIMZElectronDensitySources").isValid()) { |
| 195 |
QVariant xElectronDensitySourcesVariant = |
| 196 |
molecule.property("QTAIMXElectronDensitySources"); |
| 197 |
QVariant yElectronDensitySourcesVariant = |
| 198 |
molecule.property("QTAIMYElectronDensitySources"); |
| 199 |
QVariant zElectronDensitySourcesVariant = |
| 200 |
molecule.property("QTAIMZElectronDensitySources"); |
| 201 |
QVariantList xElectronDensitySourcesVariantList = |
| 202 |
xElectronDensitySourcesVariant.toList(); |
| 203 |
QVariantList yElectronDensitySourcesVariantList = |
| 204 |
yElectronDensitySourcesVariant.toList(); |
| 205 |
QVariantList zElectronDensitySourcesVariantList = |
| 206 |
zElectronDensitySourcesVariant.toList(); |
| 207 |
if (xElectronDensitySourcesVariantList.length() == |
| 208 |
yElectronDensitySourcesVariantList.length() && |
| 209 |
xElectronDensitySourcesVariantList.length() == |
| 210 |
zElectronDensitySourcesVariantList.length()) { |
| 211 |
Vector3ub color(64, 64, 255); |
| 212 |
Vector3f xyz; |
| 213 |
for (qint64 i = 0; i < xElectronDensitySourcesVariantList.length(); ++i) { |
| 214 |
xyz << xElectronDensitySourcesVariantList.at(i).toFloat(), |
| 215 |
yElectronDensitySourcesVariantList.at(i).toFloat(), |
| 216 |
zElectronDensitySourcesVariantList.at(i).toFloat(); |
| 217 |
|
| 218 |
// map->setFromPrimitive(ncp); |
| 219 |
|
| 220 |
spheres->addSphere(xyz, color, 0.1f); |
| 221 |
} |
| 222 |
} |
| 223 |
} |
| 224 |
} |
| 225 |
|
| 226 |
} // namespace Avogadro::QtPlugins |