Code for Calculating MSD

I ran the following code snippet in order to calculate MSD of two
hydrogen atoms that I placed manually in an FCC copper system.

units metal

dimension 3

boundary p p p
atom_style atomic

atom_modify map array sort 0 0
read_data Data25.R1

pair_style bop

pair_coeff * * CuH.bop.table Cu H

comm_modify cutoff 11.4

mass 1 63.5460

mass 2 1.00794

timestep 0.001

thermo 200000

fix 1 all nvt temp 600 600 0.1

fix 3 all momentum 1 linear 1 1 1
thermo_style custom step temp press vol enthalpy ke pe etotal lx ly lz density atoms
group Cu type 1

group H type 2

compute 2 H msd
fix 4 H ave/time 20000 5 100000 c_2 file H.txt mode vector

thermo_style custom step temp press vol enthalpy ke pe etotal lx ly lz density atoms

thermo_modify lost warn

dump 2 all atom 200000 copper_box_300K.lammpstrj

dump 3 all custom 200000 copper_box_300k_final.dump id type x y z vx vy vz

restart 100000 poly.restart

write_data Data.R2

write_restart copper_box_300k.restart

run 1000000 upto

These two following lines that I have used to compute MSD and
then to take time averages, are they correct?

compute 2 H msd
fix 4 H ave/time 20000 5 100000 c_2 file H.txt mode vector

If yes, in the text file that is generated as H.txt, how will the data be presented?

Also, in the built in LAMMPS example list, I found a folder called DIFFUSION.

I am copying and pasting a few lines in that code used for computing MSD and
eventually, the slope. For now, all I need help with is to find the MSD in every timestep
for Hydrogen atoms in my case. So, how should I modify the codes in the example to
get just the MSD in every timestep? Any help would be highly appreciated.

Your commands are fine, but you don’t want to time average the MSD with fix ave/time.
You want the slope of the raw data. So I suggest you dump it to a file with fix ave/time
with params like 1000 1 1000, which will do no time averaging.

Also note that compute mid produces 4 values. The first 3 are the xyz components.
The 4th is the total MSD. The latter is typically what you want to fit a line to for
a diffusion coeff.

Steve