base_force
torch_admp.base_force
Base force module for torch-admp.
This module provides the abstract base class for force modules in torch-admp, which defines the common interface for force calculations. It includes standardized input validation and unit conversion functionality.
BaseForceModule(units_dict: Optional[Dict] = None)
Bases: Module, ABC
Abstract base class for force modules in torch-admp.
This class provides a common interface for force modules that take atomic positions and simulation box as input and return energy values. It is designed to be compatible with OpenMM-torch and sets up a constants library as a class attribute for necessary physical constants.
Notes
All subclasses must implement the _forward_impl method to define specific force calculations.
Initialize the BaseForceModule.
| PARAMETER | DESCRIPTION |
|---|---|
units_dict
|
Dictionary containing unit conversion factors. If None, default units will be used.
TYPE:
|
| ATTRIBUTE | DESCRIPTION |
|---|---|
const_lib |
Library containing physical constants and unit conversions.
TYPE:
|
Source code in torch_admp/base_force.py
forward(positions: torch.Tensor, box: Optional[torch.Tensor], pairs: torch.Tensor, ds: torch.Tensor, buffer_scales: torch.Tensor, params: Dict[str, torch.Tensor]) -> torch.Tensor
Compute the potential energy for the given atomic configuration.
This method validates input dimensions and then calls the abstract _forward_impl method which must be implemented by subclasses.
| PARAMETER | DESCRIPTION |
|---|---|
positions
|
Atomic positions with shape (natoms, 3). Each row contains the x, y, z coordinates of an atom.
TYPE:
|
box
|
Simulation box vectors with shape (3, 3). Each row represents a box vector. Required for periodic boundary conditions.
TYPE:
|
pairs
|
Tensor of atom pairs with shape (n_pairs, 2). Each row contains the indices of two atoms that form a pair.
TYPE:
|
ds
|
Distance tensor with shape (n_pairs,). Contains the distances between atom pairs specified in the pairs tensor.
TYPE:
|
buffer_scales
|
Buffer scales for each pair with shape (n_pairs,). Contains values of 1 if i < j else 0 for each pair, used for buffer management.
TYPE:
|
params
|
Dictionary of parameters for the PES model. Common parameters include atomic charges, Lennard-Jones parameters, etc.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Scalar energy tensor representing the total potential energy of the system. |
Source code in torch_admp/base_force.py
standardize_input_tensor(positions: torch.Tensor, box: Optional[torch.Tensor], pairs: torch.Tensor, ds: torch.Tensor, buffer_scales: torch.Tensor) -> Tuple[torch.Tensor, Optional[torch.Tensor], torch.Tensor, torch.Tensor, torch.Tensor]
Verify the shape of input tensors.
| PARAMETER | DESCRIPTION |
|---|---|
positions
|
Atomic positions with shape (natoms, 3) or (nframes, natoms, 3)
TYPE:
|
box
|
Simulation box vectors with shape (3, 3) or (nframes, 3, 3)
TYPE:
|
pairs
|
Tensor of atom pairs with shape (n_pairs, 2) or (nframes, n_pairs, 2)
TYPE:
|
ds
|
Distance tensor with shape (n_pairs,) or (nframes, n_pairs)
TYPE:
|
buffer_scales
|
Buffer scales with shape (n_pairs,) or (nframes, n_pairs)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tuple[Tensor, Optional[Tensor], Tensor, Tensor, Tensor]
|
Standardized tensors with shapes: - positions: (nframes, natoms, 3) - box: (nframes, 3, 3) or None if input was None - pairs: (nframes, n_pairs, 2) - ds: (nframes, n_pairs) - buffer_scales: (nframes, n_pairs) |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If any tensor has incorrect dimensions |
Source code in torch_admp/base_force.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 | |