Author Topic: How to get the coordination number of particular atoms?  (Read 179 times)

RMCtestFYP

  • Newbie
  • *
  • Posts: 18
How to get the coordination number of particular atoms?
« on: July 26, 2018, 05:14:24 PM »
Hello, I encounter some problems when I use the OVITO.
It is my first time to use this software.

I have a .cfg file. I have uploaded it here. Is the format correct to input in OVITO?

I made a RMC simulation, the sample contains 3 elements.
I use OVITO to analyze its atomic structure.
How should I find the coordination number of certain pairs of atoms?
For example, the sample is Ag Al Mg alloy, I want to find the number of Ag atoms which surrounds Al atoms.

I find the option 'histogram' in the list, but it only shows the total coordination number within the configuration.
How should I do?
Please give a detail procedure if it is possible, because I really don't know how to use this software. :'(

Thank you for your answer! I am still learning how to use this software :)

RMCtestFYP

  • Newbie
  • *
  • Posts: 18
Can OVITO plot the distribution of coordination number?
« Reply #1 on: July 27, 2018, 03:19:31 AM »
I find the option 'histogram' in OVITO, it plots the coordination number vs. count number. (the picture uploaded)

However, can I have the graph or data of the distribution of coordination number by OVITO? (like the example picture)



Thank you for reply :)

Constanze Kalcher

  • Administrator
  • Newbie
  • *****
  • Posts: 35
Re: How to get the coordination number of particular atoms?
« Reply #2 on: July 27, 2018, 12:28:22 PM »
Hi there!  :)

Regarding your first question, I had a look at the example file you uploaded. It seems that the cell size is not correct, it's only a 1/8 of what it should be. Have a look at the first picture I attached. Before you continue with the analysis you should fix that.

You also asked about how to get the coordination number of certain pairs of atoms. In the FAQ Alexander gave a detailed description of how to calculate partial radial distribution functions using a Python script modifier. I suggest you try this, but make sure you adapt the cutoff radius to your system. I'm not sure what your units are but to reproduce  the coordination histogram you showed us I used a cutoff radius of 3.

Then, after having performed the Coordination analysis you can add the Histogram modifier on top of your modification pipeline and choose the particle property "Coordination".

I understand you're just learning how to use OVITO, so don't hesitate to get back to us if you have any trouble. :)

-Constanze







RMCtestFYP

  • Newbie
  • *
  • Posts: 18
Re: How to get the coordination number of particular atoms?
« Reply #3 on: July 27, 2018, 01:06:47 PM »
Thank you so much! :D

(1) Yes, I also find this problem, I see that the cell length is always half the total size.
As the picture uploaded, I have changed value in the red circle. However, no matter I change, the cell size shown in OVITO is still half the total atomic configuration. The only change is just the density.

Should I change the cell size is .cfg file directly or change in OVITO "simulation cell" option?


(2) I have tried it as shown in picture below. I got two columns of value which is the partial g(r). But how can I calculate the coordination number from it? Or any other method? :'(

(3) Can the histogram show certain pair of atom that I choose?
For example, the sample contain atom types A, B and C.
Can I get the histogram of coordination number that contains atom A and B only?

I tried to click on 'select types' to tick atom C. Then, I click on 'delete select'.
Atom C disappears, but the graph of the coordination number in 'histogram' still show the total number (contains atom types A, B, C).


Thank you for your reply again! It is my first time to use this kinds of software, sorry for asking too much silly questions lol :'(
« Last Edit: July 27, 2018, 01:12:48 PM by RMCtestFYP »

Constanze Kalcher

  • Administrator
  • Newbie
  • *****
  • Posts: 35
Re: How to get the coordination number of particular atoms?
« Reply #4 on: July 27, 2018, 02:54:02 PM »
(1) Ah okay thanks for letting me know! I don't have much experience with this file format yet, but I will look into this. For now, please either change the cell size parameters in the .cfg file or if you don't want to alter your original file you could use the Affine Transformation modifier to change only the cell size (not the atoms) before you perform any further analysis, see screenshot (1). Both should work.

(2+3) As you correctly noted the Coordination analysis modifier always takes into account all the atoms. But let me show you one way how to work around this by again using the Python script modifier and defining your own modifier function.
This is how you calculate the number of B-Type neighbors for every A-Type atom and store that value as a new particle property. Afterwards, you can access this particle property in the Histogram modifier:

