from ase import units
from ase.build import bulk
from ase.calculators.emt import EMT
from ase.md import thermalize_momenta
from ase.md.langevin import Langevin
from ase.md.velocitydistribution import Stationary


def test_langevin_asapcompat():
    """Check that the Langevin object has the attributes that Asap needs."""
    # parameters
    size = 2
    temperature = 300.0  # K
    dt = 0.01

    # setup
    atoms = bulk('CuAg', 'rocksalt', a=4.0).repeat(size)
    atoms.pbc = False
    atoms.calc = EMT()

    thermalize_momenta(atoms, temperature)
    Stationary(atoms)
    with Langevin(
        atoms,
        dt * units.fs,
        temperature_K=temperature,
        friction=0.02,
        fixcm=False,
    ) as dyn:
        dyn.run(1)

    at = ('temp', 'fr', 'c1', 'c2', 'c3', 'c4', 'c5', 'v', 'rnd_pos', 'rnd_vel')
    for attrib in at:
        assert hasattr(dyn, attrib), (
            f'Langevin object must have a "{attrib}" attribute or Asap fails.'
        )
