Potential¶
Numerical potential energy functions for bonds, angles, dihedrals, and pairs.
Quick reference¶
| Symbol | Summary | Preferred for |
|---|---|---|
BondHarmonic |
Harmonic bond: E = k(r - r₀)² | Standard bonded interactions |
AngleHarmonic |
Harmonic angle: E = k(θ - θ₀)² | Standard angle terms |
LJ126 |
Lennard-Jones 12-6 pair | Standard nonbonded interactions |
TypeIndexedArray |
Array indexed by type name strings | Vectorized parameter lookup |
Canonical example¶
ff = mp.AtomisticForcefield(name="demo", units="real")
bond_style = ff.def_bondstyle("harmonic")
bond_style.def_type(ct, hc, k0=340.0, r0=1.09)
pot = bond_style.to_potential()
print(pot.k["CT-HC"]) # [340.]
print(pot.r0["CT-HC"]) # [1.09]
Related¶
Full API¶
Base¶
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 ¶
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 ¶
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.
calc_forces ¶
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.
Bond¶
bond ¶
BondClass2Style ¶
BondHarmonic ¶
Bases: BondPotential
Initialize harmonic bond potential.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k
|
NDArray[floating] | float | dict[str, float]
|
Force constant (array for multiple types, scalar, or dict mapping type names to values) |
required |
r0
|
NDArray[floating] | float | dict[str, float]
|
Equilibrium bond length (array for multiple types, scalar, or dict mapping type names to values) |
required |
calc_energy ¶
Calculate bond energy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r
|
NDArray[floating]
|
Atom coordinates (shape: (n_atoms, 3)) |
required |
bond_idx
|
NDArray[integer]
|
Bond indices (shape: (n_bonds, 2)) |
required |
bond_types
|
NDArray[integer] | NDArray[str_]
|
Bond types (shape: (n_bonds,)) - can be integer indices or string type names |
required |
Returns:
| Type | Description |
|---|---|
float
|
Total bond energy |
calc_forces ¶
Calculate bond forces.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r
|
NDArray[floating]
|
Atom coordinates (shape: (n_atoms, 3)) |
required |
bond_idx
|
NDArray[integer]
|
Bond indices (shape: (n_bonds, 2)) |
required |
bond_types
|
NDArray[integer] | NDArray[str_]
|
Bond types (shape: (n_bonds,)) - can be integer indices or string type names |
required |
Returns:
| Type | Description |
|---|---|
NDArray[floating]
|
Array of forces on each atom (shape: (n_atoms, 3)) |
BondHarmonicStyle ¶
Bases: BondStyle
Harmonic bond style with fixed name='harmonic'.
def_type ¶
Define harmonic bond type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
itom
|
AtomType
|
First atom type |
required |
jtom
|
AtomType
|
Second atom type |
required |
k
|
float
|
Force constant |
required |
r0
|
float
|
Equilibrium bond length |
required |
name
|
str
|
Optional name (defaults to itom-jtom) |
''
|
Returns:
| Type | Description |
|---|---|
BondHarmonicType
|
BondHarmonicType instance |
BondHarmonicType ¶
Angle¶
angle ¶
AngleClass2BondAngleStyle ¶
AngleClass2BondBondStyle ¶
AngleClass2Style ¶
AngleHarmonic ¶
Bases: AnglePotential
Initialize harmonic angle potential.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k
|
NDArray[floating] | float | dict[str, float]
|
Force constant in kcal/mol/rad² (array, scalar, or dict mapping type names to values) |
required |
theta0
|
NDArray[floating] | float | dict[str, float]
|
Equilibrium angle in degrees (array, scalar, or dict mapping type names to values) |
required |
calc_energy ¶
Calculate angle energy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r
|
NDArray[floating]
|
Atom coordinates (shape: (n_atoms, 3)) |
required |
angle_idx
|
NDArray[integer]
|
Angle indices (shape: (n_angles, 3)) |
required |
angle_types
|
NDArray[integer] | NDArray[str_]
|
Angle types (shape: (n_angles,)) |
required |
Returns:
| Type | Description |
|---|---|
float
|
Total angle energy |
calc_forces ¶
Calculate angle forces.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r
|
NDArray[floating]
|
Atom coordinates (shape: (n_atoms, 3)) |
required |
angle_idx
|
NDArray[integer]
|
Angle indices (shape: (n_angles, 3)) |
required |
angle_types
|
NDArray[integer] | NDArray[str_]
|
Angle types (shape: (n_angles,)) |
required |
Returns:
| Type | Description |
|---|---|
NDArray[floating]
|
Array of forces on each atom (shape: (n_atoms, 3)) |
AngleHarmonicStyle ¶
Bases: AngleStyle
Harmonic angle style with fixed name='harmonic'.
def_type ¶
Define harmonic angle type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
itom
|
AtomType
|
First atom type |
required |
jtom
|
AtomType
|
Central atom type |
required |
ktom
|
AtomType
|
Third atom type |
required |
k
|
float
|
Force constant |
required |
theta0
|
float
|
Equilibrium angle in degrees |
required |
name
|
str
|
Optional name (defaults to itom-jtom-ktom) |
''
|
Returns:
| Type | Description |
|---|---|
AngleHarmonicType
|
AngleHarmonicType instance |
AngleHarmonicType ¶
Bases: AngleType
Harmonic angle type with k and theta0 parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Type name |
required |
itom
|
AtomType
|
First atom type |
required |
jtom
|
AtomType
|
Central atom type |
required |
ktom
|
AtomType
|
Third atom type |
required |
k
|
float
|
Force constant |
required |
theta0
|
float
|
Equilibrium angle in degrees |
required |
Dihedral¶
dihedral ¶
Dihedral potentials.
DihedralCharmmStyle ¶
DihedralClass2Style ¶
DihedralFourierStyle ¶
Bases: DihedralStyle
LAMMPS fourier dihedral style for AMBER/GAFF force fields.
Parameters stored per type: k1=K, k2=n (int), k3=phase (degrees), k4=weight. Written as: dihedral_coeff ID m K n phase (m=1 for single-term AMBER dihedrals).
def_type ¶
Define periodic 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 |
name
|
str
|
Optional name (defaults to itom-jtom-ktom-ltom) |
''
|
**kwargs
|
Any
|
Periodic parameters (periodicity1, k1, phase1, ...). |
{}
|
Returns:
| Type | Description |
|---|---|
DihedralPeriodicType
|
DihedralPeriodicType instance |
DihedralMultiHarmonicStyle ¶
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.
def_type ¶
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
|
float
|
OPLS Ryckaert-Bellemans coefficient c0. |
0.0
|
c1
|
float
|
OPLS Ryckaert-Bellemans coefficient c1. |
0.0
|
c2
|
float
|
OPLS Ryckaert-Bellemans coefficient c2. |
0.0
|
c3
|
float
|
OPLS Ryckaert-Bellemans coefficient c3. |
0.0
|
c4
|
float
|
OPLS Ryckaert-Bellemans coefficient c4. |
0.0
|
c5
|
float
|
OPLS Ryckaert-Bellemans coefficient c5. |
0.0
|
name
|
str
|
Optional name (defaults to itom-jtom-ktom-ltom) |
''
|
Returns:
| Type | Description |
|---|---|
DihedralOPLSType
|
DihedralOPLSType instance |
to_lammps_params ¶
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 |
DihedralOPLSType ¶
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
|
float
|
OPLS Ryckaert-Bellemans coefficient c0. |
0.0
|
c1
|
float
|
OPLS Ryckaert-Bellemans coefficient c1. |
0.0
|
c2
|
float
|
OPLS Ryckaert-Bellemans coefficient c2. |
0.0
|
c3
|
float
|
OPLS Ryckaert-Bellemans coefficient c3. |
0.0
|
c4
|
float
|
OPLS Ryckaert-Bellemans coefficient c4. |
0.0
|
c5
|
float
|
OPLS Ryckaert-Bellemans coefficient c5. |
0.0
|
DihedralPeriodicStyle ¶
Bases: DihedralStyle
Periodic torsion dihedral style (AMBER/GAFF).
Uses periodic cosine terms: V(phi) = sum_i k_i * (1 + cos(n_i * phi - phi0_i))
DihedralPeriodicType ¶
Bases: DihedralType
Periodic torsion dihedral type with multiple terms.
Each term has: periodicity (n), force constant (k), phase angle (phi0). V(phi) = sum_i k_i * (1 + cos(n_i * phi - phi0_i))
Pair¶
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 ¶
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 |
calc_forces ¶
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)) |
LJ126 ¶
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 |
calc_energy ¶
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 |
calc_forces ¶
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)) |
LJ126CoulLong ¶
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 |
PairBuckStyle ¶
PairCoulLongStyle ¶
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
|
PairLJ126CoulCutStyle ¶
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
|
def_type ¶
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 |
PairLJ126CoulLongStyle ¶
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
|
def_type ¶
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 |
PairLJ126Style ¶
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
|
def_type ¶
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 |
PairLJ126Type ¶
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
|
PairLJClass2Style ¶
PairMorseStyle ¶
Pair Params¶
pair_params ¶
Specialized TypeIndexedArray for pair potentials with combining rules.
PairTypeIndexedArray ¶
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'
|
get_pair_array ¶
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 |
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 |
create_lj_parameters ¶
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
Utils¶
utils ¶
Utility functions and classes for potentials.
TypeIndexedArray ¶
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 |
calc_energy_from_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 |
calc_energy_from_frame_multi ¶
Calculate total energy from multiple potentials.
calc_forces_from_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 |
extract_angle_data ¶
Extract angle data from Frame.
Returns:
| Type | Description |
|---|---|
NDArray
|
(r, angle_idx, angle_types) where: |
NDArray
|
|
NDArray
|
|
tuple[NDArray, NDArray, NDArray]
|
|
extract_bond_data ¶
Extract bond data from Frame.
Returns:
| Type | Description |
|---|---|
NDArray
|
(r, bond_idx, bond_types) where: |
NDArray
|
|
NDArray
|
|
tuple[NDArray, NDArray, NDArray]
|
|
extract_pair_data ¶
Extract pair interaction data from Frame.
Generates all pairwise interactions between atoms and calculates displacement vectors and distances.
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
tuple
|
A tuple |