First, use Select Type to select all Type A atoms. Then insert the Python Script modifer and edit the script:

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 = input.particles['Particle Type']
   
    #Create a new particle property that stores the number of neighbors with particle type 2 and initialize with zeros
    values = np.zeros(input.particles.count, dtype=int)
    new_property = output.particles.create_property('Type2 Coordination', data=values)
   
    # Initialize neighbor finder object:
    cutoff = 3.
    finder = CutoffNeighborFinder(cutoff, input)
   
    # Loop over all particles:
    for index in range(input.particles.count):
        #Only iterate over particles of type 1
        if(ptypes[index] == 1):
           # Get a list of particle types of all neighbors of the current particle:
            neighbor_types = [ptypes[neigh.index] for neigh in finder.find(index)]
            #Count the number of neighbor types of all types and store the count for type 2 in the newly created particle property
            with new_property:
                new_property[index] = np.bincount(neighbor_types, minlength=4)[2]
Note that in the script we make use of the CutoffNeighborFinder function, that lets you compute particle neighbor lists.

Now, you should be able to see your newly created property in the Data inspector, see screenshot (2).

Finally, you can plot the coordination number of all A-atoms using the Histogram modifer and enabling the option "Use only selected elements" as shown in screenshot (3).

I know this is already quite advanced so let me know if you have questions  :)

-Constanze
« Last Edit: July 28, 2018, 05:23:47 PM by Constanze Kalcher »

RMCtestFYP

  • Newbie
  • *
  • Posts: 18
Re: How to get the coordination number of particular atoms?
« Reply #5 on: July 28, 2018, 05:23:47 AM »
Good morning :) Thank you for your reply again!

For (1), I try to change the cell size but I don't know why it doesn't change.
In picture one, it is the original one.
In the second picture, I made the change but the cell size remains half the whole size :'(


For (2) and (3), I have some questions.

(a) My procedures: insert the script > select type A atom in 'Select type' > click 'histogram' > chose 'Type 2 coordination' > click 'Use only selected elemetns'
Am I correct? 8)

(b) Do I need to edit the script? If yes, what thing should I change?

(c) In the script, why the cut-off be 3? Can I change to other value?

(d) It seems that the coordination number I get is very big. (picture 3) Perhaps it is due to the problems of cell size or the cut-off is too large?

(e) In the 'histogram', if I choose 'coordination' and click 'use only selected elements'
For example, my sample contain atom types A, B, C.
I only click atom A in 'Select type'.

So it show the coordination of number of A (number of B and C that surround A)?

Again, thank you very much!  :)
Sorry for my silly questions again and again, since it is my first times to do the work on the analysis of simulation of atomic configuration, I don't know a lot of thing in this field
And I have few experience on computer coding too:'(
Thank for your great help! I really learn more about how to use OVITO

Constanze Kalcher

  • Administrator
  • Newbie
  • *****
  • Posts: 35
Re: How to get the coordination number of particular atoms?
« Reply #6 on: July 28, 2018, 03:41:23 PM »
Hi!

Good job, you're almost there!  :)

For (1) you need to deactivate the "Particles" in the "Operate on" options of the Affine Transformation modifier since you only want to rescale the cell (not both the cell and the particles).

Regarding the script (2+3) you can of course change the cut-off, which will then also influence the coordination number. I only used 3 as an example.
Note, though, that the histogram you plot only shows you the number of B-type atoms surrounding every A-type atom. If you like to include C-type atoms as well, you need to adapt your modifier function. You could, e.g., edit the last line in the script:

Code: [Select]
new_property[index] = np.bincount(neighbor_types)[2] + np.bincount(neighbor_types)[3]

I also noticed I made a mistake there myself: np.bincount() counts the number of occurrences of each value in an array of non-negative integers. That means zero is included. So the number of A-type atoms in neighbor_types is np.bincount(neighbor_types)[1], the number of B-type atoms is np.bincount(neighbor_types)[2] and the number of C-type atoms is np.bincount(neighbor_types)[3]. The first entry np.bincount(neighbortypes)[0] should always be zero, since we don't have atoms of type "zero".

