Skip to content

Commit

Permalink
Fix segfaults in Surfaces and Select Backbone (#1031)
Browse files Browse the repository at this point in the history
* Fix a couple segfault issues

Signed-off-by: Aritz Erkiaga <aerkiaga3@gmail.com>
  • Loading branch information
aerkiaga authored Jul 19, 2022
1 parent b6c230c commit 673c985
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 26 deletions.
38 changes: 14 additions & 24 deletions avogadro/qtplugins/select/select.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,30 +247,20 @@ void Select::selectBackboneAtoms()
selectNone();

for (const auto residue : m_molecule->residues()) {
auto atom = residue.getAtomByName("CA");
if (atom.isValid())
atom.setSelected(evalSelect(true, atom.index()));

atom = residue.getAtomByName("C");
if (atom.isValid())
atom.setSelected(evalSelect(true, atom.index()));

atom = residue.getAtomByName("N");
if (atom.isValid())
atom.setSelected(evalSelect(true, atom.index()));

atom = residue.getAtomByName("O");
if (atom.isValid())
atom.setSelected(evalSelect(true, atom.index()));

// also select hydrogens connected to the backbone atoms
if (atom.atomicNumber() == 1) {
auto bonds = m_molecule->bonds(atom.index());
if (bonds.size() == 1) {
auto otherAtom = bonds[0].getOtherAtom(atom.index());
auto name = residue.getAtomName(otherAtom);
if (name == "CA" || name == "C" || name == "N" || name == "O")
atom.setSelected(evalSelect(true, atom.index()));
for (auto atom : residue.residueAtoms()) {
auto name = residue.getAtomName(atom);
if (name == "CA" || name == "C" || name == "N" || name == "O")
atom.setSelected(evalSelect(true, atom.index()));

// also select hydrogens connected to the backbone atoms
if (atom.atomicNumber() == 1) {
auto bonds = m_molecule->bonds(atom.index());
if (bonds.size() == 1) {
auto otherAtom = bonds[0].getOtherAtom(atom.index());
auto otherName = residue.getAtomName(otherAtom);
if (otherName == "CA" || otherName == "C" || otherName == "N" || otherName == "O")
atom.setSelected(evalSelect(true, atom.index()));
}
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions avogadro/qtplugins/surfaces/surfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,7 @@ void Surfaces::calculateEDT()

// first, make a list of all atom positions and radii
Array<Vector3> atomPositions = m_molecule->atomPositions3d();
auto *atoms =
new std::vector<std::pair<Vector3, double>>(m_molecule->atomCount());
auto *atoms = new std::vector<std::pair<Vector3, double>>();
double max_radius = probeRadius;
QtGui::RWLayerManager layerManager;
for (size_t i = 0; i < m_molecule->atomCount(); i++) {
Expand Down

0 comments on commit 673c985

Please sign in to comment.