quadlib 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. quadlib/__init__.py +39 -0
  2. quadlib/basis/__init__.py +60 -0
  3. quadlib/basis/boson.py +61 -0
  4. quadlib/basis/discrete.py +71 -0
  5. quadlib/basis/expdvr.py +80 -0
  6. quadlib/basis/hodvr.py +51 -0
  7. quadlib/basis/jbasis.py +87 -0
  8. quadlib/basis/sindvr.py +97 -0
  9. quadlib/basis/spin.py +64 -0
  10. quadlib/cli/__init__.py +0 -0
  11. quadlib/cli/qlb_offset_oper_dof.py +34 -0
  12. quadlib/experimental/__init__.py +17 -0
  13. quadlib/experimental/cpd_eom.py +95 -0
  14. quadlib/experimental/mctdh.py +32 -0
  15. quadlib/experimental/node.py +259 -0
  16. quadlib/experimental/pdof.py +9 -0
  17. quadlib/experimental/tree.py +138 -0
  18. quadlib/hdmctdh/__init__.py +0 -0
  19. quadlib/hdmctdh/rundirectory.py +74 -0
  20. quadlib/legacy/__init__.py +14 -0
  21. quadlib/legacy/math.py +1337 -0
  22. quadlib/operator/sop.py +250 -0
  23. quadlib/propagation/__init__.py +17 -0
  24. quadlib/propagation/cpd.py +35 -0
  25. quadlib/propagation/exact.py +139 -0
  26. quadlib/propagation/integrators.py +108 -0
  27. quadlib/tools/__init__.py +0 -0
  28. quadlib/tools/bath.py +84 -0
  29. quadlib/tools/constants.py +289 -0
  30. quadlib/tools/iterators.py +276 -0
  31. quadlib/tools/linalg.py +215 -0
  32. quadlib/tools/pulses.py +187 -0
  33. quadlib/tools/spectra.py +179 -0
  34. quadlib/tools/tensor.py +227 -0
  35. quadlib/wavefunction/__init__.py +0 -0
  36. quadlib/wavefunction/wfn_cpd.py +266 -0
  37. quadlib/wavefunction/wfn_exact.py +147 -0
  38. quadlib-0.1.0.dist-info/METADATA +135 -0
  39. quadlib-0.1.0.dist-info/RECORD +43 -0
  40. quadlib-0.1.0.dist-info/WHEEL +5 -0
  41. quadlib-0.1.0.dist-info/entry_points.txt +2 -0
  42. quadlib-0.1.0.dist-info/licenses/LICENSE +19 -0
  43. quadlib-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,289 @@
