SetDirectory[NotebookDirectory[]];
"Say 2 particles' coordinate at time steps it=1, it=2 and it=3 are given in terms of x[it,np],y[it,np]"

x[1,1]=x[1,1]
y[1,1]=y[1,1]
z[1,1]=z[1,1]
x[1,2]=x[1,2]
y[1,2]=y[1,2]
z[1,2]=z[1,2]

x[2,1]=x[2,1]
y[2,1]=y[2,1]
z[2,1]=z[2,1]
x[2,2]=x[2,2]
y[2,2]=y[2,2]
z[2,2]=z[2,2]

x[3,1]=x[3,1]
y[3,1]=y[3,1]
z[3,1]=z[3,1]
x[3,2]=x[3,2]
y[3,2]=y[3,2]
z[3,2]=z[3,2]

"You can group them according to time step specified by it"

txyz[it_]:=Table[{x[it,np],y[it,np],z[it,np]},{np,1,2}]
txyz[1]
txyz[2]
txyz[3]

"Let's assign random values to these coodinates"
For[it=1,it≤3,it++,
For[np=1,np≤2,np++,
x[it,np]=Random[];
y[it,np]=Random[];
z[it,np]=Random[];
];
];(*end for it*)

"Display them using Table[]"
txyz[1]
txyz[2]
txyz[3]

"Visualise these coordinates using Graphics3D[Points] for it=1,2,3"
Graphics3D[{PointSize[0.02],Point[txyz[1]]},Boxed->True,PlotRange->{{0,1},{0,1},{0,1}},Axes->True]
Graphics3D[{PointSize[0.02],Point[txyz[2]]},Boxed->True,PlotRange->{{0,1},{0,1},{0,1}},Axes->True]

"Check the length of txyz[1]"
Length[txyz[1]]

"Export txyz[1] as txyz1.dat and then view it using FilePrint['txyz1.dat']"
Export["txyz1.dat",txyz[1]]
 FilePrint["txyz1.dat"]
"The output file looks good. There are two lines in txyz1.dat, correspond to the number of lines in the original data txyz[1]"

"What happen if you join up txyz[1],txyz[2],txyz[3] using Table and then export them?"

"Check the length of ttxyz" 
ttxyz=Table[txyz[it],{it,1,3}]
Length[ttxyz]

"If you export ttxyz into ttxyz.dat, how many lines of data do you think you will get?"
"Export ttxyz as ttxyz.dat and then view it using FilePrint['ttxyz.dat']"
Export["ttxyz.dat",ttxyz]
 FilePrint["ttxyz.dat"]
"The output file contains three lines, the same number of Length[ttxyz]"

" So, now how to make ttxyz to have only 6 lines of data, and without any curly brackter? You 'Flatten' them ".
"Original ttxyz looks like "
ttxyz

"After Flattening, they looks like "
Flatten[ttxyz,1]

"Length of Flatten[ttxyz,1]?"
Length[ Flatten[ttxyz,1]]

"So, now if you export Flatten[ttxyz,1] into ttxyz.dat, do you expect it a data file of how many lines ? And do you expect to see curly bracket in ttxyz.dat?"
"Let's do it and see"

"Export ttxyz as ttxyz.dat and then view it using FilePrint['ttxyz.dat']"
Export["ttxyz.dat",Flatten[ttxyz,1]]
 FilePrint["ttxyz.dat"]
"The output file contains three lines, the same number of Length[Flatten[ttxyz,1]], which is " 
Length[Flatten[ttxyz,1]]

"So, now how look at the xyz format"

;

"Using the coordinates of the two particles at time step it=1, how do you creat a file, txyz1.dat that has the format as displayed?"
"First, you got to modify the definition of txyz[it]"
txyz[it_]:=Table[{x[it,np],y[it,np],z[it,np]},{np,1,2}]
txyz[1]

"Define instead txyz[it] as "
txyz[it_]:=Table[{C,x[it,np],y[it,np],z[it,np]},{np,1,2}]
txyz[1]

"where C in the first column in the row refers to the type of element of that particle"

"How would you append the first two lines of information 'number of atom' and 'comment' to the block of txzy[1], so that it completes the format of a *.xyz file ?"

txyz[1]

Length[txyz[1]]

"Try {2,Comment,txyz[1]}"
{2,"Comment",txyz[1]}

"Check the Length to make sure that it is 4 in total, as a block of data at a given time step in 8.xyz format has 2 + number of atoms = 2 + 2 = 4 in our case"

Length[{2,"Comment",txyz[1]}]

"Nope. It is 3, not 4. How would you fix the problem? Again, use Flaten lah"

Flatten[{2,"Comment",txyz[1]},1]
Length[Flatten[{2,"Comment",txyz[1]},1]]

"Export and FilePrint the table to see if we have got the format right"
Export["txyz1.dat",Flatten[{2,"Comment",txyz[1]},1]]
FilePrint["txyz1.dat"];

"The formated data file now looks like that of a *.xyz format"

"You can view the *.xyz file containing a single time step by Import it in XYZ format"
Import["txyz1.dat","XYZ"]

"Now combine all data, txyz[it], it = 1, 2, 3, into a single data file that has the right *.xyz format"

dataxyz[it_]:=Flatten[{2,"Comment",txyz[it]},1];
dataxyz[1]
dataxyz[2]
tdataxyz=Table[dataxyz[it],{it,1,3}]
Length[tdataxyz]

"Need to Flatten tdataxyz"
Flatten[tdataxyz,1]
Length[Flatten[tdataxyz,1]]

"Export and FilePrint the table to see if we have got the format right"

Export["tdataxyz.dat",Flatten[tdataxyz,1]]
FilePrint["tdataxyz.dat"];

"So, now we have completed our task of casting the simulation data of the two particles in the 3D box in three time steps into the form of a *.xyz format. "

"Nope. You can't import tdataxyz.dat as XYZ format in Mathematica as the file contains more than a single frame of configuration. The video of tdataxyz.dat can be visualised using VMD, a visualisation softwere"