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

9 statements  

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

1from ase import Atoms 

2from icet import ClusterExpansion 

3from mchammer.observers.base_observer import BaseObserver 

4 

5 

6class ClusterExpansionObserver(BaseObserver): 

7 """ 

8 This class represents a cluster expansion (CE) observer. 

9 

10 A CE observer allows to compute a property described by a CE along the 

11 trajectory sampled by a Monte Carlo (MC) simulation. In general this CE 

12 differs from the CE that is used to generate the trajectory. For example in 

13 a canonical MC simulation the latter would usually represent an energy 

14 (total or mixing energy) whereas the former CE(s) could map lattice 

15 constant or band gap. 

16 

17 Parameters 

18 ---------- 

19 cluster_expansion 

20 Cluster expansion to be used for observation. 

21 interval 

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

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

24 will determine the interval. 

25 """ 

26 

27 def __init__(self, cluster_expansion: ClusterExpansion, 

28 interval: int = None) -> None: 

29 super().__init__(interval=interval, return_type=float, tag='ClusterExpansionObserver') 

30 self._cluster_expansion = cluster_expansion 

31 

32 def get_observable(self, structure: Atoms) -> float: 

33 """ 

34 Returns the value of the property from a cluster expansion model 

35 for a given atomic configuration. 

36 

37 Parameters 

38 ---------- 

39 structure 

40 Input atomic structure. 

41 """ 

42 return self._cluster_expansion.predict(structure)