Force¶
- class hoomd.md.force.Force¶
Bases:
Compute
Defines a force for molecular dynamics simulations.
Force
is the base class for all molecular dynamics forces and provides common methods.A
Force
class computes the force and torque on each particle in the simulation state \(\vec{F}_i\) and \(\vec{\tau}_i\). With a few exceptions (noted in the documentation of the specific force classes),Force
subclasses also compute the contribution to the system’s potential energy \(U\) and the the virial tensor \(W\).Force
breaks the computation of the total system \(U\) and \(W\) into per-particle and additional terms as detailed in the documentation for each specificForce
subclass.\[\begin{split}U & = U_\mathrm{additional} + \sum_{i=0}^{N_\mathrm{particles}-1} U_i \\ W & = W_\mathrm{additional} + \sum_{i=0}^{N_\mathrm{particles}-1} W_i\end{split}\]Force
represents virial tensors as six element arrays listing the components of the tensor in this order:\[(W^{xx}, W^{xy}, W^{xz}, W^{yy}, W^{yz}, W^{zz}).\]The components of the virial tensor for a force on a single particle are:
\[W^{kl}_i = F^k \cdot r_i^l\]where the superscripts select the x,y, and z components of the vectors. To properly account for periodic boundary conditions, pairwise interactions evaluate the virial:
\[W^{kl}_i = \frac{1}{2} \sum_j F^k_{ij} \cdot \mathrm{minimum\_image}(\vec{r}_j - \vec{r}_i)^l\]Tip
Add a
Force
to your integrator’sforces
list to include it in the equations of motion of your system. Add aForce
to your simulation’soperations.computes
list to compute the forces and energy without influencing the system dynamics.Warning
This class should not be instantiated by users. The class can be used for
isinstance
orissubclass
checks.
Members inherited from
AutotunedObject
:- property kernel_parameters¶
Kernel parameters.
Read more...
- property is_tuning_complete¶
Check if kernel parameter tuning is complete.
Read more...
- tune_kernel_parameters()¶
Start tuning kernel parameters.
Read more...
Members defined in
Force
:- property additional_energy¶
Additional energy term \(U_\mathrm{additional}\) \([\mathrm{energy}]\).
(
Loggable
: category=”scalar”)- Type:
- property additional_virial¶
Additional virial tensor term \(W_\mathrm{additional}\) \([\mathrm{energy}]\).
(
Loggable
: category=”sequence”)- Type:
(1, 6)
numpy.ndarray
offloat
- property cpu_local_force_arrays¶
Local force arrays on the CPU.
Provides direct access to the force, potential energy, torque, and virial data of the particles in the system on the cpu through a context manager. All data is MPI rank-local.
The
hoomd.md.data.ForceLocalAccess
object returned by this property has four arrays through which one can modify the force data:Note
The local arrays are read only for built-in forces. Use
Custom
to implement custom forces.Examples:
with self.cpu_local_force_arrays as arrays: arrays.force[:] = ... arrays.potential_energy[:] = ... arrays.torque[:] = ... arrays.virial[:] = ...
- property energies¶
Energy contribution \(U_i\) from each particle \([\mathrm{energy}]\).
Attention
In MPI parallel execution, the array is available on rank 0 only.
energies
isNone
on ranks >= 1.(
Loggable
: category=”particle”)- Type:
(N_particles, )
numpy.ndarray
offloat
- property energy¶
The potential energy \(U\) of the system from this force \([\mathrm{energy}]\).
(
Loggable
: category=”scalar”)- Type:
- property forces¶
The force \(\vec{F}_i\) applied to each particle \([\mathrm{force}]\).
Attention
In MPI parallel execution, the array is available on rank 0 only.
forces
isNone
on ranks >= 1.(
Loggable
: category=”particle”)- Type:
(N_particles, 3)
numpy.ndarray
offloat
- property gpu_local_force_arrays¶
Local force arrays on the GPU.
Provides direct access to the force, potential energy, torque, and virial data of the particles in the system on the gpu through a context manager. All data is MPI rank-local.
The
hoomd.md.data.ForceLocalAccessGPU
object returned by this property has four arrays through which one can modify the force data:Note
The local arrays are read only for built-in forces. Use
Custom
to implement custom forces.Examples:
with self.gpu_local_force_arrays as arrays: arrays.force[:] = ... arrays.potential_energy[:] = ... arrays.torque[:] = ... arrays.virial[:] = ...
Note
GPU local force data is not available if the chosen device for the simulation is
hoomd.device.CPU
.
- property torques¶
The torque \(\vec{\tau}_i\) applied to each particle \([\mathrm{force} \cdot \mathrm{length}]\).
Attention
In MPI parallel execution, the array is available on rank 0 only.
torques
isNone
on ranks >= 1.(
Loggable
: category=”particle”)- Type:
(N_particles, 3)
numpy.ndarray
offloat
- property virials¶
Virial tensor contribution \(W_i\) from each particle \([\mathrm{energy}]\).
Attention
To improve performance
Force
objects only compute virials when needed. When not computed,virials
isNone
. Virials are computed on every step when using amd.methods.ConstantPressure
integrator, on steps where a writer is triggered (such aswrite.GSD
which may log pressure or virials), or whenSimulation.always_compute_pressure
isTrue
.Attention
In MPI parallel execution, the array is available on rank 0 only.
virials
isNone
on ranks >= 1.(
Loggable
: category=”particle”)- Type:
(N_particles, 6)
numpy.ndarray
offloat