Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sad fix #35

Merged
merged 11 commits into from
May 2, 2024
8 changes: 7 additions & 1 deletion qstack/spahm/guesses.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@ def SAD(mol, func):
mf = pyscf.dft.RKS(mol)
mf.xc = func
vhf = mf.get_veff(dm=dm)
fock = hc + vhf
if vhf.ndim == 2:
fock = hc + vhf
else:
fock = hc + vhf[0]
if not numpy.array_equal(vhf[0], vhf[1]):
msg = f'The effective potential ({func}) return different alpha and beta matrix components from atomicHF DM'
warnings.warn(msg)
return fock

def SAP(mol, *_):
Expand Down
Binary file added tests/data/SPAHM_a_H2O/X_H2O-RC_SAD.npy
Binary file not shown.
Binary file added tests/data/SPAHM_a_H2O/X_H2O_SAD.npy
Binary file not shown.
24 changes: 0 additions & 24 deletions tests/test_atomic_spahm.py

This file was deleted.

6 changes: 4 additions & 2 deletions tests/test_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ def test_avg_kernel():

path = os.path.dirname(os.path.realpath(__file__))
X_dir = os.path.join(path, 'data/SPAHM_a_H2O/')
mols = [np.load(os.path.join(X_dir, f), allow_pickle=True) for f in os.listdir(X_dir) if os.path.isfile(os.path.join(X_dir,f))]
mollist = [os.path.join(X_dir, s) for s in ['X_H2O.npy', 'X_rotated_H2O.npy', 'X_H2O_dist.npy']]
mols = [np.load(f, allow_pickle=True) for f in mollist]
K = kernel.kernel(mols, akernel='L', gkernel='avg', sigma=1.0)

true_K = np.array( [[1. , 1. , 0.79179528], \
Expand All @@ -22,7 +23,8 @@ def test_avg_kernel():
def test_rem_kernel():
path = os.path.dirname(os.path.realpath(__file__))
X_dir = os.path.join(path, 'data/SPAHM_a_H2O/')
mols = [np.load(os.path.join(X_dir, f), allow_pickle=True) for f in os.listdir(X_dir) if os.path.isfile(os.path.join(X_dir,f))]
mollist = [os.path.join(X_dir, s) for s in ['X_H2O.npy', 'X_rotated_H2O.npy', 'X_H2O_dist.npy']]
mols = [np.load(f, allow_pickle=True) for f in mollist]
K = kernel.kernel(mols, akernel='L', gkernel='rem', sigma=1.0, gdict={'alpha':1.0, 'normalize':1})

true_K = np.array( [[1. , 0.6528238, 1. ], \
Expand Down
51 changes: 51 additions & 0 deletions tests/test_spahm_a.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env python3

import os
import numpy as np
from qstack import compound
from qstack.spahm.rho import atom


def test_water():
path = os.path.dirname(os.path.realpath(__file__))
mol = compound.xyz_to_mol(path+'/data/H2O.xyz', 'minao', charge=0, spin=None)

X = atom.get_repr(mol, ["H", "O"], 0, None, dm=None,
guess='LB', model='lowdin-long-x', auxbasis='ccpvdzjkfit')

X_true = np.load(path+'/data/SPAHM_a_H2O/X_H2O.npy', allow_pickle=True)
assert(X.shape == X_true.shape)
for a, a_true in zip(X, X_true):
assert(a[0] == a_true[0]) # atom type
assert(np.linalg.norm(a[1]-a_true[1]) < 1e-08) # atom representations

def test_water_SAD_guess_open_shell():
path = os.path.dirname(os.path.realpath(__file__))
mol = compound.xyz_to_mol(path+'/data/H2O.xyz', 'sto3g', charge=1, spin=1) ## test breaks when effective open-shell caluclation is needed

Xsad = atom.get_repr(mol, ["H", "O"], 1, 1, dm=None,
xc = 'hf', guess='sad', model='lowdin-long-x', auxbasis='ccpvdzjkfit')
Xtrue = np.load(path+'/data/SPAHM_a_H2O/X_H2O-RC_SAD.npy', allow_pickle=True)
assert(Xsad.shape == Xtrue.shape)
for a, a_true in zip(Xsad, Xtrue):
assert(a[0] == a_true[0]) # atom type
assert(np.linalg.norm(a[1]-a_true[1]) < 1e-08) # atom representations

def test_water_SAD_guess_close_shell():
path = os.path.dirname(os.path.realpath(__file__))
mol = compound.xyz_to_mol(path+'/data/H2O.xyz', 'sto3g', charge=0, spin=0) ## test breaks when effective open-shell caluclation is needed

Xsad = atom.get_repr(mol, ["H", "O"], 0, None, dm=None,
xc = 'hf', guess='sad', model='lowdin-long-x', auxbasis='ccpvdzjkfit')
Xtrue = np.load(path+'/data/SPAHM_a_H2O/X_H2O_SAD.npy', allow_pickle=True)
assert(Xsad.shape == Xtrue.shape)
for a, a_true in zip(Xsad, Xtrue):
assert(a[0] == a_true[0]) # atom type
assert(np.linalg.norm(a[1]-a_true[1]) < 1e-08) # atom representations



if __name__ == '__main__':
test_water()
test_water_SAD_guess_close_shell()
test_water_SAD_guess_open_shell()
Loading