Skip to content

Commit

Permalink
Fix some crashes found with testing
Browse files Browse the repository at this point in the history
A few remaining spots required the dialog to exist

Signed-off-by: Geoff Hutchison <[email protected]>
  • Loading branch information
ghutchis committed Sep 14, 2023
1 parent c944183 commit c5e0741
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
2 changes: 2 additions & 0 deletions avogadro/core/cube.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class AVOGADROCORE_EXPORT Cube
enum Type
{
VdW,
SolventAccessible,
SolventExcluded,
ESP,
ElectronDensity,
SpinDensity,
Expand Down
40 changes: 33 additions & 7 deletions avogadro/qtplugins/surfaces/surfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Surfaces::Surfaces(QObject* p) : ExtensionPlugin(p), d(new PIMPL())
Surfaces::~Surfaces()
{
delete d;
delete m_cube;
// delete m_cube; // should be freed by the molecule
}

void Surfaces::registerCommands()
Expand All @@ -113,6 +113,7 @@ void Surfaces::registerCommands()
emit registerCommand("renderSolventExcluded",
tr("Render the solvent-excluded molecular surface."));
emit registerCommand("renderOrbital", tr("Render a molecular orbital."));
emit registerCommand("renderMO", tr("Render a molecular orbital."));
emit registerCommand("renderElectronDensity",
tr("Render the electron density."));
emit registerCommand("renderSpinDensity", tr("Render the spin density."));
Expand All @@ -125,6 +126,8 @@ bool Surfaces::handleCommand(const QString& command, const QVariantMap& options)
if (m_molecule == nullptr)
return false; // No molecule to handle the command.

qDebug() << "handle surface cmd:" << command << options;

// Set up some defaults for the options.
int index = -1;
int homo = -1;
Expand All @@ -148,12 +151,12 @@ bool Surfaces::handleCommand(const QString& command, const QVariantMap& options)

if (m_basis != nullptr)
homo = m_basis->homo();
if (options.contains("index")) {
if (options.contains("orbital")) {
// check if options contains "homo" or "lumo"
bool string = options["index"].canConvert<QString>();
bool string = options["orbital"].canConvert<QString>();
if (string) {
// should be something like "homo-1" or "lumo+2"
QString name = options["index"].toString();
QString name = options["orbital"].toString();
QString expression, modifier;
if (name.contains("homo", Qt::CaseInsensitive)) {
index = homo; // modified by the expression after the string
Expand Down Expand Up @@ -185,7 +188,8 @@ bool Surfaces::handleCommand(const QString& command, const QVariantMap& options)
beta = options["spin"].toString().contains("beta");
}

if (command.compare("renderVanDerWaals", Qt::CaseInsensitive) == 0) {
if ((command.compare("renderVanDerWaals", Qt::CaseInsensitive) == 0) ||
(command.compare("renderVDW", Qt::CaseInsensitive) == 0)) {
calculateEDT(VanDerWaals, cubeResolution);
return true;
} else if (command.compare("renderSolventAccessible", Qt::CaseInsensitive) ==
Expand All @@ -196,7 +200,8 @@ bool Surfaces::handleCommand(const QString& command, const QVariantMap& options)
0) {
calculateEDT(SolventExcluded, cubeResolution);
return true;
} else if (command.compare("renderOrbital", Qt::CaseInsensitive) == 0) {
} else if ((command.compare("renderOrbital", Qt::CaseInsensitive) == 0) ||
(command.compare("renderMO", Qt::CaseInsensitive) == 0)) {
calculateQM(MolecularOrbital, index, beta, isoValue, cubeResolution);
return true;
} else if (command.compare("renderElectronDensity", Qt::CaseInsensitive) ==
Expand Down Expand Up @@ -239,6 +244,14 @@ QStringList Surfaces::menuPath(QAction*) const

void Surfaces::surfacesActivated()
{
if (!m_dialog) {
m_dialog = new SurfaceDialog(qobject_cast<QWidget*>(parent()));
connect(m_dialog, SIGNAL(calculateClickedSignal()),
SLOT(calculateSurface()));
connect(m_dialog, SIGNAL(recordClicked()), SLOT(recordMovie()));
connect(m_dialog, SIGNAL(stepChanged(int)), SLOT(stepChanged(int)));
}

if (m_basis) {
// we have quantum data, set up the dialog accordingly
auto gaussian = dynamic_cast<Core::GaussianSet*>(m_basis);
Expand Down Expand Up @@ -339,14 +352,20 @@ void Surfaces::calculateEDT(Type type, float defaultResolution)
if (type == Unknown && m_dialog != nullptr)
type = m_dialog->surfaceType();

if (!m_cube)
m_cube = m_molecule->addCube();

QFuture future = QtConcurrent::run([=]() {
double probeRadius = 0.0;
switch (type) {
case VanDerWaals:
m_cube->setCubeType(Core::Cube::Type::VdW);
break;
case SolventAccessible:
m_cube->setCubeType(Core::Cube::Type::SolventAccessible);
case SolventExcluded:
probeRadius = 1.4;
m_cube->setCubeType(Core::Cube::Type::SolventExcluded);
break;
default:
break;
Expand Down Expand Up @@ -618,6 +637,9 @@ void Surfaces::calculateCube(int index, float isoValue)

// check bounds
m_cube = m_cubes[index];
if (m_cube == nullptr)
return;

if (isoValue == 0.0 && m_dialog != nullptr)
m_isoValue = m_dialog->isosurfaceValue();
else
Expand Down Expand Up @@ -764,6 +786,9 @@ void Surfaces::colorMeshByPotential()

void Surfaces::colorMesh()
{
if (m_dialog == nullptr)
return;

switch (m_dialog->colorProperty()) {
case None:
break;
Expand All @@ -784,7 +809,8 @@ void Surfaces::meshFinished()
m_molecule->emitChanged(QtGui::Molecule::Added);
movieFrame();
} else {
m_dialog->reenableCalculateButton();
if (m_dialog != nullptr)
m_dialog->reenableCalculateButton();

qDebug() << " mesh finished";

Expand Down

0 comments on commit c5e0741

Please sign in to comment.