Can lammps output trajectory files by atom type?

Dear Lammps-users,
I’m running nvt MD using lammps and dump trajectory file using ‘dump’ command.

dump 2 all custom 1000 nvt.xyz id type x y z

But I find that it didn’t sort by atoms’ type. I mean, it output this:

ITEM: ATOMS id type x y z
1 1 1.21449 48.8156 1.53761
2 2 49.6714 36.0736 12.3089
3 1 21.4936 1.41038 16.272
4 2 23.5148 20.2871 49.1109
5 1 12.1225 42.1564 21.4642
6 2 38.9356 31.4116 16.8126
7 1 18.2961 19.6674 6.59833
8 2 17.7378 6.54736 31.8863
9 1 7.63241 33.1461 49.549
10 2 14.8429 41.6708 34.7358

but I want this(first output the type 1, then type 2):

ITEM: ATOMS id type x y z
1 1 1.21449 48.8156 1.53761
3 1 21.4936 1.41038 16.272
5 1 12.1225 42.1564 21.4642
7 1 18.2961 19.6674 6.59833
9 1 7.63241 33.1461 49.549
2 2 49.6714 36.0736 12.3089
4 2 23.5148 20.2871 49.1109
6 2 38.9356 31.4116 16.8126
8 2 17.7378 6.54736 31.8863
10 2 14.8429 41.6708 34.7358

Is there any method to do this?

Best regards,
Bill

Why not create a python code to order it in ascending order with respect to atom type? :slight_smile:

Hello,

@ceciliaalvares’ solution would definitely work, but there is actually a simpler way: you can directly use the sort id option of the dump_modify command:

dump 2 all custom 1000 nvt.xyz id type x y z
dump_modify 2 sort id

Simon

1 Like

Interesting… It definately would have saved me some time when post-processing trajectories :"D
Oh well… why solve it in a simple way when you can solve it with “for” loops in python haha

hi simon
thank you very much
I have tried your method, and the output are sort by id, not type, which is the first result shown below

I hope lammps have its own way :joy: If it didn’t I will try python

True, I read your message too fast and though you wanted to sort by ids.

Sorting by type does not seem to be an option currently offered by the dump_modify, therefore the homemade script proposed by @ceciliaalvares is probably the best option.

If not required by the file format itself, LAMMPS dump files are always unsorted. The order of atoms in the dump file depends on the neighbor list build and - if run in parallel - on the domain decomposition. This is for maximum efficiency and to avoid additional communication which can limit parallel scaling for large numbers of processors.

It is quite possible to request sorted output, but it has to be done explicitly through the dump_modify command. Sorting can be done on the atom-ID (always) or on any property that is output in the dump. To sort your dump file by atom type you would need to issue the command:

dump_modify 2 sort 2

Please note that this will not guarantee that identity of atoms will always be the same between the dumps as the atom ID will be mixed as atoms move around as explained above. For having a more complex sorting you would need to create a per-atom property that defines the unique sort priority and output it. E.g. if you have no more than 10000 atoms per type in your system, you could define an atom style variable and output and sort on that as follows:

variable sortme atom 10000*type+id
dump 2 all custom 1000 nvt.xyz id type x y z v_sortme
dump_modify 2 sort 6
2 Likes

It is an option for as long as “type” is one of the output columns.

thank you very much