Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions news/structure-dep.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
**Added:**

* ``diffpy.srfit.structure.structure_to_parameter_set`` and ``SrRealParSet.restrain_bvs``, which take the names they have in ``diffpy.cmistructure``.

**Changed:**

* The deprecation messages of ``constrainAsSpaceGroup`` and of ``setConst`` on the ObjCrystParSet bond length, bond angle and dihedral angle parameters now point to ``diffpy.cmistructure`` instead of ``diffpy.srfit.structure``.

**Deprecated:**

* ``diffpy.srfit.structure``, which moved to ``diffpy.cmistructure``. Importing it now raises a ``DeprecationWarning``.
* ``diffpy.srfit.structure.struToParameterSet``. Please use ``diffpy.cmistructure.structure_to_parameter_set`` instead.
* ``SrRealParSet.restrainBVS``. Please use ``diffpy.cmistructure.srrealparset.SrRealParSet.restrain_bvs`` instead.
* The ``.stru`` attribute of the structure parameter sets and of ``ObjCrystMoleculeParSet``. Please use ``.structure`` in ``diffpy.cmistructure`` instead.

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ dependencies = {file = ["requirements/pip.txt"]}
# Fail when srfit source calls one of srfit's own deprecated names.
filterwarnings = [
"error:'diffpy\\.srfit\\.:DeprecationWarning:diffpy\\.srfit",
"ignore:'diffpy\\.srfit\\.(pdf|sas|structure)' is deprecated:DeprecationWarning",
]

[tool.codespell]
Expand Down
6 changes: 3 additions & 3 deletions src/diffpy/srfit/pdf/basepdfgenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from diffpy.srfit.exceptions import SrFitError
from diffpy.srfit.fitbase import ProfileGenerator
from diffpy.srfit.fitbase.parameter import ParameterAdapter
from diffpy.srfit.structure import struToParameterSet
from diffpy.srfit.structure import structure_to_parameter_set

# FIXME - Parameter creation will have to be smarter once deeper calculator
# configuration is enabled.
Expand Down Expand Up @@ -282,7 +282,7 @@ def setStructure(self, stru, name="phase", periodic=True):
PDF calculation.
"""
# Create the ParameterSet
parset = struToParameterSet(name, stru)
parset = structure_to_parameter_set(name, stru)

# Set the phase
self.setPhase(parset, periodic)
Expand Down Expand Up @@ -310,7 +310,7 @@ def setPhase(self, parset, periodic=True):
"""
# Store the ParameterSet for easy access
self._phase = parset
self.stru = self._phase.stru
self.stru = self._phase.structure

# Put this ParameterSet in the ProfileGenerator.
self.add_parameter_set(parset)
Expand Down
81 changes: 63 additions & 18 deletions src/diffpy/srfit/structure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,50 +16,95 @@
ParameterSet interface and automatic structure constraint generation
from space group information."""

import warnings

from diffpy.srfit.structure.sgconstraints import (
constrain_as_space_group,
constrainAsSpaceGroup,
)
from diffpy.utils._deprecator import build_deprecation_message, deprecated

removal_version = "4.0.0"

warnings.warn(
build_deprecation_message(
"diffpy.srfit",
"structure",
"cmistructure",
removal_version,
new_base="diffpy",
),
DeprecationWarning,
stacklevel=2,
)

struToParameterSet_dep_msg = build_deprecation_message(
"diffpy.srfit.structure",
"struToParameterSet",
"structure_to_parameter_set",
removal_version,
new_base="diffpy.cmistructure",
)


def struToParameterSet(name, stru):
"""Creates a ParameterSet from an structure.
def structure_to_parameter_set(name, structure):
"""Create a ParameterSet adapted to a structure object.

This returns a ParameterSet adapted for the structure depending on its
type.
The adapter is chosen from the type of `structure`. Supported types
are diffpy.structure.Structure, pyobjcryst.crystal.Crystal,
pyobjcryst.molecule.Molecule and
cctbx.crystal.special_position_settings.

Parameters
----------
stru
a structure object known by this module
name
A name to give the structure.

Raises TypeError if stru cannot be adapted
name : str
The name to give the structure.
structure : object
The structure object to adapt.

Returns
-------
BaseStructureParSet
The ParameterSet adapting `structure`.

Raises
------
TypeError
If `structure` is not one of the supported structure types.
"""
from diffpy.srfit.structure.diffpyparset import DiffpyStructureParSet

if DiffpyStructureParSet.canAdapt(stru):
return DiffpyStructureParSet(name, stru)
if DiffpyStructureParSet.canAdapt(structure):
return DiffpyStructureParSet(name, structure)

from diffpy.srfit.structure.objcrystparset import ObjCrystCrystalParSet

if ObjCrystCrystalParSet.canAdapt(stru):
return ObjCrystCrystalParSet(name, stru)
if ObjCrystCrystalParSet.canAdapt(structure):
return ObjCrystCrystalParSet(name, structure)

from diffpy.srfit.structure.objcrystparset import ObjCrystMoleculeParSet

if ObjCrystMoleculeParSet.canAdapt(stru):
return ObjCrystMoleculeParSet(name, stru)
if ObjCrystMoleculeParSet.canAdapt(structure):
return ObjCrystMoleculeParSet(name, structure)

from diffpy.srfit.structure.cctbxparset import CCTBXCrystalParSet

