Author Topic: Find neighbors of atoms(structure = 0)?  (Read 49 times)

DJing

  • Newbie
  • *
  • Posts: 3
Find neighbors of atoms(structure = 0)?
« on: March 06, 2019, 06:58:14 PM »
Hi everyone,

I am trying to find neighbors of atoms which structure type==0(non-fcc, non-bcc and non-hcp structure), and at the same time I need to make sure all the neighbors' structure type==0, then save those qualified atoms. I am a new to Ovito and want to use the following Python script but I noticed that it may calculate with 'particle type' not 'structure type'. How can I use this?

Code: [Select]
from ovito.data import *
import numpy as np

def modify(frame, input, output):
# Prefetch the property array containing the particle type information:

  ptypes = data.particles['Particle Type']
N = 12
finder = NearestNeighborFinder(N, data)

# Prefetch the property array containing the particle type information:
ptypes = data.particles.particle_types

# Loop over all input particles:
for index in range(data.particles.count):
    print("Nearest neighbors of particle %i:" % index)
    # Iterate over the neighbors of the current particle, starting with the closest:
    for neigh in finder.find(index):
        print(neigh.index, neigh.distance, neigh.delta)
        # The index can be used to access properties of the current neighbor, e.g.
        type_of_neighbor = ptypes[neigh.index] 
« Last Edit: March 07, 2019, 08:10:27 AM by Alexander Stukowski »

Alexander Stukowski

  • Administrator
  • Hero Member
  • *****
  • Posts: 577
Re: Find neighbors of atoms(structure = 0)?
« Reply #1 on: March 07, 2019, 08:37:27 AM »
Hi,

You wrote that you would like to select atoms whose neighbors all fulfill a specific criterion. I am wondering how you define what is a neighbor atom in this case. The code snippet you posted uses the NearestNeighborFinder class, which will visit the N nearest neighbors of the central atom (N=12 in your example). Here, it doesn't play a role how far these 12 neighbors are away from the central atom. And this approach ignores the fact that a non-crystalline atom may actually have fewer or more than 12 nearest neighbors.

An alternative approach would be to use the CutoffNeighborFinder instead and consider all neighbors that are within a specific range. This would make your life easier, because then you could directly make use of the Compute property modifier to identify the desired atoms, without the need to write a Python script.

The attached screenshot shows how to set it up: The Boolean expression "StructureType != 0" has been assign to both the central atom field and the neighbor atom field. This expression will yield non-zero contributions in case either the central atom or any of its neighbors within the given cutoff radius have a non-zero structure type. Thus, all you have to do next is use the Expression selection modifier to create a selection set containing all atom whose "MyProperty" particle property (created by the Compute Property modifier) is zero.

-Alex

DJing

  • Newbie
  • *
  • Posts: 3
Re: Find neighbors of atoms(structure = 0)?
« Reply #2 on: March 08, 2019, 12:33:38 AM »
Hi Alex,

Thanks for your help.