@@ -183,22 +183,18 @@ def momentum_kinetic_operator(grid, spinless=False):
183183 return operator
184184
185185
186- def momentum_potential_operator (n_dimensions , grid_length ,
187- length_scale , spinless = False ):
186+ def momentum_potential_operator (grid , spinless = False ):
188187 """Return the potential operator in momentum second quantization.
189188
190189 Args:
191- n_dimensions: An int giving the number of dimensions for the model.
192- grid_length: Int, the number of points in one dimension of the grid.
193- length_scale: Float, the real space length of a box dimension.
190+ grid (Grid): The discretization to use.
194191 spinless: Boole, whether to use the spinless model or not.
195192
196193 Returns:
197194 operator: An instance of the FermionOperator class.
198195 """
199196 # Initialize.
200- n_points = grid_length ** n_dimensions
201- volume = length_scale ** float (n_dimensions )
197+ volume = grid .volume_scale ()
202198 prefactor = 2. * numpy .pi / volume
203199 operator = FermionOperator ((), 0.0 )
204200 if spinless :
@@ -207,14 +203,13 @@ def momentum_potential_operator(n_dimensions, grid_length,
207203 spins = [0 , 1 ]
208204
209205 # Loop once through all plane waves.
210- for omega_indices in itertools .product (range (grid_length ),
211- repeat = n_dimensions ):
212- shifted_omega_indices = [index - grid_length // 2 for
206+ for omega_indices in grid .all_points_indices ():
207+ shifted_omega_indices = [index - grid .length // 2 for
213208 index in omega_indices ]
214209
215210 # Get the momenta vectors.
216211 omega_momenta = momentum_vector (
217- omega_indices , grid_length , length_scale )
212+ omega_indices , grid . length , grid . scale )
218213
219214 # Skip if omega momentum is zero.
220215 if not omega_momenta .any ():
@@ -224,28 +219,27 @@ def momentum_potential_operator(n_dimensions, grid_length,
224219 coefficient = prefactor / \
225220 omega_momenta .dot (omega_momenta )
226221
227- for grid_indices_a in itertools .product (range (grid_length ),
228- repeat = n_dimensions ):
222+ for grid_indices_a in grid .all_points_indices ():
229223 shifted_indices_d = [
230- (grid_indices_a [i ] - shifted_omega_indices [i ]) %
231- grid_length for i in range (n_dimensions )]
232- for grid_indices_b in itertools .product (range (grid_length ),
233- repeat = n_dimensions ):
224+ (grid_indices_a [i ] - shifted_omega_indices [i ]) % grid .length
225+ for i in range (grid .dimensions )]
226+ for grid_indices_b in grid .all_points_indices ():
234227 shifted_indices_c = [
235228 (grid_indices_b [i ] + shifted_omega_indices [i ]) %
236- grid_length for i in range (n_dimensions )]
229+ grid .length
230+ for i in range (grid .dimensions )]
237231
238232 # Loop over spins.
239233 for spin_a in spins :
240234 orbital_a = orbital_id (
241- grid_length , grid_indices_a , spin_a )
235+ grid . length , grid_indices_a , spin_a )
242236 orbital_d = orbital_id (
243- grid_length , shifted_indices_d , spin_a )
237+ grid . length , shifted_indices_d , spin_a )
244238 for spin_b in spins :
245239 orbital_b = orbital_id (
246- grid_length , grid_indices_b , spin_b )
240+ grid . length , grid_indices_b , spin_b )
247241 orbital_c = orbital_id (
248- grid_length , shifted_indices_c , spin_b )
242+ grid . length , shifted_indices_c , spin_b )
249243
250244 # Add interaction term.
251245 if (orbital_a != orbital_b ) and \
@@ -386,10 +380,7 @@ def jellium_model(grid, spinless=False, momentum_space=True):
386380
387381 if momentum_space :
388382 hamiltonian = momentum_kinetic_operator (grid , spinless )
389- hamiltonian += momentum_potential_operator (grid .dimensions ,
390- grid .length ,
391- grid .scale ,
392- spinless )
383+ hamiltonian += momentum_potential_operator (grid , spinless )
393384 else :
394385 hamiltonian = position_kinetic_operator (grid , spinless )
395386 hamiltonian += position_potential_operator (grid .dimensions ,
0 commit comments