3838 check_operation_applied ,
3939)
4040from deepmd .dpmodel .utils import (
41- build_neighbor_list ,
42- extend_coord_with_ghosts ,
41+ DefaultNeighborList ,
42+ NeighborList ,
4343 nlist_distinguish_types ,
44- normalize_coord ,
4544)
4645from deepmd .utils .path import (
4746 DPPath ,
@@ -78,6 +77,7 @@ def model_call_from_call_lower(
7877 do_atomic_virial : bool = False ,
7978 coord_corr_for_virial : Array | None = None ,
8079 charge_spin : Array | None = None ,
80+ neighbor_list : NeighborList | None = None ,
8181) -> dict [str , Array ]:
8282 """Return model prediction from lower interface.
8383
@@ -96,6 +96,12 @@ def model_call_from_call_lower(
9696 atomic parameter. nf x nloc x nda
9797 do_atomic_virial
9898 If calculate the atomic virial.
99+ neighbor_list
100+ The neighbor-list construction strategy. ``None`` uses the default
101+ all-pairs builder (:class:`DefaultNeighborList`), reproducing the
102+ historical behavior. An alternative strategy (e.g. an O(N) cell list)
103+ may be injected to speed up neighbor-list construction; it returns the
104+ same extended representation, so model outputs are unchanged.
99105
100106 Returns
101107 -------
@@ -107,26 +113,9 @@ def model_call_from_call_lower(
107113 nframes , nloc = atype .shape [:2 ]
108114 cc , bb , fp , ap = coord , box , fparam , aparam
109115 del coord , box , fparam , aparam
110- if bb is not None :
111- coord_normalized = normalize_coord (
112- cc .reshape (nframes , nloc , 3 ),
113- bb .reshape (nframes , 3 , 3 ),
114- )
115- else :
116- xp = array_api_compat .array_namespace (cc )
117- coord_normalized = xp .reshape (cc , (nframes , nloc , 3 ))
118- extended_coord , extended_atype , mapping = extend_coord_with_ghosts (
119- coord_normalized , atype , bb , rcut
120- )
121- nlist = build_neighbor_list (
122- extended_coord ,
123- extended_atype ,
124- nloc ,
125- rcut ,
126- sel ,
127- # types will be distinguished in the lower interface,
128- # so it doesn't need to be distinguished here
129- distinguish_types = False ,
116+ builder = neighbor_list if neighbor_list is not None else DefaultNeighborList ()
117+ extended_coord , extended_atype , nlist , mapping = builder .build (
118+ cc , atype , bb , rcut , sel
130119 )
131120 extended_coord = extended_coord .reshape (nframes , - 1 , 3 )
132121 if coord_corr_for_virial is not None :
@@ -269,6 +258,7 @@ def call_common(
269258 do_atomic_virial : bool = False ,
270259 coord_corr_for_virial : Array | None = None ,
271260 charge_spin : Array | None = None ,
261+ neighbor_list : NeighborList | None = None ,
272262 ) -> dict [str , Array ]:
273263 """Return model prediction.
274264
@@ -290,6 +280,11 @@ def call_common(
290280 coord_corr_for_virial
291281 The coordinates correction for virial.
292282 shape: nf x (nloc x 3)
283+ neighbor_list
284+ The neighbor-list construction strategy. ``None`` uses the
285+ default all-pairs builder; an alternative strategy (e.g. an O(N)
286+ cell list) may be injected to speed up neighbor-list construction
287+ without changing model outputs.
293288
294289 Returns
295290 -------
@@ -316,6 +311,7 @@ def call_common(
316311 do_atomic_virial = do_atomic_virial ,
317312 coord_corr_for_virial = coord_corr_for_virial ,
318313 charge_spin = cs ,
314+ neighbor_list = neighbor_list ,
319315 )
320316 model_predict = self ._output_type_cast (model_predict , input_prec )
321317 return model_predict
0 commit comments