I seem to be having trouble using the python interface to do something.
I want to be able to displace an atom and then query the forces that are generated.
So I create a ctype thing using gather_atoms
x0ctype = lmp.gather_atoms("x",1,3)
["lmp" is my instance of lammps]
As I understand it, this array now has x,y,z for the first atom, then x,y,z for the second, and so forth
Then I displace an atoms by modifying x0ctype
For example,
x0ctype[0] += h
then I use scatter_atoms to put the entire array back into LAMMPS' memory locations:
lmp.scatter_atoms("x",1,3,x0ctype)
[I have set
atom_modify map hash
which I understand is necessary for this to work.]
Then I execute a single step
lmp.command("run 0 post no")
To query the forces and make an array which corresponds to the atoms as contained in x0ctype,
I do this:
fx = lmp.extract_variable("fx","all",1)
fy = lmp.extract_variable("fy","all",1)
fz = lmp.extract_variable("fz","all",1)
fs = np.array([ [fx[i],fy[i],fz[i]] for i in range(len(fz)) ]).flatten()
(np is "numpy")
In the input to lammps, I have
variable fx atom fx
variable fy atom fy
variable fz atom fz
to define the variables.
This does not seem to be working. The forces are not as expected.
I seem to be doing something fundamentally wrong.
Any suggestions would be appreciated.