| 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 "qtaimextension.h" |
| 7 |
|
| 8 |
#include "qtaimcriticalpointlocator.h" |
| 9 |
#include "qtaimcubature.h" |
| 10 |
#include "qtaimwavefunctionevaluator.h" |
| 11 |
|
| 12 |
#include <avogadro/qtgui/molecule.h> |
| 13 |
|
| 14 |
#include <QAction> |
| 15 |
#include <QDebug> |
| 16 |
#include <QDir> |
| 17 |
#include <QFileDialog> |
| 18 |
#include <QList> |
| 19 |
#include <QPair> |
| 20 |
#include <QString> |
| 21 |
#include <QThread> |
| 22 |
#include <QTime> |
| 23 |
#include <QVector3D> |
| 24 |
|
| 25 |
using namespace Eigen; |
| 26 |
|
| 27 |
namespace Avogadro::QtPlugins { |
| 28 |
|
| 29 |
enum QTAIMExtensionIndex |
| 30 |
{ |
| 31 |
FirstAction = 0, |
| 32 |
SecondAction, |
| 33 |
ThirdAction |
| 34 |
}; |
| 35 |
|
| 36 |
QTAIMExtension::QTAIMExtension(QObject* aParent) |
| 37 |
: QtGui::ExtensionPlugin(aParent) |
| 38 |
{ |
| 39 |
// create an action for our first action |
| 40 |
auto* action = new QAction(this); |
| 41 |
action->setText(tr("Molecular Graph…")); |
| 42 |
m_actions.append(action); |
| 43 |
action->setData(FirstAction); |
| 44 |
connect(action, SIGNAL(triggered()), SLOT(triggered())); |
| 45 |
|
| 46 |
// create an action for our second action |
| 47 |
action = new QAction(this); |
| 48 |
action->setText(tr("Molecular Graph with Lone Pairs…")); |
| 49 |
m_actions.append(action); |
| 50 |
action->setData(SecondAction); |
| 51 |
connect(action, SIGNAL(triggered()), SLOT(triggered())); |
| 52 |
|
| 53 |
// create an action for our third action |
| 54 |
action = new QAction(this); |
| 55 |
action->setText(tr("Atomic Charge…")); |
| 56 |
m_actions.append(action); |
| 57 |
action->setData(ThirdAction); |
| 58 |
connect(action, SIGNAL(triggered()), SLOT(triggered())); |
| 59 |
} |
| 60 |
|
| 61 |
QList<QAction*> QTAIMExtension::actions() const |
| 62 |
{ |
| 63 |
return m_actions; |
| 64 |
} |
| 65 |
|
| 66 |
QStringList QTAIMExtension::menuPath(QAction*) const |
| 67 |
{ |
| 68 |
return QStringList() << tr("&Analyze") << tr("QTAIM"); |
| 69 |
} |
| 70 |
|
| 71 |
void QTAIMExtension::setMolecule(QtGui::Molecule* molecule) |
| 72 |
{ |
| 73 |
m_molecule = molecule; |
| 74 |
} |
| 75 |
|
| 76 |
void QTAIMExtension::triggered() |
| 77 |
{ |
| 78 |
auto* action = qobject_cast<QAction*>(sender()); |
| 79 |
if (!action) |
| 80 |
return; |
| 81 |
|
| 82 |
bool wavefunctionAlreadyLoaded = |
| 83 |
m_molecule->property("QTAIMComment").isValid(); |
| 84 |
|
| 85 |
int i = action->data().toInt(); |
| 86 |
|
| 87 |
QString fileName; |
| 88 |
if (!wavefunctionAlreadyLoaded) { |
| 89 |
fileName = QFileDialog::getOpenFileName( |
| 90 |
new QWidget, tr("Open WFN File"), QDir::homePath(), |
| 91 |
tr("WFN files (*.wfn);;All files (*.*)")); |
| 92 |
|
| 93 |
if (fileName.isNull()) { |
| 94 |
qDebug() << "No such file."; |
| 95 |
return; |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
// Instantiate a Wavefunction |
| 100 |
bool success = false; |
| 101 |
QTAIMWavefunction wfn; |
| 102 |
if (wavefunctionAlreadyLoaded) { |
| 103 |
success = wfn.initializeWithMoleculeProperties(m_molecule); |
| 104 |
} else { |
| 105 |
success = wfn.initializeWithWFNFile(fileName); |
| 106 |
} |
| 107 |
|
| 108 |
if (!success) { |
| 109 |
if (wavefunctionAlreadyLoaded) { |
| 110 |
qDebug() << "Error initializing wavefunction."; |
| 111 |
} else { |
| 112 |
qDebug() << "Error reading WFN file."; |
| 113 |
} |
| 114 |
return; |
| 115 |
} |
| 116 |
|
| 117 |
QtGui::Molecule::MoleculeChanges changes; |
| 118 |
if (m_molecule->atomCount() > 0) |
| 119 |
changes |= QtGui::Molecule::Atoms | QtGui::Molecule::Removed; |
| 120 |
if (m_molecule->bondCount() > 0) |
| 121 |
changes |= QtGui::Molecule::Bonds | QtGui::Molecule::Removed; |
| 122 |
|
| 123 |
m_molecule->clearAtoms(); |
| 124 |
m_molecule->emitChanged(static_cast<unsigned int>(changes)); |
| 125 |
|
| 126 |
// Instantiate an Evaluator |
| 127 |
QTAIMWavefunctionEvaluator eval(wfn); |
| 128 |
|
| 129 |
switch (i) { |
| 130 |
case FirstAction: // Molecular Graph |
| 131 |
{ |
| 132 |
// Instantiate a Critical Point Locator |
| 133 |
QTAIMCriticalPointLocator cpl(wfn); |
| 134 |
|
| 135 |
// Locate the Nuclear Critical Points |
| 136 |
cpl.locateNuclearCriticalPoints(); |
| 137 |
|
| 138 |
// QLists of results |
| 139 |
QList<qint64> nucChargeList = wfn.nuclearChargesList(); |
| 140 |
QList<QVector3D> ncpList = cpl.nuclearCriticalPoints(); |
| 141 |
|
| 142 |
QVariantList xNCPsVariantList; |
| 143 |
QVariantList yNCPsVariantList; |
| 144 |
QVariantList zNCPsVariantList; |
| 145 |
QVariantList nuclearChargesVariantList; |
| 146 |
|
| 147 |
const qreal convertBohrToAngstrom = 0.529177249; |
| 148 |
|
| 149 |
// Nuclear Critical Points |
| 150 |
for (qint64 n = 0; n < ncpList.length(); ++n) { |
| 151 |
QVector3D thisNuclearCriticalPoint = ncpList.at(n); |
| 152 |
|
| 153 |
qreal x = thisNuclearCriticalPoint.x() * convertBohrToAngstrom; |
| 154 |
qreal y = thisNuclearCriticalPoint.y() * convertBohrToAngstrom; |
| 155 |
qreal z = thisNuclearCriticalPoint.z() * convertBohrToAngstrom; |
| 156 |
|
| 157 |
xNCPsVariantList.append(x); |
| 158 |
yNCPsVariantList.append(y); |
| 159 |
zNCPsVariantList.append(z); |
| 160 |
nuclearChargesVariantList.append(wfn.nuclearCharge(n)); |
| 161 |
} |
| 162 |
|
| 163 |
m_molecule->setProperty("QTAIMXNuclearCriticalPoints", xNCPsVariantList); |
| 164 |
m_molecule->setProperty("QTAIMYNuclearCriticalPoints", yNCPsVariantList); |
| 165 |
m_molecule->setProperty("QTAIMZNuclearCriticalPoints", zNCPsVariantList); |
| 166 |
m_molecule->setProperty("QTAIMNuclearCharges", nuclearChargesVariantList); |
| 167 |
|
| 168 |
// Nuclei stored as Atoms |
| 169 |
for (qint64 n = 0; n < wfn.numberOfNuclei(); ++n) { |
| 170 |
qreal x = wfn.xNuclearCoordinate(n) * convertBohrToAngstrom; |
| 171 |
qreal y = wfn.yNuclearCoordinate(n) * convertBohrToAngstrom; |
| 172 |
qreal z = wfn.zNuclearCoordinate(n) * convertBohrToAngstrom; |
| 173 |
|
| 174 |
int Z = (int)wfn.nuclearCharge(n); |
| 175 |
|
| 176 |
m_molecule->addAtom(static_cast<unsigned char>(Z)) |
| 177 |
.setPosition3d(Vector3(static_cast<Real>(x), static_cast<Real>(y), |
| 178 |
static_cast<Real>(z))); |
| 179 |
} |
| 180 |
|
| 181 |
if (m_molecule->atomCount() > 0) { |
| 182 |
m_molecule->emitChanged(QtGui::Molecule::Atoms | |
| 183 |
QtGui::Molecule::Added); |
| 184 |
} |
| 185 |
|
| 186 |
// Locate the Bond Critical Points and Trace Bond Paths |
| 187 |
cpl.locateBondCriticalPoints(); |
| 188 |
|
| 189 |
// BCP and Bond Path Results |
| 190 |
QList<QVector3D> bcpList = cpl.bondCriticalPoints(); |
| 191 |
QList<QList<QVector3D>> bondPathList = cpl.bondPaths(); |
| 192 |
QList<QPair<qint64, qint64>> bondedAtomsList = cpl.bondedAtoms(); |
| 193 |
QList<qreal> laplacianAtBondCriticalPoints = |
| 194 |
cpl.laplacianAtBondCriticalPoints(); |
| 195 |
QList<qreal> ellipticityAtBondCriticalPoints = |
| 196 |
cpl.ellipticityAtBondCriticalPoints(); |
| 197 |
|
| 198 |
QVariantList xBCPsVariantList; |
| 199 |
QVariantList yBCPsVariantList; |
| 200 |
QVariantList zBCPsVariantList; |
| 201 |
QVariantList firstNCPIndexVariantList; |
| 202 |
QVariantList secondNCPIndexVariantList; |
| 203 |
QVariantList laplacianAtBondCriticalPointsVariantList; |
| 204 |
QVariantList ellipticityAtBondCriticalPointsVariantList; |
| 205 |
|
| 206 |
QVariantList bondPathSegmentStartIndexVariantList; |
| 207 |
QVariantList bondPathSegmentEndIndexVariantList; |
| 208 |
QVariantList xBondPathsVariantList; |
| 209 |
QVariantList yBondPathsVariantList; |
| 210 |
QVariantList zBondPathsVariantList; |
| 211 |
|
| 212 |
// Connectivity stored as Bonds |
| 213 |
|
| 214 |
qint64 bpCtr = 0; |
| 215 |
auto numAtoms = static_cast<qint64>(m_molecule->atomCount()); |
| 216 |
|
| 217 |
for (qint64 atom0 = 0; atom0 < numAtoms - 1; ++atom0) { |
| 218 |
for (qint64 atom1 = atom0 + 1; atom1 < numAtoms; ++atom1) { |
| 219 |
|
| 220 |
bool areBonded = false; |
| 221 |
|
| 222 |
for (qint64 bondPair = 0; bondPair < bondedAtomsList.length(); |
| 223 |
++bondPair) { |
| 224 |
if (atom0 == bondedAtomsList.at(bondPair).first && |
| 225 |
atom1 == bondedAtomsList.at(bondPair).second) { |
| 226 |
areBonded = true; |
| 227 |
|
| 228 |
if (areBonded) { |
| 229 |
|
| 230 |
if ((wfn.nuclearCharge(atom0) == 1 || |
| 231 |
wfn.nuclearCharge(atom1) == 1) && |
| 232 |
laplacianAtBondCriticalPoints.at(bondPair) > 0.0) { |
| 233 |
// do not draw Bond because it looks like hydrogen bond |
| 234 |
} else { |
| 235 |
m_molecule->addBond( |
| 236 |
m_molecule->atom(static_cast<Index>(atom0)), |
| 237 |
m_molecule->atom(static_cast<Index>(atom1))); |
| 238 |
// bond->setAromaticity(isAromatic); |
| 239 |
// bond->setOrder( (int) order); |
| 240 |
} |
| 241 |
|
| 242 |
qreal x = bcpList.at(bondPair).x() * convertBohrToAngstrom; |
| 243 |
qreal y = bcpList.at(bondPair).y() * convertBohrToAngstrom; |
| 244 |
qreal z = bcpList.at(bondPair).z() * convertBohrToAngstrom; |
| 245 |
|
| 246 |
xBCPsVariantList.append(x); |
| 247 |
yBCPsVariantList.append(y); |
| 248 |
zBCPsVariantList.append(z); |
| 249 |
|
| 250 |
firstNCPIndexVariantList.append(atom0); |
| 251 |
secondNCPIndexVariantList.append(atom1); |
| 252 |
|
| 253 |
laplacianAtBondCriticalPointsVariantList.append( |
| 254 |
laplacianAtBondCriticalPoints.at(bondPair)); |
| 255 |
ellipticityAtBondCriticalPointsVariantList.append( |
| 256 |
ellipticityAtBondCriticalPoints.at(bondPair)); |
| 257 |
|
| 258 |
bondPathSegmentStartIndexVariantList.append(bpCtr); |
| 259 |
for (auto j : bondPathList.at(bondPair)) { |
| 260 |
x = j.x() * convertBohrToAngstrom; |
| 261 |
y = j.y() * convertBohrToAngstrom; |
| 262 |
z = j.z() * convertBohrToAngstrom; |
| 263 |
|
| 264 |
xBondPathsVariantList.append(x); |
| 265 |
yBondPathsVariantList.append(y); |
| 266 |
zBondPathsVariantList.append(z); |
| 267 |
|
| 268 |
bpCtr++; |
| 269 |
} |
| 270 |
bondPathSegmentEndIndexVariantList.append(bpCtr); |
| 271 |
} |
| 272 |
} |
| 273 |
} // bond pairs |
| 274 |
} // atom1 |
| 275 |
} // atom 0 |
| 276 |
|
| 277 |
m_molecule->setProperty("QTAIMXBondCriticalPoints", xBCPsVariantList); |
| 278 |
m_molecule->setProperty("QTAIMYBondCriticalPoints", yBCPsVariantList); |
| 279 |
m_molecule->setProperty("QTAIMZBondCriticalPoints", zBCPsVariantList); |
| 280 |
m_molecule->setProperty("QTAIMFirstNCPIndexVariantList", |
| 281 |
firstNCPIndexVariantList); |
| 282 |
m_molecule->setProperty("QTAIMSecondNCPIndexVariantList", |
| 283 |
secondNCPIndexVariantList); |
| 284 |
m_molecule->setProperty("QTAIMLaplacianAtBondCriticalPoints", |
| 285 |
laplacianAtBondCriticalPointsVariantList); |
| 286 |
m_molecule->setProperty("QTAIMEllipticityAtBondCriticalPoints", |
| 287 |
ellipticityAtBondCriticalPointsVariantList); |
| 288 |
|
| 289 |
m_molecule->setProperty("QTAIMBondPathSegmentStartIndex", |
| 290 |
bondPathSegmentStartIndexVariantList); |
| 291 |
m_molecule->setProperty("QTAIMBondPathSegmentEndIndex", |
| 292 |
bondPathSegmentEndIndexVariantList); |
| 293 |
m_molecule->setProperty("QTAIMXBondPaths", xBondPathsVariantList); |
| 294 |
m_molecule->setProperty("QTAIMYBondPaths", yBondPathsVariantList); |
| 295 |
m_molecule->setProperty("QTAIMZBondPaths", zBondPathsVariantList); |
| 296 |
|
| 297 |
if (m_molecule->bondCount()) { |
| 298 |
m_molecule->emitChanged(QtGui::Molecule::Bonds | |
| 299 |
QtGui::Molecule::Added); |
| 300 |
} |
| 301 |
} break; |
| 302 |
case SecondAction: // Molecular Graph with Lone Pairs |
| 303 |
{ |
| 304 |
// Instantiate a Critical Point Locator |
| 305 |
QTAIMCriticalPointLocator cpl(wfn); |
| 306 |
|
| 307 |
// Locate the Nuclear Critical Points |
| 308 |
cpl.locateNuclearCriticalPoints(); |
| 309 |
|
| 310 |
// QLists of results |
| 311 |
QList<qint64> nucChargeList = wfn.nuclearChargesList(); |
| 312 |
QList<QVector3D> ncpList = cpl.nuclearCriticalPoints(); |
| 313 |
|
| 314 |
QVariantList xNCPsVariantList; |
| 315 |
QVariantList yNCPsVariantList; |
| 316 |
QVariantList zNCPsVariantList; |
| 317 |
QVariantList nuclearChargesVariantList; |
| 318 |
|
| 319 |
const qreal convertBohrToAngstrom = 0.529177249; |
| 320 |
|
| 321 |
// Nuclear Critical Points |
| 322 |
for (qint64 n = 0; n < ncpList.length(); ++n) { |
| 323 |
QVector3D thisNuclearCriticalPoint = ncpList.at(n); |
| 324 |
|
| 325 |
qreal x = thisNuclearCriticalPoint.x() * convertBohrToAngstrom; |
| 326 |
qreal y = thisNuclearCriticalPoint.y() * convertBohrToAngstrom; |
| 327 |
qreal z = thisNuclearCriticalPoint.z() * convertBohrToAngstrom; |
| 328 |
|
| 329 |
xNCPsVariantList.append(x); |
| 330 |
yNCPsVariantList.append(y); |
| 331 |
zNCPsVariantList.append(z); |
| 332 |
nuclearChargesVariantList.append(wfn.nuclearCharge(n)); |
| 333 |
} |
| 334 |
|
| 335 |
m_molecule->setProperty("QTAIMXNuclearCriticalPoints", xNCPsVariantList); |
| 336 |
m_molecule->setProperty("QTAIMYNuclearCriticalPoints", yNCPsVariantList); |
| 337 |
m_molecule->setProperty("QTAIMZNuclearCriticalPoints", zNCPsVariantList); |
| 338 |
m_molecule->setProperty("QTAIMNuclearCharges", nuclearChargesVariantList); |
| 339 |
|
| 340 |
// Nuclei stored as Atoms |
| 341 |
for (qint64 n = 0; n < wfn.numberOfNuclei(); ++n) { |
| 342 |
qreal x = wfn.xNuclearCoordinate(n) * convertBohrToAngstrom; |
| 343 |
qreal y = wfn.yNuclearCoordinate(n) * convertBohrToAngstrom; |
| 344 |
qreal z = wfn.zNuclearCoordinate(n) * convertBohrToAngstrom; |
| 345 |
|
| 346 |
int Z = (int)wfn.nuclearCharge(n); |
| 347 |
|
| 348 |
m_molecule->addAtom(static_cast<unsigned char>(Z)) |
| 349 |
.setPosition3d(Vector3(static_cast<Real>(x), static_cast<Real>(y), |
| 350 |
static_cast<Real>(z))); |
| 351 |
} |
| 352 |
|
| 353 |
if (m_molecule->atomCount() > 0) { |
| 354 |
m_molecule->emitChanged(QtGui::Molecule::Atoms | |
| 355 |
QtGui::Molecule::Added); |
| 356 |
} |
| 357 |
|
| 358 |
// Locate the Bond Critical Points and Trace Bond Paths |
| 359 |
cpl.locateBondCriticalPoints(); |
| 360 |
|
| 361 |
// BCP and Bond Path Results |
| 362 |
QList<QVector3D> bcpList = cpl.bondCriticalPoints(); |
| 363 |
QList<QList<QVector3D>> bondPathList = cpl.bondPaths(); |
| 364 |
QList<QPair<qint64, qint64>> bondedAtomsList = cpl.bondedAtoms(); |
| 365 |
QList<qreal> laplacianAtBondCriticalPoints = |
| 366 |
cpl.laplacianAtBondCriticalPoints(); |
| 367 |
QList<qreal> ellipticityAtBondCriticalPoints = |
| 368 |
cpl.ellipticityAtBondCriticalPoints(); |
| 369 |
|
| 370 |
QVariantList xBCPsVariantList; |
| 371 |
QVariantList yBCPsVariantList; |
| 372 |
QVariantList zBCPsVariantList; |
| 373 |
QVariantList firstNCPIndexVariantList; |
| 374 |
QVariantList secondNCPIndexVariantList; |
| 375 |
QVariantList laplacianAtBondCriticalPointsVariantList; |
| 376 |
QVariantList ellipticityAtBondCriticalPointsVariantList; |
| 377 |
|
| 378 |
QVariantList bondPathSegmentStartIndexVariantList; |
| 379 |
QVariantList bondPathSegmentEndIndexVariantList; |
| 380 |
QVariantList xBondPathsVariantList; |
| 381 |
QVariantList yBondPathsVariantList; |
| 382 |
QVariantList zBondPathsVariantList; |
| 383 |
|
| 384 |
// Connectivity stored as Bonds |
| 385 |
|
| 386 |
qint64 bpCtr = 0; |
| 387 |
auto numAtoms = static_cast<qint64>(m_molecule->atomCount()); |
| 388 |
|
| 389 |
for (qint64 atom0 = 0; atom0 < numAtoms - 1; ++atom0) { |
| 390 |
for (qint64 atom1 = atom0 + 1; atom1 < numAtoms; ++atom1) { |
| 391 |
|
| 392 |
bool areBonded = false; |
| 393 |
|
| 394 |
for (qint64 bondPair = 0; bondPair < bondedAtomsList.length(); |
| 395 |
++bondPair) { |
| 396 |
if (atom0 == bondedAtomsList.at(bondPair).first && |
| 397 |
atom1 == bondedAtomsList.at(bondPair).second) { |
| 398 |
areBonded = true; |
| 399 |
|
| 400 |
if (areBonded) { |
| 401 |
|
| 402 |
if ((wfn.nuclearCharge(atom0) == 1 || |
| 403 |
wfn.nuclearCharge(atom1) == 1) && |
| 404 |
laplacianAtBondCriticalPoints.at(bondPair) > 0.0) { |
| 405 |
// do not draw Bond because it looks like hydrogen bond |
| 406 |
} else { |
| 407 |
m_molecule->addBond( |
| 408 |
m_molecule->atom(static_cast<Index>(atom0)), |
| 409 |
m_molecule->atom(static_cast<Index>(atom1))); |
| 410 |
// bond->setAromaticity(isAromatic); |
| 411 |
// bond->setOrder( (int) order); |
| 412 |
} |
| 413 |
|
| 414 |
qreal x = bcpList.at(bondPair).x() * convertBohrToAngstrom; |
| 415 |
qreal y = bcpList.at(bondPair).y() * convertBohrToAngstrom; |
| 416 |
qreal z = bcpList.at(bondPair).z() * convertBohrToAngstrom; |
| 417 |
|
| 418 |
xBCPsVariantList.append(x); |
| 419 |
yBCPsVariantList.append(y); |
| 420 |
zBCPsVariantList.append(z); |
| 421 |
|
| 422 |
firstNCPIndexVariantList.append(atom0); |
| 423 |
secondNCPIndexVariantList.append(atom1); |
| 424 |
|
| 425 |
laplacianAtBondCriticalPointsVariantList.append( |
| 426 |
laplacianAtBondCriticalPoints.at(bondPair)); |
| 427 |
ellipticityAtBondCriticalPointsVariantList.append( |
| 428 |
ellipticityAtBondCriticalPoints.at(bondPair)); |
| 429 |
|
| 430 |
bondPathSegmentStartIndexVariantList.append(bpCtr); |
| 431 |
for (auto j : bondPathList.at(bondPair)) { |
| 432 |
x = j.x() * convertBohrToAngstrom; |
| 433 |
y = j.y() * convertBohrToAngstrom; |
| 434 |
z = j.z() * convertBohrToAngstrom; |
| 435 |
|
| 436 |
xBondPathsVariantList.append(x); |
| 437 |
yBondPathsVariantList.append(y); |
| 438 |
zBondPathsVariantList.append(z); |
| 439 |
|
| 440 |
bpCtr++; |
| 441 |
} |
| 442 |
bondPathSegmentEndIndexVariantList.append(bpCtr); |
| 443 |
} |
| 444 |
} |
| 445 |
} // bond pairs |
| 446 |
} // atom1 |
| 447 |
} // atom 0 |
| 448 |
|
| 449 |
m_molecule->setProperty("QTAIMXBondCriticalPoints", xBCPsVariantList); |
| 450 |
m_molecule->setProperty("QTAIMYBondCriticalPoints", yBCPsVariantList); |
| 451 |
m_molecule->setProperty("QTAIMZBondCriticalPoints", zBCPsVariantList); |
| 452 |
m_molecule->setProperty("QTAIMFirstNCPIndexVariantList", |
| 453 |
firstNCPIndexVariantList); |
| 454 |
m_molecule->setProperty("QTAIMSecondNCPIndexVariantList", |
| 455 |
secondNCPIndexVariantList); |
| 456 |
m_molecule->setProperty("QTAIMLaplacianAtBondCriticalPoints", |
| 457 |
laplacianAtBondCriticalPointsVariantList); |
| 458 |
m_molecule->setProperty("QTAIMEllipticityAtBondCriticalPoints", |
| 459 |
ellipticityAtBondCriticalPointsVariantList); |
| 460 |
|
| 461 |
m_molecule->setProperty("QTAIMBondPathSegmentStartIndex", |
| 462 |
bondPathSegmentStartIndexVariantList); |
| 463 |
m_molecule->setProperty("QTAIMBondPathSegmentEndIndex", |
| 464 |
bondPathSegmentEndIndexVariantList); |
| 465 |
m_molecule->setProperty("QTAIMXBondPaths", xBondPathsVariantList); |
| 466 |
m_molecule->setProperty("QTAIMYBondPaths", yBondPathsVariantList); |
| 467 |
m_molecule->setProperty("QTAIMZBondPaths", zBondPathsVariantList); |
| 468 |
|
| 469 |
if (m_molecule->bondCount()) { |
| 470 |
m_molecule->emitChanged(QtGui::Molecule::Bonds | |
| 471 |
QtGui::Molecule::Added); |
| 472 |
} |
| 473 |
|
| 474 |
// Locate Electron Density Sources / Lone Pairs |
| 475 |
|
| 476 |
cpl.locateElectronDensitySources(); |
| 477 |
QList<QVector3D> electronDensitySourcesList = |
| 478 |
cpl.electronDensitySources(); |
| 479 |
|
| 480 |
QVariantList xElectronDensitySourcesVariantList; |
| 481 |
QVariantList yElectronDensitySourcesVariantList; |
| 482 |
QVariantList zElectronDensitySourcesVariantList; |
| 483 |
|
| 484 |
for (auto thisCriticalPoint : electronDensitySourcesList) { |
| 485 |
qreal x = thisCriticalPoint.x() * convertBohrToAngstrom; |
| 486 |
qreal y = thisCriticalPoint.y() * convertBohrToAngstrom; |
| 487 |
qreal z = thisCriticalPoint.z() * convertBohrToAngstrom; |
| 488 |
|
| 489 |
xElectronDensitySourcesVariantList.append(x); |
| 490 |
yElectronDensitySourcesVariantList.append(y); |
| 491 |
zElectronDensitySourcesVariantList.append(z); |
| 492 |
} |
| 493 |
|
| 494 |
m_molecule->setProperty("QTAIMXElectronDensitySources", |
| 495 |
xElectronDensitySourcesVariantList); |
| 496 |
m_molecule->setProperty("QTAIMYElectronDensitySources", |
| 497 |
yElectronDensitySourcesVariantList); |
| 498 |
m_molecule->setProperty("QTAIMZElectronDensitySources", |
| 499 |
zElectronDensitySourcesVariantList); |
| 500 |
|
| 501 |
// TODO need some way to indicate that the properties have changed: |
| 502 |
// m_molecule->update(); |
| 503 |
|
| 504 |
} break; |
| 505 |
case ThirdAction: |
| 506 |
// perform third action |
| 507 |
{ |
| 508 |
// Instantiate a Critical Point Locator |
| 509 |
QTAIMCriticalPointLocator cpl(wfn); |
| 510 |
|
| 511 |
// Locate the Nuclear Critical Points |
| 512 |
cpl.locateNuclearCriticalPoints(); |
| 513 |
|
| 514 |
// QLists of results |
| 515 |
QList<qint64> nucChargeList = wfn.nuclearChargesList(); |
| 516 |
QList<QVector3D> ncpList = cpl.nuclearCriticalPoints(); |
| 517 |
|
| 518 |
QVariantList xNCPsVariantList; |
| 519 |
QVariantList yNCPsVariantList; |
| 520 |
QVariantList zNCPsVariantList; |
| 521 |
QVariantList nuclearChargesVariantList; |
| 522 |
|
| 523 |
const qreal convertBohrToAngstrom = 0.529177249; |
| 524 |
|
| 525 |
// Nuclear Critical Points |
| 526 |
for (qint64 n = 0; n < ncpList.length(); ++n) { |
| 527 |
QVector3D thisNuclearCriticalPoint = ncpList.at(n); |
| 528 |
|
| 529 |
qreal x = thisNuclearCriticalPoint.x() * convertBohrToAngstrom; |
| 530 |
qreal y = thisNuclearCriticalPoint.y() * convertBohrToAngstrom; |
| 531 |
qreal z = thisNuclearCriticalPoint.z() * convertBohrToAngstrom; |
| 532 |
|
| 533 |
xNCPsVariantList.append(x); |
| 534 |
yNCPsVariantList.append(y); |
| 535 |
zNCPsVariantList.append(z); |
| 536 |
nuclearChargesVariantList.append(wfn.nuclearCharge(n)); |
| 537 |
} |
| 538 |
|
| 539 |
m_molecule->setProperty("QTAIMXNuclearCriticalPoints", |
| 540 |
xNCPsVariantList); |
| 541 |
m_molecule->setProperty("QTAIMYNuclearCriticalPoints", |
| 542 |
yNCPsVariantList); |
| 543 |
m_molecule->setProperty("QTAIMZNuclearCriticalPoints", |
| 544 |
zNCPsVariantList); |
| 545 |
m_molecule->setProperty("QTAIMNuclearCharges", |
| 546 |
nuclearChargesVariantList); |
| 547 |
|
| 548 |
// Nuclei stored as Atoms |
| 549 |
for (qint64 n = 0; n < wfn.numberOfNuclei(); ++n) { |
| 550 |
qreal x = wfn.xNuclearCoordinate(n) * convertBohrToAngstrom; |
| 551 |
qreal y = wfn.yNuclearCoordinate(n) * convertBohrToAngstrom; |
| 552 |
qreal z = wfn.zNuclearCoordinate(n) * convertBohrToAngstrom; |
| 553 |
|
| 554 |
int Z = (int)wfn.nuclearCharge(n); |
| 555 |
|
| 556 |
m_molecule->addAtom(static_cast<unsigned char>(Z)) |
| 557 |
.setPosition3d(Vector3(static_cast<Real>(x), static_cast<Real>(y), |
| 558 |
static_cast<Real>(z))); |
| 559 |
} |
| 560 |
|
| 561 |
if (m_molecule->atomCount() > 0) { |
| 562 |
m_molecule->emitChanged(QtGui::Molecule::Atoms | |
| 563 |
QtGui::Molecule::Added); |
| 564 |
} |
| 565 |
|
| 566 |
// Locate the Bond Critical Points and Trace Bond Paths |
| 567 |
cpl.locateBondCriticalPoints(); |
| 568 |
|
| 569 |
// BCP and Bond Path Results |
| 570 |
QList<QVector3D> bcpList = cpl.bondCriticalPoints(); |
| 571 |
QList<QList<QVector3D>> bondPathList = cpl.bondPaths(); |
| 572 |
QList<QPair<qint64, qint64>> bondedAtomsList = cpl.bondedAtoms(); |
| 573 |
QList<qreal> laplacianAtBondCriticalPoints = |
| 574 |
cpl.laplacianAtBondCriticalPoints(); |
| 575 |
QList<qreal> ellipticityAtBondCriticalPoints = |
| 576 |
cpl.ellipticityAtBondCriticalPoints(); |
| 577 |
|
| 578 |
QVariantList xBCPsVariantList; |
| 579 |
QVariantList yBCPsVariantList; |
| 580 |
QVariantList zBCPsVariantList; |
| 581 |
QVariantList firstNCPIndexVariantList; |
| 582 |
QVariantList secondNCPIndexVariantList; |
| 583 |
QVariantList laplacianAtBondCriticalPointsVariantList; |
| 584 |
QVariantList ellipticityAtBondCriticalPointsVariantList; |
| 585 |
|
| 586 |
QVariantList bondPathSegmentStartIndexVariantList; |
| 587 |
QVariantList bondPathSegmentEndIndexVariantList; |
| 588 |
QVariantList xBondPathsVariantList; |
| 589 |
QVariantList yBondPathsVariantList; |
| 590 |
QVariantList zBondPathsVariantList; |
| 591 |
|
| 592 |
// Connectivity stored as Bonds |
| 593 |
|
| 594 |
qint64 bpCtr = 0; |
| 595 |
auto numAtoms = static_cast<qint64>(m_molecule->atomCount()); |
| 596 |
|
| 597 |
for (qint64 atom0 = 0; atom0 < numAtoms - 1; ++atom0) { |
| 598 |
for (qint64 atom1 = atom0 + 1; atom1 < numAtoms; ++atom1) { |
| 599 |
|
| 600 |
bool areBonded = false; |
| 601 |
|
| 602 |
for (qint64 bondPair = 0; bondPair < bondedAtomsList.length(); |
| 603 |
++bondPair) { |
| 604 |
if (atom0 == bondedAtomsList.at(bondPair).first && |
| 605 |
atom1 == bondedAtomsList.at(bondPair).second) { |
| 606 |
areBonded = true; |
| 607 |
|
| 608 |
if (areBonded) { |
| 609 |
|
| 610 |
if ((wfn.nuclearCharge(atom0) == 1 || |
| 611 |
wfn.nuclearCharge(atom1) == 1) && |
| 612 |
laplacianAtBondCriticalPoints.at(bondPair) > 0.0) { |
| 613 |
// do not draw Bond because it looks like hydrogen bond |
| 614 |
} else { |
| 615 |
m_molecule->addBond( |
| 616 |
m_molecule->atom(static_cast<Index>(atom0)), |
| 617 |
m_molecule->atom(static_cast<Index>(atom1))); |
| 618 |
// bond->setAromaticity(isAromatic); |
| 619 |
// bond->setOrder( (int) order); |
| 620 |
} |
| 621 |
|
| 622 |
qreal x = bcpList.at(bondPair).x() * convertBohrToAngstrom; |
| 623 |
qreal y = bcpList.at(bondPair).y() * convertBohrToAngstrom; |
| 624 |
qreal z = bcpList.at(bondPair).z() * convertBohrToAngstrom; |
| 625 |
|
| 626 |
xBCPsVariantList.append(x); |
| 627 |
yBCPsVariantList.append(y); |
| 628 |
zBCPsVariantList.append(z); |
| 629 |
|
| 630 |
firstNCPIndexVariantList.append(atom0); |
| 631 |
secondNCPIndexVariantList.append(atom1); |
| 632 |
|
| 633 |
laplacianAtBondCriticalPointsVariantList.append( |
| 634 |
laplacianAtBondCriticalPoints.at(bondPair)); |
| 635 |
ellipticityAtBondCriticalPointsVariantList.append( |
| 636 |
ellipticityAtBondCriticalPoints.at(bondPair)); |
| 637 |
|
| 638 |
bondPathSegmentStartIndexVariantList.append(bpCtr); |
| 639 |
for (auto j : bondPathList.at(bondPair)) { |
| 640 |
x = j.x() * convertBohrToAngstrom; |
| 641 |
y = j.y() * convertBohrToAngstrom; |
| 642 |
z = j.z() * convertBohrToAngstrom; |
| 643 |
|
| 644 |
xBondPathsVariantList.append(x); |
| 645 |
yBondPathsVariantList.append(y); |
| 646 |
zBondPathsVariantList.append(z); |
| 647 |
|
| 648 |
bpCtr++; |
| 649 |
} |
| 650 |
bondPathSegmentEndIndexVariantList.append(bpCtr); |
| 651 |
} |
| 652 |
} |
| 653 |
} // bond pairs |
| 654 |
} // atom1 |
| 655 |
} // atom 0 |
| 656 |
|
| 657 |
m_molecule->setProperty("QTAIMXBondCriticalPoints", xBCPsVariantList); |
| 658 |
m_molecule->setProperty("QTAIMYBondCriticalPoints", yBCPsVariantList); |
| 659 |
m_molecule->setProperty("QTAIMZBondCriticalPoints", zBCPsVariantList); |
| 660 |
m_molecule->setProperty("QTAIMFirstNCPIndexVariantList", |
| 661 |
firstNCPIndexVariantList); |
| 662 |
m_molecule->setProperty("QTAIMSecondNCPIndexVariantList", |
| 663 |
secondNCPIndexVariantList); |
| 664 |
m_molecule->setProperty("QTAIMLaplacianAtBondCriticalPoints", |
| 665 |
laplacianAtBondCriticalPointsVariantList); |
| 666 |
m_molecule->setProperty("QTAIMEllipticityAtBondCriticalPoints", |
| 667 |
ellipticityAtBondCriticalPointsVariantList); |
| 668 |
|
| 669 |
m_molecule->setProperty("QTAIMBondPathSegmentStartIndex", |
| 670 |
bondPathSegmentStartIndexVariantList); |
| 671 |
m_molecule->setProperty("QTAIMBondPathSegmentEndIndex", |
| 672 |
bondPathSegmentEndIndexVariantList); |
| 673 |
m_molecule->setProperty("QTAIMXBondPaths", xBondPathsVariantList); |
| 674 |
m_molecule->setProperty("QTAIMYBondPaths", yBondPathsVariantList); |
| 675 |
m_molecule->setProperty("QTAIMZBondPaths", zBondPathsVariantList); |
| 676 |
|
| 677 |
if (m_molecule->bondCount() > 0) { |
| 678 |
m_molecule->emitChanged(QtGui::Molecule::Bonds | |
| 679 |
QtGui::Molecule::Added); |
| 680 |
} |
| 681 |
|
| 682 |
// Electron Density |
| 683 |
qint64 mode = 0; |
| 684 |
|
| 685 |
// All Atomic Basins |
| 686 |
QList<qint64> basins; |
| 687 |
for (qint64 j = 0; j < wfn.numberOfNuclei(); ++j) { |
| 688 |
basins.append(j); |
| 689 |
} |
| 690 |
|
| 691 |
QTAIMCubature cub(wfn); |
| 692 |
|
| 693 |
// QTime time; |
| 694 |
// time.start(); |
| 695 |
QList<QPair<qreal, qreal>> results = cub.integrate(mode, basins); |
| 696 |
// qDebug() << "Time Elapsed:" << time.elapsed(); |
| 697 |
|
| 698 |
for (qint64 j = 0; j < results.length(); ++j) { |
| 699 |
qDebug() << "basin" << j << results.at(j).first |
| 700 |
<< results.at(j).second; |
| 701 |
} |
| 702 |
|
| 703 |
// TODO: Set the properties of the atoms. |
| 704 |
// I don't know why this bombs. |
| 705 |
for (qint64 j = 0; static_cast<qint64>(m_molecule->atomCount()); ++j) { |
| 706 |
// Atom *atom=m_molecule->atoms().at(i); |
| 707 |
// const qreal charge=results.at(i).first; |
| 708 |
// atom->setPartialCharge( charge ); |
| 709 |
} |
| 710 |
} |
| 711 |
break; |
| 712 |
} |
| 713 |
|
| 714 |
emit requestActiveTool("Navigator"); |
| 715 |
emit requestActiveDisplayTypes(QStringList() << "QTAIMScenePlugin"); |
| 716 |
} |
| 717 |
|
| 718 |
} // namespace Avogadro::QtPlugins |