Skip to content

Commit

Permalink
Add NMR plot
Browse files Browse the repository at this point in the history
Signed-off-by: Geoff Hutchison <[email protected]>
  • Loading branch information
ghutchis committed Dec 20, 2024
1 parent 9f512e8 commit fb6e8a6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 4 additions & 0 deletions avogadro/qtplugins/spectra/spectra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ void Spectra::openDialog()
}

gatherSpectra();
// update the elements
auto elements = m_molecule->atomicNumbers();
std::vector<unsigned char> atomicNumbers(elements.begin(), elements.end());
m_dialog->setElements(atomicNumbers);
m_dialog->show();
}

Expand Down
16 changes: 15 additions & 1 deletion avogadro/qtplugins/spectra/spectradialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ float scaleAndBlur(float x, float peak, float intensity, float scale = 1.0,

// x is the absolute position, but we need to scale the peak position
float scaled_peak = (peak - shift) / scale;

float delta = x - scaled_peak;
float exponent = -(delta * delta) / (2 * sigma * sigma);
float gaussian = exp(exponent);
Expand Down Expand Up @@ -136,8 +137,13 @@ void SpectraDialog::updateElementCombo()
SLOT(changeSpectra()));
m_ui->elementCombo->clear();

// go through the elements in atomic number order
// make a copy of the vector
std::vector<unsigned char> elements = m_elements;
std::sort(elements.begin(), elements.end());

// add the unique elements, with the element number as the data
for (auto& element : m_elements) {
for (auto& element : elements) {
// check to see if it's already in the combo box
bool found = false;
for (int i = 0; i < m_ui->elementCombo->count(); ++i) {
Expand Down Expand Up @@ -186,6 +192,7 @@ void SpectraDialog::updateElementCombo()
// connect the element combo box
connect(m_ui->elementCombo, SIGNAL(currentIndexChanged(int)), this,
SLOT(changeSpectra()));
changeSpectra(); // default to 1H
}

void SpectraDialog::changeSpectra()
Expand Down Expand Up @@ -661,6 +668,11 @@ void SpectraDialog::updatePlot()
// now compose the plot data
float scale = m_ui->scaleSpinBox->value();
float offset = m_ui->offsetSpinBox->value();
// NMR offsets should be inverted
if (type == SpectraType::NMR) {
scale = -scale;
}

float fwhm = m_ui->peakWidth->value();

float xMin = m_ui->xAxisMinimum->value();
Expand All @@ -672,6 +684,8 @@ void SpectraDialog::updatePlot()
float xScale = 1.0;
if (type == SpectraType::Electronic || type == SpectraType::CircularDichroism)
xScale = 1.0f / 0.05f;
else if (type == SpectraType::NMR)
xScale = 1.0f / 0.01f;

float stickWidth = fwhm / (xScale * 30.0);

Expand Down

0 comments on commit fb6e8a6

Please sign in to comment.