Skip to content

Commit

Permalink
Add option for pair interaction highlighting without info window show…
Browse files Browse the repository at this point in the history
…ing, update info label behaviour when pressing I or ctrl + right click
  • Loading branch information
peterspackman committed Sep 11, 2024
1 parent 83e2282 commit 81cad19
Show file tree
Hide file tree
Showing 20 changed files with 315 additions and 128 deletions.
1 change: 1 addition & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ add_library(cx_core
"${CMAKE_CURRENT_SOURCE_DIR}/adp.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/chemicalstructure.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/close_contact_criteria.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/colormap.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/dynamicstructure.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/element.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/elementdata.cpp"
Expand Down
62 changes: 57 additions & 5 deletions src/core/chemicalstructure.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "chemicalstructure.h"
#include "colormap.h"
#include "elementdata.h"
#include "mesh.h"
#include "object_tree_model.h"
Expand All @@ -22,7 +23,10 @@ occ::Vec3 ChemicalStructure::atomPosition(GenericAtomIndex idx) const {
return m_atomicPositions.col(i);
}

void ChemicalStructure::updateBondGraph() { guessBondsBasedOnDistances(); }
void ChemicalStructure::updateBondGraph() {
guessBondsBasedOnDistances();
setAllFragmentColors(FragmentColorSettings{});
}

void ChemicalStructure::guessBondsBasedOnDistances() {

Expand Down Expand Up @@ -645,7 +649,7 @@ void ChemicalStructure::resetAtomsAndBonds(bool toSelection) {
// TODO
}

void ChemicalStructure::setShowContacts(const ContactSettings & state) {
void ChemicalStructure::setShowContacts(const ContactSettings &state) {
// TODO
}

Expand Down Expand Up @@ -1081,9 +1085,19 @@ void ChemicalStructure::setFragmentColor(FragmentIndex fragment,
}
}

void ChemicalStructure::setAllFragmentColors(const QColor &color) {
for (auto &[fragIndex, frag] : m_fragments) {
frag.color = color;
void ChemicalStructure::setAllFragmentColors(
const FragmentColorSettings &settings) {
if (settings.method == FragmentColorSettings::Method::Constant) {
for (auto &[fragIndex, frag] : m_fragments) {
frag.color = settings.color;
}
} else if (settings.method ==
FragmentColorSettings::Method::SymmetryUniqueFragment) {
size_t nasym = m_symmetryUniqueFragments.size();
ColorMapFunc cmap(ColorMapName::Hokusai1, 0, nasym);
for (auto &[idx, frag] : m_fragments) {
frag.color = cmap(frag.asymmetricFragmentIndex.u);
}
}
emit atomsChanged();
}
Expand All @@ -1108,6 +1122,44 @@ ChemicalStructure::atomicDisplacementParametersForAtoms(
return std::vector<AtomicDisplacementParameters>(idxs.size());
}

QString ChemicalStructure::getFragmentLabel(const FragmentIndex &index) {
const auto &fragments = symmetryUniqueFragments();
if (m_fragmentLabels.size() != fragments.size()) {
ankerl::unordered_dense::map<QString, std::pair<QString, int>>
formulaToIndex;
char currentLabel = 'A';
int labelCount = 0;

for (const auto &[fragmentIndex, fragment] : fragments) {
QString formula = formulaSumForAtoms(fragment.atomIndices, false);
auto it = formulaToIndex.find(formula);

if (it == formulaToIndex.end()) {
QString label = QString(1, currentLabel);
formulaToIndex[formula] = {label, 1};
m_fragmentLabels[fragmentIndex] = "1" + label;

labelCount++;
if (labelCount == 26) {
currentLabel = 'A';
labelCount = 0;
} else {
currentLabel++;
}
} else {
auto &[label, count] = it->second;
count++;
m_fragmentLabels[fragmentIndex] = QString::number(count) + label;
}
}
}

const auto kv = m_fragmentLabels.find(index);
if (kv != m_fragmentLabels.end())
return kv->second;
return "??";
}

AtomicDisplacementParameters
ChemicalStructure::atomicDisplacementParameters(GenericAtomIndex idx) const {
return AtomicDisplacementParameters{};
Expand Down
5 changes: 4 additions & 1 deletion src/core/chemicalstructure.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ class ChemicalStructure : public QObject {

virtual occ::Mat3N convertCoordinates(const occ::Mat3N &pos, CoordinateConversion) const;

QString getFragmentLabel(const FragmentIndex &);

// colors
QColor atomColor(GenericAtomIndex atomIndex) const;
void overrideAtomColor(GenericAtomIndex, const QColor &);
Expand Down Expand Up @@ -205,7 +207,7 @@ class ChemicalStructure : public QObject {

virtual QColor getFragmentColor(FragmentIndex) const;
virtual void setFragmentColor(FragmentIndex, const QColor &);
virtual void setAllFragmentColors(const QColor &color);
virtual void setAllFragmentColors(const FragmentColorSettings &);

// dynamics data
inline bool hasFrameData() const { return frameCount() > 0; }
Expand Down Expand Up @@ -313,6 +315,7 @@ class ChemicalStructure : public QObject {

// all of these must be updated when the bondGraph is updated
FragmentMap m_fragments;
ankerl::unordered_dense::map<FragmentIndex, QString, FragmentIndexHash> m_fragmentLabels;
FragmentMap m_symmetryUniqueFragments;

std::vector<FragmentIndex> m_fragmentForAtom;
Expand Down
File renamed without changes.
File renamed without changes.
14 changes: 13 additions & 1 deletion src/core/fragment.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,24 @@
#include <QVector3D>
#include <occ/core/linear_algebra.h>

using Transform = Eigen::Isometry3d;

struct DimerAtoms {
std::vector<GenericAtomIndex> a;
std::vector<GenericAtomIndex> b;
};

using Transform = Eigen::Isometry3d;
struct FragmentColorSettings {
enum class Method {
UnitCellFragment,
SymmetryUniqueFragment,
Constant
};

Method method{Method::SymmetryUniqueFragment};
QColor color{Qt::gray};
};

struct Fragment {

struct NearestAtomResult {
Expand Down
17 changes: 14 additions & 3 deletions src/crystal/crystalstructure.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "crystalstructure.h"
#include <iostream>
#include <occ/core/kabsch.h>
#include "colormap.h"

using VertexDesc =
typename occ::core::graph::PeriodicBondGraph::VertexDescriptor;
Expand Down Expand Up @@ -154,6 +155,7 @@ void CrystalStructure::updateBondGraph() {
m_fragmentForAtom[genericIndexToIndex(idx)] = frag.index;
}
}
setAllFragmentColors(FragmentColorSettings{});
}

void CrystalStructure::resetAtomsAndBonds(bool toSelection) {
Expand Down Expand Up @@ -326,9 +328,18 @@ void CrystalStructure::setFragmentColor(FragmentIndex fragment,
}
}

void CrystalStructure::setAllFragmentColors(const QColor &color) {
for (auto &[fragIndex, frag] : m_fragments) {
frag.color = color;
void CrystalStructure::setAllFragmentColors(const FragmentColorSettings &settings) {
if(settings.method == FragmentColorSettings::Method::Constant) {
for (auto &[fragIndex, frag] : m_fragments) {
frag.color = settings.color;
}
}
else if(settings.method == FragmentColorSettings::Method::SymmetryUniqueFragment) {
size_t nasym = m_symmetryUniqueFragments.size();
ColorMapFunc cmap(ColorMapName::Hokusai1, 0, nasym);
for(auto &[idx, frag] : m_fragments) {
frag.color = cmap(frag.asymmetricFragmentIndex.u);
}
}
emit atomsChanged();
}
Expand Down
2 changes: 1 addition & 1 deletion src/crystal/crystalstructure.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class CrystalStructure : public ChemicalStructure {

QColor getFragmentColor(FragmentIndex) const override;
void setFragmentColor(FragmentIndex, const QColor &) override;
void setAllFragmentColors(const QColor &color) override;
void setAllFragmentColors(const FragmentColorSettings &) override;

Fragment::State getSymmetryUniqueFragmentState(FragmentIndex) const override;
void setSymmetryUniqueFragmentState(FragmentIndex, Fragment::State) override;
Expand Down
18 changes: 16 additions & 2 deletions src/crystalx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ void Crystalx::initConnections() {
*/
connect(glWindow, &GLWindow::resetCurrentCrystal, project,
&Project::resetCurrentCrystal);
connect(glWindow, &GLWindow::contextualFilterAtoms,
project, &Project::filterAtomsForCurrentScene);

connect(m_taskManager, &TaskManager::taskComplete, this,
&Crystalx::taskManagerTaskComplete);
Expand Down Expand Up @@ -408,6 +410,9 @@ void Crystalx::initMenuConnections() {
connect(energyFrameworksAction, &QAction::triggered, this,
&Crystalx::showEnergyFrameworkDialog);

connect(togglePairHighlightingAction, &QAction::toggled, this,
&Crystalx::togglePairInteractionHighlighting);

connect(selectAllAtomsAction, &QAction::triggered, project,
&Project::selectAllAtoms);
connect(selectsAtomsInsideCurrentSurfaceAction, &QAction::triggered, project,
Expand All @@ -420,8 +425,9 @@ void Crystalx::initMenuConnections() {
&Project::selectSuppressedAtoms);
connect(removeIncompleteFragmentsAction, &QAction::triggered, project,
&Project::removeIncompleteFragmentsForCurrentCrystal);
connect(removeSelectedAtomsAction, &QAction::triggered, project,
&Project::removeSelectedAtomsForCurrentCrystal);
connect(removeSelectedAtomsAction, &QAction::triggered,[this]() {
project->filterAtomsForCurrentScene(AtomFlag::Selected, true);
});
connect(suppressSelectedAtomsAction, &QAction::triggered, project,
&Project::suppressSelectedAtoms);
connect(unsuppressSelectedAtomsAction, &QAction::triggered, project,
Expand Down Expand Up @@ -1926,6 +1932,14 @@ void Crystalx::updateInfo(InfoType infoType) {
}
}

void Crystalx::togglePairInteractionHighlighting(bool state) {
qDebug() << "Toggle pair interaction highlighting";
Scene *scene = project->currentScene();
if(!scene) return;
scene->togglePairHighlighting(state);
glWindow->redraw();
}

void Crystalx::setInfoTabSpecificViewOptions(InfoType infoType) {
Scene *scene = project->currentScene();
Q_ASSERT(scene);
Expand Down
1 change: 1 addition & 0 deletions src/crystalx.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class Crystalx : public QMainWindow, public Ui::Crystalx {
void loadExternalFileData(QString);

public slots:
void togglePairInteractionHighlighting(bool);
void handleBusyStateChange(bool);
void generateSurface(isosurface::Parameters);
void generateSurfaceRequiringWavefunction(isosurface::Parameters, wfn::Parameters);
Expand Down
13 changes: 11 additions & 2 deletions src/crystalx.ui
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@
<addaction name="optionsMoleculeStylePopup"/>
<addaction name="enableMultipleUnitCellBoxesAction"/>
<addaction name="cycleDisorderHighlightingAction"/>
<addaction name="togglePairHighlightingAction"/>
<addaction name="separator"/>
<addaction name="selectMenu"/>
<addaction name="removeMenu"/>
Expand Down Expand Up @@ -975,10 +976,10 @@
<bool>true</bool>
</property>
<property name="text">
<string>Toggle Pair Highlighting</string>
<string>Fragment pair colouring</string>
</property>
<property name="shortcut">
<string>Ctrl+Y</string>
<string>Shift+P</string>
</property>
</action>
<action name="calculateVoidDomainsAction">
Expand Down Expand Up @@ -1127,6 +1128,14 @@
<enum>QAction::NoRole</enum>
</property>
</action>
<action name="removeUnselectedAtomsAction">
<property name="text">
<string>Remove unselected atoms</string>
</property>
<property name="toolTip">
<string>Show Only Selected Atoms</string>
</property>
</action>
</widget>
<resources>
<include location="../icons/crystalexplorer.qrc"/>
Expand Down
Loading

0 comments on commit 81cad19

Please sign in to comment.