Combining multiple chunks -- ugly way!

The task is to compute a density profile for a slab, making it less noisy by using a sufficiently large bin. The problem is that the larger the bin, the coarser the profile is. My solution is to compute multiple chunks, whose number is bin/resolution, in this case, I want a spacing of 0.5 A and a bin size of 4 A, hence I need 8 computes.

The problem is that I haven’t found an elegant fix to combine the chunks into a single output, so my ugly solution is to define an identical number of fix ave/chunk and then combine the output files into a single one at the end of the calculation. Here the relevant snippet:

compute c2 all chunk/atom bin/1d z -55.5 4 units box
compute c3 all chunk/atom bin/1d z -56.0 4 units box
compute c4 all chunk/atom bin/1d z -56.5 4 units box
compute c5 all chunk/atom bin/1d z -57.0 4 units box
compute c6 all chunk/atom bin/1d z -57.5 4 units box
compute c7 all chunk/atom bin/1d z -58.0 4 units box
compute c8 all chunk/atom bin/1d z -58.5 4 units box
# average every 1 frame, repeat 500 times, print only once at last timestep.
fix f1 all ave/chunk 1 500 2502 c1 density/mass ave running file ${run}.out1
fix f2 all ave/chunk 1 500 2502 c2 density/mass ave running file ${run}.out2
fix f3 all ave/chunk 1 500 2502 c3 density/mass ave running file ${run}.out3
fix f4 all ave/chunk 1 500 2502 c4 density/mass ave running file ${run}.out4
fix f5 all ave/chunk 1 500 2502 c5 density/mass ave running file ${run}.out5
fix f6 all ave/chunk 1 500 2502 c6 density/mass ave running file ${run}.out6
fix f7 all ave/chunk 1 500 2502 c7 density/mass ave running file ${run}.out7
fix f8 all ave/chunk 1 500 2502 c8 density/mass ave running file ${run}.out8

# Output.
thermo          1
thermo_style custom step cpu
thermo_modify flush yes
rerun ../${run}.dcd first 2002 dump x y z box yes format molfile dcd /usr/local/lib/vmd/plugins/LINUXAMD64/molfile

# Merge all output files:
shell bash merge.sh ${run}.out1 ${run}.out2 ${run}.out3 ${run}.out4 ${run}.out5 ${run}.out6 ${run}.out7 ${run}.out8 > ${run}.out 

# Where the script merge.sh is as follows:
## Extract the column 2 and 4 from a number of files.
#awk '$1>0{print $2,$4}' $@ | sort -n
## hide my crimes.
#rm -f $@

This is the result. For comparison, you can see the outcome of using a single bin size, in this case with spacing 0.5 (noisy profile) and 4 Angstroms (coarse profile).

Any idea?

1 Like

Solution for which problem? The converged profile you expect depends on the resolution you use and the material. A fine grained profile of a crystal will show you peaks at crystalline positions and 0 values inbetween (it can also depends on the slabs orientation wrt. the crystal axes), while a large grained profile will converge to a flat average density of the material. For an glass material, you expect to go from local density variation to a flat average as well. You only expect a flat profile for amorphous liquids, and convergence can depend on temperature and liquid complexity (amorphous polymer can be long to converge).
With enough statistics you expect to get the larger resolution result by averaging neighbour bins of the smaller resolution (which might be a cleaner way of getting your black curve).

If you want the actual converged profile, you might need more data/longer simulations. If you want an estimate of the average profile, you might want to compute rolling averages with different windows in post-processing scripts. For this last solution, a programming language like Python, Perl or C might be more suited than LAMMPS.

Thanks for the comment! I forgot to mention that the sample is an amorphous material and that the particular results shown here refer to a small sample of 1000 molecules.

The point was not to discuss the physics of my system, but rather if there is a way to combine the output of different compute chunk/atom commands into a single file. I shared a possible solution; I am just wondering if there is a more elegant solution :slight_smile: