#### Safy

• Newbie
• Posts: 9
##### Partial radial distribution function (RDF)
« on: October 17, 2018, 08:15:49 AM »
Hello! I am  trying to calculate the partial RDF for my systems. I used the instruction on this page:

http://forum.ovito.org/index.php?topic=131.0

As a result, I have the following: http://prntscr.com/l6yltd

I'm sorry, but I just started to learn the program Ovito and maybe I make some mistakes..

#### Alexander Stukowski

• Hero Member
• Posts: 533
##### Re: Partial radial distribution function (RDF)
« Reply #1 on: October 17, 2018, 09:05:08 AM »
Dear Safy,

Don't paste the code into the 'modifier name' input field. Instead, click the 'Edit script...' button. This will open the code editor window. Replace the existing default script in this window with the one you copied from the forum topic.

-Alex

#### Safy

• Newbie
• Posts: 9
##### Re: Partial radial distribution function (RDF)
« Reply #2 on: October 23, 2018, 06:46:22 AM »
Thank you very much, Dr.Alexander Stukowski!
I followed your recommendations and I have successfully get the partial RDF (http://prntscr.com/l99vxl)

I have a question, how can I get a graphical representation of the output result?

#### Constanze Kalcher

• Full Member
• Posts: 158
##### Re: Partial radial distribution function (RDF)
« Reply #3 on: October 23, 2018, 10:43:51 AM »
Hi Safy,
the answer depends on what version of OVITO you're using. In the latest developer version, you can already see the plot under "Data Plots" in the Data Inspector (see attached screenshot).

In OVITO 2.9, you can add two lines of code to your python script modifier using numpy.savetxt()

Code: [Select]
`result = np.column_stack((radii,rdf))np.savetxt("partial_rdf_%s.dat" % frame, result)`to export your data to a text file (labeled by number of the current frame) and then plot it with your favorite plotting program.

-Constanze

#### Kevin

• Newbie
• Posts: 33
##### Re: Partial radial distribution function (RDF)
« Reply #4 on: October 23, 2018, 07:40:52 PM »
I needed this same functionality and tried myself with a problem.

Just noting that the file path has to be defined for the file name as well. (At least on mac)
Otherwise, the python script will complain that permission is denied.
I guess the default file path is somewhere writing permission is not given.

Thanks,
-Kyu

#### Constanze Kalcher

• Full Member
• Posts: 158
##### Re: Partial radial distribution function (RDF)
« Reply #5 on: October 24, 2018, 02:11:14 PM »
Hi Kyu,
you're right. With these two lines you can print the current working directory:
Code: [Select]
`import osprint(os.getcwd())`Under MacOS it turns out to be "/", where you typically don't have write permission.
So on the Mac, you need to give a file path as well, when you're trying to save a file with
numpy.savetxt() from within the python modifier in the GUI.

However, in a future release, there will be a more intuitive way to export that data such that you can simply use the "File Export" function.

-Constanze

#### Safy

• Newbie
• Posts: 9
##### Re: Partial radial distribution function (RDF)
« Reply #6 on: November 09, 2018, 08:18:21 AM »
Now I have this question: how can I find the number of atoms in each coordination sphere?

Thanks

#### Constanze Kalcher

• Full Member
• Posts: 158
##### Re: Partial radial distribution function (RDF)
« Reply #7 on: November 09, 2018, 04:30:30 PM »
Hello,

why don't you use the information you already calculated in your script, i.e. when you calculate the histogram of the different bond lengths?
Code: [Select]
`hist, bin_edges = np.histogram(output.bond_properties.length.array, bins=num_bins)`
-Constanze

#### Safy

• Newbie
• Posts: 9
##### Re: Partial radial distribution function (RDF)
« Reply #8 on: November 11, 2018, 03:42:56 PM »
Hello,

When calculating the RDF, I received the following:

http://prntscr.com/lgzibw

The description says that I can determine the number of neighbors of each particle which are within a given cutoff radius:

http://prntscr.com/lgziq7

It may be easy, but I find it difficult.

Thanks,
Safy

#### Constanze Kalcher

• Full Member
• Posts: 158
##### Re: Partial radial distribution function (RDF)
« Reply #9 on: November 13, 2018, 11:06:20 AM »
Hi Safy,

If you integrate the rdf between two values r1 and r2, you will get the number density of atoms in that shell, so you still have to multiply that by its volume. That's why I suggested to start from the unnormalized histogram of the bond lengths instead.

Yes, you could also use the Coordination analysis modifier. But this will give you the number of neighbors starting from r = 0 up to a certain cutoff value. But what you're asking for is the number of atoms in different coordination shells right? You could do that analysis from r0 to r1 and r0 to r2 and subtract the results of the inner shell from the outer one. However, the Coordination analysis modifier won't distinguish between different atom types.

But let me explain another way: What's probably easier for you is to use the Compute property modifier. Say you're examining atom type 1, this is how you would count the number of atoms of type 1 in an exemplary coordination shell between 2.5 and 4.0 (length units).

Expression
0
Neighbor Expression
(Distance >= 2.5) && (Distance =< 4.0) && (ParticleType == 1) && (@Particle Type == 1)

Note that  @... references the properties of the central particle, but this feature is not yet available in OVITO 2.9.

-Constanze
« Last Edit: November 13, 2018, 11:10:44 AM by Constanze Kalcher »

#### Safy

• Newbie
• Posts: 9
##### Re: Partial radial distribution function (RDF)
« Reply #10 on: November 14, 2018, 05:42:15 AM »
Hello! In general, I have such a problem: I have two types of atoms and I need to determine the number of neighbors for a type 2 atom in 1,2,3,4 coordination spheres, that is, how many atoms of type 1 and type 2 surround a type 2 atom.
Can I solve this problem in OVITO? And which version is more convenient for this analysis?
I am still taking the first steps in OVITO, so I donâ€™t know much and I am very grateful for your help.

I have a file swap.data

You can show me step by step how to solve this problem so that I can repeat them. Excuse me, these are my first steps in OVITO and I still do not know much about this program.

Thanks,
Safy

« Last Edit: November 14, 2018, 08:03:47 AM by Safy »

#### Constanze Kalcher

• Full Member
• Posts: 158
##### Re: Partial radial distribution function (RDF)
« Reply #11 on: November 15, 2018, 11:04:24 AM »
Hello,
I would suggest you to use the latest developer version, where you can see particle properties and data plots you calculate directly in the Data inspector below the viewports.
So here is one way to calculate what you're asking for:
First, I used the Coordination analysis modifier to find out the distance of the different coordination shells (see screenshot RDF.png).
Then, you can insert a Compute property modifier which allows you to calculate and safe new particle properties, in this case let's call it "Type 2 coord. 1st shell". So to count how many atoms of type 2 are in the first coordination shell of each atom, you can use the following expressions:
Expression
0
Neighbor Expression
(Distance <= 2.6) && (ParticleType == 2)

The Neighbor Expression is evaluated for each neighbor atom in the given cutoff and is either 1 if both conditions are true or 0 otherwise. "&&" means "and" in this context. In the data-panel you will see your new particle property appear: The particle with Id 1 e.g. is of particle Type 2 and has 2 neighbors of type 2 in the first coordination shell (see last column in 2nd screenshot).

Now it's up to you to repeat that for the different particle types and distances. So simply insert more Compute property modifiers into your pipeline. As an example, "Type 1 coord. 2nd shell" could then be:
Expression
0
Neighbor Expression
(Distance >= 2.6) && (Distance <= 3.0) && (ParticleType == 1)
etc.
Don't forget to increase the cutoff radius as well.

From there, you could go on and use the Histogram modifier in conjunction with the Select particle Type modifier or a python script modifier to calculate averages of that information for only type 2 center particles e.g. But first, you should try if the above works for you.

-Constanze

« Last Edit: November 15, 2018, 10:59:27 PM by Constanze Kalcher »

#### Safy

• Newbie
• Posts: 9
##### Re: Partial radial distribution function (RDF)
« Reply #12 on: November 15, 2018, 12:11:30 PM »
Hi!
Thank you for your informative instruction, it told me that I am on the right track.

Before you answered, I used the instructions you wrote earlier.

http://forum.ovito.org/index.php?topic=340.0

Am I right? I received the values of the radius of trimming when calculating the RDF and after that I inserted these values into the script, also changed the types of atoms in the last line

Thank you for your help, it is invaluable to me.

« Last Edit: November 15, 2018, 12:34:55 PM by Safy »

#### Constanze Kalcher

• Full Member
• Posts: 158
##### Re: Partial radial distribution function (RDF)
« Reply #13 on: November 15, 2018, 01:17:41 PM »
Hi,
just to confirm, so when you talk about the number of atoms in the second shell e.g., do you mean "only" the second, or does that include the first and the second? In the first case, the solution from the other forum topic would require an extra step where you subtract the results from the inner shells from the outer ones.

-Constanze
« Last Edit: November 15, 2018, 01:24:21 PM by Constanze Kalcher »

#### Safy

• Newbie
• Posts: 9
##### Re: Partial radial distribution function (RDF)
« Reply #14 on: November 15, 2018, 01:39:55 PM »
I think I understand what you're talking about. If I take the total number of neighbors in all shells, then I leave the result as it is, if it is specifically on the second or third shells, then should I deduct the result from the previous one?

respectfully
Safy

#### Constanze Kalcher

• Full Member
• Posts: 158
##### Re: Partial radial distribution function (RDF)
« Reply #15 on: November 15, 2018, 01:44:12 PM »
Yes, you could do that. I just wanted to clarify that the difference between the two solutions is that the python script counts all neighbors up to a certain cutoff radius, whereas in the Compute property modifier you can specify both a lower and upper cutoff value.
So in the end it depends on what you want to evaluate.

-Constanze

#### Safy

• Newbie
• Posts: 9
##### Re: Partial radial distribution function (RDF)
« Reply #16 on: November 17, 2018, 11:38:02 AM »

Hi

I received the number of neighbors for each atom in different coordination areas, thank you for your help.
And I had a question, how can I get the average of the numbers from the last column? You wrote that I can use the python script modifier to calculate averages of that information
This is my first experience with similar programs, I am also a beginner in a python and therefore I have such difficulties. Could you help me with this task?

Thanks a lot for your time

Safy

#### Constanze Kalcher

• Full Member
• Posts: 158
##### Re: Partial radial distribution function (RDF)
« Reply #17 on: November 19, 2018, 04:00:18 PM »
Hi,
an example of how to calculate averages of only specific particles is also shown in the FAQ: http://forum.ovito.org/index.php?topic=376.0.

For each particle you calculated a property called "Coordination". If you now want to calculate the mean value of this property for only particles of type 2 e.g., you need to select these particles based on their type:

Code: [Select]
`from ovito.data import *import numpy as npdef modify(frame, input, output):    coord = input.particles["Coordination"]    p_types = input.particles["Particle Type"]    output.attributes["Average coord ptype2"] = np.mean( coord[ (p_types == 2) ] )`You will now see the global attribute "Average coord ptype2" appear in the Data panel when you click on "Attributes".

-Constanze
« Last Edit: November 19, 2018, 04:02:31 PM by Constanze Kalcher »

#### Safy

• Newbie
• Posts: 9
##### Re: Partial radial distribution function (RDF)
« Reply #18 on: November 20, 2018, 08:07:46 PM »
Hi, Constanze

Thank you very much! You really helped me out!

Safy