void Nmr::updatePlot() { m_plot->clearGraphs(); QList<double> data; QString isotope(currentIsotope()); if (isotope.isEmpty()) { data = m_data.shieldings(); m_plot->xAxis->setLabel("Nuclear Shielding (ppm)"); }else { data = computeShifts(currentReference(), isotope); m_plot->xAxis->setLabel("Chemical Shift (ppm)"); } if (m_ui->impulseButton->isChecked()) { // the range is really determining the resolution here plotImpulse(data, standardRange(isotope)); }else if (m_ui->lorentzianButton->isChecked()) { // There has to be an easier way double min(m_plot->xAxis->pixelToCoord(m_plot->axisRect()->right())); double max(m_plot->xAxis->pixelToCoord(m_plot->axisRect()->left())); plotSpectrum(data, qMakePair(min, max)); } m_plot->replot(); }
void Nmr::on_isotopeCombo_currentIndexChanged(QString const& text) { QString isotope(currentIsotope(text)); Data::NmrReferenceLibrary& library(Data::NmrReferenceLibrary::instance()); QList<Data::NmrReference const*> refs(library.filter(isotope)); QStringList systems; QList<Data::NmrReference const*>::iterator iter; for (iter = refs.begin(); iter != refs.end(); ++iter) { QString system((*iter)->system()); if (!systems.contains(system)) systems.append(system); } QComboBox* combo(m_ui->systemCombo); combo->clear(); combo->addItems(systems); loadShifts(currentReference(), isotope); QPair<double, double> range(standardRange(isotope)); m_plot->xAxis->setRange(range.first, range.second); updatePlot(); }
Data::NmrReference const* Nmr::currentReference() { Data::NmrReference const* reference; QString isotope(currentIsotope()); QString system(m_ui->systemCombo->currentText()); QString method(m_ui->methodCombo->currentText()); Data::NmrReferenceLibrary& library(Data::NmrReferenceLibrary::instance()); QList<Data::NmrReference const*> refs(library.filter(isotope, system, method)); if (refs.size() == 1) { reference = refs.first(); //qDebug() << "Found reference:"; //reference->dump(); }else { reference = 0; //qDebug() << "No reference found for" << isotope << system << method; } return reference; }
void Nmr::on_systemCombo_currentIndexChanged(QString const& text) { QString isotope(currentIsotope()); Data::NmrReferenceLibrary& library(Data::NmrReferenceLibrary::instance()); QString method(m_data.method()); QList<Data::NmrReference const*> refs(library.filter(isotope, text, method)); QStringList methods; QList<Data::NmrReference const*>::iterator iter; for (iter = refs.begin(); iter != refs.end(); ++iter) { method = (*iter)->method(); if (!methods.contains(method)) methods.append(method); } QComboBox* combo(m_ui->methodCombo); combo->clear(); combo->addItems(methods); loadShifts(currentReference(), isotope); updatePlot(); }
int DripLine::createFile(const std::string& file) const noexcept { std::ifstream modelFile(FRDM_file, std::ios::binary); if (!modelFile) { std::cerr << "\n" << "***ERROR***: " << FRDM_file << " couldn't be opened, does it exist?" << "\n" << std::endl; return 1; } std::ofstream dripFile(file, std::ios::binary); if (!dripFile) { std::cerr << "\n" << "***ERROR***: " << file << " couldn't be opened to write to" << "\n" << std::endl; return 2; } dripFile << "# N Z drip[MeV]\n" << "#------------------" << std::endl; dripFile.precision(4); // Starting values come from the FRLDM file int currentSingleProton = 7; int currentSingleNeutron = 7; int previousSingleNeutron = 8; int previousSingleProton = 0; int currentDoubleProton = 7; int currentDoubleNeutron = 7; int previousDoubleNeutron = 8; int previousDoubleProton = 0; int nucleonWidth = 4; int dripWidth = 8; // Rather than use a vector of Nuclide(216), create a new // smaller(56) struct to store the required values and // create a vector of these. struct isotope { int A = 0; int Z = 0; int N = 0; double s_n = 0.0; double s_2n = 0.0; double s_p = 0.0; double s_2p = 0.0; double ME = 0.0; }; std::vector<isotope> dripNuc; std::string dataline; while (std::getline(modelFile, dataline)) { if (dataline.empty() || dataline.at(0) == '#') { continue; } std::istringstream dripData(dataline); std::string dummy; dripNuc.emplace_back(isotope()); auto currentIsotope = std::rbegin(dripNuc); dripData >> currentIsotope->A >> currentIsotope->Z >> dummy >> currentIsotope->ME; currentIsotope->N = currentIsotope->A - currentIsotope->Z; // File is ordered in Z then A, by looping through backwards, // we do not need to traverse the entire contents as we can stop // once values get too far apart to provide data. for (auto otherIsotope = currentIsotope; otherIsotope != std::rend(dripNuc); ++otherIsotope) { // Depending on the drip line, we can break when differences // in N or Z get too larger i.e. 2 for single particle and // 3 for double particle lines. if ((the_line == LineType::singleneutron && currentIsotope->N - otherIsotope->N >= 2) || (the_line == LineType::doubleneutron && currentIsotope->N - otherIsotope->N >= 3) || (the_line == LineType::singleproton && currentIsotope->Z - otherIsotope->Z >= 2) || (the_line == LineType::doubleproton && currentIsotope->Z - otherIsotope->Z >= 3)) { break; } if (currentIsotope->A - otherIsotope->A == 1) { // S(n) = M(Z,N-1) - M(Z,N) + M(0,1) if (the_line == LineType::singleneutron && otherIsotope->Z == currentIsotope->Z && currentSingleProton < currentIsotope->Z) { currentIsotope->s_n = otherIsotope->ME - currentIsotope->ME + neutron_mass; if (currentIsotope->s_n < 0.0) { dripFile << std::fixed << std::setw(nucleonWidth) << currentIsotope->N << " " << std::setw(nucleonWidth) << currentIsotope->Z << " " << std::setw(dripWidth) << currentIsotope->s_n << "\n" << std::setw(nucleonWidth) << currentIsotope->N << " " << std::setw(nucleonWidth) << currentIsotope->Z + 1 << " " << std::setw(dripWidth) << currentIsotope->s_n << std::endl; ++currentSingleProton; } } // S(p) = M(Z-1,N) - M(Z,N) + M(1,0) if (the_line == LineType::singleproton && otherIsotope->N == currentIsotope->N && currentSingleNeutron < currentIsotope->N) { currentIsotope->s_p = otherIsotope->ME - currentIsotope->ME + proton_mass; if (currentIsotope->s_p < 0.0) { if (currentIsotope->N != previousSingleNeutron) { dripFile << std::fixed << std::setw(nucleonWidth) << previousSingleNeutron + 1 << " " << std::setw(nucleonWidth) << previousSingleProton << " " << std::setw(dripWidth) << currentIsotope->s_p << std::endl; } dripFile << std::fixed << std::setw(nucleonWidth) << currentIsotope->N << " " << std::setw(nucleonWidth) << currentIsotope->Z << " " << std::setw(dripWidth) << currentIsotope->s_p << std::endl; ++currentSingleNeutron; previousSingleProton = currentIsotope->Z; previousSingleNeutron = currentIsotope->N; } } } else if (currentIsotope->A - otherIsotope->A == 2) { // S(2n) = M(Z,N-2) - M(Z,N) + 2*M(0,1) if (the_line == LineType::doubleneutron && otherIsotope->Z == currentIsotope->Z && currentDoubleProton < currentIsotope->Z) { currentIsotope->s_2n = otherIsotope->ME - currentIsotope->ME + 2.0 * neutron_mass; if (currentIsotope->s_2n < 0.0) { dripFile << std::fixed << std::setw(nucleonWidth) << currentIsotope->N << " " << std::setw(nucleonWidth) << currentIsotope->Z << " " << std::setw(dripWidth) << currentIsotope->s_2n << "\n" << std::setw(nucleonWidth) << currentIsotope->N << " " << std::setw(nucleonWidth) << currentIsotope->Z + 1 << " " << std::setw(dripWidth) << currentIsotope->s_2n << std::endl; ++currentDoubleProton; } } // S(2p) = M(Z-2,N) - M(Z,N) + 2*M(1,0) if (the_line == LineType::doubleproton && otherIsotope->N == currentIsotope->N && currentDoubleNeutron < currentIsotope->N) { currentIsotope->s_2p = otherIsotope->ME - currentIsotope->ME + 2.0 * proton_mass; if (currentIsotope->s_2p < 0.0) { if (currentIsotope->N != previousDoubleNeutron) { dripFile << std::fixed << std::setw(nucleonWidth) << previousDoubleNeutron + 1 << " " << std::setw(nucleonWidth) << previousDoubleProton << " " << std::setw(dripWidth) << currentIsotope->s_2p << std::endl; } dripFile << std::fixed << std::setw(nucleonWidth) << currentIsotope->N << " " << std::setw(nucleonWidth) << currentIsotope->Z << " " << std::setw(dripWidth) << currentIsotope->s_2p << std::endl; ++currentDoubleNeutron; previousDoubleProton = currentIsotope->Z; previousDoubleNeutron = currentIsotope->N; } } } } } modelFile.close(); dripFile.close(); return 0; }