2
$\begingroup$

I'm running a LAMMPS simulation with 2197 atoms, when writing the trajectory file, I only write the information of atoms that enter a specific region in the simulation box. Because of this the number of atoms in the traj file is less than the total number of atoms defined in the toplogy file. Hence I'm getting the error:

ValueError: The topology and LAMMPSDUMP trajectory files don't have the same number of atoms! Topology number of atoms 2197 Trajectory: dump.gz Number of atoms 1 

How can I load this type of files ? Thanks for any help. Here is how I load this:

import MDAnalysis as mda u = mda.Universe('datafile.data', 'dump.gz', format='lammpsdump') 
$\endgroup$
1
  • $\begingroup$ I'm not sure you can visualize a trajectory if the number of atoms changes. I'm not familiar with LAMMPS specifically, but for example, in AMBER, when I strip molecules like water or ions from the trajectory, I have to generate a new parameter/topology file to match the modified trajectory. So I think you’ll need to generate a new parameter file for your updated trajectory as well. $\endgroup$ Commented Apr 18 at 11:02

1 Answer 1

1
$\begingroup$

If you are strictly not looking to use available libraries, it is fairly straightforward to do that using Fortran. I have copied below the code that I use to parse LAMMPS dump files, and it processes one frame at a time.

 program coordination implicit none ! declare buffers double precision, allocatable :: c(:,:), q(:) integer, allocatable :: aindex(:), atype(:) character(len=2), allocatable :: aname(:) ! declare variables double precision :: ax, ay, az double precision :: dx, dy, dz double precision :: wx, wy, wz double precision :: xl, yl, zl double precision :: xh, yh, zh double precision :: xx, yy, zz integer :: ia, ib, ic integer :: na character(len=80) :: ifile ! get input file name call get_command_argument(1, ifile) open (unit = 10, file = ifile, status = "old", action = "read") ! here 20001 is the total number of frames in my LAMMPS dump file do ia = 1, 20001 read (10, *) read (10, *) read (10, *) read (10, *) na read (10, *) read (10, *) xl, xh read (10, *) yl, yh read (10, *) zl, zh read (10, *) ! allocate buffers at each frame allocate (c(na, 3)) allocate (aindex(na)) allocate (atype(na)) allocate (aname(na)) allocate (q(na)) do ib = 1, na read (10, *) aindex(ib), atype(ib), aname(ib), (c(ib, ic), ic = 1, 3), q(ib) end do free(c) free(q) free(aindex) free(atype) free(aname) end do 

Here I am reading a LAMMPSTRJ file with the following data dumped for each atom: index, type, element name, coords and charge.

$\endgroup$
1
  • $\begingroup$ Thank you, this is good. But I need something with lazy-loading feature. I'm simulating for a few microseconds, so processing each step at a time is not practical. Meanwhile I have written my own library which can do this. I was also told that Ovito can do this. I have not tried it though. $\endgroup$ Commented May 14 at 7:49

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.