In the script above I wrote
Code: [Select]
np.bincount(neighbor_types)[1] which should be
Code: [Select]
np.bincount(neighbor_types)[2] otherwise you count the number A-type atoms surrounding each A-atom. Sorry for that. I also corrected it in the script above.

If you have time you should add a couple of print statements to your script to better understand what it does.
Keep up the enthusiasm! :)

-Constanze
« Last Edit: July 28, 2018, 04:14:57 PM by Constanze Kalcher »

Constanze Kalcher

  • Administrator
  • Newbie
  • *****
  • Posts: 35
Re: How to get the coordination number of particular atoms?
« Reply #7 on: July 28, 2018, 05:18:44 PM »
Another thing that I should add is that
Code: [Select]
np.bincount(neighbor_types)[3] e.g., will fail if no atoms of type 3 (=C-type atoms) are in the neighbor list. To avoid that use:
Code: [Select]
np.bincount(neighbor_types, minlength = 4)

-Constanze
« Last Edit: July 28, 2018, 05:23:58 PM by Constanze Kalcher »

RMCtestFYP

  • Newbie
  • *
  • Posts: 18
Re: How to get the coordination number of particular atoms?
« Reply #8 on: July 29, 2018, 09:16:42 PM »
Thank you very much! It is very hard but I still learn it. :)
You give a good instruction, I know more about how to use OVITO to analyze it.

For the coding, I still have some questions.
(1) As a red circle in the picture uploaded, if I only change this value into 2,
for example, if(ptypes[index] == 2):

Does this mean that it is to calculate the coordination number of type-2 atom
(i.e. how many type-2 atom surround type-2 atom?)


(2) For the last line, you add 'minlength=4', what does it mean?

(3) To check the coordination of type-3 atoms (surrounded by type-2 atom)
Change these two values?

if(ptypes[index] == 3):

new_property[index] = np.bincount(neighbor_types, minlength=4)[2]

Moreover, I need to select type-3 atom in 'Select type' too?


Again, thank you for your reply!
I am very weak in coding, but your teaching do help me a lot.
I am very grateful for your help :)
« Last Edit: July 29, 2018, 09:32:20 PM by RMCtestFYP »

Constanze Kalcher

  • Administrator
  • Newbie
  • *****
  • Posts: 35
Re: How to get the coordination number of particular atoms?
« Reply #9 on: July 30, 2018, 10:06:46 AM »
Hi,

(1) Yes, then you will perform your analysis for type-2 center atoms.

(2) Let's say the list of particle types of the neighbors you find for a specific atom is
neighbor_types = [1 1 2 2 1 1 3 1] ,
i.e. 5 atoms of type 1, 2 atoms of type 2 and 1 of type 3. Then np.bincount(neighbor_types) returns a "histogram" [0 5 2 1] with 4 entries.
To read out the number of neighbors of type 3 you would do
np.bincount(neighbor_types) [3] etc.

If, however, you would only find neighbor atoms of type 1 in the specified cutoff, e.g.
neighbor_types = [1 1 1 1], np.bincount(neighbor_types) returns [0 4], but we need this to look like [0 4 0 0].

(3) Yes, that works.  :)

Best,
-Constanze



Alexander Stukowski

  • Administrator
  • Sr. Member
  • *****
  • Posts: 435
Re: How to get the coordination number of particular atoms?
« Reply #10 on: July 30, 2018, 11:08:27 AM »
Dear RMCtestFYP,

I took a look at your input file "Example .cfg file.cfg". Unlike the file extension suggests, this file actually follows the POSCAR format (as used by the VASP simulation code), not the "CFG" format used by the AtomEye software.

The number in the second line of the file is the global scaling factor. If you change it from "1" to "2", the simulation box gets larger. However, since all atomic positions are given in reduced coordinates (as specified by the "Direct configuration" keyword), they get scaled along with the cell. Note that reduced coordinates must all lie in the range [0,1]. However in your file, they range from -1 to +1. This is why some of the atoms appear outside of the box, irrespective of the global scaling factor. To solve the problem, please change the reduced coordinates in your file to be in the range [0,1].

-Alexander

RMCtestFYP

  • Newbie
  • *
  • Posts: 18
Re: How to get the coordination number of particular atoms?
« Reply #11 on: July 31, 2018, 12:11:09 AM »
Hi,

