File: test_fixedmode.py

package info (click to toggle)
python-ase 3.26.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,484 kB
  • sloc: python: 148,112; xml: 2,728; makefile: 110; javascript: 47
file content (25 lines) | stat: -rw-r--r-- 764 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# fmt: off
import numpy as np

from ase.build import molecule
from ase.constraints import FixedMode, dict2constraint


def test_fixedmode():
    """Test that FixedMode can be set, turned into a dict, and
    back to a constraint with the same mode."""

    # Create a simple mode.
    atoms = molecule('CH3OH')
    initial_positions = atoms.positions.copy()
    atoms.rattle(stdev=0.5)
    mode = atoms.positions - initial_positions

    # Test the constraint.
    constraint = FixedMode(mode)
    dict_constraint = constraint.todict()
    new_constraint = dict2constraint(dict_constraint)
    assert np.isclose(new_constraint.mode, constraint.mode).all()

    atoms.set_constraint(constraint)
    assert atoms.get_number_of_degrees_of_freedom() == 2 * len(atoms)