@@ -2421,6 +2421,49 @@ def test_as_scanner_runs_energy_scan_with_fixed_gas_model(self):
24212421 self .assertIn ("GASSCF" , scanner .__class__ .__name__ )
24222422 self .assertIs (scanner .as_scanner (), scanner )
24232423
2424+ def test_repeated_kernel_and_scanner_spin_results_pass_sanity (self ):
2425+ mol = gto .M (
2426+ atom = "H 0 0 0; H 0 0 0.9; H 0 0 2.2; H 0 0 3.1" ,
2427+ basis = "sto-3g" , verbose = 0 )
2428+ mf = scf .RHF (mol ).run ()
2429+ for spin_penalty in (False , True ):
2430+ with self .subTest (spin_penalty = spin_penalty ):
2431+ mc = gasscf .GASSCF (
2432+ mf , 2 , (1 , 1 ), gas_orbs = (2 ,), ncore = 1 )
2433+ mc .max_cycle_macro = 1
2434+ mc .max_cycle_micro = 1
2435+ mc .canonicalization = False
2436+ if spin_penalty :
2437+ mc .fix_spin_ (shift = .2 , ss = 0 )
2438+ mc .verbose = 4
2439+ mc .stdout = io .StringIO ()
2440+ errors = io .StringIO ()
2441+ # Do not let earlier tests hide a warning through warn-once.
2442+ with mock .patch .dict (gasscf .lib .misc ._warn_once_registry ,
2443+ {}, clear = True ), \
2444+ mock .patch .object (sys , "stderr" , errors ):
2445+ mc .kernel (mf .mo_coeff )
2446+ mc .kernel (mc .mo_coeff , mc .ci )
2447+ scanner = mc .as_scanner ()
2448+ for distance in (.92 , .94 ):
2449+ energy = scanner (
2450+ "H 0 0 0; H 0 0 %s; H 0 0 2.2; H 0 0 3.1"
2451+ % distance )
2452+ self .assertTrue (numpy .isfinite (energy ))
2453+ penalty = scanner .e_spin_penalty
2454+ if spin_penalty :
2455+ self .assertIsNotNone (penalty )
2456+ else :
2457+ self .assertIsNone (penalty )
2458+ penalty = 0.
2459+ self .assertAlmostEqual (
2460+ scanner .e_tot_physical + penalty , energy , 10 )
2461+ self .assertAlmostEqual (
2462+ scanner .e_gas_physical + penalty ,
2463+ scanner .e_gas , 10 )
2464+ self .assertNotIn ("does not have attributes" , errors .getvalue ())
2465+ self .assertNotIn ("does not have attributes" , mc .stdout .getvalue ())
2466+
24242467 def test_as_scanner_rejects_changed_extrasym_constraint (self ):
24252468 mol = gto .M (
24262469 atom = "H 0 0 0; H 0 0 0.9; H 0 0 2.2; H 0 0 3.1" ,
0 commit comments