Potential¶
The potential module defines potential energy functions and functional forms.
Base¶
Base classes for potential functions.
Potential ¶
Base class for all potential functions in MolPy.
This class provides a template for defining potential functions that can be used in molecular simulations. Each potential class should implement calc_energy and calc_forces methods with specific parameters.
calc_energy ¶
calc_energy(*args, **kwargs)
Calculate the potential energy.
Parameters¶
args: Arguments specific to the potential type *kwargs: Keyword arguments specific to the potential type
Returns¶
float The potential energy.
Source code in src/molpy/potential/base.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
calc_forces ¶
calc_forces(*args, **kwargs)
Calculate the forces.
Parameters¶
args: Arguments specific to the potential type *kwargs: Keyword arguments specific to the potential type
Returns¶
np.ndarray An array of forces.
Source code in src/molpy/potential/base.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
Potentials ¶
Bases: UserList[Potential]
Collection of potential functions.
This class provides a way to combine multiple potentials and calculate total energy and forces. However, since different potentials require different parameters, you need to call calc_energy and calc_forces for each potential separately and sum the results.
For a simpler interface, use the helper functions in potential.utils to extract data from Frame objects.
calc_energy ¶
calc_energy(*args, **kwargs)
Calculate the total energy by summing energies from all potentials.
If a Frame object is passed as the first argument, automatically extracts the necessary data for each potential type.
Parameters¶
args: Arguments passed to each potential's calc_energy method. If first arg is a Frame, data is automatically extracted. *kwargs: Keyword arguments passed to each potential's calc_energy method
Returns¶
float The total energy.
Source code in src/molpy/potential/base.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |
calc_forces ¶
calc_forces(*args, **kwargs)
Calculate the total forces by summing forces from all potentials.
If a Frame object is passed as the first argument, automatically extracts the necessary data for each potential type.
Parameters¶
args: Arguments passed to each potential's calc_forces method. If first arg is a Frame, data is automatically extracted. *kwargs: Keyword arguments passed to each potential's calc_forces method
Returns¶
np.ndarray An array of total forces.
Source code in src/molpy/potential/base.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
Angle¶
Bond¶
Dihedral¶
Dihedral potentials.
DihedralOPLSStyle ¶
DihedralOPLSStyle()
Bases: DihedralStyle
OPLS dihedral style with fixed name='opls'.
OPLS dihedral uses Ryckaert-Bellemans (RB) coefficients c0-c5. LAMMPS opls style expects k1-k4, which are computed from c0-c5 using analytical conversion according to GROMACS manual Eqs. 200-201.
Source code in src/molpy/potential/dihedral/opls.py
211 212 | |
def_type ¶
def_type(itom, jtom, ktom, ltom, c0=0.0, c1=0.0, c2=0.0, c3=0.0, c4=0.0, c5=0.0, name='')
Define OPLS dihedral type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
itom
|
AtomType
|
First atom type |
required |
jtom
|
AtomType
|
Second atom type |
required |
ktom
|
AtomType
|
Third atom type |
required |
ltom
|
AtomType
|
Fourth atom type |
required |
c0-c5
|
OPLS Ryckaert-Bellemans coefficients |
required | |
name
|
str
|
Optional name (defaults to itom-jtom-ktom-ltom) |
''
|
Returns:
| Type | Description |
|---|---|
DihedralOPLSType
|
DihedralOPLSType instance |
Source code in src/molpy/potential/dihedral/opls.py
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 | |
to_lammps_params ¶
to_lammps_params(dihedral_type)
Convert OPLS c0-c5 coefficients to LAMMPS k1-k4 format.
Note: In OPLS XML files, c1-c4 typically contain OPLS coefficients F1-F4 directly (not RB format). So we use c1-c4 directly as k1-k4.
For true RB format coefficients, use rb_to_opls() function instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dihedral_type
|
DihedralOPLSType
|
DihedralOPLSType with c0-c5 parameters |
required |
Returns:
| Type | Description |
|---|---|
list[float]
|
List of [k1, k2, k3, k4] for LAMMPS in kcal/mol |
Source code in src/molpy/potential/dihedral/opls.py
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 | |
DihedralOPLSType ¶
DihedralOPLSType(name, itom, jtom, ktom, ltom, c0=0.0, c1=0.0, c2=0.0, c3=0.0, c4=0.0, c5=0.0)
Bases: DihedralType
OPLS dihedral type with c0-c5 coefficients.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Type name |
required |
itom
|
AtomType
|
First atom type |
required |
jtom
|
AtomType
|
Second atom type |
required |
ktom
|
AtomType
|
Third atom type |
required |
ltom
|
AtomType
|
Fourth atom type |
required |
c0-c5
|
OPLS Ryckaert-Bellemans coefficients |
required |
Source code in src/molpy/potential/dihedral/opls.py
165 166 167 168 169 170 171 172 173 174 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 | |
Pair¶
CoulCut ¶
Bases: PairPotential
Coulomb pair potential with cutoff.
The potential is defined as: V(r) = q_i * q_j / r
The force is: F(r) = q_i * q_j / r^3 * dr
calc_energy ¶
calc_energy(r, pair_idx, charges)
Calculate Coulomb energy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r
|
NDArray[floating]
|
Atom coordinates (shape: (n_atoms, 3)) |
required |
pair_idx
|
NDArray[integer]
|
Pair indices (shape: (n_pairs, 2)) |
required |
charges
|
NDArray[floating]
|
Atom charges (shape: (n_atoms,)) |
required |
Returns:
| Type | Description |
|---|---|
float
|
Total Coulomb energy |
Source code in src/molpy/potential/pair/coul.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
calc_forces ¶
calc_forces(r, pair_idx, charges)
Calculate Coulomb forces.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r
|
NDArray[floating]
|
Atom coordinates (shape: (n_atoms, 3)) |
required |
pair_idx
|
NDArray[integer]
|
Pair indices (shape: (n_pairs, 2)) |
required |
charges
|
NDArray[floating]
|
Atom charges (shape: (n_atoms,)) |
required |
Returns:
| Type | Description |
|---|---|
NDArray[floating]
|
Array of forces on each atom (shape: (n_atoms, 3)) |
Source code in src/molpy/potential/pair/coul.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
LJ126 ¶
LJ126(epsilon, sigma)
Bases: PairPotential
Lennard-Jones 12-6 pair potential with cutoff.
The potential is defined as: V(r) = 4 * ε * ((σ/r)^12 - (σ/r)^6)
The force is: F(r) = 24 * ε * (2 * (σ/r)^12 - (σ/r)^6) * dr / r^2
Attributes:
| Name | Type | Description |
|---|---|---|
epsilon |
Depth of potential well for each atom type [energy] |
|
sigma |
Finite distance at which potential is zero [length] |
Initialize LJ126 potential.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
epsilon
|
float | NDArray[float64]
|
Depth of potential well, can be scalar or array for multiple types |
required |
sigma
|
float | NDArray[float64]
|
Finite distance at which potential is zero, can be scalar or array for multiple types |
required |
Source code in src/molpy/potential/pair/lj.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
calc_energy ¶
calc_energy(dr, dr_norm, pair_types)
Calculate pair energy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dr
|
NDArray[floating]
|
Pair displacement vectors (shape: (n_pairs, 3)) |
required |
dr_norm
|
NDArray[floating]
|
Pair distances (shape: (n_pairs, 1) or (n_pairs,)) |
required |
pair_types
|
NDArray[integer]
|
Pair types (shape: (n_pairs,)) |
required |
Returns:
| Type | Description |
|---|---|
float
|
Total pair energy |
Source code in src/molpy/potential/pair/lj.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
calc_forces ¶
calc_forces(dr, dr_norm, pair_types, pair_idx, n_atoms)
Calculate pair forces.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dr
|
NDArray[floating]
|
Pair displacement vectors (shape: (n_pairs, 3)) |
required |
dr_norm
|
NDArray[floating]
|
Pair distances (shape: (n_pairs, 1) or (n_pairs,)) |
required |
pair_types
|
NDArray[integer]
|
Pair types (shape: (n_pairs,)) |
required |
pair_idx
|
NDArray[integer]
|
Pair indices (shape: (n_pairs, 2)) |
required |
n_atoms
|
int
|
Number of atoms |
required |
Returns:
| Type | Description |
|---|---|
NDArray[floating]
|
Array of forces on each atom (shape: (n_atoms, 3)) |
Source code in src/molpy/potential/pair/lj.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |
LJ126CoulLong ¶
LJ126CoulLong(epsilon, sigma, charges, type_names)
Bases: PairPotential
Combined Lennard-Jones 12-6 and Coulomb long-range pair potential.
This is a composite potential that combines LJ and Coulomb interactions. Uses PairTypeIndexedArray internally for automatic combining rules.
V(r) = V_LJ(r) + V_Coul(r)
Initialize LJ126CoulLong potential.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
epsilon
|
NDArray[float64]
|
Per-atom-type epsilon values (numpy array) |
required |
sigma
|
NDArray[float64]
|
Per-atom-type sigma values (numpy array) |
required |
charges
|
NDArray[float64]
|
Per-atom-type charges (numpy array) |
required |
type_names
|
list[str]
|
List of atom type names corresponding to array indices |
required |
Source code in src/molpy/potential/pair/lj.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
calc_energy ¶
calc_energy(dr, dr_norm, pair_types_i, pair_types_j)
Calculate combined LJ + Coulomb energy.
Uses PairTypeIndexedArray to automatically apply combining rules.
Source code in src/molpy/potential/pair/lj.py
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 | |
calc_forces ¶
calc_forces(dr, dr_norm, pair_types_i, pair_types_j, pair_idx, n_atoms)
Calculate combined LJ + Coulomb forces.
Uses PairTypeIndexedArray to automatically apply combining rules.
Source code in src/molpy/potential/pair/lj.py
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 | |
PairCoulLongStyle ¶
PairCoulLongStyle(cutoff=10.0)
Bases: PairStyle
Coulomb long-range pair style with fixed name='coul/long'.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cutoff
|
float
|
Cutoff distance in Angstroms (default: 10.0) |
10.0
|
Source code in src/molpy/potential/pair/lj.py
358 359 360 361 362 363 | |
PairLJ126CoulCutStyle ¶
PairLJ126CoulCutStyle(lj_cutoff=10.0, coul_cutoff=10.0, coulomb14scale=0.5, lj14scale=0.5)
Bases: PairStyle
Combined LJ 12-6 and Coulomb cut pair style.
This is a composite style that combines PairLJ126Style and Coulomb cut. The name is 'lj/cut/coul/cut' for LAMMPS compatibility.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lj_cutoff
|
float
|
LJ cutoff distance in Angstroms (default: 10.0) |
10.0
|
coul_cutoff
|
float
|
Coulomb cutoff distance in Angstroms (default: 10.0) |
10.0
|
coulomb14scale
|
float
|
1-4 Coulomb scaling factor (default: 0.5) |
0.5
|
lj14scale
|
float
|
1-4 LJ scaling factor (default: 0.5) |
0.5
|
Source code in src/molpy/potential/pair/lj.py
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 | |
def_type ¶
def_type(itom, jtom=None, epsilon=0.0, sigma=0.0, charge=0.0, name='')
Define LJ 12-6 pair type (same as PairLJ126Style).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
itom
|
AtomType
|
First atom type |
required |
jtom
|
AtomType | None
|
Second atom type (None for self-interaction) |
None
|
epsilon
|
float
|
LJ epsilon parameter |
0.0
|
sigma
|
float
|
LJ sigma parameter |
0.0
|
charge
|
float
|
Atomic charge (optional) |
0.0
|
name
|
str
|
Optional name |
''
|
Returns:
| Type | Description |
|---|---|
PairLJ126Type
|
PairLJ126Type instance |
Source code in src/molpy/potential/pair/lj.py
490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 | |
PairLJ126CoulLongStyle ¶
PairLJ126CoulLongStyle(lj_cutoff=10.0, coul_cutoff=10.0, coulomb14scale=0.5, lj14scale=0.5)
Bases: PairStyle
Combined LJ 12-6 and Coulomb long pair style.
This is a composite style that combines PairLJ126Style and PairCoulLongStyle. The name is 'lj/cut/coul/long' for LAMMPS compatibility.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lj_cutoff
|
float
|
LJ cutoff distance in Angstroms (default: 10.0) |
10.0
|
coul_cutoff
|
float
|
Coulomb cutoff distance in Angstroms (default: 10.0) |
10.0
|
coulomb14scale
|
float
|
1-4 Coulomb scaling factor (default: 0.5) |
0.5
|
lj14scale
|
float
|
1-4 LJ scaling factor (default: 0.5) |
0.5
|
Source code in src/molpy/potential/pair/lj.py
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 | |
def_type ¶
def_type(itom, jtom=None, epsilon=0.0, sigma=0.0, charge=0.0, name='')
Define LJ 12-6 pair type (same as PairLJ126Style).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
itom
|
AtomType
|
First atom type |
required |
jtom
|
AtomType | None
|
Second atom type (None for self-interaction) |
None
|
epsilon
|
float
|
LJ epsilon parameter |
0.0
|
sigma
|
float
|
LJ sigma parameter |
0.0
|
charge
|
float
|
Atomic charge (optional) |
0.0
|
name
|
str
|
Optional name |
''
|
Returns:
| Type | Description |
|---|---|
PairLJ126Type
|
PairLJ126Type instance |
Source code in src/molpy/potential/pair/lj.py
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 | |
to_potential ¶
to_potential()
Convert this style to a Potential object.
Source code in src/molpy/potential/pair/lj.py
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 | |
PairLJ126Style ¶
PairLJ126Style(cutoff=10.0)
Bases: PairStyle
Lennard-Jones 12-6 pair style with fixed name='lj126'.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cutoff
|
float
|
Cutoff distance in Angstroms (default: 10.0) |
10.0
|
Source code in src/molpy/potential/pair/lj.py
317 318 319 320 321 322 | |
def_type ¶
def_type(itom, jtom=None, epsilon=0.0, sigma=0.0, charge=0.0, name='')
Define LJ 12-6 pair type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
itom
|
AtomType
|
First atom type |
required |
jtom
|
AtomType | None
|
Second atom type (None for self-interaction) |
None
|
epsilon
|
float
|
LJ epsilon parameter |
0.0
|
sigma
|
float
|
LJ sigma parameter |
0.0
|
charge
|
float
|
Atomic charge (optional) |
0.0
|
name
|
str
|
Optional name |
''
|
Returns:
| Type | Description |
|---|---|
PairLJ126Type
|
PairLJ126Type instance |
Source code in src/molpy/potential/pair/lj.py
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 | |
PairLJ126Type ¶
PairLJ126Type(name, itom, jtom=None, epsilon=0.0, sigma=0.0, charge=0.0)
Bases: PairType
Lennard-Jones 12-6 pair type with epsilon and sigma parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Type name |
required |
itom
|
AtomType
|
First atom type |
required |
jtom
|
AtomType | None
|
Second atom type (None for self-interaction) |
None
|
epsilon
|
float
|
LJ epsilon parameter |
0.0
|
sigma
|
float
|
LJ sigma parameter |
0.0
|
charge
|
float
|
Atomic charge (optional) |
0.0
|
Source code in src/molpy/potential/pair/lj.py
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 | |
Pair Params¶
Specialized TypeIndexedArray for pair potentials with combining rules.
PairTypeIndexedArray ¶
PairTypeIndexedArray(data, combining_rule='geometric')
Bases: TypeIndexedArray
Specialized TypeIndexedArray for pair potential parameters.
Handles combining rules (Lorentz-Berthelot, geometric, etc.) for computing pair parameters from individual atom type parameters.
For pair potentials, we store per-atom-type parameters (epsilon, sigma) and apply combining rules when indexing with two atom types.
Examples:
>>> # Create with per-atom-type parameters
>>> epsilon = PairTypeIndexedArray(
... {'opls_135': 0.066, 'opls_140': 0.030},
... combining_rule='geometric'
... )
>>>
>>> # Index with single type (self-interaction)
>>> epsilon['opls_135'] # 0.066
>>>
>>> # Index with two types (cross-interaction, uses combining rule)
>>> epsilon[('opls_135', 'opls_140')] # sqrt(0.066 * 0.030) = 0.0445
>>>
>>> # Array indexing with pairs
>>> pairs = np.array([['opls_135', 'opls_140'], ['opls_140', 'opls_140']])
>>> epsilon[pairs] # [0.0445, 0.030]
Initialize PairTypeIndexedArray.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict[str, float] | NDArray[floating] | float
|
Dictionary mapping atom type names to parameters, or array |
required |
combining_rule
|
Literal['geometric', 'arithmetic', 'harmonic']
|
Rule for combining parameters: - 'geometric': sqrt(a * b) - for epsilon - 'arithmetic': (a + b) / 2 - for sigma - 'harmonic': 2 * a * b / (a + b) - alternative |
'geometric'
|
Source code in src/molpy/potential/pair_params.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | |
get_pair_array ¶
get_pair_array(type_pairs)
Get combined parameters for an array of type pairs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type_pairs
|
NDArray
|
Array of shape (n_pairs, 2) with type labels or indices |
required |
Returns:
| Type | Description |
|---|---|
NDArray[floating]
|
Array of combined parameters for each pair |
Source code in src/molpy/potential/pair_params.py
142 143 144 145 146 147 148 149 150 151 152 | |
get_pair_matrix ¶
get_pair_matrix()
Get full pair parameter matrix for all type combinations.
Returns:
| Type | Description |
|---|---|
NDArray[floating]
|
Matrix of shape (n_types, n_types) with combined parameters |
NDArray[floating]
|
for all pairs of atom types |
Source code in src/molpy/potential/pair_params.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
create_lj_parameters ¶
create_lj_parameters(epsilon_dict, sigma_dict)
Create LJ parameter arrays with standard Lorentz-Berthelot combining rules.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
epsilon_dict
|
dict[str, float]
|
Per-atom-type epsilon values |
required |
sigma_dict
|
dict[str, float]
|
Per-atom-type sigma values |
required |
Returns:
| Type | Description |
|---|---|
tuple[PairTypeIndexedArray, PairTypeIndexedArray]
|
Tuple of (epsilon_array, sigma_array) with combining rules applied |
Example
epsilon_dict = {'opls_135': 0.066, 'opls_140': 0.030} sigma_dict = {'opls_135': 3.5, 'opls_140': 2.5} epsilon, sigma = create_lj_parameters(epsilon_dict, sigma_dict)
Get cross-interaction parameters¶
eps_ij = epsilon[('opls_135', 'opls_140')] # sqrt(0.066 * 0.030) sig_ij = sigma[('opls_135', 'opls_140')] # (3.5 + 2.5) / 2
Source code in src/molpy/potential/pair_params.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
Utils¶
Utility functions and classes for potentials.
TypeIndexedArray ¶
TypeIndexedArray(data)
Array-like container that supports both integer and string type name indexing.
This class allows potentials to accept either integer indices or string type labels for indexing parameters. It maintains an internal mapping between type names and indices.
Examples:
>>> # Create from dictionary (type name -> value)
>>> k = TypeIndexedArray({"CT-CT": 100.0, "CT-OH": 80.0})
>>> k[0] # Access by integer index
100.0
>>> k["CT-CT"] # Access by type name
100.0
>>> k[np.array([0, 1])] # Array indexing with integers
array([100., 80.])
>>> k[np.array(["CT-CT", "CT-OH"])] # Array indexing with strings
array([100., 80.])
>>> # Create from array (for backward compatibility)
>>> k = TypeIndexedArray(np.array([100.0, 80.0]))
>>> k[0]
100.0
Initialize TypeIndexedArray.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict[str, float] | NDArray[floating] | float
|
Either a dictionary mapping type names to values, or an array/float for backward compatibility |
required |
Source code in src/molpy/potential/utils.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
reshape ¶
reshape(*args, **kwargs)
Reshape the values array (for backward compatibility).
Source code in src/molpy/potential/utils.py
113 114 115 116 | |
calc_energy_from_frame ¶
calc_energy_from_frame(potential, frame)
Calculate energy from Frame for a potential.
This is a convenience function that extracts the necessary data from Frame and calls the potential's calc_energy method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
potential
|
Potential
|
Potential instance |
required |
frame
|
Frame
|
Frame containing the necessary data |
required |
Returns:
| Type | Description |
|---|---|
float
|
Potential energy |
Raises:
| Type | Description |
|---|---|
TypeError
|
If potential type is not recognized |
ValueError
|
If required data is missing from frame |
Source code in src/molpy/potential/utils.py
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 | |
calc_energy_from_frame_multi ¶
calc_energy_from_frame_multi(potentials, frame)
Calculate total energy from multiple potentials.
Source code in src/molpy/potential/utils.py
369 370 371 372 373 374 | |
calc_forces_from_frame ¶
calc_forces_from_frame(potential, frame)
Calculate forces from Frame for a potential.
This is a convenience function that extracts the necessary data from Frame and calls the potential's calc_forces method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
potential
|
Potential
|
Potential instance |
required |
frame
|
Frame
|
Frame containing the necessary data |
required |
Returns:
| Type | Description |
|---|---|
NDArray
|
Array of forces on each atom (shape: (n_atoms, 3)) |
Raises:
| Type | Description |
|---|---|
TypeError
|
If potential type is not recognized |
ValueError
|
If required data is missing from frame |
Source code in src/molpy/potential/utils.py
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 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 | |
extract_angle_data ¶
extract_angle_data(frame)
Extract angle data from Frame.
Returns:
| Type | Description |
|---|---|
NDArray
|
(r, angle_idx, angle_types) where: |
NDArray
|
|
NDArray
|
|
tuple[NDArray, NDArray, NDArray]
|
|
Source code in src/molpy/potential/utils.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | |
extract_bond_data ¶
extract_bond_data(frame)
Extract bond data from Frame.
Returns:
| Type | Description |
|---|---|
NDArray
|
(r, bond_idx, bond_types) where: |
NDArray
|
|
NDArray
|
|
tuple[NDArray, NDArray, NDArray]
|
|
Source code in src/molpy/potential/utils.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
extract_coul_data ¶
extract_coul_data(frame)
Extract Coulomb interaction data from Frame.
Source code in src/molpy/potential/utils.py
233 234 235 236 | |
extract_pair_data ¶
extract_pair_data(frame)
Extract pair interaction data from Frame.
Generates all pairwise interactions between atoms and calculates displacement vectors and distances.
Returns:
| Type | Description |
|---|---|
|
(dr, dr_norm, pair_types_i, pair_types_j, pair_idx, n_atoms) where: |
|
|
|
|
|
|
|
|
|
|
|
|
Source code in src/molpy/potential/utils.py
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 | |