Skip to content

Commit 9f6a6de

Browse files
committed
Support SpaceGroup-types in constrainAsSpaceGroup.
This closes #16.
1 parent 4371ae9 commit 9f6a6de

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

diffpy/srfit/structure/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ def struToParameterSet(name, stru):
4848

4949
raise TypeError("Unadaptable structure format")
5050

51-
from sgconstraints import constrainAsSpaceGroup
51+
from diffpy.srfit.structure.sgconstraints import constrainAsSpaceGroup
5252

5353
# End of file

diffpy/srfit/structure/sgconstraints.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
__all__ = ["constrainAsSpaceGroup"]
2424

25-
def constrainAsSpaceGroup(phase, sgsymbol, scatterers = None,
25+
def constrainAsSpaceGroup(phase, spacegroup, scatterers = None,
2626
sgoffset = [0, 0, 0], constrainlat = True, constrainadps = True,
2727
adpsymbols = None, isosymbol = "Uiso"):
2828
"""Constrain the structure to the space group.
@@ -33,8 +33,8 @@ def constrainAsSpaceGroup(phase, sgsymbol, scatterers = None,
3333
3434
Arguments:
3535
phase -- A BaseStructure object.
36-
sgsymbol -- The space group number or symbol (compatible with
37-
diffpy.Structure.SpaceGroups.GetSpaceGroup.
36+
spacegroup -- The space group number, symbol or an instance of
37+
SpaceGroup class from diffpy.Structure package.
3838
sgoffset -- Optional offset for sg origin (default [0, 0, 0]).
3939
scatterers -- The scatterer ParameterSets to constrain. If scatterers
4040
is None (default), then all scatterers accessible from
@@ -77,9 +77,11 @@ def constrainAsSpaceGroup(phase, sgsymbol, scatterers = None,
7777
7878
"""
7979

80-
from diffpy.Structure.SpaceGroups import GetSpaceGroup
80+
from diffpy.Structure.SpaceGroups import GetSpaceGroup, SpaceGroup
8181

82-
sg = GetSpaceGroup(sgsymbol)
82+
sg = spacegroup
83+
if not isinstance(spacegroup, SpaceGroup):
84+
sg = GetSpaceGroup(spacegroup)
8385
sgp = _constrainAsSpaceGroup(phase, sg, scatterers, sgoffset,
8486
constrainlat, constrainadps, adpsymbols, isosymbol)
8587

diffpy/srfit/tests/testsgconstriants.py

+18
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,24 @@ def _alltests(par):
202202

203203
return
204204

205+
206+
def test_ConstrainAsSpaceGroup_args(self):
207+
"""Test the arguments processing of constrainAsSpaceGroup function.
208+
"""
209+
from diffpy.srfit.structure.sgconstraints import constrainAsSpaceGroup
210+
from diffpy.Structure.SpaceGroups import GetSpaceGroup
211+
stru = makeLaMnO3_P1()
212+
parset = DiffpyStructureParSet("LaMnO3", stru)
213+
sgpars = constrainAsSpaceGroup(parset, "P b n m")
214+
sg = GetSpaceGroup('P b n m')
215+
parset2 = DiffpyStructureParSet("LMO", makeLaMnO3_P1())
216+
sgpars2 = constrainAsSpaceGroup(parset2, sg)
217+
list(sgpars)
218+
list(sgpars2)
219+
self.assertEquals(sgpars.names, sgpars2.names)
220+
return
221+
222+
205223
lamno3stru =\
206224
"""\
207225
title Cell structure file of LaMnO3.0

0 commit comments

Comments
 (0)