diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..bd6697f --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,29 @@ +name: CI + +#FIXME: workflow dependency not working on non-default branch? +#on: +# workflow_run: +# workflows: +# - Lint +# types: +# - completed +on: + - push + - pull_request + +jobs: + linux-build: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: ["3.10","3.12"] + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - name: Install + run: ./.github/workflows/run_ci.sh + - name: Test with pytest + run: ./.github/workflows/test.sh diff --git a/.github/workflows/run_ci.sh b/.github/workflows/run_ci.sh new file mode 100755 index 0000000..24084fa --- /dev/null +++ b/.github/workflows/run_ci.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +set -e + +sudo apt-get -qq install \ + gcc \ + libblas-dev \ + cmake \ + curl + +python -m pip install --upgrade pip +pip install pytest +pip install . + + diff --git a/.github/workflows/test.sh b/.github/workflows/test.sh new file mode 100755 index 0000000..711cb7b --- /dev/null +++ b/.github/workflows/test.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +set -e + +cd pyscf/prop/nmr +pytest . diff --git a/pyscf/prop/nmr/test/test_hf_msc.py b/pyscf/prop/nmr/test/test_hf_msc.py index e296922..f11a39a 100644 --- a/pyscf/prop/nmr/test/test_hf_msc.py +++ b/pyscf/prop/nmr/test/test_hf_msc.py @@ -46,6 +46,14 @@ def finger(mat): return abs(mat).sum() +def proc_nmr_tensor(tsr): + tsr = (tsr + tsr.T) / 2 + eigs = numpy.linalg.eigvalsh(tsr) + eigs.sort() + nmr_iso = eigs.sum() / 3 + nmr_ani = eigs[2] - (eigs[0] + eigs[1]) / 2 + return nmr_iso, nmr_ani + class KnowValues(unittest.TestCase): def test_nr_common_gauge_ucpscf(self): m = nmr.RHF(nrhf) @@ -137,6 +145,13 @@ def test_make_h10(self): h1 = nmr.dhf.make_h10(mol, dm0, gauge_orig=(0,0,0), mb='RKB') self.assertAlmostEqual(numpy.linalg.norm(h1), 7.3636964305440609, 8) + def test_nr_giao_uhf(self): + mol_spin2 = mol.copy().set(spin=2) + nruhf = mol_spin2.UHF().set(conv_tol=1e-12).run() + m = nmr.UHF(nruhf) + msc = m.shielding() + self.assertAlmostEqual(proc_nmr_tensor(msc[1])[0], -13739.422178310575, 4) + if __name__ == "__main__": diff --git a/pyscf/prop/nmr/uhf.py b/pyscf/prop/nmr/uhf.py index 223e166..34c94cf 100644 --- a/pyscf/prop/nmr/uhf.py +++ b/pyscf/prop/nmr/uhf.py @@ -200,8 +200,11 @@ def vind(mo1): v1ao = vresp(dm1) v1a = [reduce(numpy.dot, (mo_coeff[0].T.conj(), x, orboa)) for x in v1ao[0]] v1b = [reduce(numpy.dot, (mo_coeff[1].T.conj(), x, orbob)) for x in v1ao[1]] - v1mo = numpy.hstack((numpy.asarray(v1a), - numpy.asarray(v1b))) + nset = mo1a.shape[0] + v1mo = numpy.hstack((numpy.asarray(v1a).reshape(nset,-1), + numpy.asarray(v1b).reshape(nset,-1))) + # v1mo = numpy.hstack((numpy.asarray(v1a), + # numpy.asarray(v1b))) return v1mo.ravel() return vind diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..5f411f6 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,5 @@ +[pytest] +addopts = + -k "not _high_cost and not _skip" + --ignore=examples + --ignore-glob="*_slow*.py"