(1) Yes, then you will perform your analysis for type-2 center atoms.

(2) Let's say the list of particle types of the neighbors you find for a specific atom is
neighbor_types = [1 1 2 2 1 1 3 1] ,
i.e. 5 atoms of type 1, 2 atoms of type 2 and 1 of type 3. Then np.bincount(neighbor_types) returns a "histogram" [0 5 2 1] with 4 entries.
To read out the number of neighbors of type 3 you would do
np.bincount(neighbor_types) [3] etc.

If, however, you would only find neighbor atoms of type 1 in the specified cutoff, e.g.
neighbor_types = [1 1 1 1], np.bincount(neighbor_types) returns [0 4], but we need this to look like [0 4 0 0].

(3) Yes, that works.  :)

Best,
-Constanze

Thank you Constanze.
And thank you for you explanation, I hear similar concept in Scilab course before lol.
I have just plotted all the graph of the data, and now have to do some calculation, quite tired :'(
Thank you for your patient teaching! :)

RMCtestFYP

  • Newbie
  • *
  • Posts: 18
Re: How to get the coordination number of particular atoms?
« Reply #12 on: July 31, 2018, 12:24:58 AM »
Dear RMCtestFYP,

I took a look at your input file "Example .cfg file.cfg". Unlike the file extension suggests, this file actually follows the POSCAR format (as used by the VASP simulation code), not the "CFG" format used by the AtomEye software.

The number in the second line of the file is the global scaling factor. If you change it from "1" to "2", the simulation box gets larger. However, since all atomic positions are given in reduced coordinates (as specified by the "Direct configuration" keyword), they get scaled along with the cell. Note that reduced coordinates must all lie in the range [0,1]. However in your file, they range from -1 to +1. This is why some of the atoms appear outside of the box, irrespective of the global scaling factor. To solve the problem, please change the reduced coordinates in your file to be in the range [0,1].

-Alexander

Dear Alexander,

Thank you for your reply.
The input file 'Example.cfg' is transformed from the .cfg file in RMC++. The uploaded file is the .cfg file generated by RMC++.
I change the format of .cfg file of RMC++ so that it can be inputted to OVITO.

Can I just change the cell size in OVITO, or by affine transformation to solve this problem?
After affine transformation, it seems that the coordination number shown in OVITO is reasonable.

Thank you! :)

Alexander Stukowski

  • Administrator
  • Sr. Member
  • *****
  • Posts: 435
Re: How to get the coordination number of particular atoms?
« Reply #13 on: July 31, 2018, 11:10:22 AM »
I found the following statement in section C.2.7. of the RMC user guide:

Quote
The coordinates are reduced, going between –1 and +1 and the box half-length and other distance related properties are given in Ångstrom in RMC.

So I assume that the 43.62 value found in the header of your .cfg file denotes a half box length, right?
Note that OVITO assumes the cell sizes in the POSCAR header to be full lengths and the reduced atomic coordinates to be in the range 0-1. That means, after import in OVITO, the atomic coordinates will already be correctly converted to Angstroms by chance, but the cell size will come out too small by a factor 1/2. You should be able to fix this by applying the Affine Transformation modifier with a 2x scaling matrix just to the simulation cell but not the particle coordinates. Do you agree?

RMCtestFYP

  • Newbie
  • *
  • Posts: 18
Re: How to get the coordination number of particular atoms?
« Reply #14 on: July 31, 2018, 05:37:00 PM »
I found the following statement in section C.2.7. of the RMC user guide:

Quote
The coordinates are reduced, going between –1 and +1 and the box half-length and other distance related properties are given in Ångstrom in RMC.

So I assume that the 43.62 value found in the header of your .cfg file denotes a half box length, right?
Note that OVITO assumes the cell sizes in the POSCAR header to be full lengths and the reduced atomic coordinates to be in the range 0-1. That means, after import in OVITO, the atomic coordinates will already be correctly converted to Angstroms by chance, but the cell size will come out too small by a factor 1/2. You should be able to fix this by applying the Affine Transformation modifier with a 2x scaling matrix just to the simulation cell but not the particle coordinates. Do you agree?

Thank you for your reply. :)
Yes, it seems work when change the cell size by Affine transformation.
So does this mean that I just need to change the cell size for correct analysis?