Skip to content

Commit 0cfae90

Browse files
andyclaude
andcommitted
MO coefficients: MOPAC's Slater basis; a failure shows a message
View Coefficients threw "basis set is null" for a MOPAC calculation, which writes no Gaussian basis set; on Windows that reached the unhandled-exception box and left an empty dialog behind. The dialog now uses the basis implied by the Slater exponents, as MoPanel and MoAoBasis already do, ends its grid batch and frees the basis on a throw, and the panel shows the dialog only after it is filled, with a message instead when filling fails. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BTQ7mniRtDdhU7VF9tEVBD
1 parent 8596939 commit 0cfae90

2 files changed

Lines changed: 28 additions & 16 deletions

File tree

‎src/apps/builder/MoCoeffs.C‎

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "dsm/IPropCalculation.H"
2828
#include "dsm/ICalculation.H"
2929
#include "dsm/PropFactory.H"
30+
#include "dsm/ICalcUtils.H"
3031

3132
#include "inv/ChemKit/ChemColor.H"
3233

@@ -160,7 +161,12 @@ void MoCoeffs::showCoeffs(ICalculation *expt, int moNum,
160161
{
161162
SetTitle( wxString::Format (_T("ECCE MO Coefficients: %d"), moNum));
162163

163-
p_grid->BeginBatch();
164+
// Ends the batch on a throw too, or the grid never repaints.
165+
struct BatchGuard {
166+
wxGrid *g;
167+
explicit BatchGuard(wxGrid *grid) : g(grid) { g->BeginBatch(); }
168+
~BatchGuard() { g->EndBatch(); }
169+
} batch(p_grid);
164170

165171
// Clear table
166172
p_grid->DeleteRows(0,p_grid->GetNumberRows());
@@ -180,8 +186,14 @@ void MoCoeffs::showCoeffs(ICalculation *expt, int moNum,
180186

181187
Fragment frag;
182188
expt->getFragment(frag);
183-
TGBSConfig *gbsConfig = expt->gbsConfig();
189+
std::unique_ptr<TGBSConfig> gbsOwned(expt->gbsConfig());
190+
// A semiempirical code (MOPAC) writes no basis set; use the one its
191+
// Slater exponents imply, as MoPanel and MoAoBasis do.
192+
if (!gbsOwned || gbsOwned->empty())
193+
gbsOwned.reset(ICalcUtils::slaterBasisConfig(expt));
194+
TGBSConfig *gbsConfig = gbsOwned.get();
184195
INTERNALEXCEPTION(gbsConfig,"basis set is null.");
196+
INTERNALEXCEPTION(moCoefs,"MO coefficients are missing.");
185197

186198
// MOAOORDER-marked calcs (currently ORCA) store MO with columns in
187199
// the PARSER's canonical order, not TGBSConfig's own -- see
@@ -418,17 +430,8 @@ void MoCoeffs::showCoeffs(ICalculation *expt, int moNum,
418430
wxString::Format("%.2f", 100.0*(*percent)[r]));
419431
}
420432

421-
p_grid->EndBatch();
422-
423-
424433
p_grid->AutoSizeColumns();
425434
GetSizer()->Fit(this);
426-
427-
// gbsConfig() returns a NEW TGBSConfig this function owns (a
428-
// pre-existing leak here, same shape MoDiagramPanel.C's other
429-
// gbsConfig() call sites already guard against with "delete
430-
// config" -- fixed while adding a second consumer of it above).
431-
delete gbsConfig;
432435
}
433436

434437

‎src/apps/builder/MoPanel.C‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using std::make_pair;
99

1010
#include <wx/link.h>
11+
#include <wx/msgdlg.h>
1112
#include <wx/stopwatch.h>
1213
#include <wx/settings.h>
1314
#include <wx/textctrl.h>
@@ -1001,8 +1002,7 @@ void MoPanel::showCoeffs(bool force)
10011002
if (p_coeffsDlg == 0) {
10021003
p_coeffsDlg = new MoCoeffs(this);
10031004
}
1004-
if (force) p_coeffsDlg->Show();
1005-
if (p_coeffsDlg->IsShownOnScreen()) {
1005+
if (force || p_coeffsDlg->IsShownOnScreen()) {
10061006
// The per-function percentages are the alpha ones; the dialog
10071007
// itself only reads the alpha coefficients.
10081008
MoAoBasis::Composition comp;
@@ -1012,9 +1012,18 @@ void MoPanel::showCoeffs(bool force)
10121012
mo <= (int)p_aoRows[0].size() &&
10131013
p_aoBasis->analyse(p_aoRows[0][mo-1], MoAoBasis::MULLIKEN, comp))
10141014
shown = &comp;
1015-
p_coeffsDlg->showCoeffs(
1016-
dynamic_cast<ICalculation*>(getCalculation()), mo,
1017-
shown ? &comp.perFunction : 0);
1015+
try {
1016+
p_coeffsDlg->showCoeffs(
1017+
dynamic_cast<ICalculation*>(getCalculation()), mo,
1018+
shown ? &comp.perFunction : 0);
1019+
} catch (const std::exception& ex) {
1020+
p_coeffsDlg->Hide();
1021+
wxMessageBox(wxString::Format("The coefficients of this orbital "
1022+
"cannot be shown: %s", ex.what()),
1023+
"ECCE MO Coefficients", wxOK | wxICON_WARNING, this);
1024+
return;
1025+
}
1026+
if (force) p_coeffsDlg->Show();
10181027
}
10191028
}
10201029

0 commit comments

Comments
 (0)