Skip to content

Commit cc83b05

Browse files
author
kosm6966
committed
Reduced doc strings further
1 parent 0353355 commit cc83b05

File tree

2 files changed

+14
-341
lines changed

2 files changed

+14
-341
lines changed

pyscf/occri/__init__.py

Lines changed: 8 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,6 @@
11
"""
2-
OCCRI (Occupied Orbital Coulomb Resolution of Identity) Interface for PySCF
3-
4-
This module provides an efficient implementation of the resolution-of-identity (RI)
5-
approximation for computing exact exchange in periodic systems using PySCF. The
6-
method is particularly effective for systems requiring many k-points and uses
7-
FFT-based techniques for optimal performance.
8-
9-
The OCCRI approach exploits the fact that only occupied orbitals contribute to
10-
the exchange interaction, significantly reducing computational cost compared to
11-
traditional methods while maintaining chemical accuracy.
12-
13-
Key Features:
14-
- Efficient exchange matrix evaluation using occupied orbital RI
15-
- FFT-based Coulomb potential evaluation in real space
16-
- OpenMP parallelization through C extension
17-
- Support for periodic boundary conditions (3D systems)
18-
- Compatible with RHF, UHF, RKS, UKS, and their k-point variants
19-
20-
Theory:
21-
The OCCRI method approximates the exchange matrix elements using:
22-
K_μν ≈ Σ_P C_μP W_PP' C_νP'
23-
24-
where C_μP are fitting coefficients related to occupied orbitals and
25-
W_PP' represents the Coulomb interaction in the auxiliary basis.
26-
27-
Dependencies:
28-
Required:
29-
- PySCF >= 2.0
30-
- NumPy >= 1.17
31-
- SciPy >= 1.5
32-
33-
Optional (for optimal performance):
34-
- FFTW3 (for optimized FFT operations)
35-
- BLAS (for optimized linear algebra)
36-
- OpenMP (for parallelization)
37-
38-
Build Configuration:
39-
The module automatically detects available dependencies and falls back to
40-
pure Python implementation if the optimized C extension cannot be built.
41-
42-
To control the build process:
43-
- Set BUILD_OCCRI=OFF to disable C extension build entirely
44-
- Set CMAKE_CONFIGURE_ARGS for additional CMake options
45-
46-
Example:
47-
BUILD_OCCRI=OFF pip install . # Force Python-only build
48-
pip install . # Auto-detect dependencies
49-
2+
OCCRI (Occupied Orbital Coulomb Resolution of Identity) for efficient
3+
exact exchange evaluation in periodic systems.
504
"""
515

526
import ctypes
@@ -171,24 +125,7 @@ def log_mem(mydf):
171125

172126

173127
def make_natural_orbitals(mydf, dms):
174-
"""
175-
Parameters:
176-
-----------
177-
cell : pyscf.pbc.gto.Cell
178-
Unit cell object containing atomic and basis set information
179-
dms : ndarray
180-
Density matrix or matrices in AO basis, shape (..., nao, nao)
181-
kpts : ndarray, optional
182-
k-point coordinates. If None, assumes Gamma point calculation
183-
184-
Returns:
185-
--------
186-
tuple of ndarray
187-
(mo_coeff, mo_occ) where:
188-
- mo_coeff: Natural orbital coefficients, same shape as dms
189-
mo_occ[n, k, i] = occupation of orbital i at k-point k, spin n
190-
Real values ordered from highest to lowest occupation
191-
"""
128+
"""Construct natural orbitals from density matrix"""
192129
# print("Building Orbitals")
193130
cell = mydf.cell
194131
kpts = mydf.kpts
@@ -217,34 +154,7 @@ def make_natural_orbitals(mydf, dms):
217154

218155

