Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix code for haptic ligands. Pick the furthest dummy to attach #1916

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions avogadro/qtplugins/templatetool/templatetool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,22 +542,44 @@ void TemplateTool::atomLeftClick(QMouseEvent*)
}

// Find dummy atom in template and get all necessary info
// for haptic ligands, we pick the dummy atom that's
// furthest from the centroid of the carbon atoms
Vector3 centroid(0.0, 0.0, 0.0);
unsigned carbonCount = 0;
for (size_t i = 0; i < templateMolecule.atomCount(); ++i) {
if (templateMolecule.atomicNumber(i) == 6) {
carbonCount++;
centroid += templateMolecule.atomPosition3d(i);
}
}
if (carbonCount > 1)
centroid = centroid / carbonCount;

size_t templateDummyIndex = 0;
std::vector<size_t> templateLigandIndices;
std::vector<size_t> templateLigandUIDs;
for (size_t i = 0; i < templateMolecule.atomCount(); i++) {
float maxDistance = 0.0;
for (size_t i = 0; i < templateMolecule.atomCount(); ++i) {
// in some ligands (e.g., haptic) we might have two dummy atoms
// so we only select the one furthest from the ligand centroid
if (templateMolecule.atomicNumber(i) == 0) {
Vector3 delta = templateMolecule.atomPosition3d(i) - centroid;
if (delta.squaredNorm() < maxDistance)
continue; // too close to the centroid

maxDistance = delta.squaredNorm();
templateDummyIndex = i;
templateLigandIndices.clear();
templateLigandUIDs.clear();
for (const auto& bond : templateMolecule.bonds(i)) {
size_t newIndex = bond.getOtherAtom(i).index();
templateLigandIndices.push_back(newIndex);
templateLigandUIDs.push_back(templateMolecule.atomUniqueId(newIndex));
}
break; // only use first dummy atom
}
}

// Find center atom in molecule and get all necessary info
// Find center atom in our current molecule and get all necessary info
// - first check to see if there is a bond
Vector3 moleculeLigandOutVector(0.0, 0.0, 0.0);
Vector3 displacement(0.0, 0.0, 0.0);
Expand Down
Loading