2929
3030@BaseModifier .register ("dipole_charge" )
3131class DipoleChargeModifier (DPModifier ):
32- """Parameters
32+ """Modifier for dipole-charge systems using Wannier Function Charge Centers (WFCC).
33+
34+ This modifier extends a system with Wannier Function Charge Centers (WFCC) by
35+ adding dipole vectors to atomic coordinates for selected atom types. It then
36+ calculates the electrostatic interactions using Ewald reciprocal summation
37+ to obtain energy, force, and virial corrections.
38+
39+ Parameters
3340 ----------
34- model_name
35- The model file for the DeepDipole model
36- model_charge_map
37- Gives the amount of charge for the wfcc
38- sys_charge_map
39- Gives the amount of charge for the real atoms
40- ewald_h
41- Grid spacing of the reciprocal part of Ewald sum. Unit: A
42- ewald_beta
43- Splitting parameter of the Ewald sum. Unit: A^{-1}
41+ dp_model : DipoleModel | None
42+ The DeepDipole model to use for dipole prediction
43+ model_charge_map : List[float]
44+ The amount of charge for the WFCC for each selected atom type
45+ sys_charge_map : List[float]
46+ The amount of charge for the real atoms for each atom type
47+ ewald_h : float, optional
48+ Grid spacing of the reciprocal part of Ewald sum. Unit: Å, default is 1.0
49+ ewald_beta : float, optional
50+ Splitting parameter of the Ewald sum. Unit: Å^{-1}, default is 1.0
51+ dp_model_file_name : str | None, optional
52+ Path to the model file, by default None
53+ use_cache : bool, optional
54+ Whether to use cache for computations, by default True
4455 """
4556
4657 def __init__ (
@@ -53,7 +64,30 @@ def __init__(
5364 dp_model_file_name : str | None = None ,
5465 use_cache : bool = True ,
5566 ) -> None :
56- """Constructor."""
67+ """Initialize the DipoleChargeModifier.
68+
69+ Parameters
70+ ----------
71+ dp_model : DipoleModel | None
72+ The DeepDipole model to use for dipole prediction
73+ model_charge_map : List[float]
74+ The amount of charge for the WFCC for each selected atom type
75+ sys_charge_map : List[float]
76+ The amount of charge for the real atoms for each atom type
77+ ewald_h : float, optional
78+ Grid spacing of the reciprocal part of Ewald sum. Unit: Å, default is 1.0
79+ ewald_beta : float, optional
80+ Splitting parameter of the Ewald sum. Unit: Å^{-1}, default is 1.0
81+ dp_model_file_name : str | None, optional
82+ Path to the model file, by default None
83+ use_cache : bool, optional
84+ Whether to use cache for computations, by default True
85+
86+ Raises
87+ ------
88+ ValueError
89+ If model_charge_map and sel_type have mismatching lengths
90+ """
5791 self .modifier_type = "dipole_charge"
5892 super ().__init__ (
5993 dp_model = dp_model ,
@@ -97,12 +131,12 @@ def __init__(
97131 )
98132
99133 def serialize (self ) -> dict :
100- """Serialize the modifier.
134+ """Serialize the modifier to a dictionary .
101135
102136 Returns
103137 -------
104138 dict
105- The serialized data
139+ The serialized data containing model parameters and configuration
106140 """
107141 dd = super ().serialize ()
108142 dd .update (
@@ -117,6 +151,18 @@ def serialize(self) -> dict:
117151
118152 @classmethod
119153 def deserialize (cls , data : dict ) -> "DipoleChargeModifier" :
154+ """Deserialize the modifier from a dictionary.
155+
156+ Parameters
157+ ----------
158+ data : dict
159+ The serialized data containing model parameters and configuration
160+
161+ Returns
162+ -------
163+ DipoleChargeModifier
164+ The deserialized modifier instance
165+ """
120166 data = data .copy ()
121167 data .pop ("@class" , None )
122168 data .pop ("type" , None )
@@ -342,6 +388,7 @@ def extend_system_coord(
342388 all_coord = torch .cat ((coord_reshaped , wfcc_coord ), dim = 1 )
343389 return all_coord , dipole_reshaped
344390
391+ @torch .jit .unused
345392 def eval_np (
346393 self ,
347394 coord : np .ndarray ,
@@ -350,6 +397,32 @@ def eval_np(
350397 fparam : np .ndarray | None = None ,
351398 aparam : np .ndarray | None = None ,
352399 ) -> tuple [np .ndarray , np .ndarray , np .ndarray ]:
400+ """Evaluate the modifier with NumPy input and output.
401+
402+ This method converts NumPy inputs to PyTorch tensors, evaluates the modifier,
403+ and converts the results back to NumPy arrays.
404+
405+ Parameters
406+ ----------
407+ coord : np.ndarray
408+ The coordinates of atoms with shape (nframes, natoms, 3)
409+ box : np.ndarray
410+ The simulation box with shape (nframes, 3, 3)
411+ atype : np.ndarray
412+ The atom types with shape (nframes, natoms)
413+ fparam : np.ndarray | None, optional
414+ Frame parameters with shape (nframes, nfp), by default None
415+ aparam : np.ndarray | None, optional
416+ Atom parameters with shape (nframes, natoms, nap), by default None
417+
418+ Returns
419+ -------
420+ Tuple[np.ndarray, np.ndarray, np.ndarray]
421+ A tuple containing three NumPy arrays:
422+ - energy: Energy correction with shape (nframes, 1)
423+ - force: Force correction with shape (nframes, natoms, 3)
424+ - virial: Virial correction with shape (nframes, 3, 3)
425+ """
353426 nf = coord .shape [0 ]
354427 na = coord .reshape (nf , - 1 , 3 ).shape [1 ]
355428
0 commit comments