1
+ # QuaDLib: QUAntum Dynamics LIBrary for research and methods development
2
+ # Copyright (C) 2018-2026, The Theoretical Chemistry Group, Heidelberg University
3
+ #
4
+ # This software is licensed under the MIT License (https://spdx.org/licenses/MIT.html)
5
+
6
+ """
7
+ Compendium of conversion factors and physical constants:
8
+
9
+ PI = 3.1415926535897 #Pi
10
+ E = 2.718281828459 #E
11
+ FPC_c = 299792458 #speed of light in vacuum (def) m/s
12
+ FPC_h_BAR = 1.05457266e-34 #Planck constant, reduced (63) J s
13
+ FPC_h_BAR_MeVs = 6.582122e-22 #Planck constant, reduced (20) MeV s
14
+ FPC_e_C = 1.60217733e-19 #electron charge magnitude (49) C
15
+ FPC_e_ESU = 4.8032068e-10 #electron charge magnitude (15) esu
16
+ FPC_hBARc = 197.327053 #conversion constant hbar*c (59) MeV Fm
17
+ FPC_hBARc2 = 0.38937966 #conversion constant (hbar*c)^2 (23) GeV^2 mbarn
18
+ FPC_m_e_kg = 9.1093897e-31 #electron mass (54) kg
19
+ FPC_m_e_MeV = 0.51099906 #electron mass (15) MeV/c^2
20
+ FPC_m_P_MeV = 938.27231 #proton mass (28) MeV/c^2
21
+ FPC_m_P_u = 1.00727647 #proton mass (12) u
22
+ FPC_m_P_kg = 1.6726231e-27 #proton mass (10) kg
23
+ FPC_m_P_M_E = 1836.152701 #proton mass (37) m_e
24
+ FPC_m_D_MeV = 1875.61339 #deuteron mass (57) MeV/c^2
25
+ FPC_u_MeV = 931.49432 #unified atomic mass unit (u) (28) MeV/c^2
26
+ FPC_u_kg = 1.6605402e-27 #unified atomic mass unit (u) (10) kg
27
+ FPC_EPSILON_0 = 8.854187817e-12 #permittivity of free space F/m
28
+ FPC_MU_0 = 1.2566370614e-06 #permeability of free space N/A^2
29
+ FPC_ALPHA = 0.0072973530796448 #fine-structure constant (61)
30
+ FPC_r_e = 2.81794092e-15 #classical electron radius (38) m
31
+ FPC_LAMBDA_BAR_e = 3.86159323e-13 #electron Compton wavelength (35) m
32
+ FPC_a_0 = 5.29177249e-11 #Bohr radius (mnucleus= infty) (24) m
33
+ FPC_LAMBDA_1EV = 1.23984244e-06 #wavelength of 1 eV/c particle (37) m
34
+ FPC_R_INFINITY_EV = 13.6056981 #Rydberg energy (mnucleus = infinity) (40) eV
35
+ FPC_SIGMA_0_BARN = 0.66524616 #Thomson cross section (18) barn
36
+ FPC_MU_B_MeV_T = 5.78838263e-11 #Bohr magneton (52) MeV/T
37
+ FPC_MU_N_MeV_T = 3.15245166e-14 #nuclear magneton (28) MeV/T
38
+ FPC_E_M_e = 175881962000 #electron cyclotron freq./field (53) C/kg (rad/sT)
39
+ FPC_E_M_P = 95788309 #proton cyclotron freq./field (29) C/kg (rad/sT)
40
+ FPC_G_SI = 6.67259e-11 #gravitational constant (85) m^3/kgs^2
41
+ FPC_G_P = 6.70711e-39 #gravitational constant (86) h_bar c (GeV/c^2)^{-2}
42
+ FPC_g = 9.80665 #standard grav. accel., sea level m/s^2
43
+ FPC_N_A = 6.0221367e+23 #Avogadro constant (36) /mole
44
+ FPC_K_B = 1.380658e-23 #Boltzmann constant (12) J/K
45
+ FPC_K_B_EV = 8.617385e-05 #Boltzmann constant (73) eV/K
46
+ FPC_V_MOLAR = 0.0224141 #molar volume, ideal gas at STP (19) m^3/mole
47
+ FPC_LAMBDAT = 0.002897756 #Wien displacement law constant (24) m K
48
+ FPC_SIGMA_SB = 5.67051e-08 #Stefan-Boltzmann constant (19) W/m^2K^4
49
+ FPC_G_F = 1.16639e-05 #Fermi coupling constant (2) GeV^{-2}
50
+ FPC_SIN2_THETA_W = 0.23192 #weak mixing angle (5) at M_Z
51
+ FPC_M_W = 80.22 #W boson mass (26) GeV/c^2
52
+ FPC_M_Z0 = 91.187 #Z_0 boson mass (7) GeV/c^2
53
+ FPC_G_S = 0.117 #strong coupling constant (5)) at M_Z
54
+ AUCHARGE = 1.60217733e-19 #1 a.u. charge in SI, elementary charge
55
+ AUMASS = 9.1093897e-31 #1 a.u. mass in SI, electron rest mass
56
+ AUENERGY = 4.3597482e-18 #1 a.u. energy in SI, hartree energy
57
+ AULENGTH = 5.29177249e-11 #1 a.u. length in SI, bohrradius
58
+ AUACTION = 1.05457266e-34 #1 a.u. action in SI, Planck constant/(2*PI)
59
+ AUTIME = 2.4188843341e-17 #1 a.u. time in SI
60
+ AUFORCE = 8.2387295e-08 #1 a.u. force in SI
61
+ AUVELOCITY = 2187691.42 #1 a.u. velocity in SI
62
+ AUMOMENTUM = 1.9928534e-34 #1 a.u. momentum in SI
63
+ AUEFIELD = 514220820000 #1 a.u. el. field in SI
64
+ AUEDIPOLE = 8.4783579e-30 #1 a.u. el. dipole in SI
65
+ AUMFLUX = 235051.808 #1 a.u. magn. flux in SI
66
+ AUMDIPOLE = 1.85480308e-23 #1 a.u. magn. flux in SI
67
+ ELECTRONVOLT = 1.60217733e-19 #1 eV charge in SI
68
+ ATOMICMASS = 1.6605402e-27 #1 amu mass in SI
69
+ ASTRONOMICALUNIT = 149597870000 #1 AE length in SI
70
+ MOL = 6.0221367e+23 #Avogadro constant
71
+ au2an = 0.529177249 #[a.u.] -> [Angstroem]
72
+ an2au = 1.8897259885789 #[Angstroem] -> [a.u.]
73
+ au2ev = 27.211396131788 #[a.u.] -> [eV]
74
+ ev2au = 0.036749308824762 #[eV] -> [a.u.]
75
+ au2am = 0.00054857989586762#[a.u.] -> [atomar mass units]
76
+ am2au = 1822.8885300626 #[atomar mass units] -> [a.u.]
77
+ au2fs = 0.024188843341 #[a.u.] -> [fs]
78
+ fs2au = 41.341373206755 #[fs] -> [a.u.]
79
+ ev2kc = 23.05 #[eV] -> [kcal/mol]
80
+ kc2ev = 0.043364476254697 #[kcal/mol] -> [eV]
81
+ au2kc = 627.50431878767 #[a.u.] -> [kcal/mol]
82
+ kc2au = 0.0015936145299079 #[kcal/mol] -> [a.u.]
83
+ au2ic = 219474.7 #[au] -> [1/cm]
84
+ ic2au = 4.5563338279993e-06#[1/cm] -> [au]
85
+ ev2ic = 8065.54353 #[eV] -> [1/cm]
86
+ ic2ev = 0.0001239842047 #[1/cm] -> [eV]
87
+ ev2kj = 96.485 #[eV] -> [kJoule/mol]
88
+ kj2ev = 0.0103643 #[kJoule/mol] -> [eV]
89
+ in2cm = 2.54 #[inch] -> [cm]
90
+ ft2m = 0.3048 #[feet] -> [cm]
91
+ yd2m = 0.9144 #[yard] -> [cm]
92
+ cm2in = 0.39370078740157 #[inch] -> [cm]
93
+ m2ft = 3.2808398950131 #[feet] -> [cm]
94
+ m2yd = 1.0936132983377 #[yard] -> [cm]
95
+ """
96
+
97
+ PI = 3.1415926535897 #Pi
98
+ E = 2.718281828459 #E
99
+ FPC_c = 299792458 #speed of light in vacuum (def) m/s
100
+ FPC_h_BAR = 1.05457266e-34 #Planck constant, reduced (63) J s
101
+ FPC_h_BAR_MeVs = 6.582122e-22 #Planck constant, reduced (20) MeV s
102
+ FPC_e_C = 1.60217733e-19 #electron charge magnitude (49) C
103
+ FPC_e_ESU = 4.8032068e-10 #electron charge magnitude (15) esu
104
+ FPC_hBARc = 197.327053 #conversion constant hbar*c (59) MeV Fm
105
+ FPC_hBARc2 = 0.38937966 #conversion constant (hbar*c)^2 (23) GeV^2 mbarn
106
+ FPC_m_e_kg = 9.1093897e-31 #electron mass (54) kg
107
+ FPC_m_e_MeV = 0.51099906 #electron mass (15) MeV/c^2
108
+ FPC_m_P_MeV = 938.27231 #proton mass (28) MeV/c^2
109
+ FPC_m_P_u = 1.00727647 #proton mass (12) u
110
+ FPC_m_P_kg = 1.6726231e-27 #proton mass (10) kg
111
+ FPC_m_P_M_E = 1836.152701 #proton mass (37) m_e
112
+ FPC_m_D_MeV = 1875.61339 #deuteron mass (57) MeV/c^2
113
+ FPC_u_MeV = 931.49432 #unified atomic mass unit (u) (28) MeV/c^2
114
+ FPC_u_kg = 1.6605402e-27 #unified atomic mass unit (u) (10) kg
115
+ FPC_EPSILON_0 = 8.854187817e-12 #permittivity of free space F/m
116
+ FPC_MU_0 = 1.2566370614e-06 #permeability of free space N/A^2
117
+ FPC_ALPHA = 0.0072973530796448 #fine-structure constant (61)
118
+ FPC_r_e = 2.81794092e-15 #classical electron radius (38) m
119
+ FPC_LAMBDA_BAR_e = 3.86159323e-13 #electron Compton wavelength (35) m
120
+ FPC_a_0 = 5.29177249e-11 #Bohr radius (mnucleus= infty) (24) m
121
+ FPC_LAMBDA_1EV = 1.23984244e-06 #wavelength of 1 eV/c particle (37) m
122
+ FPC_R_INFINITY_EV = 13.6056981 #Rydberg energy (mnucleus = infinity) (40) eV
123
+ FPC_SIGMA_0_BARN = 0.66524616 #Thomson cross section (18) barn
124
+ FPC_MU_B_MeV_T = 5.78838263e-11 #Bohr magneton (52) MeV/T
125
+ FPC_MU_N_MeV_T = 3.15245166e-14 #nuclear magneton (28) MeV/T
126
+ FPC_E_M_e = 175881962000 #electron cyclotron freq./field (53) C/kg (rad/sT)
127
+ FPC_E_M_P = 95788309 #proton cyclotron freq./field (29) C/kg (rad/sT)
128
+ FPC_G_SI = 6.67259e-11 #gravitational constant (85) m^3/kgs^2
129
+ FPC_G_P = 6.70711e-39 #gravitational constant (86) h_bar c (GeV/c^2)^{-2}
130
+ FPC_g = 9.80665 #standard grav. accel., sea level m/s^2
131
+ FPC_N_A = 6.0221367e+23 #Avogadro constant (36) /mole
132
+ FPC_K_B = 1.380658e-23 #Boltzmann constant (12) J/K
133
+ FPC_K_B_EV = 8.617385e-05 #Boltzmann constant (73) eV/K
134
+ FPC_V_MOLAR = 0.0224141 #molar volume, ideal gas at STP (19) m^3/mole
135
+ FPC_LAMBDAT = 0.002897756 #Wien displacement law constant (24) m K
136
+ FPC_SIGMA_SB = 5.67051e-08 #Stefan-Boltzmann constant (19) W/m^2K^4
137
+ FPC_G_F = 1.16639e-05 #Fermi coupling constant (2) GeV^{-2}
138
+ FPC_SIN2_THETA_W = 0.23192 #weak mixing angle (5) at M_Z
139
+ FPC_M_W = 80.22 #W boson mass (26) GeV/c^2
140
+ FPC_M_Z0 = 91.187 #Z_0 boson mass (7) GeV/c^2
141
+ FPC_G_S = 0.117 #strong coupling constant (5)) at M_Z
142
+ AUCHARGE = 1.60217733e-19 #1 a.u. charge in SI, elementary charge
143
+ AUMASS = 9.1093897e-31 #1 a.u. mass in SI, electron rest mass
144
+ AUENERGY = 4.3597482e-18 #1 a.u. energy in SI, hartree energy
145
+ AULENGTH = 5.29177249e-11 #1 a.u. length in SI, bohrradius
146
+ AUACTION = 1.05457266e-34 #1 a.u. action in SI, Planck constant/(2*PI)
147
+ AUTIME = 2.4188843341e-17 #1 a.u. time in SI
148
+ AUFORCE = 8.2387295e-08 #1 a.u. force in SI
149
+ AUVELOCITY = 2187691.42 #1 a.u. velocity in SI
150
+ AUMOMENTUM = 1.9928534e-34 #1 a.u. momentum in SI
151
+ AUEFIELD = 514220820000 #1 a.u. el. field in SI
152
+ AUEDIPOLE = 8.4783579e-30 #1 a.u. el. dipole in SI
153
+ AUMFLUX = 235051.808 #1 a.u. magn. flux in SI
154
+ AUMDIPOLE = 1.85480308e-23 #1 a.u. magn. flux in SI
155
+ ELECTRONVOLT = 1.60217733e-19 #1 eV charge in SI
156
+ ATOMICMASS = 1.6605402e-27 #1 amu mass in SI
157
+ ASTRONOMICALUNIT = 149597870000 #1 AE length in SI
158
+ MOL = 6.0221367e+23 #Avogadro constant
159
+ au2an = 0.529177249 #[a.u.] -> [Angstroem]
160
+ an2au = 1.8897259885789 #[Angstroem] -> [a.u.]
161
+ au2ev = 27.211396131788 #[a.u.] -> [eV]
162
+ ev2au = 0.036749308824762 #[eV] -> [a.u.]
163
+ au2am = 0.00054857989586762#[a.u.] -> [atomar mass units]
164
+ am2au = 1822.8885300626 #[atomar mass units] -> [a.u.]
165
+ au2fs = 0.024188843341 #[a.u.] -> [fs]
166
+ fs2au = 41.341373206755 #[fs] -> [a.u.]
167
+ ev2kc = 23.05 #[eV] -> [kcal/mol]
168
+ kc2ev = 0.043364476254697 #[kcal/mol] -> [eV]
169
+ au2kc = 627.50431878767 #[a.u.] -> [kcal/mol]
170
+ kc2au = 0.0015936145299079 #[kcal/mol] -> [a.u.]
171
+ au2ic = 219474.7 #[au] -> [1/cm]
172
+ ic2au = 4.5563338279993e-06#[1/cm] -> [au]
173
+ ev2ic = 8065.54353 #[eV] -> [1/cm]
174
+ ic2ev = 0.0001239842047 #[1/cm] -> [eV]
175
+ ev2kj = 96.485 #[eV] -> [kJoule/mol]
176
+ kj2ev = 0.0103643 #[kJoule/mol] -> [eV]
177
+ in2cm = 2.54 #[inch] -> [cm]
178
+ ft2m = 0.3048 #[feet] -> [cm]
179
+ yd2m = 0.9144 #[yard] -> [cm]
180
+ cm2in = 0.39370078740157 #[inch] -> [cm]
181
+ m2ft = 3.2808398950131 #[feet] -> [cm]
182
+ m2yd = 1.0936132983377 #[yard] -> [cm]
183
+
184
+ au2va = 51.4220652 #[au of E-Field] -> [V/A]
185
+ va2au = 1.0/au2va #[V/A] -> [au of E-Field]
186
+ de2au = 0.393430307 #[debye] -> [au of dipole]
187
+
188
+ def wcm22va(I):
189
+ return 2.744e-7 * I**0.5
190
+
191
+ def va2wcm2(E):
192
+ return (E/2.744e-7)**2
193
+
194
+ # Dictionary of element names and atomic number:
195
+ periodicTable = {
196
+ 'H' : { 'atomic_number' : 1,
197
+ 'atomic_mass' : 1.007825
198
+ },
199
+ 'D' : { 'atomic_number' : 1,
200
+ 'atomic_mass' : 2.0140
201
+ },
202
+ 'He' : { 'atomic_number' : 2,
203
+ 'atomic_mass' : 4.00260 # He 4
204
+ },
205
+ 'Li' : { 'atomic_number' : 3,
206
+ 'atomic_mass' : 7.016003 # Li 7
207
+ },
208
+ 'Be' : { 'atomic_number' : 4,
209
+ 'atomic_mass' : 9.012182
210
+ },
211
+ 'B' : { 'atomic_number' : 5,
212
+ 'atomic_mass' : 11.009305 # Be 11
213
+ },
214
+ 'C' : { 'atomic_number' : 6,
215
+ 'atomic_mass' : 12.000000 # C 12
216
+ },
217
+ 'N' : { 'atomic_number' : 7,
218
+ 'atomic_mass' : 14.003074 # N 14
219
+ },
220
+ 'O' : { 'atomic_number' : 8,
221
+ 'atomic_mass' : 15.994915 # O 16
222
+ },
223
+ 'F' : { 'atomic_number' : 9,
224
+ 'atomic_mass' : 18.9984032
225
+ },
226
+ 'Ne' : { 'atomic_number' : 10,
227
+ 'atomic_mass' : 19.992435 # Ne 20
228
+ },
229
+ 'Na' : { 'atomic_number' : 11,
230
+ 'atomic_mass' : 22.989767 # Na 23 100% abundance/Nist
231
+ },
232
+ 'S' : { 'atomic_number' : 16,
233
+ 'atomic_mass' : 32.065 # Nist value
234
+ },
235
+ 'I' : { 'atomic_number' : 53,
236
+ 'atomic_mass' : 126.904473 # NIST value
237
+ },
238
+ 'Pb': { 'atomic_number' : 82,
239
+ 'atomic_mass' : 207.976627 # NIST value Pb 208
240
+ }
241
+ }
242
+
243
+
244
+ def factor(unit,unit_type):
245
+ if unit == 'au':
246
+ return 1.0
247
+ if unit_type == 'energy' and unit == 'cm-1':
248
+ return ic2au
249
+ if unit_type == 'energy' and unit == 'ic':
250
+ return ic2au
251
+ if unit_type == 'energy' and unit == 'ev':
252
+ return ev2au
253
+ if unit_type == 'time' and unit == 'fs':
254
+ return fs2au
255
+ if unit_type == 'time' and unit == 'ps':
256
+ return fs2au*1.0e3
257
+ if unit_type == 'efield' and unit == 'va':
258
+ return va2au
259
+ raise ValueError('Conversion of '+unit_type+' from '+unit+' not available')
260
+
261
+
262
+ def numval(inpline,unit_type):
263
+ """
264
+ Return numeric value of input parameter in atomic units
265
+
266
+ Input:
267
+ inpline -- list ['value','unit']
268
+ unit_type -- 'energy', 'time',...
269
+
270
+ It also accepts ['value'], then au are assumed
271
+ """
272
+ if len(inpline) == 2:
273
+ return factor(inpline[1],unit_type) * float( inpline[0] )
274
+ elif len(inpline) == 1:
275
+ return float( inpline[0] )
276
+ else:
277
+ raise ValueError
278
+
279
+
280
+ def filterNum(line):
281
+ """
282
+ Filter a line of numbers and look for occurrences of the exponential
283
+ Fortran format, e.g. -3.45432345-324, which does not contain the E sign for
284
+ the exponential, and add it.
285
+ """
286
+ pass
287
+
288
+
289
+
@@ -0,0 +1,276 @@
1
+ # QuaDLib: QUAntum Dynamics LIBrary for research and methods development
2
+ # Copyright (C) 2018-2026, The Theoretical Chemistry Group, Heidelberg University
3
+ #
4
+ # This software is licensed under the MIT License (https://spdx.org/licenses/MIT.html)
5
+
6
+ import numpy as np
7
+
8
+
9
+ class MultiCounter:
10
+ """Emulate the behaviour of multiple nested do loops
11
+
12
+ Maintains a list of integers that evolve as the indexes
13
+ of a nested "for" loop.
14
+ It may be useful to construct nested "for" loops from which
15
+ the number of nested elements is not known at programming time,
16
+ but at execution time.
17
+ """
18
+
19
+ def __init__(self,length=1,maxiter=1):
20
+ self.pointers=[]
21
+ self.ini_pointers=[]
22
+ self.limits=[]
23
+ self.ini_limits=[]
24
+ self.start=True
25
+ self.end=False
26
+ self.setPointersN(0,length)
27
+ self.setLimitsN(maxiter,length)
28
+
29
+ def __iter__(self):
30
+ return self
31
+
32
+ def __next__(self):
33
+ """Increase the pointers vector and return it
34
+ """
35
+ if self.start:
36
+ self.start = False
37
+ return self.getPointers()
38
+ else:
39
+ self.increase()
40
+ return self.getPointers()
41
+
42
+ def setPointers(self,p):
43
+ """set the list of initial pointers from a given list
44
+ """
45
+ self.pointers=[]
46
+ self.ini_pointers=[]
47
+ for n in p:
48
+ self.pointers.append(n)
49
+ self.ini_pointers.append(n)
50
+
51
+ def setPointersN(self,n=0,nd=1):
52
+ """set the list of initial pointers to a given number N
53
+ n -- number at which the pointers are set
54
+ nd -- length of the vector
55
+ """
56
+ self.pointers=[]
57
+ self.ini_pointers=[]
58
+ for _ in range(nd):
59
+ self.pointers.append(n)
60
+ self.ini_pointers.append(n)
61
+
62
+ def setLimits(self,l):
63
+ """set the list of index limits from a given list
64
+ """
65
+ self.limits=[]
66
+ self.ini_limits=[]
67
+ for n in l:
68
+ self.limits.append(n)
69
+ self.ini_limits.append(n)
70
+
71
+ def setLimitsN(self,n=0,nd=1):
72
+ """set the list of initial limits to a given number N
73
+ n -- number at which the pointers are set
74
+ nd -- length of the vector
75
+ """
76
+ self.limits=[]
77
+ for _ in range(nd):
78
+ self.limits.append(n)
79
+ self.ini_limits.append(n)
80
+
81
+ def setMaxIter(self,l):
82
+ """set the list of maximum iterations per index
83
+ """
84
+ self.limits=[]
85
+ self.ini_limits=[]
86
+ for n in l:
87
+ self.limits.append(n-1)
88
+ self.ini_limits.append(n-1)
89
+
90
+ def setMaxIterN(self,n=1,nd=1):
91
+ """set the list of initial limits to a given number N
92
+ n -- number at which the pointers are set
93
+ nd -- length of the vector
94
+ """
95
+ self.limits=[]
96
+ self.ini_limits=[]
97
+ for _ in range(nd):
98
+ self.limits.append(n-1)
99
+ self.ini_limits.append(n-1)
100
+
101
+ def getPointers(self):
102
+ """return the list of pointers
103
+ """
104
+ return tuple(self.pointers)
105
+
106
+ def getLimits(self):
107
+ """return the list of limits
108
+ """
109
+ return tuple(self.limits)
110
+
111
+ def reset(self):
112
+ """reset the iterator to the initial state
113
+ """
114
+ self.start=True
115
+ self.end=False
116
+ for i in range(len(self.pointers)):
117
+ self.pointers[i] = self.ini_pointers[i]
118
+ self.limits[i] = self.ini_limits[i]
119
+
120
+ def increase(self):
121
+ """increase the list of pointers
122
+ return 0 if the end is reached
123
+ return 1 if succeed
124
+ """
125
+ _increase(self.pointers,self.limits,self.end)
126
+
127
+
128
+ class MultiCombination:
129
+ """
130
+ Iterate over all possible combinations of n indices taken in groups of m
131
+ """
132
+ def __init__(self,n,m):
133
+ self.n = n
134
+ self.m = m
135
+ self.mm = m
136
+ self.ind = np.zeros((m),int)
137
+ self.min = np.zeros((m),int)
138
+ self.max = np.zeros((m),int)
139
+ for k in range(m):
140
+ self.ind[k] = k
141
+ self.min[k] = k
142
+ self.max[k] = n - m + k
143
+ if m > 0:
144
+ self.ind[-1] = self.ind[-1] - 1
145
+
146
+ def __iter__(self):
147
+ return self
148
+
149
+ def __next__(self):
150
+ if (self.ind==self.max).all():
151
+ raise StopIteration
152
+ k = self.m - 1
153
+ while(self.ind[k] == self.max[k]):
154
+ k = k - 1
155
+ self.ind[k] += 1
156
+ for kk in range(k+1,self.m):
157
+ self.ind[kk] = self.ind[kk-1] + 1
158
+ return self.ind
159
+
160
+
161
+ def _increase(p,l,end):
162
+ for i in range(len(p)):
163
+ if i == len(p)-1:
164
+ if p[i] == l[i]:
165
+ raise StopIteration
166
+ if p[i] < l[i]:
167
+ p[i] = p[i]+1
168
+ break
169
+ else:
170
+ p[i] = 0
171
+
172
+
173
+ def decreaseTuple(t):
174
+ """Decrease in 1 the value at every position of a tuple
175
+ """
176
+ l = list(t)
177
+ for i in range(len(l)):
178
+ l[i]=l[i]-1
179
+ return tuple(l)
180
+
181
+ def mapTuple(t1,t2):
182
+ """Return a new tuple with the elements of t1 mapped at the positions
183
+ specified in t2
184
+ """
185
+ l=[]
186
+ for i in t2:
187
+ l.append(t1[i])
188
+ return tuple(l)
189
+
190
+
191
+
192
+ #def excitations(x,m):
193
+ # """
194
+ # Generate excitation indices for x degrees of freedom up to m quanta
195
+
196
+ # x -- integer, number of degrees of freedom
197
+ # m -- integer, maximum quanta of excitation
198
+ # returns an interator object.
199
+ # """
200
+ # if isinstance(x,int):
201
+ # ref = np.ones(x,int)
202
+ # yield ref
203
+ # else:
204
+ # ref = x
205
+ # if ref.sum() - len(ref) == m: return
206
+ # # make excitations
207
+ # exclist = []
208
+ # for i in range(len(ref)):
209
+ # exc = ref.copy()
210
+ # exc[i] = exc[i] + 1
211
+ # exclist.append(exc)
212
+ # yield exc
213
+ # for exc in exclist:
214
+ # for exc2 in excitations(exc,m):
215
+ # yield exc2
216
+
217
+
218
+ def excitations(x,m,n=None,r=None):
219
+ """
220
+ Generate excitation indices for x degrees of freedom up to m quanta
221
+
222
+ x -- integer, number of degrees of freedom
223
+ m -- integer, maximum quanta of excitation
224
+ ----
225
+ n -- tuple with maximum states per DOF (max states = max quanta + 1)
226
+ r -- reference tuple passed recursively
227
+ returns an interator object.
228
+ """
229
+ if r is None:
230
+ ref = _zeroTuple(x)
231
+ yield ref
232
+ else:
233
+ ref = r
234
+ if _sumTuple(ref) == m: return
235
+ # make excitations
236
+ excdict = {}
237
+ for i in range(x):
238
+ exc = list(ref)
239
+ if n is None:
240
+ exc[i] += 1
241
+ elif exc[i] < n[i] - 1:
242
+ exc[i] += 1
243
+ else:
244
+ continue
245
+ texc = tuple(exc)
246
+ excdict[texc] = 0
247
+ yield texc
248
+ for exc in list(excdict.keys()):
249
+ for exc2 in excitations(x,m,n,exc):
250
+ if exc2 not in excdict:
251
+ excdict[exc2] = 0
252
+ yield exc2
253
+
254
+
255
+ def excitationsN(x,m,n=None):
256
+ """
257
+ Generate excitations exactly of m quanta for x degrees of freedom
258
+
259
+ x -- integer, number of degrees of freedom
260
+ m -- integer, exact quanta of excitation
261
+ ----
262
+ n -- tuple with maximum states per DOF (max states = max quanta + 1)
263
+ """
264
+ for e in excitations(x,m,n):
265
+ if _sumTuple(e) == m: yield e
266
+
267
+
268
+
269
+ def _sumTuple(t):
270
+ s = 0
271
+ for e in t: s = s + e
272
+ return s
273
+
274
+ def _zeroTuple(l):
275
+ z = np.zeros(l,int)
276
+ return tuple(z)