fix efield/lepton command — LAMMPS documentation

\(\renewcommand{\AA}{\text{Å}}\)

# fix efield/lepton command

## Syntax

    fix ID group-ID efield/lepton V ...

- ID, group-ID are documented in the fix command

- style = efield/lepton

- V = electric potential (electric field * distance units)

- V must be a Lepton expression (see below)

- zero or more keyword/value pairs may be appended to args

- keyword = region or step

      region value = region-ID
        region-ID = ID of region atoms must be in to have effect
      step value = h
        h = step size for numerical differentiation (distance units)

## Examples

    fix ex all efield/lepton "-E*x; E=1"
    fix dexx all efield/lepton "-0.5*x^2" step 1
    fix yukawa all efield/lepton "A*exp(-B*r)/r; r=abs(sqrt(x^2+y^2+z^2)); A=1; B=1" step 1e-6
    fix infp all efield/lepton "-abs(x)" step 1

    variable th equal 2*PI*ramp(0,1)
    fix erot all efield/lepton "-(x*cos(v_th)+y*sin(v_th))"

## Description

Added in version 4Feb2025.

Add an electric potential \(V\) that applies to a group of charged atoms a force \(\vec{F} = q \vec{E}\), and to dipoles a force \(\vec{F} = (\vec{p} \cdot \nabla) \vec{E}\) and torque \(\vec{T} = \vec{p} \times \vec{E}\), where \(\vec{E} = - \nabla V\). The fix also evaluates the electrostatic energy (\(U_{q} = q V\) and \(U_{p} = - \vec{p} \cdot \vec{E}\)) due to this potential when the fix_modify energy yes command is specified (see below).

Note

This command should be used instead of fix efield if you want to impose a non-uniform electric field on a system with dipoles since the latter does not include the dipole force term. If you only have charges or if the electric field gradient is negligible, fix efield should be used since it is faster.

The Lepton library, that the efield/lepton fix style interfaces with, evaluates the expression string at run time to compute the energy, forces, and torques. It creates an analytical representation of \(V\) and \(\vec{E}\), while the gradient force is computed using a central difference scheme

\[\vec{F} = \frac{|\vec{p}|}{2h} \left[ \vec{E}(\vec{x} + h \hat{p}) - \vec{E}(\vec{x} - h \hat{p}) \right] .\]

The Lepton expression must be either enclosed in quotes or must not contain any whitespace so that LAMMPS recognizes it as a single keyword. More on valid Lepton expressions below. The final Lepton expression must be a function of only \(x, y, z\), which refer to the current unwrapped coordinates of the atoms to ensure continuity. Special care must be taken when using this fix with periodic boundary conditions or box-changing commands.

## Lepton expression syntax and features

Lepton supports the following operators in expressions:

+ | Add |  | - | Subtract |  | * | Multiply |  | / | Divide |  | ^ | Power

The following mathematical functions are available:

sqrt(x) | Square root | exp(x) | Exponential
log(x) | Natural logarithm | sin(x) | Sine (angle in radians)
cos(x) | Cosine (angle in radians) | sec(x) | Secant (angle in radians)
csc(x) | Cosecant (angle in radians) | tan(x) | Tangent (angle in radians)
cot(x) | Cotangent (angle in radians) | asin(x) | Inverse sine (in radians)
acos(x) | Inverse cosine (in radians) | atan(x) | Inverse tangent (in radians)
sinh(x) | Hyperbolic sine | cosh(x) | Hyperbolic cosine
tanh(x) | Hyperbolic tangent | erf(x) | Error function
erfc(x) | Complementary Error function | abs(x) | Absolute value
min(x,y) | Minimum of two values | max(x,y) | Maximum of two values
delta(x) | delta(x) is 1 for x = 0, otherwise 0 | step(x) | step(x) is 0 for x < 0, otherwise 1

Numbers may be given in either decimal or exponential form. All of the following are valid numbers: 5, -3.1, 1e6, and 3.12e-2.

As an extension to the standard Lepton syntax, it is also possible to use LAMMPS variables in the format “v_name”. Before evaluating the expression, “v_name” will be replaced with the value of the variable “name”. This is compatible with all kinds of scalar variables, but not with vectors, arrays, local, or per-atom variables. If necessary, a custom scalar variable needs to be defined that can access the desired (single) item from a non-scalar variable. As an example, the following lines will instruct LAMMPS to ramp the force constant for a harmonic bond from 100.0 to 200.0 during the next run:

    variable fconst equal ramp(100.0, 200)
    bond_style lepton
    bond_coeff 1 1.5 "v_fconst * (r^2)"

An expression may be followed by definitions for intermediate values that appear in the expression. A semicolon “;” is used as a delimiter between value definitions. For example, the expression:

    a^2+a*b+b^2; a=a1+a2; b=b1+b2

is exactly equivalent to

    (a1+a2)^2+(a1+a2)*(b1+b2)+(b1+b2)^2

The definition of an intermediate value may itself involve other intermediate values. Whitespace and quotation characters (’'’ and ‘”’) are ignored. All uses of a value must appear before that value’s definition. For efficiency reasons, the expression string is parsed, optimized, and then stored in an internal, pre-parsed representation for evaluation.

Evaluating a Lepton expression is typically between 2.5 and 5 times slower than the corresponding compiled and optimized C++ code. If additional speed or GPU acceleration (via GPU or KOKKOS) is required, the interaction can be represented as a table. Suitable table files can be created either internally using the pair_write or bond_write command or through the Python scripts in the tools/tabulate folder.

If the region keyword is used, the atom must also be in the specified geometric region in order to be affected by the potential.

The step keyword is required when atom_style dipole is used and the electric field is non-uniform.

## Restart, fix_modify, output, run start/stop, minimize info

No information about this fix is written to binary restart files.

The fix_modify energy option is supported by this fix to add the potential energy defined above to the global potential energy of the system as part of thermodynamic output. The default setting for this fix is fix_modify energy no.

The fix_modify virial option is supported by this fix to add the contribution due to the added *forces* on charges and dipoles to both the global pressure and per-atom stress of the system via the compute pressure and compute stress/atom commands. The former can be accessed by thermodynamic output. The default setting for this fix is fix_modify virial no.

The fix_modify respa option is supported by this fix. This allows to set at which level of the r-RESPA integrator the fix adding its forces. Default is the outermost level.

This fix computes a global scalar and a global 3-vector of forces, which can be accessed by various output commands. The scalar is the potential energy discussed above. The vector is the total force added to the group of atoms. The scalar and vector values calculated by this fix are “extensive”.

This fix cannot be used with the start/stop keywords of the run command.

The forces due to this fix are imposed during an energy minimization, invoked by the minimize command. You should not specify force components with a variable that has time-dependence for use with a minimizer, since the minimizer increments the timestep as the iteration count during the minimization.

Note

If you want the electric potential energy to be included in the total potential energy of the system (the quantity being minimized), you MUST enable the fix_modify energy option for this fix.

## Restrictions

Fix style efield/lepton is part of the LEPTON package. It is only enabled if LAMMPS was built with that package. See the Build package page for more info.

## Related commands

fix efield

## Default

none