@@ -101,8 +101,11 @@ class SOGEnergyFittingNet(LRFittingNet):
101101 Base bandwidth used by SOG parameterization.
102102 M : int
103103 Number of geometric bandwidth levels.
104- n_dl : float
105- NUFFT long-range grid density control factor.
104+ n_dl : float, optional (deprecated)
105+ Legacy grid density control. Use `cubes2_phi_max` instead.
106+ cubes2_phi_max : float, optional
107+ φ = Δ/r_c grid control factor. Auto-defaults from Predescu 2020 Table III
108+ when not specified. See sog lib documentation for recommended values.
106109 remove_self_interaction : bool
107110 If True, remove self interaction term in long-range correction.
108111 external_kspace : bool
@@ -141,7 +144,8 @@ def __init__(
141144 b : float | torch .Tensor | None = None ,
142145 sigma : float | torch .Tensor | None = None ,
143146 M : int | None = None ,
144- n_dl : float | int = 1.0 ,
147+ n_dl : float | int | None = None ,
148+ cubes2_phi_max : float | None = None ,
145149 remove_self_interaction : bool = False ,
146150 external_kspace : bool = False ,
147151 ** kwargs : Any ,
@@ -174,27 +178,25 @@ def __init__(
174178 ** kwargs ,
175179 )
176180 if b is None :
177- b_tensor = torch . as_tensor ( SOG_DEFAULT_B , dtype = dtype , device = device )
181+ b_value = SOG_DEFAULT_B # sog lib default (b=2 )
178182 else :
179183 b_tensor = torch .as_tensor (b , dtype = dtype , device = device )
180- if b_tensor .numel () == 0 :
181- b_tensor = torch .as_tensor (SOG_DEFAULT_B , dtype = dtype , device = device )
182- b_value = float (b_tensor .reshape (- 1 )[0 ].item ())
184+ b_value = float (b_tensor .reshape (- 1 )[0 ].item ())
183185 if b_value <= 0.0 :
184186 raise ValueError ("`b` should be positive." )
185187
186188 if sigma is None :
187- sigma_tensor = torch . as_tensor ( SOG_DEFAULT_SIGMA , dtype = dtype , device = device )
189+ sigma_value = SOG_DEFAULT_SIGMA # will be overridden by sog lib via rcut
188190 else :
189191 sigma_tensor = torch .as_tensor (sigma , dtype = dtype , device = device )
190- if sigma_tensor .numel () == 0 :
191- sigma_tensor = torch .as_tensor (SOG_DEFAULT_SIGMA , dtype = dtype , device = device )
192- sigma_value = float (sigma_tensor .reshape (- 1 )[0 ].item ())
192+ sigma_value = float (sigma_tensor .reshape (- 1 )[0 ].item ())
193193 if sigma_value <= 0.0 :
194194 raise ValueError ("`sigma` should be positive." )
195195
196- m_value = SOG_DEFAULT_M if M is None else int (M )
197- m_value = max (1 , m_value )
196+ if M is None :
197+ m_value = SOG_DEFAULT_M # sog lib default (M=12)
198+ else :
199+ m_value = max (1 , int (M ))
198200
199201 if bandwidth is None :
200202 b_base = torch .tensor (b_value , dtype = dtype , device = device )
@@ -233,11 +235,18 @@ def __init__(
233235 # Store amp as sog-lib internal amplitude (already includes bw^2 factor).
234236 amp_tensor *= bandwidth_tensor
235237
236- n_dl_value = float (n_dl )
237- if (not np .isfinite (n_dl_value )) or n_dl_value <= 0.0 :
238- raise ValueError ("`n_dl` should be a positive finite number." )
238+ # Grid control: prefer cubes2_phi_max, fall back to n_dl (deprecated)
239+ if n_dl is not None :
240+ n_dl_value = float (n_dl )
241+ if (not np .isfinite (n_dl_value )) or n_dl_value <= 0.0 :
242+ raise ValueError ("`n_dl` should be a positive finite number." )
243+ if cubes2_phi_max is not None :
244+ phi_val = float (cubes2_phi_max )
245+ if (not np .isfinite (phi_val )) or phi_val <= 0.0 :
246+ raise ValueError ("`cubes2_phi_max` should be positive finite." )
239247
240- self .n_dl = n_dl_value
248+ self .n_dl = float (n_dl ) if n_dl is not None else None
249+ self .cubes2_phi_max = float (cubes2_phi_max ) if cubes2_phi_max is not None else None
241250 self .amp = torch .nn .Parameter (
242251 amp_tensor ,
243252 requires_grad = bool (self .trainable ),
@@ -282,7 +291,10 @@ def serialize(self) -> dict:
282291 data ["b" ] = float (self .b )
283292 data ["sigma" ] = float (self .sigma )
284293 data ["M" ] = int (self .M )
285- data ["n_dl" ] = self .n_dl
294+ if self .cubes2_phi_max is not None :
295+ data ["cubes2_phi_max" ] = self .cubes2_phi_max
296+ if self .n_dl is not None :
297+ data ["n_dl" ] = self .n_dl # legacy
286298 data ["remove_self_interaction" ] = bool (self .remove_self_interaction )
287299 data ["external_kspace" ] = bool (self .external_kspace )
288300 return data
0 commit comments