LAMMPS WWW Site - LAMMPS Documentation - LAMMPS Mailing List Archives
Re: [lammps-users] Questions about loop in lammps

# Re: [lammps-users] Questions about loop in lammps

 From: Giacomo Fiorin Date: Tue, 12 Dec 2017 11:02:35 -0500

The "clear" command will delete all atoms, therefore the loop index goes out of bounds when you enter the next iteration.

Also, it is very inefficient to loop over all atoms explicitly, you may consider passing the entire atom-style variables x, y and z to the Python command in one go.

Inside the Python script, try using as many NumPy library functions, and avoid again explicit loops over atoms.

Giacomo

On Tue, Dec 12, 2017 at 10:53 AM, Xuechen Zheng wrote:

Dear all,

I would like to addforce to lammps and the force is calculated by python scripts. However, it seems that it just evaluates the forces per atom. I want to sum the force of all atoms and add it to all atoms. The present input file is

variable         tz2 equal z[1]
variable         tx2 equal x[1]

variable         tz2 equal z[1]

variable         force_z python force_CH4_z
python           force_CH4_z input 3 v_tx2 v_ty2 v_tz2 return v_force_z format ffff file  interp.py

fix               3 all addforce 0 0 v_force_z

It just calculate the first atom's force and it works. Could you tell me how to do a loop that can sum the force of all atoms and do the remaining calculation. I tried the flowing commend

label            loop

variable         a loop 100

variable         tz2 equal z[a]

variable         tx2 equal x[a]

variable         ty2 equal y[a]

variable         force_z python force_CH4_z

python           force_CH4_z input 3 v_tx2 v_ty2 v_tz2 return v_force_z format ffff file interp.py

fix               3 all addforce 0 0 v_force_z

clear

next              a

jump             z_move.force

"

But the result is that "Segmentation fault". Could you tell me how to set a corect loop?

Thanks!

Xuechen Zheng

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most