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
« prev ^ index » next coverage.py v7.13.5, created at 2026-03-30 08:22 +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 ----------
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)
37 def script(self, label):
38 """
39 Write the fdf script for the block.
41 Parameters
42 ----------
43 -label : The label to insert in front of the block.
44 """
45 return label + ' ' + self['block']
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.
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 """
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)
71def format_fdf(key, value):
72 """
73 Write an fdf key-word value pair.
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 ''
83 key = format_key(key)
84 new_value = format_value(value)
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'
93 return string
96def format_value(value):
97 """
98 Format python values to fdf-format.
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)
113 return value
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('#', '_')
122 return key