Skip to content

Commit 0f38328

Browse files
committed
Polishing NEB analysis and adding new icons
1 parent 2033017 commit 0f38328

7 files changed

Lines changed: 330 additions & 79 deletions

File tree

assets/icon/add_fragment.png

-24.2 KB
Loading

assets/icon/expand_xy.png

-36.7 KB
Loading

assets/icon/expand_z.png

-23.4 KB
Loading

src/data/neb_calculation_loader.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,8 @@ bool NebCalculationLoader::load(const QString& root_directory, QString* error_me
7272
}
7373

7474
try {
75-
auto trajectory = structure_loader.load_outcar(outcar_path.toStdString());
76-
if(trajectory.empty()) {
77-
if(error_message) {
78-
*error_message = QObject::tr("OUTCAR in folder '%1' does not contain ionic images.")
79-
.arg(image_directories[i].fileName());
80-
}
81-
structures_.clear();
82-
return false;
83-
}
84-
85-
structures_.push_back(trajectory.back());
75+
auto final_structure = structure_loader.load_outcar_last(outcar_path.toStdString());
76+
structures_.push_back(final_structure);
8677
} catch (const std::exception& e) {
8778
if(error_message) {
8879
*error_message = QObject::tr("Failed to read OUTCAR in folder '%1': %2")

src/data/structure_loader.cpp

Lines changed: 267 additions & 61 deletions
Large diffs are not rendered by default.

src/data/structure_loader.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ class StructureLoader {
6464
*/
6565
std::vector<std::shared_ptr<Structure>> load_outcar(const std::string& filename);
6666

67+
/**
68+
* @brief Load only the final ionic structure from an OUTCAR file
69+
*
70+
* @param[in] filename The filename
71+
*
72+
* @return Last ionic structure
73+
*/
74+
std::shared_ptr<Structure> load_outcar_last(const std::string& filename);
75+
6776
/**
6877
* @brief Load structure + vibrational data from pymkmkit YAML file
6978
*

src/gui/interface_window.cpp

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
#include "interface_window.h"
2121

2222
#include <QCursor>
23+
#include <QDir>
24+
#include <QFileInfo>
25+
#include <QSettings>
2326

2427
/**
2528
* @brief Constructs the object.
@@ -55,7 +58,7 @@ InterfaceWindow::InterfaceWindow(MainWindow *mw)
5558
QVBoxLayout *editorLayout = new QVBoxLayout(editorPanel);
5659

5760
QMenuBar *editorMenuBar = new QMenuBar(editorPanel);
58-
QMenu *editorMenuFile = editorMenuBar->addMenu(tr("&File"));
61+
QMenu *editorMenuFile = editorMenuBar->addMenu(tr("&Load"));
5962
QMenu *editorMenuView = editorMenuBar->addMenu(tr("&View"));
6063
QMenu *editorMenuSelect = editorMenuBar->addMenu(tr("&Select"));
6164
editorMenuBar->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed);
@@ -243,7 +246,7 @@ InterfaceWindow::InterfaceWindow(MainWindow *mw)
243246
QMenuBar *analysisMenuBar = new QMenuBar(this);
244247
analysisMenuBar->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed);
245248
analysisMenuBar->setStyleSheet(editorMenuBar->styleSheet());
246-
QMenu *analysisMenuFile = analysisMenuBar->addMenu(tr("&File"));
249+
QMenu *analysisMenuFile = analysisMenuBar->addMenu(tr("&Load"));
247250
QMenu *analysisMenuView = analysisMenuBar->addMenu(tr("&View"));
248251

249252
QMenu *analysisMenuCamera = new QMenu(tr("Camera"), analysisMenuView);
@@ -274,7 +277,7 @@ InterfaceWindow::InterfaceWindow(MainWindow *mw)
274277
QAction *analysisActionOpen = analysisMenuFile->addAction(tr("Open"));
275278
analysisActionOpen->setShortcuts(QKeySequence::Open);
276279
QAction *analysisActionOpenNeb = analysisMenuFile->addAction(tr("Open NEB calculation"));
277-
QAction *analysisActionSendToEditor = analysisMenuFile->addAction(tr("Send to editor"));
280+
QAction *analysisActionSendToEditor = new QAction(tr("Send to editor"), this);
278281

279282
analysisActionCameraDefault->setText(tr("Default"));
280283
analysisActionCameraDefault->setData(QVariant((int)CameraAlignment::DEFAULT));
@@ -357,7 +360,24 @@ InterfaceWindow::InterfaceWindow(MainWindow *mw)
357360
analysisMenuProjectionInterlaced->addAction(analysisActionProjectionInterlacedCheckerboardLr);
358361
analysisMenuProjectionInterlaced->addAction(analysisActionProjectionInterlacedCheckerboardRl);
359362

360-
structureAnalysis->viewer()->set_header_widget(analysisMenuBar);
363+
QWidget *analysisHeaderWidget = new QWidget(this);
364+
QHBoxLayout *analysisHeaderLayout = new QHBoxLayout(analysisHeaderWidget);
365+
analysisHeaderLayout->setContentsMargins(0, 0, 0, 0);
366+
analysisHeaderLayout->setSpacing(6);
367+
QPushButton *analysisSendToEditorButton = new QPushButton(tr("Send to editor"), analysisHeaderWidget);
368+
analysisSendToEditorButton->setStyleSheet(
369+
"QPushButton { border: 1px solid #7a7a7a; border-radius: 4px; margin: 2px; padding: 3px 10px;"
370+
" background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #fbfbfb, stop:1 #d5d5d5); }"
371+
"QPushButton:hover { border: 1px solid #6f95cc;"
372+
" background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #ffffff, stop:1 #c7ddff); }"
373+
"QPushButton:pressed { border: 1px solid #6f95cc;"
374+
" background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #cfe1ff, stop:1 #ffffff); }"
375+
);
376+
analysisHeaderLayout->addWidget(analysisMenuBar, 0, Qt::AlignLeft);
377+
analysisHeaderLayout->addWidget(analysisSendToEditorButton, 0, Qt::AlignLeft);
378+
analysisHeaderLayout->addStretch();
379+
380+
structureAnalysis->viewer()->set_header_widget(analysisHeaderWidget);
361381

362382
analysis_toolbar = new ToolBarWidget(structureAnalysis->viewer(), false);
363383
analysis_toolbar->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding);
@@ -458,6 +478,7 @@ InterfaceWindow::InterfaceWindow(MainWindow *mw)
458478
connect(analysisActionOpen, &QAction::triggered, this, &InterfaceWindow::open_analysis_file);
459479
connect(analysisActionOpenNeb, &QAction::triggered, this, &InterfaceWindow::open_analysis_neb_calculation);
460480
connect(analysisActionSendToEditor, &QAction::triggered, this, &InterfaceWindow::load_structure_from_geometry_analysis);
481+
connect(analysisSendToEditorButton, &QPushButton::clicked, analysisActionSendToEditor, &QAction::trigger);
461482

462483
connect(editorActionSelectAll, SIGNAL(triggered()), this, SLOT(select_all_atoms()));
463484
connect(editorActionDeselectAll, SIGNAL(triggered()), this, SLOT(deselect_all_atoms()));
@@ -689,11 +710,19 @@ void InterfaceWindow::save_file(const QString& filename) {
689710

690711
void InterfaceWindow::open_editor_file()
691712
{
692-
QString filename = QFileDialog::getOpenFileName(this, tr("Open file"), "", tr("All supported files (*.geo *.xyz *.yaml *.yml *.vasp OUTCAR* CONTCAR* POSCAR*);;VASP files (*.vasp POSCAR* CONTCAR* OUTCAR*);;YAML frequency files (*.yaml *.yml);;ADF geometry files (*.geo);;XYZ files (*.xyz)"));
713+
QSettings settings;
714+
const QString start_dir = settings.value(
715+
"ui/lastLoadDir",
716+
QDir::homePath()
717+
).toString();
718+
719+
QString filename = QFileDialog::getOpenFileName(this, tr("Open file"), start_dir, tr("All supported files (*.geo *.xyz *.yaml *.yml *.vasp OUTCAR* CONTCAR* POSCAR*);;VASP files (*.vasp POSCAR* CONTCAR* OUTCAR*);;YAML frequency files (*.yaml *.yml);;ADF geometry files (*.geo);;XYZ files (*.xyz)"));
693720
if(filename.isEmpty()) {
694721
return;
695722
}
696723

724+
settings.setValue("ui/lastLoadDir", QFileInfo(filename).absolutePath());
725+
697726
std::shared_ptr<Structure> structure;
698727
try {
699728
structure = structure_loader.load_file(filename.toStdString());
@@ -714,27 +743,43 @@ void InterfaceWindow::open_editor_file()
714743

715744
void InterfaceWindow::open_analysis_file()
716745
{
717-
QString filename = QFileDialog::getOpenFileName(this, tr("Open file"), "", tr("Trajectory / Frequency files (OUTCAR* *.yaml *.yml);;VASP OUTCAR (OUTCAR*);;YAML frequency files (*.yaml *.yml)"));
746+
QSettings settings;
747+
const QString start_dir = settings.value(
748+
"ui/lastLoadDir",
749+
QDir::homePath()
750+
).toString();
751+
752+
QString filename = QFileDialog::getOpenFileName(this, tr("Open file"), start_dir, tr("Trajectory / Frequency files (OUTCAR* *.yaml *.yml);;VASP OUTCAR (OUTCAR*);;YAML frequency files (*.yaml *.yml)"));
718753
if(filename.isEmpty()) {
719754
return;
720755
}
721756

757+
settings.setValue("ui/lastLoadDir", QFileInfo(filename).absolutePath());
758+
722759
structureAnalysis->load_file(filename);
723760
}
724761

725762
void InterfaceWindow::open_analysis_neb_calculation()
726763
{
764+
QSettings settings;
765+
const QString start_dir = settings.value(
766+
"ui/lastLoadDir",
767+
QDir::homePath()
768+
).toString();
769+
727770
const QString folder = QFileDialog::getExistingDirectory(
728771
this,
729772
tr("Open NEB calculation"),
730-
QString(),
773+
start_dir,
731774
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks
732775
);
733776

734777
if(folder.isEmpty()) {
735778
return;
736779
}
737780

781+
settings.setValue("ui/lastLoadDir", folder);
782+
738783
NebCalculationLoader neb_loader;
739784
QString error_message;
740785
if(!neb_loader.load(folder, &error_message)) {

0 commit comments

Comments
 (0)