diff --git a/qt/scientific_interfaces/General/MantidEV.cpp b/qt/scientific_interfaces/General/MantidEV.cpp index 0a02fe491a6316aa24e8c26e5e284260b4ac1ec1..0409e634d4553764075d80a3fd4874077c15f821 100644 --- a/qt/scientific_interfaces/General/MantidEV.cpp +++ b/qt/scientific_interfaces/General/MantidEV.cpp @@ -312,6 +312,9 @@ void MantidEV::initLayout() { QObject::connect(m_uiForm.SelectCellOfType_rbtn, SIGNAL(toggled(bool)), this, SLOT(setEnabledSetCellTypeParams_slot(bool))); + QObject::connect(m_uiForm.CreateHKLWorkspace_ckbx, SIGNAL(clicked(bool)), this, + SLOT(setEnabledCreateHKLWorkspaceParams_slot(bool))); + QObject::connect(m_uiForm.SelectCellWithForm_rbtn, SIGNAL(toggled(bool)), this, SLOT(setEnabledSetCellFormParams_slot(bool))); @@ -452,6 +455,7 @@ void MantidEV::setDefaultState_slot() { m_uiForm.BestCellOnly_ckbx->setChecked(true); m_uiForm.AllowPermutations_ckbx->setChecked(true); m_uiForm.SelectCellOfType_rbtn->setChecked(false); + m_uiForm.CreateHKLWorkspace_ckbx->setChecked(false); m_uiForm.CellType_cmbx->setCurrentIndex(0); m_uiForm.CellCentering_cmbx->setCurrentIndex(0); m_uiForm.SelectCellWithForm_rbtn->setChecked(false); @@ -952,6 +956,7 @@ void MantidEV::chooseCell_slot() { bool show_cells = m_uiForm.ShowPossibleCells_rbtn->isChecked(); bool select_cell_type = m_uiForm.SelectCellOfType_rbtn->isChecked(); + bool create_hkl_workspace = m_uiForm.CreateHKLWorkspace_ckbx->isChecked(); bool select_cell_form = m_uiForm.SelectCellWithForm_rbtn->isChecked(); bool allow_perm = m_uiForm.AllowPermutations_ckbx->isChecked(); @@ -998,6 +1003,20 @@ void MantidEV::chooseCell_slot() { m_uiForm.SelectEventWorkspace_ledt->text().trimmed().toStdString(); worker->copyLattice(peaks_ws_name, md_ws_name, event_ws_name); } + + if (create_hkl_workspace) { // Try to create the HKL md_workspace. + double minQ; + getDouble(m_uiForm.MinMagQ_ledt, minQ); + + double maxQ; + getDouble(m_uiForm.MaxMagQ_ledt, maxQ); + + std::string md_ws_name = + m_uiForm.MDworkspace_ledt->text().trimmed().toStdString(); + std::string ev_ws_name = + m_uiForm.SelectEventWorkspace_ledt->text().trimmed().toStdString(); + worker->convertToHKL(ev_ws_name, md_ws_name, minQ, maxQ); + } } /** @@ -2020,6 +2039,8 @@ void MantidEV::saveSettings(const std::string &filename) { m_uiForm.AllowPermutations_ckbx->isChecked()); state->setValue("SelectCellOfType_rbtn", m_uiForm.SelectCellOfType_rbtn->isChecked()); + state->setValue("CreateHKLWorkspace_ckbx", + m_uiForm.CreateHKLWorkspace_ckbx->isChecked()); state->setValue("CellType_cmbx", m_uiForm.CellType_cmbx->currentIndex()); state->setValue("CellCentering_cmbx", m_uiForm.CellCentering_cmbx->currentIndex()); @@ -2157,6 +2178,7 @@ void MantidEV::loadSettings(const std::string &filename) { restore(state, "BestCellOnly_ckbx", m_uiForm.BestCellOnly_ckbx); restore(state, "AllowPermutations_ckbx", m_uiForm.AllowPermutations_ckbx); restore(state, "SelectCellOfType_rbtn", m_uiForm.SelectCellOfType_rbtn); + restore(state, "CreateHKLWorkspace_ckbx", m_uiForm.CreateHKLWorkspace_ckbx); restore(state, "CellType_cmbx", m_uiForm.CellType_cmbx); restore(state, "CellCentering_cmbx", m_uiForm.CellCentering_cmbx); restore(state, "SelectCellWithForm_rbtn", m_uiForm.SelectCellWithForm_rbtn); diff --git a/qt/scientific_interfaces/General/MantidEV.ui b/qt/scientific_interfaces/General/MantidEV.ui index f4074ca5c2cf490283a3ff1590a9e7b9d14353f8..c8ae7ae74c628e248e5d708fd847ea70666421e5 100644 --- a/qt/scientific_interfaces/General/MantidEV.ui +++ b/qt/scientific_interfaces/General/MantidEV.ui @@ -2493,6 +2493,16 @@ </item> </layout> </item> + <item> + <widget class="QCheckBox" name="CreateHKLWorkspace_ckbx"> + <property name="toolTip"> + <string>Convert the event workspace after cell is chosen into a HKL MD Workspace.</string> + </property> + <property name="text"> + <string>Create HKL MD Workspace</string> + </property> + </widget> + </item> <item> <spacer name="verticalSpacer_4"> <property name="orientation"> diff --git a/qt/scientific_interfaces/General/MantidEVWorker.cpp b/qt/scientific_interfaces/General/MantidEVWorker.cpp index eb74d337ce8dfc81a2bcc3abcb963406a092841c..46d67b31833ccf369825c3e398ea7ff6de35d33d 100644 --- a/qt/scientific_interfaces/General/MantidEVWorker.cpp +++ b/qt/scientific_interfaces/General/MantidEVWorker.cpp @@ -247,6 +247,79 @@ bool MantidEVWorker::loadAndConvertToMD( return true; } +/** + * Take the specified EventWorkspace + * and convert it to the specified MD workspace. + * + * @param ev_ws_name Name of the event workspace to create + * @param md_ws_name Name of the MD workspace to create + * @param minQ The smallest value of any component + * of Q to include. + * @param maxQ The largest absolute value of any component + * of Q to include. When ConvertToMD is called, + * @param do_lorentz_corr Set true to do the Lorentz correction when + * converting to reciprocal space. + * + * @return true if the file was loaded and MD workspace was + * successfully created. + */ +bool MantidEVWorker::convertToHKL( + const std::string &ev_ws_name, + const std::string &md_ws_name, const double minQ, + const double maxQ) { + try { + IAlgorithm_sptr alg; + const auto &ADS = AnalysisDataService::Instance(); + Mantid::API::MatrixWorkspace_sptr ev_ws = + ADS.retrieveWS<MatrixWorkspace>(ev_ws_name); + Mantid::Geometry::OrientedLattice o_lattice = + ev_ws->mutableSample().getOrientedLattice(); + V3D h = o_lattice.hklFromQ(V3D(maxQ,0,0)); + V3D k = o_lattice.hklFromQ(V3D(0,maxQ,0)); + V3D l = o_lattice.hklFromQ(V3D(0,0,maxQ)); + + std::ostringstream min_str; + if (minQ != Mantid::EMPTY_DBL()){ + V3D minh = o_lattice.hklFromQ(V3D(minQ,0,0)); + V3D mink = o_lattice.hklFromQ(V3D(0,minQ,0)); + V3D minl = o_lattice.hklFromQ(V3D(0,0,minQ)); + min_str << minh[0] << "," << mink[1] << "," << minl[2]; + } + else { + min_str << -h[0] << "," << -k[1] << "," << -l[2]; + } + + std::ostringstream max_str; + max_str << h[0] << "," << k[1] << "," << l[2]; + + alg = AlgorithmManager::Instance().create("ConvertToMD"); + alg->setProperty("InputWorkspace", ev_ws_name); + alg->setProperty("OutputWorkspace", md_ws_name + "_HKL"); + alg->setProperty("OverwriteExisting", true); + alg->setProperty("QDimensions", "Q3D"); + alg->setProperty("dEAnalysisMode", "Elastic"); + alg->setProperty("QConversionScales", "HKL"); + alg->setProperty("Q3DFrames", "HKL"); + alg->setProperty("LorentzCorrection", true); + alg->setProperty("MinValues", min_str.str()); + alg->setProperty("MaxValues", max_str.str()); + alg->setProperty("SplitInto", "2"); + alg->setProperty("SplitThreshold", "50"); + alg->setProperty("MaxRecursionDepth", "13"); + alg->setProperty("MinRecursionDepth", "7"); + + if (!alg->execute()) + return false; + } catch (std::exception &e) { + g_log.error() << "Error:" << e.what() << '\n'; + return false; + } catch (...) { + g_log.error() << "Error: Could Not load file and convert to MD\n"; + return false; + } + return true; +} + /** * Find peaks in the specified MD workspace and save them in the * specified peaks workspace. diff --git a/qt/scientific_interfaces/General/MantidEVWorker.h b/qt/scientific_interfaces/General/MantidEVWorker.h index a820b0a9384ad8841974a278959f7dac5ad8e951..e108fe73bb5484d6563ee8d41ae1b7d6d28528fa 100644 --- a/qt/scientific_interfaces/General/MantidEVWorker.h +++ b/qt/scientific_interfaces/General/MantidEVWorker.h @@ -53,6 +53,9 @@ public: const bool load_det_cal, const std::string &det_cal_file, const std::string &det_cal_file2); + bool convertToHKL(const std::string &ev_ws_name, + const std::string &md_ws_name, const double minQ, + const double maxQ); /// Find peaks in MD workspace and set peaks into peaks workspace bool findPeaks(const std::string &ev_ws_name, const std::string &md_ws_name,