Author Topic: Create custom bins for each frame  (Read 300 times)

ad

  • Newbie
  • *
  • Posts: 25
Create custom bins for each frame
« on: December 13, 2018, 05:14:41 AM »
Hello,
Code: [Select]
for frame_index in range(node.source.num_frames):
    data = node.compute(frame_index)
    mean = numpy.mean(data.particles["Position"][:,1])

I want to create (cube)bin 2 units up and 2 unit down in Y-axis from the mean value get from above code and count the number of selected particle types in that bin region. I looked over the Ovito.modifier I didn't find anything straight, if you can tell, will be great help. My goal is to create customize bin that change it's position over time, relative to statistics of Y-coordinates.

Thanks,
ad

ad

  • Newbie
  • *
  • Posts: 25
Re: Create custom bins for each frame
« Reply #1 on: December 14, 2018, 05:01:21 AM »
Hello Alex,

I tried following
Code: [Select]
for frame_index in range(node.source.num_frames):
    data = node.compute(frame_index)
    selection1 = (data.particles["Particle Type"] == 1)
    selection2 = (data.particles["Particle Type"] == 2)
    mean = numpy.mean(data.particles["Position"][selection1,1])
    lim = 2
   
    if numpy.any(selection2):
      pos = (data.particles["Position"][selection2,1])
      count = numpy.count_nonzero(((mean-lim) < pos) & (pos < (mean+lim)))
      print(count)
    else:
      continue

Works well if I have single selection (portion of the code above if statement) after the if statement, it showed the results for selection 1 particle types instead of selection 2 particle types. Can you please tell me whats wrong going on here? (Particle type 2 was absent in starting several frames so I included if statement ( as suggested in previous forum answer)).

Thanks,
ad
   

Constanze Kalcher

  • Administrator
  • Sr. Member
  • *****
  • Posts: 259
Re: Create custom bins for each frame
« Reply #2 on: December 14, 2018, 04:09:27 PM »
Hello ad,
     
it's not really clear to me what you're trying to do. So in your code snippet, you're calculating the average y-Position of all particles with particle type 1. Then you're calculating how many particles of type 2 are located in a thin slab (d_y=4), whose center coincides with the average position of all particles of type 1.

What do you mean by this?
Quote
... it showed the results for selection 1 particle types instead of selection 2 particle types.

-Constanze

Constanze Kalcher

  • Administrator
  • Sr. Member
  • *****
  • Posts: 259
Re: Create custom bins for each frame
« Reply #3 on: December 14, 2018, 04:23:52 PM »
So just to clarify, I used an example structure of a binary alloy to show you what the region you select in your script would look like.
When you select atoms based on their y-position you create a thin slab that will look similar to the region marked in red in the screenshot. It's not a cube. Is that what you wanted to achieve?

-Constanze

ad

  • Newbie
  • *
  • Posts: 25
Re: Create custom bins for each frame
« Reply #4 on: December 17, 2018, 01:23:31 AM »
Thanks for replying Constanze,

Your answer for my question is absolutely correct. Let me explain you once again what's my problem with it. I had a trajectory with two particle types. At the start of trajectory there was only one particle type out of two particle types and second particle type come's into picture after 10th frame of trajectory. Program runs fine for first 10 frames showing particle type 2 count zero( as there was no  particle type 2). After that it kinda confused and show the count of particle type one ( acting reverse way, counting particle type 1 instead particle type 2). I am using OVITO 3.0.0.

So, that's my actual problem.

This may showing correct result for your system because in your system atom number is fixed for both particles as compare to my system it's variable.You can think of something is growing over the period of time.

-ad
« Last Edit: December 17, 2018, 03:39:25 AM by ad »

Constanze Kalcher

  • Administrator
  • Sr. Member
  • *****
  • Posts: 259
Re: Create custom bins for each frame
« Reply #5 on: December 17, 2018, 11:21:39 AM »
Hello ad,
what's the file format you're importing? Could you please upload an example? Maybe it's related to the bug report here.
http://forum.ovito.org/index.php?topic=439.0

-Constanze

ad

  • Newbie
  • *
  • Posts: 25
Re: Create custom bins for each frame
« Reply #6 on: December 17, 2018, 04:49:59 PM »
Yeah, it's similar problem. I'm importing XYZ format. 

Constanze Kalcher

  • Administrator
  • Sr. Member
  • *****
  • Posts: 259
Re: Create custom bins for each frame
« Reply #7 on: December 19, 2018, 11:40:48 AM »
Hello ad,

in case you didn't follow the other topic, Alexander has fixed the issue. Please download Ovito 3.0.0-dev322 and let me know if this solves the problem of changing particle types.

-Constanze