Skip to content

Commit fb6e8a6

Browse files
committed
Add NMR plot
Signed-off-by: Geoff Hutchison <[email protected]>
1 parent 9f512e8 commit fb6e8a6

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

avogadro/qtplugins/spectra/spectra.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ void Spectra::openDialog()
106106
}
107107

108108
gatherSpectra();
109+
// update the elements
110+
auto elements = m_molecule->atomicNumbers();
111+
std::vector<unsigned char> atomicNumbers(elements.begin(), elements.end());
112+
m_dialog->setElements(atomicNumbers);
109113
m_dialog->show();
110114
}
111115

avogadro/qtplugins/spectra/spectradialog.cpp

+15-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ float scaleAndBlur(float x, float peak, float intensity, float scale = 1.0,
3737

3838
// x is the absolute position, but we need to scale the peak position
3939
float scaled_peak = (peak - shift) / scale;
40+
4041
float delta = x - scaled_peak;
4142
float exponent = -(delta * delta) / (2 * sigma * sigma);
4243
float gaussian = exp(exponent);
@@ -136,8 +137,13 @@ void SpectraDialog::updateElementCombo()
136137
SLOT(changeSpectra()));
137138
m_ui->elementCombo->clear();
138139

140+
// go through the elements in atomic number order
141+
// make a copy of the vector
142+
std::vector<unsigned char> elements = m_elements;
143+
std::sort(elements.begin(), elements.end());
144+
139145
// add the unique elements, with the element number as the data
140-
for (auto& element : m_elements) {
146+
for (auto& element : elements) {
141147
// check to see if it's already in the combo box
142148
bool found = false;
143149
for (int i = 0; i < m_ui->elementCombo->count(); ++i) {
@@ -186,6 +192,7 @@ void SpectraDialog::updateElementCombo()
186192
// connect the element combo box
187193
connect(m_ui->elementCombo, SIGNAL(currentIndexChanged(int)), this,
188194
SLOT(changeSpectra()));
195+
changeSpectra(); // default to 1H
189196
}
190197

191198
void SpectraDialog::changeSpectra()
@@ -661,6 +668,11 @@ void SpectraDialog::updatePlot()
661668
// now compose the plot data
662669
float scale = m_ui->scaleSpinBox->value();
663670
float offset = m_ui->offsetSpinBox->value();
671+
// NMR offsets should be inverted
672+
if (type == SpectraType::NMR) {
673+
scale = -scale;
674+
}
675+
664676
float fwhm = m_ui->peakWidth->value();
665677

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

676690
float stickWidth = fwhm / (xScale * 30.0);
677691

0 commit comments

Comments
 (0)