Skip to content

Commit

Permalink
Estimate bond distances in template tool (#1099)
Browse files Browse the repository at this point in the history
* Estimate bond distances for all ligands

Signed-off-by: Aritz Erkiaga <aerkiaga3@gmail.com>
  • Loading branch information
aerkiaga authored Aug 16, 2022
1 parent cc691a9 commit 020d117
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions avogadro/qtplugins/templatetool/templatetool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,25 @@ void TemplateTool::atomLeftClick(QMouseEvent *e)
moleculeLigandOutVector += newPos - m_molecule->atomPosition3d(moleculeCenterIndex);
}

// Estimate and try to realize bond distances
Vector3 displacement(0.0, 0.0, 0.0);
for (size_t i = 0; i < templateLigandIndices.size(); i++) {
unsigned char ligandAtomicNumber = templateMolecule.atomicNumber(templateLigandIndices[i]);
ligandAtomicNumber = (ligandAtomicNumber == 0)? 6 : ligandAtomicNumber;
// Estimate as the sum of covalent radii
double bondDistance = Elements::radiusCovalent(ligandAtomicNumber)
+ Elements::radiusCovalent(m_molecule->atomicNumber(moleculeCenterIndex));
Vector3 inVector = templateMolecule.atomPosition3d(templateDummyIndex)
- templateMolecule.atomPosition3d(templateLigandIndices[i]);
Vector3 correctionVector = inVector;
correctionVector.normalize();
correctionVector *= bondDistance - inVector.norm();
displacement += correctionVector;
}
displacement *= 1.0 / templateLigandIndices.size();
Vector3 newPos = templateMolecule.atomPosition3d(templateDummyIndex) + displacement;
templateMolecule.setAtomPosition3d(templateDummyIndex, newPos);

// Translate template so dummy atom is brought to center atom
for (size_t i = 0; i < templateMolecule.atomCount(); i++) {
if (i != templateDummyIndex) {
Expand Down

0 comments on commit 020d117

Please sign in to comment.