Skip to content

Commit

Permalink
Merge pull request cryos#93 from psavery/symmetrize-add-undo
Browse files Browse the repository at this point in the history
Added undo commands for symmetrizing cells.
  • Loading branch information
cryos authored Jul 11, 2016
2 parents d87479c + e2ee858 commit 99dc812
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
21 changes: 21 additions & 0 deletions avogadro/qtgui/rwmolecule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1208,6 +1208,27 @@ bool RWMolecule::conventionalizeCell(double cartTol)
return true;
}

bool RWMolecule::symmetrizeCell(double cartTol)
{
// If there is no unit cell, there is nothing to do
if (!m_molecule.unitCell())
return false;

// Make a copy of the molecule to edit so we can store the old one
// The unit cell, atom positions, and numbers of atoms may all change
Molecule newMolecule = m_molecule;

if (!Core::AvoSpglib::symmetrize(newMolecule, cartTol))
return false;

Molecule::MoleculeChanges changes = Molecule::UnitCell | Molecule::Atoms |
Molecule::Added;
QString undoText = tr("Symmetrize Cell");

modifyMolecule(newMolecule, changes, undoText);
return true;
}

void RWMolecule::emitChanged(unsigned int change)
{
m_molecule.emitChanged(change);
Expand Down
7 changes: 7 additions & 0 deletions avogadro/qtgui/rwmolecule.h
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,13 @@ class AVOGADROQTGUI_EXPORT RWMolecule : public QObject
*/
bool conventionalizeCell(double cartTol = 1e-5);

/**
* Use spglib to symmetrize the cell. Changes are emitted.
* @param cartTol Cartesian tolerance for symmetrization.
* @return True if the algorithm succeeded, and false if it failed.
*/
bool symmetrizeCell(double cartTol = 1e-5);

/**
* @brief Begin or end an interactive edit.
*
Expand Down
6 changes: 1 addition & 5 deletions avogadro/qtplugins/spacegroup/spacegroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ void SpaceGroup::symmetrize()
if (reply == QMessageBox::No)
setTolerance();

bool success = AvoSpglib::symmetrize(*m_molecule, m_spgTol);
bool success = m_molecule->undoMolecule()->symmetrizeCell(m_spgTol);

if (!success) {
// Print an error message.
Expand All @@ -256,10 +256,6 @@ void SpaceGroup::symmetrize()
"with a different tolerance."));
retMsgBox.exec();
}
else {
m_molecule->emitChanged(Molecule::Added |
Molecule::Atoms | Molecule::UnitCell);
}
}

void SpaceGroup::setTolerance()
Expand Down

0 comments on commit 99dc812

Please sign in to comment.