if CCTBXCrystalParSet.canAdapt(stru):
return CCTBXCrystalParSet(name, stru)
if CCTBXCrystalParSet.canAdapt(structure):
return CCTBXCrystalParSet(name, structure)

raise TypeError("Unadaptable structure format")


@deprecated(struToParameterSet_dep_msg)
def struToParameterSet(name, stru):
"""This function has been deprecated and will be removed in version
4.0.0.

Please use diffpy.cmistructure.structure_to_parameter_set instead.
"""
return structure_to_parameter_set(name, stru)


# silence pyflakes checker
assert constrain_as_space_group
assert constrainAsSpaceGroup
Expand Down
30 changes: 29 additions & 1 deletion src/diffpy/srfit/structure/basestructureparset.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@
__all__ = ["BaseStructureParSet"]

from diffpy.srfit.fitbase.parameterset import ParameterSet
from diffpy.utils._deprecator import build_deprecation_message, deprecated

removal_version = "4.0.0"

stru_dep_msg = build_deprecation_message(
"diffpy.srfit.structure.basestructureparset.BaseStructureParSet",
"stru",
"structure",
removal_version,
new_base="diffpy.cmistructure.basestructureparset.BaseStructureParSet",
)


class BaseStructureParSet(ParameterSet):
Expand All @@ -32,10 +43,27 @@ class BaseStructureParSet(ParameterSet):

Attributes
----------
stru
structure
The adapted object
"""

@property
@deprecated(stru_dep_msg)
def stru(self):
"""This function has been deprecated and will be removed in version
4.0.0.

Please use
diffpy.cmistructure.basestructureparset.BaseStructureParSet.structure
instead.
"""
return self.structure

@stru.setter
@deprecated(stru_dep_msg)
def stru(self, value):
self.structure = value

@classmethod
def canAdapt(self, stru):
"""Return whether the structure can be adapted by this class."""
Expand Down
24 changes: 12 additions & 12 deletions src/diffpy/srfit/structure/cctbxparset.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,32 +92,32 @@ def __init__(self, name, strups, idx):
def _xyzgetter(self, i):

def f(dummy):
return self.strups.stru.scatterers()[self.idx].site[i]
return self.strups.structure.scatterers()[self.idx].site[i]

return f

def _xyzsetter(self, i):

def f(dummy, value):
xyz = list(self.strups.stru.scatterers()[self.idx].site)
xyz = list(self.strups.structure.scatterers()[self.idx].site)
xyz[i] = value
self.strups.stru.scatterers()[self.idx].site = tuple(xyz)
self.strups.structure.scatterers()[self.idx].site = tuple(xyz)
return

return f

def _getocc(self, dummy):
return self.strups.stru.scatterers()[self.idx].occupancy
return self.strups.structure.scatterers()[self.idx].occupancy

def _setocc(self, dummy, value):
self.strups.stru.scatterers()[self.idx].occupancy = value
self.strups.structure.scatterers()[self.idx].occupancy = value
return

def _getuiso(self, dummy):
return self.strups.stru.scatterers()[self.idx].u_iso
return self.strups.structure.scatterers()[self.idx].u_iso

def _setuiso(self, dummy, value):
self.strups.stru.scatterers()[self.idx].u_iso = value
self.strups.structure.scatterers()[self.idx].u_iso = value
return

def _getelem(self):
Expand Down Expand Up @@ -161,7 +161,7 @@ def __init__(self, strups):
"""
ParameterSet.__init__(self, "unitcell")
self.strups = strups
self._latpars = list(self.strups.stru.unit_cell().parameters())
self._latpars = list(self.strups.structure.unit_cell().parameters())

self.add_parameter(
ParameterAdapter("a", None, self._latgetter(0), self._latsetter(0))
Expand Down Expand Up @@ -236,7 +236,7 @@ def __init__(self, name, stru):
A CCTBX structure instance.
"""
ParameterSet.__init__(self, name)
self.stru = stru
self.structure = stru
self.add_parameter_set(CCTBXUnitCellParSet(self))
self.scatterers = []

Expand Down Expand Up @@ -272,7 +272,7 @@ def update(self):
return

self._update = False
stru = self.stru
stru = self.structure
sgn = stru.space_group().match_tabulated_settings().number()

# Create the symmetry object
Expand All @@ -289,7 +289,7 @@ def update(self):

self.unitcell._latpars = list(newstru.unit_cell().parameters())

self.stru = newstru
self.structure = newstru
return

@classmethod
Expand Down Expand Up @@ -317,7 +317,7 @@ def getScatterers(self):

def getSpaceGroup(self):
"""Get the HM space group symbol for the structure."""
sg = self.stru.space_group()
sg = self.structure.space_group()
t = sg.type()
return t.lookup_symbol()

Expand Down
4 changes: 2 additions & 2 deletions src/diffpy/srfit/structure/diffpyparset.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def __init__(self, name, stru):
A diffpy.structure.Structure instance
"""
SrRealParSet.__init__(self, name)
self.stru = stru
self.structure = stru
self.add_parameter_set(DiffpyLatticeParSet(stru.lattice))
self.atoms = []

Expand All @@ -305,7 +305,7 @@ def __init__(self, name, stru):
return

def __repr__(self):
return repr(self.stru)
return repr(self.structure)

def getLattice(self):
"""Get the ParameterSet containing the lattice Parameters."""
Expand Down
Loading
Loading