BoothGroup / Vayesta

A Python package for wave function-based quantum embedding
Apache License 2.0
33 stars 8 forks source link

PBC error when using space_group_symmetry=True #106

Closed cjcscott closed 1 year ago

cjcscott commented 1 year ago

I've run into an issue when performing PBC calculations and enforcing space_group_symmetry=True where initialisation of an IAO fragmentation fails. Minimal example is

import pyscf.gto
import pyscf.lo
import pyscf.pbc
import numpy as np
import vayesta.ewf

cell = pyscf.pbc.gto.Cell()
cell.atom = ['He 0.0 0.0 0.0']
cell.a = 1.4 * np.eye(3)
cell.basis = 'def2-svp'
cell.output = 'pyscf.out'
cell.space_group_symmetry = True
cell.symmorphic = True
cell.build()

kpts = cell.make_kpts([2,2,2], space_group_symmetry=True, time_reversal_symmetry=True, symmorphic=True)

# Hartree-Fock with k-points
mf = pyscf.pbc.scf.KRHF(cell, kpts)
mf = mf.density_fit(auxbasis='def2-svp-ri')
mf.kernel()

emb = vayesta.ewf.EWF(mf)
with emb.iao_fragmentation() as f:
    f.add_atomic_fragment([0])

emb.kernel()

resulting in the error

          |  IAO:  computational basis= def2-svp  minimal reference basis= minao (automatically chosen)
Traceback (most recent call last):
  File "/users/k1819443/code/graphene/minex_vayesta_issue.txt", line 25, in <module>
    with emb.iao_fragmentation() as f:
  File "/scratch/users/k1819443/code/Vayesta/vayesta/core/qemb/qemb.py", line 1387, in iao_fragmentation
    return IAO_Fragmentation(self, minao=minao, **kwargs)
  File "/scratch/users/k1819443/code/Vayesta/vayesta/core/fragmentation/__init__.py", line 28, in IAO_Fragmentation
    return IAO_Fragmentation_RHF(emb, *args, **kwargs)
  File "/scratch/users/k1819443/code/Vayesta/vayesta/core/fragmentation/iao.py", line 43, in __init__
    self.refmol = pyscf.lo.iao.reference_mol(self.mol, minao=self.minao)
  File "/scratch/users/k1819443/miniconda3/envs/vayesta/lib/python3.10/site-packages/pyscf/lo/iao.py", line 135, in reference_mol
    pmol.build(False, False, basis=minao)
  File "/scratch/users/k1819443/miniconda3/envs/vayesta/lib/python3.10/site-packages/pyscf/pbc/gto/cell.py", line 1516, in build
    _lattice_symm.build(space_group_symmetry=True,
  File "/scratch/users/k1819443/miniconda3/envs/vayesta/lib/python3.10/site-packages/pyscf/pbc/symm/symmetry.py", line 176, in build
    self.spacegroup = space_group.SpaceGroup(cell).build(dump_info=False)
  File "/scratch/users/k1819443/miniconda3/envs/vayesta/lib/python3.10/site-packages/pyscf/pbc/symm/space_group.py", line 302, in build
    self.ops = geom.search_space_group_ops(self.cell, tol=self.symprec)
  File "/scratch/users/k1819443/miniconda3/envs/vayesta/lib/python3.10/site-packages/pyscf/pbc/symm/geom.py", line 81, in search_space_group_ops
    atmgrp = mole.atom_types(cell._atom, magmom=cell.magmom)
  File "/scratch/users/k1819443/miniconda3/envs/vayesta/lib/python3.10/site-packages/pyscf/gto/mole.py", line 308, in atom_types
    uniq_mag = np.unique(magmom[idx])
IndexError: index 1 is out of bounds for axis 0 with size 1

This seems to be a pyscf issue with generating IAOs for a supercell- I'm going to post an issue there with a corresponding minimal example.

cjcscott commented 1 year ago

Added error message on how to solve this in #107 ; can't be fixed on our end for now.