How to call the Number of atoms in a dump file using pizza.py?

Hi,
I’m trying to reorganize the data from a dump file using pizza.py, but I’m having trouble trying to call the ITEM: NUMBER OF ATOMS, and be able to update the value as it change in every timestep, any idea about how I can do this using dump.py in pizza.py?

That is a question for @sjplimp. This should notify him.

After looking at the dump.py file for a little bit and reading through the embedded documentation.

How about the following?

from dump import dump

d = dump('my.dump')
d.tselect.all()
frames = d.time()
for f in frames:
  print("Step %d has %d atoms" % (f, len(d.vecs(f,'id'))))
1 Like

I did what you suggested and additionally, I put the following code in order to recount the number id for the atoms each timestep:

from dump import dump
import numpy as np

d = dump(‘second.dump’)

d.tselect.all()
frames = d.time()
numcols=len(frames)-1
v = np.empty((numcols,0),int)

for f in frames:
print("Step %d has d atoms" (f, len(d.vecs(f,‘id’))))
for f in frames:
v = np.append(v,np.array([len(d.vecs(f,‘id’))]))
print(v)
for i in range(len(v)):
d.setv(‘id’,range(1,v[i]+1))
d.sort(‘id’)
d.write(‘organize.dump’)

But, I’m getting the following error:

Traceback (most recent call last):
File “/home/v.sierrajimenez/Valentina/pizza-9Oct15/src/pizza.py”, line 229, in trap
execfile(fullfile,namespace)
File “/home/v.sierrajimenez/Valentina/pizza-9Oct15/scripts/test_dump2.py”, line 20, in
d.setv(‘id’,range(1,v[i]+1))
File “/home/v.sierrajimenez/Valentina/pizza-9Oct15/src/dump.py”, line 831, in setv
raise StandardError,“vec length does not match # of selected atoms”
StandardError: vec length does not match # of selected atoms

do you know how I could fix this error? it seems like it is not reading the vector each timestep. Thank you!

If you insert a print statement:

for i in range(len(v)):
    print(i, v[i])
    ...

What do you see?

Hi

from dump import dump
import numpy as np

d = dump(‘second.dump’)

d.tselect.all()
frames = d.time()
numcols=len(frames)-1
v = np.empty((numcols,0),int)

for f in frames:
print("Step %d has d atoms" (f, len(d.vecs(f,‘id’))))
for f in frames:
v = np.append(v,np.array([len(d.vecs(f,‘id’))]))
print(v)
for i in range(len(v)):
lst = np.append(lst,np.array([list(range(1,v[i]+1))]))
print(lst)
print(i, v[i])

this is part of the results:
(21, 15103)
[ 1 2 3 …, 15101 15102 15103]
(22, 15103)
[ 1 2 3 …, 15100 15101 15102]
(23, 15102)
[ 1 2 3 …, 15100 15101 15102]
(24, 15102)
[ 1 2 3 …, 15098 15099 15100]
(25, 15100)
[ 1 2 3 …, 15098 15099 15100]
(26, 15100)

I’ve been using dump.py from tools/python/pizza. That is python 3 compatible and has a bunch of issues fixed. The version from the pizza.py repo is many years old and only supports python 2.

BTW: To sort a dump file by ID, I only need to do:

from dump import dump

d = dump('my.dump')
d.tselect.all()
d.sort()
d.write('sorted.dump')

Sorry, but I have helped as much as I am willing to invest time and as far as I consider meaningful.

  • If you want to figure out whether there are significant differences between the dump.py file you have from the Pizza.py repo or what is available from the LAMMPS distribution, you can just use both and compare
  • I and others have already voiced our concern that changing the files in such a way that atom-IDs no longer remain constant with the same atoms is a bad idea.

You are - obviously - free to continue, but it should be understandable, that you are on your own with that. At least as far as I am concerned.