@@ -236,42 +236,41 @@ def Epv_atom(mol, mf, atom_index, dm=None):
236236 # Prefactor
237237 fac = (2.2225 * 10 ** (- 14 ) * QW ) / (2 * numpy .sqrt (2 ))
238238
239- # ------------------------------------------------------------
240- # PV operator in AO basis
241- # ------------------------------------------------------------
242-
243- # Get the Fermi Contact integrals for the selected atom
244- fc_ao = fc_integrals (mol , mf , atom_index )
239+ if dm is None :
240+ # ------------------------------------------------------------
241+ # PV operator in AO basis
242+ # ------------------------------------------------------------
245243
246- # Get the Gamma5 Fermi- Contact integrals for the selected atom (in AO basis)
247- gamma5_fc_ao = gamma5_fc_integrals (mol , mf , atom_index )
244+ # Get the Fermi Contact integrals for the selected atom
245+ fc_ao = fc_integrals (mol , mf , atom_index )
248246
249- # ------------------------------------------------------------
250- # Orbital expectation values (4c-DHF or 4c-DFT reference)
251- # ------------------------------------------------------------
247+ # ------------------------------------------------------------
248+ # Orbital expectation values (4c-DHF or 4c-DFT reference)
249+ # ------------------------------------------------------------
252250
253- # Get the positive components of the MO spinors
254- Lo = mf .mo_coeff [:n2c , nNeg :nNeg + nocc ]
255- So = mf .mo_coeff [n2c :, nNeg :nNeg + nocc ]
251+ # Get the positive components of the MO spinors
252+ Lo = mf .mo_coeff [:n2c , nNeg :nNeg + nocc ]
253+ So = mf .mo_coeff [n2c :, nNeg :nNeg + nocc ]
256254
257- # Expectation values
258- expval_LS = numpy .einsum ('ij,ji->i' , Lo .conjugate ().T @ fc_ao [:n2c , n2c :], So )
259- expval_SL = numpy .einsum ('ij,ji->i' , So .conjugate ().T @ fc_ao [n2c :, :n2c ], Lo )
260- expval_perorb = expval_LS + expval_SL
255+ # Expectation values
256+ expval_LS = numpy .einsum ('ij,ji->i' , Lo .conjugate ().T @ fc_ao [:n2c , n2c :], So )
257+ expval_SL = numpy .einsum ('ij,ji->i' , So .conjugate ().T @ fc_ao [n2c :, :n2c ], Lo )
258+ expval_perorb = expval_LS + expval_SL
261259
262260 # ------------------------------------------------------------
263261 # Density matrix contraction
264262 # ------------------------------------------------------------
265263
266- expval_dm = None
267-
268264 if dm is not None :
269265
270266 # Positive-energy MO coefficient matrix
271267 C = mf .mo_coeff [:, nNeg :]
272268
273269 nmo_pos = C .shape [1 ]
274270
271+ # Get the Gamma5 Fermi-Contact integrals for the selected atom (in AO basis)
272+ gamma5_fc_ao = gamma5_fc_integrals (mol , mf , atom_index )
273+
275274 # Transform operator AO -> MO
276275 # Operator transformation:
277276 #
@@ -309,10 +308,12 @@ def Epv_atom(mol, mf, atom_index, dm=None):
309308
310309 # Total expectation value
311310 # E = Tr(𝑫 h)
312- expval_dm = numpy .trace (dm_mo @ gamma5_fc_mo )
311+ # expval_dm = numpy.trace(dm_mo @ gamma5_fc_mo)
313312
314313 # Orbital decomposition in MO basis
315- expval_dm_perorb = numpy .einsum (
314+ # For correlated densities (MP2/CCSD), the orbital decomposition
315+ # is representation-dependent. Only the total trace is invariant.
316+ expval_perorb = numpy .einsum (
316317 'ij,ji->i' ,
317318 gamma5_fc_mo ,
318319 dm_mo
@@ -323,12 +324,7 @@ def Epv_atom(mol, mf, atom_index, dm=None):
323324 # Return
324325 # ------------------------------------------------------------
325326
326- if expval_dm is None :
327- return fac * expval_perorb .real
328-
329- else :
330- return fac * expval_dm_perorb .real
331-
327+ return fac * expval_perorb .real
332328
333329
334330
0 commit comments