Commit b999e637 authored by Thomas Purcell's avatar Thomas Purcell
Browse files

Merge branch 'elena/patch-fix-symmetry' into 'master'

Bug fix: update constraint optimisation path to use the correct FixSymmetry.

See merge request !120
parents ae53cefd a12d1f94
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -58,7 +58,7 @@ Currently only [BFGS](https://wiki.fysik.dtu.dk/ase/ase/optimize.html#bfgs) is s

#### `fix_symmetry`

`True/False`: keep the spacegroup of the system fixed using [`ase.constraints.FixSymmetry`](https://wiki.fysik.dtu.dk/ase/dev/ase/constraints.html?highlight=fixsymmetry#ase.spacegroup.symmetrize.FixSymmetry)
`True/False`: keep the spacegroup of the system fixed using [`ase.constraints.FixSymmetry`](https://wiki.fysik.dtu.dk/ase/dev/ase/constraints.html?highlight=fixsymmetry#ase.constraints.FixSymmetry)

#### `hydrostatic_strain`

+1 −0
Original line number Diff line number Diff line
@@ -130,6 +130,7 @@ lint.ignore = [
    "C416",
    "C901",    # function too complex
    "COM812",  # trailing comma missing
    "CPY001",
    "D100",
    "D101",
    "D102",
+1 −1
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@ settings = Settings(settings_file=parent / "md.in")
calculator = EMT()

np.random.seed(4)
MaxwellBoltzmannDistribution(atoms, 300 * u.kB)
MaxwellBoltzmannDistribution(atoms, temperature_K=300)


def test_run(tmp_path):
+22 −0
Original line number Diff line number Diff line
@@ -42,5 +42,27 @@ def test_relaxation(workdir=workdir):
            assert np.allclose(pos, refpos)


def test_relaxation_fix_symmetry(workdir=workdir):
    with cwd(parent):
        settings = Settings(settings_file=settings_file)

        if workdir.exists():
            shutil.rmtree(workdir)

        ctx = RelaxationContext(settings, workdir=workdir)
        ctx.kw["fix_symmetry"] = True  # exercise the `from ase.constraints` path
        ctx.atoms.rattle(0.01, seed=4)
        ctx.calculator = EMT()

        # runs without FixSymmetry import error
        ctx.run()

        # constraints have been applies
        from ase.constraints import FixSymmetry
        _ = ctx.opt_atoms
        assert any(isinstance(c, FixSymmetry) for c in ctx.atoms.constraints)


if __name__ == "__main__":
    test_relaxation()
    test_relaxation_fix_symmetry()
+1 −1
Original line number Diff line number Diff line
@@ -85,7 +85,7 @@ def generate_samples(
        info_str += ["created from force constants", f"T = {temp} K"]
        talk(f"Random seed: {seed}")
    else:
        mb_args = {"temp": temp * u.kB, "rng": rng}
        mb_args = {"temperature_K": temp, "rng": rng}
        info_str += ["created from MB distribution", f"T = {temperature} K"]
        talk("Use Maxwell Boltzamnn to set up samples")

Loading