How Do i Extract Only The Coordinates xyz (Number) From This Log file

this Log contains the information of all coordinates of many atoms in a molecular dynamics simulation for a long sequence of time steps, along with some extra information other than the coordinates.

i just want to extract only the coordinates and want to Sort[] it in increasing number of atoms as you can see the Atoms column is not sorted out.

All Help Is Appreciated. Thank you.

• What have you tried? Why not to post the data (not just screenshot) so we can copy it and try. Have you tried Import? – BlacKow Apr 22 '16 at 17:09
• use Import[ filename , "Table" ]. From there it is straightforward to extract the data you need. – george2079 Apr 22 '16 at 17:36

Here is an example using your log file. Your file is very well structured, at each "TIMESEP" log, the data always starts from the 10th line. Using that information, you can easily split each time step into a group, and read the data from each group.

data = ReadList["atom.lammpstrj", "String"];
data2 = Split[data, #2 =!= "ITEM: TIMESTEP" &][[All, 10 ;; -1]];
data3 = ReadList[StringToStream[StringRiffle[#, "\n"]],
{Number, Number, Number, Number, Number}] & /@ data2;


Now you can use something like data3[[All, All,{3,4,5}]] to get the column you want.

Hope that can get you started.

Cases[ ] helps selecting just what we want from a file with many different types of records. First, import the file

file = Import["filename", "Table"]


define the appropriate pattern

pattern = {_Integer, _Integer, _Real, _Real, _Real}


and extract the selected records

u = Cases[file, pattern]


Sort by the first column

v = SortBy[u, #[[1]] &]


Sure it can be performed in a single command line

v = SortBy[Cases[file, {_Integer, _Integer, _Real, _Real, _Real}], #[[1]]&][[All, {3, 4, 5}]]


including also the reduction of the list to the coordinates values.