Skip to content

Move `FixSymmetry` to constraints module and fix the `.todict()` method

Andrew Rosen requested to merge symfixer into master

This MR moves FixSymmetry to the ase.constraints module.

All of the constraints are in ase.constraints except for FixSymmetry. This imposes some significant problems, in addition to just being annoying. Most notably, the FixSymmetry class cannot be used in an optimization with a Trajectory written to the filesystem because the dict2constraints function can't resolve the FixSymmetry class from the ase.constraints module since it does not exist there, as exemplified below:

__all__ = [
    'FixCartesian', 'FixBondLength', 'FixedMode',
    'FixAtoms', 'FixScaled', 'FixCom', 'FixSubsetCom', 'FixedPlane',
    'FixConstraint', 'FixedLine', 'FixBondLengths', 'FixLinearTriatomic',
    'FixInternals', 'Hookean', 'ExternalForce', 'MirrorForce', 'MirrorTorque',
    "FixScaledParametricRelations", "FixCartesianParametricRelations"]


def dict2constraint(dct):
    if dct['name'] not in __all__:
        raise ValueError
    return globals()[dct['name']](**dct['kwargs'])

Comically, FixSymmetry was already referenced in all the usual constraints places. For instance, ase/test/constraints/test_fix_symmetry.py is the test for FixSymmetry, and doc/ase/constraints.rst direcrtly mentions FixSymmetry.

Edit: This also would close #1397 (closed).

Checklist

Edited by Andrew Rosen

Merge request reports