Skip to content

Commit d231082

Browse files
authored
Merge pull request #1901 from ghutchis/tweak-fill-unit-cell
Fixes for filling the unit cell
2 parents 6fb9111 + 932739b commit d231082

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

avogadro/core/spacegroups.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,7 @@ void SpaceGroups::fillUnitCell(Molecule& mol, unsigned short hallNumber,
301301
}
302302
}
303303

304-
// if (wrapToCell)
305-
// CrystalTools::wrapAtomsToUnitCell(mol);
306-
307-
// Now we need to generate any copies on the unit boundary
304+
// Now we generate any copies on the unit boundary
308305
// We need to loop through all the atoms again
309306
// if a fractional coordinate contains 0.0, we need to generate a copy
310307
// of the atom at 1.0

avogadro/core/spacegroups.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class AVOGADROCORE_EXPORT SpaceGroups
126126
*/
127127
static void fillUnitCell(Molecule& mol, unsigned short hallNumber,
128128
double cartTol = 1e-5, bool wrapToCell = true,
129-
bool allCopies = true);
129+
bool allCopies = false);
130130

131131
/**
132132
* Reduce a cell to its asymmetric unit.

avogadro/core/unitcell.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,14 @@ inline Vector3 UnitCell::wrapFractional(const Vector3& f) const
291291
++result[1];
292292
if (result[2] < static_cast<Real>(0.0))
293293
++result[2];
294+
// set anything at 1.0 to 0.0
295+
if (result[0] >= static_cast<Real>(0.999999))
296+
result[0] = static_cast<Real>(0.0);
297+
if (result[1] == static_cast<Real>(0.999999))
298+
result[1] = static_cast<Real>(0.0);
299+
if (result[2] == static_cast<Real>(0.999999))
300+
result[2] = static_cast<Real>(0.0);
301+
294302
return result;
295303
}
296304

@@ -305,6 +313,14 @@ inline void UnitCell::wrapFractional(const Vector3& f, Vector3& wrapped) const
305313
++wrapped[1];
306314
if (wrapped[2] < static_cast<Real>(0.0))
307315
++wrapped[2];
316+
317+
// set anything at 1.0 to 0.0
318+
if (wrapped[0] >= static_cast<Real>(0.999999))
319+
wrapped[0] = static_cast<Real>(0.0);
320+
if (wrapped[1] >= static_cast<Real>(0.999999))
321+
wrapped[1] = static_cast<Real>(0.0);
322+
if (wrapped[2] >= static_cast<Real>(0.999999))
323+
wrapped[2] = static_cast<Real>(0.0);
308324
}
309325

310326
inline Vector3 UnitCell::wrapCartesian(const Vector3& cart) const

avogadro/qtplugins/spacegroup/spacegroup.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ SpaceGroup::SpaceGroup(QObject* parent_)
7373
m_fillUnitCellAction->setText(tr("Fill Unit Cell…"));
7474
connect(m_fillUnitCellAction, SIGNAL(triggered()), SLOT(fillUnitCell()));
7575
m_actions.push_back(m_fillUnitCellAction);
76-
m_fillUnitCellAction->setProperty("menu priority", 50);
76+
// should fall next to the "Wrap Atoms to Unit Cell" action
77+
m_fillUnitCellAction->setProperty("menu priority", 185);
7778

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

103-
QStringList SpaceGroup::menuPath(QAction*) const
104+
QStringList SpaceGroup::menuPath(QAction* action) const
104105
{
106+
if (action == m_fillUnitCellAction)
107+
return QStringList() << tr("&Crystal");
108+
105109
return QStringList() << tr("&Crystal") << tr("Space Group");
106110
}
107111

0 commit comments

Comments
 (0)