Skip to content

Commit

Permalink
Improve bond symmetry detection, fixup labels for surface clones, fix…
Browse files Browse the repository at this point in the history
… masking of surface for fingerprint plots
  • Loading branch information
peterspackman committed Jan 14, 2025
1 parent 02b008d commit 6a26513
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 56 deletions.
2 changes: 1 addition & 1 deletion src/childpropertycontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void ChildPropertyController::setup() {
connect(modelComboBox, &QComboBox::currentIndexChanged,
[this]() { updatePairInteractionComponents(); });

connect(frameworkTubeSizeSpinBox, &QSpinBox::valueChanged,
connect(frameworkTubeSizeSpinBox, &QDoubleSpinBox::valueChanged,
[this]() { emitFrameworkOptions(); });

connect(frameworkCutoffSpinBox, &QDoubleSpinBox::valueChanged,
Expand Down
25 changes: 8 additions & 17 deletions src/childpropertycontroller.ui
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<string/>
</property>
<property name="currentIndex">
<number>0</number>
<number>4</number>
</property>
<widget class="QWidget" name="surfaceOptionsTab">
<property name="sizePolicy">
Expand Down Expand Up @@ -858,22 +858,6 @@
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QSpinBox" name="frameworkTubeSizeSpinBox">
<property name="suffix">
<string> Å mol / J</string>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>1000</number>
</property>
<property name="value">
<number>10</number>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="frameworkTubeSizeLabel">
<property name="text">
Expand Down Expand Up @@ -961,6 +945,13 @@
<item row="5" column="1">
<widget class="QComboBox" name="frameworkLabelDisplayComboBox"/>
</item>
<item row="3" column="1">
<widget class="QDoubleSpinBox" name="frameworkTubeSizeSpinBox">
<property name="value">
<double>10.000000000000000</double>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down
22 changes: 19 additions & 3 deletions src/core/chemicalstructure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ void ChemicalStructure::guessBondsBasedOnDistances() {
};

for (const auto &[k, v] : m_bondOverrides) {
if(v != BondMethod::Bond) continue;
if (v != BondMethod::Bond)
continue;
size_t l = genericIndexToIndex(k.a);
size_t r = genericIndexToIndex(k.b);
double d = (m_atomicPositions.col(r) - m_atomicPositions.col(l)).norm();
Expand Down Expand Up @@ -150,8 +151,6 @@ void ChemicalStructure::guessBondsBasedOnDistances() {
results.clear();
}



m_bondsNeedUpdate = false;
m_fragments.clear();
m_symmetryUniqueFragments.clear();
Expand Down Expand Up @@ -909,6 +908,23 @@ ChemicalStructure::getAtomIndicesUnderTransformation(
return result;
}

QString ChemicalStructure::getTransformationString(
const Eigen::Isometry3d &transform) const {

Eigen::AngleAxisd aa(transform.rotation());
const auto &axis = aa.axis();
float angle = aa.angle();
const auto &t = transform.translation();

std::string desc{""};
if (angle > 1e-3)
desc += fmt::format(" Rot {:.3f}° @ [{:.3f},{:.3f},{:.3f}]",
angle * 180 / M_PI, axis(0), axis(1), axis(2));
desc += fmt::format(" + [{:.3f},{:.3f},{:.3f}]", t(0), t(1), t(2));

return QString::fromStdString(desc);
}

bool ChemicalStructure::getTransformation(
const std::vector<GenericAtomIndex> &from_orig,
const std::vector<GenericAtomIndex> &to_orig,
Expand Down
3 changes: 3 additions & 0 deletions src/core/chemicalstructure.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ class ChemicalStructure : public QObject {
const std::vector<GenericAtomIndex> &to,
Eigen::Isometry3d &result) const;

virtual QString
getTransformationString(const Eigen::Isometry3d &) const;

virtual std::vector<GenericAtomIndex>
getAtomIndicesUnderTransformation(const std::vector<GenericAtomIndex> &idxs,
const Eigen::Isometry3d &result) const;
Expand Down
27 changes: 10 additions & 17 deletions src/core/meshinstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ void MeshInstance::setTransparent(bool transparent) {
emit transparencyChanged();
}

void MeshInstance::setTransparency(float transparency)
{
void MeshInstance::setTransparency(float transparency) {
if (transparency == m_transparency)
return;
m_transparency = transparency;
Expand Down Expand Up @@ -156,18 +155,11 @@ MeshInstance *MeshInstance::newInstanceFromSelectedAtoms(
return nullptr;
if (mesh->haveChildMatchingTransform(transform))
return nullptr;
Eigen::AngleAxisd aa(transform.rotation());
auto instance = new MeshInstance(mesh, transform);
const auto &axis = aa.axis();
float angle = aa.angle();
const auto &t = transform.translation();
std::string desc{""};
if (angle > 1e-3)
desc += fmt::format(" Rot {:.3f}° @ [{:.3f},{:.3f},{:.3f}]",
angle * 180 / M_PI, axis(0), axis(1), axis(2));
desc += fmt::format(" + [{:.3f},{:.3f},{:.3f}]", t(0), t(1), t(2));

instance->setObjectName(QString::fromStdString(desc));
auto fragment = structure->makeFragment(atoms);
QString fragmentLabel = fragment.name;

instance->setObjectName(fragmentLabel);
return instance;
}

Expand Down Expand Up @@ -231,13 +223,14 @@ MeshInstance::nearestPoint(const MeshInstance *other) const {
return result;
}


void MeshInstance::populateSurroundingAtoms() {
ChemicalStructure *structure =
qobject_cast<ChemicalStructure *>(m_mesh->parent());
if(structure) {
m_atomsInside = structure->getAtomIndicesUnderTransformation(m_mesh->atomsInside(), m_transform);
m_atomsOutside = structure->getAtomIndicesUnderTransformation(m_mesh->atomsOutside(), m_transform);
if (structure) {
m_atomsInside = structure->getAtomIndicesUnderTransformation(
m_mesh->atomsInside(), m_transform);
m_atomsOutside = structure->getAtomIndicesUnderTransformation(
m_mesh->atomsOutside(), m_transform);
qDebug() << "m_atomsOutside" << m_atomsOutside.size();
}
}
2 changes: 1 addition & 1 deletion src/crystal/crystalstructure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,7 @@ Fragment CrystalStructure::makeFragment(
result.asymmetricFragmentTransform *= t;
result.name = ucFrag.name;
if (result.index != ucIndex) {
result.name = result.name.left(result.name.lastIndexOf(' ')) +
result.name = result.name.left(result.name.lastIndexOf(' ')) + " " +
getTransformationString(result.asymmetricFragmentTransform);
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/crystal/crystalstructure.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class CrystalStructure : public ChemicalStructure {
atomicDisplacementParameters(GenericAtomIndex) const override;

[[nodiscard]] QString
getTransformationString(const Eigen::Isometry3d &result) const;
getTransformationString(const Eigen::Isometry3d &) const override;

[[nodiscard]] nlohmann::json toJson() const override;
bool fromJson(const nlohmann::json &) override;
Expand Down
2 changes: 1 addition & 1 deletion src/graphics/meshinstancerenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ void MeshInstanceRenderer::setMesh(Mesh *mesh) {
for (size_t i = 0; i < vals.rows(); i++) {
QColor color = cmap(vals(i));
int sign = vertexMask(i) ? 1 : -1;
propertyData.push_back(sign * color.redF());
propertyData.push_back(sign * (color.redF() + 0.000001f));
propertyData.push_back(color.greenF());
propertyData.push_back(color.blueF());
propertyData.push_back(color.alphaF());
Expand Down
27 changes: 12 additions & 15 deletions src/occ/crystal/dimer_mapping_table.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <occ/core/kdtree.h>
#include <occ/crystal/crystal.h>
#include <occ/crystal/dimer_mapping_table.h>

Expand Down Expand Up @@ -188,24 +189,19 @@ DimerMappingTable::create_atomic_pair_table(const Crystal &crystal,
const auto &vdw_radii = crystal.asymmetric_unit().vdw_radii();
double max_vdw = vdw_radii.maxCoeff();
double max_dist = (max_vdw * 2 + 0.6) * (max_vdw * 2 + 0.6);
occ::core::KDTree<double> tree(s.cart_pos.rows(), s.cart_pos,
occ::core::max_leaf);
tree.index->buildIndex();

core::KdResultSet idxs_dists;
core::KdRadiusResultSet results(max_dist, idxs_dists);

// For each atom in the unit cell
for (int i = 0; i < uc_atoms.size(); i++) {
Vec3 pos_i = uc_atoms.frac_pos.col(i);
Vec3 cart_pos_i = uc_atoms.cart_pos.col(i);

// Look through expanded slab for possible bonds
for (int j = 0; j < s.frac_pos.cols(); j++) {
if (j % uc_atoms.size() <= i)
continue; // avoid duplicates
// Then in the pair loop:
Vec3 cart_pos_j = s.cart_pos.col(j);
Vec3 pos_diff = cart_pos_j - cart_pos_i;
if (pos_diff.squaredNorm() > max_dist)
continue; // Skip pairs too far apart

const double *q = s.cart_pos.col(i).data();
tree.index->findNeighbors(results, q, nanoflann::SearchParams());
for (const auto &[j, dist2] : results.m_indices_dists) {
Vec3 pos_j = s.frac_pos.col(j);

int uc_idx_j = s.uc_idx(j);
HKL cell_offset{s.hkl(0, j), s.hkl(1, j), s.hkl(2, j)};

Expand Down Expand Up @@ -245,9 +241,10 @@ DimerMappingTable::create_atomic_pair_table(const Crystal &crystal,
table.m_symmetry_unique_dimer_map[norm_ab] =
table.m_symmetry_unique_dimer_map[canonical_ab];
}

results.clear();
}

// Populate unique dimers as before
for (const auto &dimer : table.m_unique_dimers) {
if (table.m_symmetry_unique_dimer_map[dimer] == dimer) {
table.m_symmetry_unique_dimers.push_back(dimer);
Expand Down

0 comments on commit 6a26513

Please sign in to comment.