Coverage for ase / calculators / siesta / parameters.py: 100.00%

36 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-03-30 08:22 +0000

1# fmt: off 

2 

3from ase.calculators.calculator import Parameters 

4 

5""" 

62017.04 - Pedro Brandimarte: changes for python 2-3 compatible 

7""" 

8 

9 

10class PAOBasisBlock(Parameters): 

11 """ 

12 Representing a block in PAO.Basis for one species. 

13 """ 

14 

15 def __init__(self, block): 

16 """ 

17 Parameters 

18 ---------- 

19 -block : String. A block defining the basis set of a single 

20 species using the format of a PAO.Basis block. 

21 The initial label should be left out since it is 

22 determined programatically. 

23 Example1: 2 nodes 1.0 

24 n=2 0 2 E 50.0 2.5 

25 3.50 3.50 

26 0.95 1.00 

27 1 1 P 2 

28 3.50 

29 Example2: 1 

30 0 2 S 0.2 

31 5.00 0.00 

32 See siesta manual for details. 

33 """ 

34 assert isinstance(block, str) 

35 Parameters.__init__(self, block=block) 

36 

37 def script(self, label): 

38 """ 

39 Write the fdf script for the block. 

40 

41 Parameters 

42 ---------- 

43 -label : The label to insert in front of the block. 

44 """ 

45 return label + ' ' + self['block'] 

46 

47 

48class Species(Parameters): 

49 """ 

50 Parameters for specifying the behaviour for a single species in the 

51 calculation. If the tag argument is set to an integer then atoms with 

52 the specified element and tag will be a separate species. 

53 

54 Pseudopotential and basis set can be specified. Additionally the species 

55 can be set be a ghost species, meaning that they will not be considered 

56 atoms, but the corresponding basis set will be used. 

57 """ 

58 

59 def __init__(self, 

60 symbol, 

61 basis_set='DZP', 

62 pseudopotential=None, 

63 tag=None, 

64 ghost=False, 

65 excess_charge=None): 

66 kwargs = locals() 

67 kwargs.pop('self') 

68 Parameters.__init__(self, **kwargs) 

69 

70 

71def format_fdf(key, value): 

72 """ 

73 Write an fdf key-word value pair. 

74 

75 Parameters 

76 ---------- 

77 - key : The fdf-key 

78 - value : The fdf value. 

79 """ 

80 if isinstance(value, (list, tuple)) and len(value) == 0: 

81 return '' 

82 

83 key = format_key(key) 

84 new_value = format_value(value) 

85 

86 if isinstance(value, list): 

87 string = '%block ' + key + '\n' +\ 

88 new_value + '\n' + \ 

89 '%endblock ' + key + '\n' 

90 else: 

91 string = f'{key}\t{new_value}\n' 

92 

93 return string 

94 

95 

96def format_value(value): 

97 """ 

98 Format python values to fdf-format. 

99 

100 Parameters 

101 ---------- 

102 - value : The value to format. 

103 """ 

104 if isinstance(value, tuple): 

105 sub_values = [format_value(v) for v in value] 

106 value = '\t'.join(sub_values) 

107 elif isinstance(value, list): 

108 sub_values = [format_value(v) for v in value] 

109 value = '\n'.join(sub_values) 

110 else: 

111 value = str(value) 

112 

113 return value 

114 

115 

116def format_key(key): 

117 """ Fix the fdf-key replacing '_' with '.' and '__' with '_' """ 

118 key = key.replace('__', '#') 

119 key = key.replace('_', '.') 

120 key = key.replace('#', '_') 

121 

122 return key