Coverage for /builds/ase/ase/ase/calculators/siesta/parameters.py: 100.00%
36 statements
« prev ^ index » next coverage.py v7.5.3, created at 2025-08-02 00:12 +0000
« prev ^ index » next coverage.py v7.5.3, created at 2025-08-02 00:12 +0000
1# fmt: off
3from ase.calculators.calculator import Parameters
5"""
62017.04 - Pedro Brandimarte: changes for python 2-3 compatible
7"""
10class PAOBasisBlock(Parameters):
11 """
12 Representing a block in PAO.Basis for one species.
13 """
15 def __init__(self, block):
16 """
17 Parameters:
18 -block : String. A block defining the basis set of a single
19 species using the format of a PAO.Basis block.
20 The initial label should be left out since it is
21 determined programatically.
22 Example1: 2 nodes 1.0
23 n=2 0 2 E 50.0 2.5
24 3.50 3.50
25 0.95 1.00
26 1 1 P 2
27 3.50
28 Example2: 1
29 0 2 S 0.2
30 5.00 0.00
31 See siesta manual for details.
32 """
33 assert isinstance(block, str)
34 Parameters.__init__(self, block=block)
36 def script(self, label):
37 """
38 Write the fdf script for the block.
40 Parameters:
41 -label : The label to insert in front of the block.
42 """
43 return label + ' ' + self['block']
46class Species(Parameters):
47 """
48 Parameters for specifying the behaviour for a single species in the
49 calculation. If the tag argument is set to an integer then atoms with
50 the specified element and tag will be a separate species.
52 Pseudopotential and basis set can be specified. Additionally the species
53 can be set be a ghost species, meaning that they will not be considered
54 atoms, but the corresponding basis set will be used.
55 """
57 def __init__(self,
58 symbol,
59 basis_set='DZP',
60 pseudopotential=None,
61 tag=None,
62 ghost=False,
63 excess_charge=None):
64 kwargs = locals()
65 kwargs.pop('self')
66 Parameters.__init__(self, **kwargs)
69def format_fdf(key, value):
70 """
71 Write an fdf key-word value pair.
73 Parameters:
74 - key : The fdf-key
75 - value : The fdf value.
76 """
77 if isinstance(value, (list, tuple)) and len(value) == 0:
78 return ''
80 key = format_key(key)
81 new_value = format_value(value)
83 if isinstance(value, list):
84 string = '%block ' + key + '\n' +\
85 new_value + '\n' + \
86 '%endblock ' + key + '\n'
87 else:
88 string = f'{key}\t{new_value}\n'
90 return string
93def format_value(value):
94 """
95 Format python values to fdf-format.
97 Parameters:
98 - value : The value to format.
99 """
100 if isinstance(value, tuple):
101 sub_values = [format_value(v) for v in value]
102 value = '\t'.join(sub_values)
103 elif isinstance(value, list):
104 sub_values = [format_value(v) for v in value]
105 value = '\n'.join(sub_values)
106 else:
107 value = str(value)
109 return value
112def format_key(key):
113 """ Fix the fdf-key replacing '_' with '.' and '__' with '_' """
114 key = key.replace('__', '#')
115 key = key.replace('_', '.')
116 key = key.replace('#', '_')
118 return key