add_electric_field¶
- mdhelper.openmm.system.add_electric_field(system: System, nbforce: NonbondedForce, E: float | Quantity, *, axis: int = 2, dielectric: float = 1, charge_index: int = 0, atom_indices: int | ndarray[int] = None) None [source]¶
Adds an electric field to all charged particles by adding a force \(f_i=q_iE\) in the axis specified in axis, where \(q_i\) is the per-particle charge and \(E\) is the electric field.
Hint
The following schematic shows how directionality is handled:
|-| (-) ---> |+| |-| <-- E -- |+| |-| <--- (+) |+|
With a positive potential difference (\(\Delta V>0\;\mathrm{V}\)), the electric field is negative (\(E<0\;\mathrm{V/m}\)) such that it is pointing from the right (positive) plate to the left (negative) plate. If an ion has a positive charge (\(q_i>0\;\mathrm{e}\)), the force will be negative, indicating that it will be drawn to the left plate, and vice versa.
- Parameters:
- systemopenmm.System
OpenMM molecular system.
- nbforceopenmm.NonbondedForce or openmm.CustomNonbondedForce
Pair potential object containing particle charge information.
Note
It is assumed that the charge \(q\) information is the first per-particle parameter stored in nbforce. If not, the index can be specified in charge_index.
- Efloat or openmm.unit.Quantity
Electric field \(E\).
Reference unit: \(\mathrm{kJ/(mol\cdot nm\cdot e)}\).
- axisint, keyword-only, default:
2
Axis along which the walls are placed.
0
,1
, and2
correspond to \(x\), \(y\), and \(z\), respectively.- dielectricfloat, keyword-only, default:
1
Relative permittivity \(\varepsilon_\mathrm{r}\) of the medium. Used to scale the particle charges by \(\sqrt{\varepsilon_\mathrm{r}}\) and recover the original values.
- charge_indexint, keyword-only, default:
0
Index of charge \(q\) information in the per-particle parameters stored in nbforce.
- atom_indicesint or array-like, keyword-only, optional
Indices of atoms to apply the electric field to. By default, the electric field is applied to all atoms, but this can be computationally expensive when there are charged particles that do not need to be included, such as image charges. If an int is provided, all atoms up to that index are included.