From: Lutz Maibaum (maibaum_at_berkeley.edu)
Date: Thu Oct 05 2006 - 12:44:30 CDT

On Thursday 05 October 2006 08:06, Marco Kalweit wrote:
> If I remember correctly then following this, I had a look at the dump
> files and found that the types were messed up.
> So I thought that this was a Lammps bug and did not care about it futher
> at the moment.

I don't think it's a bug in LAMMPS. Please take a look at the sample file I
posted a few days ago:

http://www.ks.uiuc.edu/Research/vmd/mailing_list/vmd-l/att-7959/np2.lammpstrj

In gnuplot you can display the positions of the different atom types with the
following command:

splot "np2.lammpstrj" u 3:4:($2 == 1 ? $5 : 1/0) w p, "" u 3:4:($2 == 2 ? $5 :
1/0) w p, "" u 3:4:($2 == 3 ? $5 : 1/0) w p

You see five parallel planar layers as expected. If you load the same file
into vmd and choose "type" as the coloring method, you get atoms at the same
positions, but the type assignment is incorrect.

> The change you made will stop reading the file in as soon as it finds an
> error. So I do not quite understand how it reads in correctly, following
> a problem with the type or the id.

In the current version of the LAMMPS plugin the function read_lammps_structue
basically looks like

  for(i=0;i<data->numatoms;i++) {
    j = sscanf(szBuffer, "%d %s %f %f %f", &atomid, atom_type, &x, &y, &z);
    atom = atoms + i;
    strncpy(atom->type, atom_type, sizeof(atom->type));
  }

For the i-th line in the LAMMPS trajectory file, the atom type is assigned to
the atom with index i in the vmd data structure. On the other hand, in
read_lammps_timestep, we have

  for (i=0; i<natoms; i++) {
    j = sscanf(szBuffer, "%d %s %f %f %f", &atomid, atom_name, &x, &y, &z);
    if (atomid > 0 && atomid <= natoms) {
      int addr = 3 * (atomid - 1);
      ts->coords[addr ] = x * l[0];
      ts->coords[addr + 1] = y * l[1];
      ts->coords[addr + 2] = z * l[2];
    }
  }

so that the position of each atom is assign to the atom with index atomid in
the vmd data structure. This is inconsistent with type assignment, unless the
trajectory file is ordered by increasing atomid. By simply changing

      atom = atoms + i;

to

    atom = atoms + atomid - 1;

in read_lammps_structure, the assignment of atom type to an atom in the vmd
data structure is based on the atomid rather than the position in the
trajectory file, which makes it consistent with the assignment of the atom
coordinates.

Hope this helps,

  Lutz