Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1""" Data container class. """ 

2 

3import numpy as np 

4from .base_data_container import BaseDataContainer 

5from ..data_analysis import analyze_data 

6 

7 

8class DataContainer(BaseDataContainer): 

9 """ 

10 Data container for storing information concerned with 

11 Monte Carlo simulations performed with mchammer. 

12 

13 Parameters 

14 ---------- 

15 structure : ase.Atoms 

16 reference atomic structure associated with the data container 

17 

18 ensemble_parameters : dict 

19 parameters associated with the underlying ensemble 

20 

21 metadata : dict 

22 metadata associated with the data container 

23 """ 

24 

25 def analyze_data(self, tag: str, start: int = None, max_lag: int = None) -> dict: 

26 """ 

27 Returns detailed analysis of a scalar observerable. 

28 

29 Parameters 

30 ---------- 

31 tag 

32 tag of field over which to average 

33 start 

34 minimum value of trial step to consider; by default the 

35 smallest value in the mctrial column will be used. 

36 max_lag 

37 maximum lag between two points in data series, by default the 

38 largest length of the data series will be used. 

39 Used for computing autocorrelation 

40 

41 Raises 

42 ------ 

43 ValueError 

44 if observable is requested that is not in data container 

45 ValueError 

46 if observable is not scalar 

47 ValueError 

48 if observations is not evenly spaced 

49 

50 Returns 

51 ------- 

52 dict 

53 calculated properties of the data including mean, 

54 standard_deviation, correlation_length and error_estimate 

55 (95% confidence) 

56 """ 

57 

58 # get data for tag 

59 if tag in ['trajectory', 'occupations']: 59 ↛ 60line 59 didn't jump to line 60, because the condition on line 59 was never true

60 raise ValueError('{} is not scalar'.format(tag)) 

61 steps, data = self.get('mctrial', tag, start=start) 

62 

63 # check that steps are evenly spaced 

64 diff = np.diff(steps) 

65 step_length = diff[0] 

66 if not np.allclose(step_length, diff): 66 ↛ 67line 66 didn't jump to line 67, because the condition on line 66 was never true

67 raise ValueError('data records must be evenly spaced.') 

68 

69 summary = analyze_data(data, max_lag=max_lag) 

70 summary['correlation_length'] *= step_length # in mc-trials 

71 return summary 

72 

73 def get_average(self, tag: str, start: int = None) -> float: 

74 """ 

75 Returns average of a scalar observable. 

76 

77 Parameters 

78 ---------- 

79 tag 

80 tag of field over which to average 

81 start 

82 minimum value of trial step to consider; by default the 

83 smallest value in the mctrial column will be used. 

84 

85 Raises 

86 ------ 

87 ValueError 

88 if observable is requested that is not in data container 

89 ValueError 

90 if observable is not scalar 

91 """ 

92 if tag in ['trajectory', 'occupations']: 

93 raise ValueError('{} is not scalar'.format(tag)) 

94 data = self.get(tag, start=start) 

95 return np.mean(data)