Force¶
- class hoomd.md.force.Force¶
Bases:
ComputeDefines a force for molecular dynamics simulations.
Forceis the base class for all molecular dynamics forces and provides common methods.A
Forceclass 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),Forcesubclasses also compute the contribution to the system’s potential energy \(U\) and the the virial tensor \(W\).Forcebreaks the computation of the total system \(U\) and \(W\) into per-particle and additional terms as detailed in the documentation for each specificForcesubclass.\[\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}\]Forcerepresents 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
Forceto your integrator’sforceslist to include it in the equations of motion of your system. Add aForceto your simulation’soperations.computeslist 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
isinstanceorissubclasschecks.
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.ndarrayoffloat
- 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.ForceLocalAccessobject 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
Customto 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.
energiesisNoneon ranks >= 1.(
Loggable: category=”particle”)- Type:
(N_particles, )
numpy.ndarrayoffloat
- 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.
forcesisNoneon ranks >= 1.(
Loggable: category=”particle”)- Type:
(N_particles, 3)
numpy.ndarrayoffloat
- 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.ForceLocalAccessGPUobject 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
Customto 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.
torquesisNoneon ranks >= 1.(
Loggable: category=”particle”)- Type:
(N_particles, 3)
numpy.ndarrayoffloat
- property virials¶
Virial tensor contribution \(W_i\) from each particle \([\mathrm{energy}]\).
Attention
To improve performance
Forceobjects only compute virials when needed. When not computed,virialsisNone. Virials are computed on every step when using amd.methods.ConstantPressureintegrator, on steps where a writer is triggered (such aswrite.GSDwhich may log pressure or virials), or whenSimulation.always_compute_pressureisTrue.Attention
In MPI parallel execution, the array is available on rank 0 only.
virialsisNoneon ranks >= 1.(
Loggable: category=”particle”)- Type:
(N_particles, 6)
numpy.ndarrayoffloat