Skip to content

refactor: small interface and style improvements for constraint handling #211

Description

@ycexiao

This is a collection of small issues related to handling constraints in diffpy.srfit.


Problem

In SpaceGroupParameters, self._makeConstraints() is only called in __iter__() which means the parameters will not be set up properly by:

sgpars = constrainAsSpaceGroup(phase, "Fm-3m")

The following lines are required

for par in sgpars.latpars:
    pass  # usually recipe.addVar(par)
for par in sgpars.adppars:
    pass  # usually recipe.addVar(par) 

Proposed solution

Move self._makeConstraints() to __init__()


Problem

When imposing space group symmetry, if there exists isotropic ADPs, isotropic ADPs are handled but others are not. e.g.

sgpars = constrainAsSpaceGroup(ni_phase, "Fm-3m")
print(pdf_generator.phase.Ni0.Uiso.constrained)  # False as expected
print(pdf_generator.phase.Ni1.Uiso.constrained)  # True as expected

print(pdf_generator.phase.Ni0.U11.constrained)  # False, but Ni0.U11 should equal to Ni0.Uiso
print(pdf_generator.phase.Ni1.U11.constrained)  # False, but Ni1.U11 should equal to Ni1.Uiso equal to Ni0.Uiso

This is because diffpy.srfit intends to use Uiso to handle isotropic ADP and use Uij to handle anisotropic ADP. Both variables are created but only the ones that it intends to use are constrained correctly.

Proposed solution

I think _constrain_adps is part of the core functionalities and has been heavily tested so I don't want to change it. Maybe we could allow SpaceGroupParameters._make_constraints() or create a new method to return the variable g = SymmetryConstraints(sg, positions, Uijs, sgoffset=sgoffset), so that the downstream app can interact this part of information directly?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions