Skip to content

Commit

Permalink
Merge pull request #1901 from ghutchis/tweak-fill-unit-cell
Browse files Browse the repository at this point in the history
Fixes for filling the unit cell
  • Loading branch information
ghutchis authored Dec 29, 2024
2 parents 6fb9111 + 932739b commit d231082
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
5 changes: 1 addition & 4 deletions avogadro/core/spacegroups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,7 @@ void SpaceGroups::fillUnitCell(Molecule& mol, unsigned short hallNumber,
}
}

// if (wrapToCell)
// CrystalTools::wrapAtomsToUnitCell(mol);

// Now we need to generate any copies on the unit boundary
// Now we generate any copies on the unit boundary
// We need to loop through all the atoms again
// if a fractional coordinate contains 0.0, we need to generate a copy
// of the atom at 1.0
Expand Down
2 changes: 1 addition & 1 deletion avogadro/core/spacegroups.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class AVOGADROCORE_EXPORT SpaceGroups
*/
static void fillUnitCell(Molecule& mol, unsigned short hallNumber,
double cartTol = 1e-5, bool wrapToCell = true,
bool allCopies = true);
bool allCopies = false);

/**
* Reduce a cell to its asymmetric unit.
Expand Down
16 changes: 16 additions & 0 deletions avogadro/core/unitcell.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,14 @@ inline Vector3 UnitCell::wrapFractional(const Vector3& f) const
++result[1];
if (result[2] < static_cast<Real>(0.0))
++result[2];
// set anything at 1.0 to 0.0
if (result[0] >= static_cast<Real>(0.999999))
result[0] = static_cast<Real>(0.0);
if (result[1] == static_cast<Real>(0.999999))
result[1] = static_cast<Real>(0.0);
if (result[2] == static_cast<Real>(0.999999))
result[2] = static_cast<Real>(0.0);

return result;
}

Expand All @@ -305,6 +313,14 @@ inline void UnitCell::wrapFractional(const Vector3& f, Vector3& wrapped) const
++wrapped[1];
if (wrapped[2] < static_cast<Real>(0.0))
++wrapped[2];

// set anything at 1.0 to 0.0
if (wrapped[0] >= static_cast<Real>(0.999999))
wrapped[0] = static_cast<Real>(0.0);
if (wrapped[1] >= static_cast<Real>(0.999999))
wrapped[1] = static_cast<Real>(0.0);
if (wrapped[2] >= static_cast<Real>(0.999999))
wrapped[2] = static_cast<Real>(0.0);
}

inline Vector3 UnitCell::wrapCartesian(const Vector3& cart) const
Expand Down
8 changes: 6 additions & 2 deletions avogadro/qtplugins/spacegroup/spacegroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ SpaceGroup::SpaceGroup(QObject* parent_)
m_fillUnitCellAction->setText(tr("Fill Unit Cell…"));
connect(m_fillUnitCellAction, SIGNAL(triggered()), SLOT(fillUnitCell()));
m_actions.push_back(m_fillUnitCellAction);
m_fillUnitCellAction->setProperty("menu priority", 50);
// should fall next to the "Wrap Atoms to Unit Cell" action
m_fillUnitCellAction->setProperty("menu priority", 185);

m_reduceToAsymmetricUnitAction->setText(tr("Reduce to Asymmetric Unit"));
connect(m_reduceToAsymmetricUnitAction, SIGNAL(triggered()),
Expand All @@ -100,8 +101,11 @@ QList<QAction*> SpaceGroup::actions() const
return m_actions;
}

QStringList SpaceGroup::menuPath(QAction*) const
QStringList SpaceGroup::menuPath(QAction* action) const
{
if (action == m_fillUnitCellAction)
return QStringList() << tr("&Crystal");

return QStringList() << tr("&Crystal") << tr("Space Group");
}

Expand Down

0 comments on commit d231082

Please sign in to comment.