Author Topic: minimum distance between two atoms  (Read 264 times)

Dori

  • Newbie
  • *
  • Posts: 7
minimum distance between two atoms
« on: June 25, 2019, 10:19:46 PM »
Hello OVITO users,
I need to know the minimum distance between two atoms inside my super crystal. Can this be done by adding a modification in OVITO?
Thanks,
Dori

Alexander Stukowski

  • Administrator
  • Hero Member
  • *****
  • Posts: 638
Re: minimum distance between two atoms
« Reply #1 on: June 26, 2019, 07:18:06 AM »
Hi Dori,

This can probably be implemented using a small Python modifier function. Do you mean the minimum distance between any two atoms in you super cell or a particular pair of atoms?

-Alex

Dori

  • Newbie
  • *
  • Posts: 7
Re: minimum distance between two atoms
« Reply #2 on: June 26, 2019, 08:11:27 PM »
Hello Mr. Stukowski,
Thanks for your response.

 I need to know which two atoms are closest to each other in my supercell and what is the shortest distance. If this can be done in Ovito, may I have a link to that Python modifier function?
« Last Edit: June 26, 2019, 08:24:01 PM by Dori »

Constanze Kalcher

  • Administrator
  • Sr. Member
  • *****
  • Posts: 301
Re: minimum distance between two atoms
« Reply #3 on: June 27, 2019, 12:13:39 PM »
Hello Dori,

here is an example of a custom modifier function that uses the nearest neighbor finder function of OVITO to find the closest neighbor of each particle and then loops over all those neighbor distances to find the minimum.
Code: [Select]
from ovito.data import *

def modify(frame, data):
    finder = NearestNeighborFinder(1, data)
    neighbor_pairs = [ (neigh.distance, index, neigh.index) for index in range(data.particles.count) for neigh in finder.find(index)]
    print("min_dist \t Index_A \t Index B")
    print(min(neighbor_pairs))

-Constanze
« Last Edit: June 27, 2019, 12:21:25 PM by Constanze Kalcher »

Dori

  • Newbie
  • *
  • Posts: 7
Re: minimum distance between two atoms
« Reply #4 on: June 28, 2019, 01:54:24 AM »
Hello Constanze,
Thank you so much for your response.

It totally makes sense that I need to put N=1 in order to find the nearest neighbor of a particle.
I am wondering if my dump file is sufficient to get the required output. My dump file includes:
ITEM: TIMESTEP
ITEM: NUMBER OF ATOMS
ITEM: BOX BOUNDS pp pp pp
ITEM: ATOMS id type xs ys zs

However I could see in the following link that  https://ovito.org/manual/python/modules/ovito_data.html#ovito.data.DataCollection
data collection file includes:
ParticleProperty and ParticleTypeProperty
SimulationCell
Bonds
BondProperty and BondTypeProperty
SurfaceMesh
DislocationNetwork

Mathematically, what is required is to select every two particles and calculate the value of SQRT[(x2-x1)^2+(y2-y1)^2+(z2-z1)^2]. So I am thinking only coordinates of atoms and atom id in my dump file would suffice to get the results. Do I need to build a data collection?

with thanks,
Dourna







Constanze Kalcher

  • Administrator
  • Sr. Member
  • *****
  • Posts: 301
Re: minimum distance between two atoms
« Reply #5 on: June 28, 2019, 09:59:41 AM »
Hello Dourna,

a DataCollection is a container class holding together individual data objects, each representing different fragments of a dataset. For example, a dataset loaded from a simulation data file may consist of particles, the simulation cell information and additional auxiliary data such as the current timestep number of the snaphots, etc. In the GUI, when you import your dump file, everything is automatically set up for you.

Your goal is to find the shortest distance between two particles, so yes, the position vectors is all you need.
Have you tried the modifier function I posted above? It already is the solution to your question: The Nearest Neighbor function NearestNeighborFinder(1, data).find(index) returns an iterator that visits the N nearest neighbors
of the given particle in order of ascending distance (although in your case there will be just 1 neighbor anyways). It also returns an object (in the above script called neigh) with the following attributes: index, distance, distance_squared, delta, see manual for more details:
https://ovito.org/manual_testing/python/modules/ovito_data.html#ovito.data.NearestNeighborFinder
So there is no need to implement that yourself.
In the GUI, simply add a Python modifier https://ovito.org/manual_testing/particles.modifiers.python_script.html, click on "Edit script" and copy the above code snippet into the text editor.
 
-Constanze
« Last Edit: June 28, 2019, 10:53:30 AM by Constanze Kalcher »