Impose forces at each timestep

Hi everyone,
I am using Lammps version 2Aug2023.
I want Lammps not to calculate force at each timestep. Instead, I will impose forces at each timestep. Do you have any hints for me?
I tried imposing forces by ‘extract_atom’ but I dont exactly how it works.
Thank you very much.
Below is code example in PyLammps:

from lammps import lammps
import numpy as np

lmp = lammps()

######################################

# INITIALIZATION

lmp.command('units metal')

lmp.command('dimension 2')

lmp.command('boundary p p p')

lmp.command('atom_style atomic')

######################################

# SIMULATION BOX

lmp.command('region whole block 0 5 0 5 0 10')

lmp.command('create_box 1 whole')

lmp.command('create_atoms 1 single 4 4 5')

lmp.command('create_atoms 1 single 3 1 5')

lmp.command('create_atoms 1 single 0.2 4 5')

lmp.command('create_atoms 1 single 3.5 3.5 5')

lmp.command('create_atoms 1 single 0.2 2 5')

######################################

# ATOM DEFINITION

lmp.command('mass 1 26.98')

lmp.command('neighbor 0 bin')

lmp.command('neigh_modify every 1 check no')

######################################

# DEFINE INTERATOMIC POTENTIAL

lmp.command('pair_style lj/cut 10')

lmp.command('pair_coeff * * 0.01 0.01')

######################################

# EQUILIBRATION

lmp.command('timestep 0.001')

lmp.command('velocity all create 300 12345 mom yes rot no')

lmp.command('fix 1 all nvt temp 300 300 1 ')

lmp.command('run 1')

pos = lmp.numpy.extract_atom('x')

force = lmp.numpy.extract_atom('f')

f = lmp.extract_atom('f')

pred_force = np.random.rand(5,3)

for i in range (force.shape[0]):

f[i][0], f[i][1], f[i][2] = pred_force[i][0], pred_force[i][1], pred_force[i][2]

lmp.command('run 1')

You can use either pair style none or pair style zero (and the corresponding styles for bonded interactions, if needed).

https://docs.lammps.org/fix_external.html

That cannot work the way you did it because forces (and torques etc.) are cleared before calling the compute functions for the force styles. You would have to make your modification during the run using fix python/invoke fix python/invoke command — LAMMPS documentation
But fix external is the more general and recommended approach.

Yes, thank you for your answers.
I have some additional questions.
I also use pair_style lj/cut in my simulation because I want to get neighbor list. But I want Lammps not to calculate forces or using my own forces which I impose. Do you have any hints?
Thanks a lot.

I have already given them. Please study my response and the corresponding LAMMPS documentation more carefully.

Thank you very much.