Problem about python variable in LAMMPS

Hi all,
I meet a problem when defining Python style variable in LAMMPS. I want to calculate the distances of atoms between two groups. The related part of input file is like follows:

Hi all,
I meet a problem when defining Python style variable in LAMMPS. I want to
calculate the distances of atoms between two groups. The related part of
input file is like follows:

********************
compute ygr1 gr1 property/atom y
compute ygr2 gr2 property/atom y
variable hgr1 atom c_ygr1
variable hgr2 atom c_ygr2
variable r0 equal 3.0

variable ncont python myCL
python myCL input 3 v_hgr1 v_hgr2 v_r0 return v_ncont format ffff
here """
def myCL(hgr1,hgr2,r0):
  n = len(hgr1)
  m = int(n/2)
  print "n = ", n
  ncont = 0
  for i in range(0,m):
    dy = hgr2[m+i]-hgr1[i]
    if (dy <= r0):
      ncont+=1
  return ncont
"""
thermo_style custom step cpu etotal pe ke v_ncont
********************
When I run the input file, it printed an ERROR: Could not evaluate Python
function input variable (../python.cpp:227).
However, if I delete "v_ncont" from the last line, i.e.,
thermo_style custom step cpu etotal pe ke
The input file ran correctly.
I have checked that the Python function can run correctly by using Python
directly.
Does anyone know what is the reason? Thank you in advance!

​i don't think you can pass atom style variables with a python function,
hence the error message.
if you want to access internal properties ​directly, you will have to
compute/install the lammps python wrapper as well and then access per-atom
properties via the library interface.

axel.

Dear Axel
I see. Thanks for your suggestions!

Best,
Ouyang