File: test_fix_bond_length_mic.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 (34 lines) | stat: -rw-r--r-- 940 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
26
27
28
29
30
31
32
33
34
# fmt: off
import pytest

import ase
from ase.calculators.lj import LennardJones
from ase.constraints import FixBondLength
from ase.optimize import FIRE


@pytest.mark.optimize()
@pytest.mark.parametrize('wrap', [False, True])
def test_fix_bond_length_mic(wrap):
    a = ase.Atoms('CCC',
                  positions=[[1, 0, 5],
                             [0, 1, 5],
                             [-1, 0.5, 5]],
                  cell=[10, 10, 10],
                  pbc=True)

    if wrap:
        a.set_scaled_positions(a.get_scaled_positions() % 1.0)
    a.calc = LennardJones()
    a.set_constraint(FixBondLength(0, 2))

    assert a.get_number_of_degrees_of_freedom() == len(a) * 3 - 1

    d1 = a.get_distance(0, 2, mic=True)

    with FIRE(a, logfile=None) as opt:
        opt.run(fmax=0.01)
    e = a.get_potential_energy()
    d2 = a.get_distance(0, 2, mic=True)
    assert abs(e - -2.034988) < 1e-6
    assert abs(d1 - d2) < 1e-6