219156
class OCCRI(pyscf.pbc.df.fft.FFTDF):
220-
"""
221-
Occupied Orbital Coulomb Resolution of Identity (OCCRI) density fitting class.
222-
223-
This class implements the OCCRI method for efficient evaluation of exact exchange
224-
in periodic systems. It extends PySCF's FFTDF class to provide optimized exchange
225-
matrix construction using the resolution of identity approximation restricted to
226-
occupied orbitals.
227-
228-
The method is particularly efficient for systems with many k-points and provides
229-
significant speedup over traditional exact exchange implementations while
230-
maintaining chemical accuracy.
231-
232-
Attributes:
233-
method (str): The type of mean-field method being used (e.g., 'rhf', 'uhf', 'rks', 'uks')
234-
cell: The unit cell object
235-
kmesh (list): k-point mesh dimensions [nkx, nky, nkz]
236-
kpts (ndarray): Array of k-point coordinates
237-
238-
Example:
239-
>>> from pyscf.pbc import gto, scf
240-
>>> from pyscf.occri import OCCRI
241-
>>>
242-
>>> cell = gto.Cell()
243-
>>> # ... set up cell ...
244-
>>> mf = scf.RHF(cell)
245-
>>> mf.with_df = OCCRI(mf)
246-
>>> energy = mf.kernel()
247-
"""
157+
"""Occupied Orbital Coulomb Resolution of Identity density fitting"""
248158

249159
def __init__(
250160
self,
@@ -253,24 +163,7 @@ def __init__(
253163
disable_c=False,
254164
**kwargs,
255165
):
256-
"""
257-
Initialize the OCCRI density fitting object.
258-
259-
Parameters:
260-
-----------
261-
mydf : SCF object
262-
The self-consistent field object (RHF, UHF, RKS, UKS, or k-point variants)
263-
kmesh : list of int, optional
264-
k-point mesh dimensions [nkx, nky, nkz]. Default is [1,1,1] (Gamma point)
265-
**kwargs : dict
266-
Additional keyword arguments passed to parent FFTDF class
267-
268-
Raises:
269-
-------
270-
AssertionError
271-
If the method type is not supported (must be one of:
272-
'hf', 'uhf', 'khf', 'kuhf', 'rks', 'uks', 'krks', 'kuks')
273-
"""
166+
"""Initialize OCCRI density fitting object"""
274167

275168
mydf._is_mem_enough = lambda: False
276169
# NOTE: PySCF calls get_jk -> get_jk passing dm.reshape(...), dropping the mo_coeff.
@@ -331,41 +224,7 @@ def get_jk(
331224
exxdiv="ewald",
332225
**kwargs,
333226
):
334-
"""
335-
Compute Coulomb (J) and exchange (K) matrices using OCCRI method.
336-
337-
This method combines the efficient J matrix evaluation from PySCF's FFTDF
338-
with the optimized K matrix evaluation from OCCRI. The exchange part uses
339-
the occupied orbital resolution of identity approach for improved performance.
340-
341-
Parameters:
342-
-----------
343-
dm : ndarray
344-
Density matrix or matrices in AO basis
345-
hermi : int, optional
346-
Hermiticity flag (1 for Hermitian, 0 for non-Hermitian). Default is 1
347-
kpt : ndarray, optional
348-
Single k-point (not used in current implementation)
349-
kpts_band : ndarray, optional
350-
k-points for band structure (not used in current implementation)
351-
with_j : bool, optional
352-
Whether to compute Coulomb matrix. Default inferred from context
353-
with_k : bool, optional
354-
Whether to compute exchange matrix. Default inferred from context
355-
omega : float, optional
356-
Range separation parameter (not used in current implementation)
357-
exxdiv : str, optional
358-
Treatment of exchange divergence. 'ewald' adds Ewald correction
359-
**kwargs : dict
360-
Additional keyword arguments
361-
362-
Returns:
363-
--------
364-
tuple of ndarray
365-
(vj, vk) where:
366-
- vj: Coulomb matrix (or None if with_j=False)
367-
- vk: Exchange matrix (or None if with_k=False)
368-
"""
227+
"""Compute J and K matrices using OCCRI"""
369228
if cell is None:
370229
cell = self.cell
371230
if dm is None:
@@ -430,13 +289,9 @@ def __del__(self):
430289
return
431290

432291
def copy(self):
433-
"""
434-
Create a shallow copy of the OCCRI object.
435-
"""
292+
"""Create a shallow copy"""
436293
return self.view(self.__class__)
437294

438295
def get_keyword_arguments(self):
439-
"""
440-
Retrieve all keyword arguments for the OCCRI object.
441-
"""
296+
"""Get keyword arguments"""
442297
return {key: value for key, value in self.__dict__.items() if key != "cell"}

0 commit comments

Comments
 (0)