Coverage for mchammer/observers/constituent_strain_observer.py: 100%

11 statements  

« prev     ^ index     » next       coverage.py v7.5.0, created at 2024-05-06 04:14 +0000

1from mchammer.observers.base_observer import BaseObserver 

2from icet.tools import ConstituentStrain 

3from ase import Atoms 

4 

5 

6class ConstituentStrainObserver(BaseObserver): 

7 """This class represents a constituent strain observer. It allows 

8 observation of constituent strain energy separate from the energy 

9 calculated by the cluster expansion. 

10 

11 Parameters 

12 ---------- 

13 constituent_strain 

14 :class:`ConstituentStrain` object. 

15 interval 

16 Observation interval. Defaults to ``None`` meaning that if the 

17 observer is used in a Monte Carlo simulations, then the :class:`Ensemble` object 

18 will determine the interval. 

19 """ 

20 

21 def __init__(self, 

22 constituent_strain: ConstituentStrain, 

23 interval: int = None) -> None: 

24 super().__init__(interval=interval, return_type=dict, tag='ConstituentStrainObserver') 

25 self.constituent_strain = constituent_strain 

26 

27 def get_observable(self, structure: Atoms) -> dict: 

28 """Returns the constituent strain energy for a given atomic configuration. 

29 

30 Parameters 

31 ---------- 

32 structure 

33 Input atomic structure. 

34 """ 

35 cs = self.constituent_strain.get_constituent_strain(structure.get_atomic_numbers()) 

36 cs = {'constituent_strain_energy': cs * len(structure)} 

37 return cs