Coverage for ase/calculators/openmx/parameters.py: 84.38%
32 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-11-27 15:21 +0000
« prev ^ index » next coverage.py v7.16.2, created at 2026-11-27 15:21 +0000
1"""
2The ASE Calculator for OpenMX <https://www.openmx-square.org>: Python interface
3to the software package for nano-scale material simulations based on density
4functional theories.
5 Copyright (C) 2018 Jae Hwan Shim and JaeJun Yu
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation, either version 2.1 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with ASE. If not, see <https://www.gnu.org/licenses/>.
19"""
21from typing import Any
23from ase.calculators.calculator import Parameters
24from ase.calculators.openmx.default_settings import default_dictionary
26# Keys that have length 3
27tuple_integer_keys = [
28 'scf.Ngrid',
29 'scf.Kgrid',
30 'Dos.Kgrid',
31]
32tuple_float_keys = ['scf.Electric.Field', 'scf.fixed.grid']
33tuple_bool_keys: list[str] = []
34integer_keys = [
35 'level.of.stdout',
36 'level.of.fileout',
37 'Species.Number',
38 'Atoms.Number',
39 'scf.maxIter',
40 'scf.Mixing.History',
41 'scf.Mixing.StartPulay',
42 'scf.Mixing.EveryPulay',
43 '1DFFT.NumGridK',
44 '1DFFT.NumGridR',
45 'orbitalOpt.scf.maxIter',
46 'orbitalOpt.Opt.maxIter',
47 'orbitalOpt.Opt.Method',
48 'orbitalOpt.HistoryPulay',
49 'Num.CntOrb.Atoms',
50 'orderN.KrylovH.order',
51 'orderN.KrylovS.order',
52 'MD.maxIter',
53 'MD.Opt.DIIS.History',
54 'MD.Opt.StartDIIS',
55 'Band.Nkpath',
56 'num.HOMOs',
57 'num.LUMOs',
58 'MO.Nkpoint',
59 'MD.Current.Iter',
60]
61float_keys = [
62 'scf.Constraint.NC.Spin.v',
63 'scf.ElectronicTemperature',
64 'scf.energycutoff',
65 'scf.Init.Mixing.Weight',
66 'scf.Min.Mixing.Weight',
67 'scf.Max.Mixing.Weight',
68 'scf.Kerker.factor',
69 'scf.criterion',
70 'scf.system.charge',
71 '1DFFT.EnergyCutoff',
72 'orbitalOpt.SD.step',
73 'orbitalOpt.criterion',
74 'orderN.HoppingRanges',
75 'MD.TimeStep',
76 'MD.Opt.criterion',
77 'NH.Mass.HeatBath',
78 'scf.NC.Mag.Field.Spin',
79 'scf.NC.Mag.Field.Orbital',
80]
81string_keys = [
82 'System.CurrentDirectory',
83 'System.Name',
84 'DATA.PATH',
85 'Atoms.SpeciesAndCoordinates.Unit',
86 'Atoms.UnitVectors.Unit',
87 'scf.XcType',
88 'scf.SpinPolarization',
89 'scf.Hubbard.Occupation',
90 'scf.EigenvalueSolver',
91 'scf.Mixing.Type',
92 'orbitalOpt.Method',
93 'orbitalOpt.StartPulay',
94 'MD.Type',
95 'Wannier.Initial.Projectors.Unit',
96]
97bool_keys = [
98 'scf.partialCoreCorrection',
99 'scf.Hubbard.U',
100 'scf.Constraint.NC.Spin',
101 'scf.ProExpn.VNA',
102 'scf.SpinOrbit.Coupling',
103 'CntOrb.fileout',
104 'orderN.Exact.Inverse.S',
105 'orderN.Recalc.Buffer',
106 'orderN.Expand.Core',
107 'Band.Dispersion',
108 'scf.restart',
109 'MO.fileout',
110 'Dos.fileout',
111 'HS.fileout',
112 'Voronoi.charge',
113 'scf.NC.Zeeman.Spin',
114 'scf.stress.tensor',
115 'Energy.Decomposition',
116]
117list_int_keys: list[str] = []
118list_bool_keys: list[str] = []
119list_float_keys = [
120 'Dos.Erange',
121]
122matrix_keys = [
123 'Definition.of.Atomic.Species',
124 'Atoms.SpeciesAndCoordinates',
125 'Atoms.UnitVectors',
126 'Hubbard.U.values',
127 'Atoms.Cont.Orbitals',
128 'MD.Fixed.XYZ',
129 'MD.TempControl',
130 'MD.Init.Velocity',
131 'Band.KPath.UnitCell',
132 'Band.kpath',
133 'MO.kpoint',
134 'Wannier.Initial.Projectors',
135]
136unit_dat_keywords = {
137 'Hubbard.U.Values': 'eV',
138 'scf.Constraint.NC.Spin.v': 'eV',
139 'scf.ElectronicTemperature': 'K',
140 'scf.energycutoff': 'Ry',
141 'scf.criterion': 'Ha',
142 'scf.Electric.Field': 'GV / m',
143 'OneDFFT.EnergyCutoff': 'Ry',
144 'orbitalOpt.criterion': '(Ha/Borg)**2',
145 'MD.Opt.criterion': 'Ha/Bohr',
146 'MD.TempControl': 'K',
147 'NH.Mass.HeatBath': '_amu',
148 'MD.Init.Velocity': 'm/s',
149 'Dos.Erange': 'eV',
150 'scf.NC.Mag.Field.Spin': 'Tesla',
151 'scf.NC.Mag.Field.Orbital': 'Tesla',
152}
155omx_parameter_defaults: dict[str, Any] = dict(
156 scf_ngrid=None,
157 scf_kgrid=None,
158 dos_kgrid=None,
159 scf_electric_field=None,
160 level_of_stdout=None,
161 level_of_fileout=None,
162 species_number=None,
163 atoms_number=None,
164 scf_maxiter=None, # default 40
165 scf_mixing_history=None,
166 scf_mixing_startpulay=None,
167 scf_mixing_everypulay=None,
168 onedfft_numgridk=None, # 1Dfft
169 onedfft_numgridr=None, # 1Dfft
170 orbitalopt_scf_maxiter=None,
171 orbitalopt_opt_maxiter=None,
172 orbitalopt_opt_method=None,
173 orbitalopt_historypulay=None,
174 num_cntorb_atoms=None,
175 ordern_krylovh_order=None,
176 ordern_krylovs_order=None,
177 md_maxiter=None,
178 md_opt_diis_history=None,
179 md_opt_startdiis=None,
180 band_nkpath=None,
181 num_homos=None,
182 num_lumos=None,
183 mo_nkpoint=None,
184 md_current_iter=None,
185 scf_constraint_nc_spin_v=None,
186 scf_electronictemperature=None,
187 scf_fixed_grid=None,
188 scf_energycutoff=150,
189 scf_init_mixing_weight=None,
190 scf_min_mixing_weight=None,
191 scf_max_mixing_weight=None,
192 scf_kerker_factor=None,
193 scf_criterion=None, # Ha unit defualt 1e-6
194 scf_system_charge=None,
195 onedfft_energycutoff=None, # 1Dfft
196 orbitalopt_sd_step=None,
197 orbitalopt_criterion=None,
198 ordern_hoppingranges=None,
199 md_timestep=None,
200 md_opt_criterion=None,
201 nh_mass_heatbath=None,
202 scf_nc_mag_field_spin=None,
203 scf_nc_mag_field_orbital=None,
204 system_currentdirectory=None,
205 system_name=None,
206 data_path=None,
207 atoms_speciesandcoordinates_unit='Ang',
208 atoms_unitvectors_unit='Ang',
209 scf_xctype='LDA',
210 scf_spinpolarization=None,
211 scf_hubbard_occupation=None,
212 scf_eigenvaluesolver='Cluster', # Band | Cluster
213 scf_mixing_type='Rmm-Diis',
214 orbitalopt_method=None,
215 orbitalopt_startpulay=None,
216 md_type=None,
217 wannier_initial_projectors_unit=None,
218 scf_partialcorecorrection=None,
219 scf_hubbard_u=None,
220 scf_constraint_nc_spin=None,
221 scf_proexpn_vna=None,
222 scf_spinorbit_coupling=None,
223 cntorb_fileout=None,
224 ordern_exact_inverse_s=None,
225 ordern_recalc_buffer=None,
226 ordern_expand_core=None,
227 band_dispersion=None,
228 scf_restart=None,
229 mo_fileout=None,
230 dos_fileout=None,
231 hs_fileout=None,
232 voronoi_charge=None,
233 scf_nc_zeeman_spin=None,
234 scf_stress_tensor=None,
235 energy_decomposition=None,
236 dos_erange=None,
237 definition_of_atomic_species=None,
238 atoms_speciesandcoordinates=None,
239 atoms_unitvectors=None,
240 hubbard_u_values=None,
241 atoms_cont_orbitals=None,
242 md_fixed_xyz=None,
243 md_tempcontrol=None,
244 md_init_velocity=None,
245 band_kpath_unitcell=None,
246 band_kpath=None,
247 mo_kpoint=None,
248 wannier_initial_projectors=None,
249 xc=None, # Default is set to 'LDA' as 'scf_xctype' keyword
250 maxiter=None,
251 energy_cutoff=None, # Please make sure written in eV unit not Ry
252 kpts=None, # Default value is set to (4, 4, 4) in 'scf_kgrid'
253 band_kpts=(), # To separate monkhorst and band kpts
254 eigensolver=None,
255 spinpol=None,
256 convergence=None,
257 external=None,
258 mixer=None,
259 charge=None,
260 smearing=None,
261 restart=None, # Beginning of calculator parameters
262 mpi=None,
263 pbs=None,
264 debug=False,
265 nohup=True,
266 dft_data_dict=None, # dft_data_year : Pseudo potential generated year
267 dft_data_year=None,
268) # writting in 'Definition.Of.Atomic.Species'. 13 or 19
271class OpenMXParameters(Parameters):
272 """
273 Parameters class for the OpenMX calculator. OpenMX parameters are defined
274 here. If values seems unreasonable, for example, energy_cutoff=0.01, it
275 gives warning. Changing standard parameters to openmx kewords is not a job
276 for this class. We translate the variable right before we write. Hence,
277 translation processes are written in `writers.py`. Here we only deals with
278 default parameters and the reasonable boundary for that value.
280 (1, 1, 1) < scf_kgrid < (16, 16, 16)
281 1 < scf_maxiter < 10000
282 1e-10 < scf_criterion < 1e-1
283 100 < scf_energycutoff < 600
284 100 * Ha < convergence < 600 * Ha
286 """
288 allowed_xc = [
289 'LDA',
290 'GGA',
291 'PBE',
292 'GGA-PBE',
293 'LSDA',
294 'LSDA-PW',
295 'LSDA-CA',
296 'CA',
297 'PW',
298 ]
300 def __init__(self, **kwargs):
301 kw = omx_parameter_defaults.copy()
302 kw.update(kwargs)
303 Parameters.__init__(self, **kw)
305 if self.kpts == (1, 1, 1):
306 print(
307 "When only the gamma point is considered, the eigenvalue \
308 solver is changed to 'Cluster' with the periodic boundary \
309 condition."
310 )
311 self.eigensolver = 'Cluster'
312 self.mpi = None
313 self.pbs = None
315 from copy import deepcopy
317 dft_data_dict = deepcopy(default_dictionary)
318 if self.dft_data_dict is not None:
319 dft_data_dict.update(self.dft_data_dict)
320 self.dft_data_dict = dft_data_dict
322 # keys = {k: v for k, v in kwargs.items() if not(v is None or v == [])}