Skip to content

Commit 7681d8a

Browse files
committed
Fix a5c99ed: add l=3,4
TODO: open-shell MOs
1 parent 534ae7e commit 7681d8a

File tree

19 files changed

+5718
-22
lines changed

19 files changed

+5718
-22
lines changed

qstack/io/turbomole.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def read_mos(mol, fname, reorder_dest='pyscf'):
2626
RuntimeError: If the file format is invalid or unsupported.
2727
"""
2828
with open(fname) as f:
29-
lines = f.readlines()
29+
lines = [*filter(lambda x: not x.strip().startswith('#'), f.readlines())]
3030

3131
l0 = lines[0].split()
3232
if l0[0] != '$scfmo':

qstack/reorder.py

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
from .constants import XYZ
2727

2828

29+
_TURBOMOLE_MAX_L = 4
30+
31+
2932
class MagneticOrder:
3033
"""Class to handle ordering conventions of atomic orbitals.
3134
@@ -123,12 +126,13 @@ def _conv2gpr_idx(nao, l_slices, convention):
123126
return idx
124127

125128

126-
def _get_idx(l_shells, m, convention):
129+
def _get_idx(l, m, shell_start, convention):
127130
"""Get the indices and sign multipliers to convert from a given convention to SA-GPR.
128131
129132
Args:
130-
l_shells (iterable): List of angular momentum quantum numbers per shell.
133+
l (numpy.ndarray): Array of magnetic quantum numbers per atomic orbital.
131134
m (numpy.ndarray): Array of magnetic quantum numbers per atomic orbital.
135+
shell_start (numpy.ndarray): Starting AO indices for each shell (2*l+1 block).
132136
convention (str): Ordering convention.
133137
134138
Returns:
@@ -137,31 +141,35 @@ def _get_idx(l_shells, m, convention):
137141
signs: Sign multipliers to convert from given convention to SA-GPR.
138142
139143
Raises:
140-
NotImplementedError: If the specified convention is not implemented or if l>2 for Turbomole convention.
144+
NotImplementedError: If the specified convention is not implemented or if l>4 for Turbomole convention.
141145
"""
142146
convention = convention.lower()
147+
l_shells = l[shell_start]
143148
l_slices = slice_generator(l_shells, inc=lambda l: 2*l+1)
144149

145150
if convention not in _conventions:
146151
errstr = f'Conversion to/from the {convention} convention is not implemented'
147152
raise NotImplementedError(errstr)
148153

149-
if convention == 'turbomole':
150-
#TODO: check signs:
151-
# l=3 m=-3
152-
# l=4 m=-3
153-
# l=4 m=2
154-
lmax = max(l_shells)
155-
if lmax>=3:
156-
raise NotImplementedError("Phase convention differences orbitals with l>2 are not implemented yet. You can contribute by adding them to the _turbomole2gpr_idx function.")
154+
idx = _conv2gpr_idx(len(l), l_slices, convention)
157155

158-
idx = _conv2gpr_idx(len(m), l_slices, convention)
156+
signs = np.ones_like(idx)
159157
if convention == 'orca':
160-
signs = np.ones_like(idx)
161158
signs[np.where(np.abs(m)>=3)] = -1 # in pyscf order
162-
signs[idx] = np.copy(signs) # in orca order. copy for numpy < 2
163-
else:
164-
signs = np.ones_like(m)
159+
elif convention == 'turbomole':
160+
"""
161+
To get this, use `infsao` command of Turbomole's `define` program.
162+
It will print AO order and equations for each spherical harmonic.
163+
Check if the phase convention is the same we use
164+
(https://en.wikipedia.org/wiki/Table_of_spherical_harmonics#Real_spherical_harmonics).
165+
"""
166+
if max(l)>_TURBOMOLE_MAX_L:
167+
raise NotImplementedError(f"Phase convention differences orbitals with l>{_TURBOMOLE_MAX_L} are not implemented yet. You can contribute!")
168+
signs[(l==3) & (m==-3)] = -1 # in pyscf order
169+
signs[(l==4) & (m==-3)] = -1 # in pyscf order
170+
signs[(l==4) & (m== 2)] = -1 # in pyscf order
171+
signs[idx] = np.copy(signs) # in convention order. copy for numpy < 2
172+
165173
return idx, signs
166174

167175

@@ -196,10 +204,9 @@ def reorder_ao(mol, vector, src='pyscf', dest='gpr'):
196204
return vector
197205

198206
(_, l, m), shell_start = basis_flatten(mol, return_both=False, return_shells=True)
199-
l_shells = l[shell_start]
200207

201-
idx_src, sign_src = _get_idx(l_shells, m, src)
202-
idx_dest, sign_dest = _get_idx(l_shells, m, dest)
208+
idx_src, sign_src = _get_idx(l, m, shell_start, src)
209+
idx_dest, sign_dest = _get_idx(l, m, shell_start, dest)
203210

204211
if vector is None:
205212
idx = np.arange(mol.nao)
File renamed without changes.

0 commit comments

Comments
 (0)