QMCPACK / QMCPACK/qmcpack

Pyscf UCAS wavefunctions unsupported by converter (partial fix suggested)

Open
#5,589 3 comments 0 reactions 0 assignees View on GitHub
bug converter enhancement stale
Dominant language
C++
Stars
403
Forks
154
Avg merge
1d 12h
Merged PRs (30d)
82

Description

**Describe the bug**
Pyscf UCAS wavefunctions are not supported by the PyscfToQmcpack converter.

**To Reproduce**
call `PyscfToQmcpack.savetoqmcpack` with a UCAS object (UCASCI or UCASSCF)

**Expected behavior**
generate hdf5 orbs and multidet file for qmcpack

I discussed this with @jtkrogel and @anbenali on Slack, but I wanted to mention it here in case that disappears beyond the 90-day time horizon.
There've been similar instances where we've found a temporary working solution to a problem and then needed to solve the same thing again several months/years later.

Here is a tarball containing some example inputs from @jtkrogel that I modified (along with using a modified converter) to produce hdf5 orbs and multidets for QMCPACK (also included here): [nitrogen_uhf_ucas.tar.gz](https://github.com/user-attachments/files/21691228/nitrogen_uhf_ucas.tar.gz)

Here is a diff of some of the needed changes in the converter: [PyscfToQmcpack_UCAS.patch](https://github.com/user-attachments/files/21690680/PyscfToQmcpack_UCAS_patch.txt)

Summary of changes:
- detect `UCASCI` and `UCASSCF` as unrestricted
- detect `UCASCI` and `UCASSCF` as multidet
- modify the way multidet objects are handled to more closely mirror the way we handle `Restricted` and `PBC`
- correctly handle `nstate` in unrestricted multidet h5 generation (also see note below about this)

Remaining issues:
- the converter still expects the CAS object to have `mo_energy`. This isn't present in UCAS objects.
- We should handle this in the converter, but a hacky workaround is to assign it before calling the converter.
Something like:
```
mycas.mo_energy = ucas_fock_diag(mycas)
```
with this function to compute diagonal elements of the "fock matrix" (not sure if this is even correct; it's just a quick fix, so use at your own risk)
```
def ucas_fock_diag(mc):
rdms=mc.make_rdm1s()
vj,vk=mc._scf.get_jk(mc.mol,rdms)
veff=vj[0]+vj[1]-vk
fock = mc.get_hcore() + veff
c = np.array(mc.mo_coeff) # can use mc.mo_coeff for UCASCI, but for UCASSCF it's a tuple, so convert to array
fock_mo_diag = np.einsum('sui,suv,svj->si',c.conj(),fock,c)
return fock_mo_diag
```
- somewhat related to this is the way we assign `MultiDet/nstate` in the generated hdf5 file. It looks like it's being set as the number of AOs [here](https://github.com/QMCPACK/qmcpack/blob/7f1dd802c7d5c003c79779c3529676a04d7539df/src/QMCTools/PyscfToQmcpack.py#L623), but I would have thought that this would be the number of MOs (i.e. the space corresponding to the occupation bitstrings). It might be fine already, but I noticed it while applying the UCAS fixes and thought it was worth checking

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.