Author Topic: histogram integrated over all frames  (Read 1557 times)

nico

  • Newbie
  • *
  • Posts: 3
histogram integrated over all frames
« on: March 13, 2017, 07:19:23 AM »
Hello,

* I can nicely generate and see the trajectory file for some selected particles, but I cannot export the trajectory file as a function of frame for the selected particles. For example:
Frame nb, particle 1 X, particle 1 Y, particle 1 Z, particle 2 X, particle 2 Y, particle 2 Z.

* Another related question is that I'd simply use the nice histogram analysis tool, but for all the frames; i.e. for the selected particles integrated over all the selected frames. Do I need to write a python script for that?

Thank you,
Nicolas

Alexander Stukowski

  • Administrator
  • Hero Member
  • *****
  • Posts: 555
Re: histogram integrated over all frames
« Reply #1 on: March 13, 2017, 10:19:48 AM »
Hi Nicolas,

1)
I'm not sure if that is what you have in mind, but OVITO can export the positions of just the selected particles to an XYZ or LAMMPS dump file, for example. Simply apply the "Invert selection" modifier followed by the "Delete selected particles" modifier before using OVITO's file export function.
In case you already knew that, please clarify why this isn't sufficient for you.

2)
Currently, none of the modifiers in OVITO, and that includes the Histogram function, have access to all frames of the loaded simulation. So no global analyses of an entire trajectory is possible. The reason is that OVITO only loads one frame at a time into memory and the data pipeline processes only one frame at a time as well. Otherwise the program would quickly run out of memory in cases of large simulations and/or long trajectories.

Improvements to the data pipeline system in OVITO are being developed as we write. In a not to distant future, I expect that global analyses like the one you describe will become possible. However, that future is still months away.

In the meantime you could write a Python script, yes. You basically have to loop over all input frames in your script and collect whatever data you need in a Numpy array. You may either accumulate already binned per-frame data generated by OVITO's Histogram modifier, or you can collect the raw data and use Numpy's histogram function and do the binning at the end.

nico

  • Newbie
  • *
  • Posts: 3
Re: histogram integrated over all frames
« Reply #2 on: March 13, 2017, 11:10:33 AM »
Hi Alexander,

Thank you.

for 1), in fact I have tried what you suggest. I was just wondering if the formatting can be different. For example, if a single particle is selected, just a 4 column files with
Frame; X; Y; Z. That would be more easy to treat with standard graphic softwares such as origin. That could replace 2) in the meantime.

for 2) thank you. I ll try tomorrow and let you know if I face some difficulties.
Kind regards,
Nicolas

Alexander Stukowski

  • Administrator
  • Hero Member
  • *****
  • Posts: 555
Re: histogram integrated over all frames
« Reply #3 on: March 13, 2017, 04:49:18 PM »
I have written a small Python script modifier for you, which can be inserted into the pipeline. The script function extracts the position of just the selected particle(s), converts the data to a string, and injects it into the data pipeline. You can then use OVITO's file export function (output format: "Calculation Results Text File") to write that string to a text file, one line per time step.

Code: [Select]
def modify(frame, input, output):
# Input data:
pos = input.particle_properties.position.array
sel = input.particle_properties.selection.array

# Retreive the positions of just the selected particles
selected_positions = pos[sel==1].flatten()

# Build a string from the Numpy array that is appropriate for file export
output.attributes['selected_pos'] = ' '.join(map(str, selected_positions))

nico

  • Newbie
  • *
  • Posts: 3
Re: histogram integrated over all frames
« Reply #4 on: March 14, 2017, 03:19:40 AM »
Hi Alexander,

Thanks. I've tried this Python script modifier, but I cannot make it work. I'm new in Ovito, so I need to figure out things. Is it related to the fact that I use the Windows version? or do I have to include some libraries in the header?

What I've done is : Add_modification => Python script => Edit script => Past your python program (I kept the header ovito.data.import*)

I got this error message:
The Python script has exited with an error.
Traceback (most recent call last):
  File "<string>", line 6, in modify
  File "C:\Program Files\Ovito\plugins\python\ovito\data\particles\__init__.py", line 81, in __getattr__
    raise AttributeError("DataCollection does not contain the particle property '%s'." % name)
AttributeError: DataCollection does not contain the particle property 'selection'.

Thanks,
Nicolas

Alexander Stukowski

  • Administrator
  • Hero Member
  • *****
  • Posts: 555
Re: histogram integrated over all frames
« Reply #5 on: March 14, 2017, 08:25:20 AM »
So far you have been doing the right thing. What is missing -and what causes the error message- is the particle selection. The script assumes that one of the atoms is already selected.

In other words, you first have to select the atom for which you want to extract the trajectory. There are various ways of doing that in OVITO. For example, you could use the Expression select modifier to select an atom by index or ID. Or you could use the Manual selection modifier to select an atom using the mouse.

It's important that the selection modifier precedes the Python script modifier in the data pipeline. That means it needs to appear below the Python script modifier in the list box, as explained here.