Author Topic: Select atoms at the interface of two materials  (Read 724 times)

mike.franky

  • Newbie
  • *
  • Posts: 4
Select atoms at the interface of two materials
« on: July 31, 2018, 11:38:23 PM »
Hi,

I have just switched from VMD to OVITO and am quickly becoming a big fan.

I am trying to select the atoms that are at an interface between two materials. In VMD, I would do that by selecting the atoms of two different types that are within a given distance (i.e. if an atom is of type 1 and another atom is of type 2 and the distance between them is smaller than x then select). This would give me the atoms at the interface. Can I do something similar with OVITO?

Thanks in advance for any help
Mike
« Last Edit: July 31, 2018, 11:44:06 PM by mike.franky »

Constanze Kalcher

  • Administrator
  • Full Member
  • *****
  • Posts: 119
Re: Select atoms at the interface of two materials
« Reply #1 on: August 01, 2018, 10:28:14 AM »
Hi Mike,

one possible way to do this is to only generate bonds between type1 and type2 atoms using the Create bonds modifier.
Therein, activate the option pair-wise cutoff radii and specify only the value for type1-type2 interactions.

Then, you could use the Python script modifier to create a modifier function that loops over all these bonds and select the atoms that are connected by a bond.
For example:

Code: [Select]
from ovito.data import *

def modify(frame, input, output):
 
    bonded_atoms = set(input.bonds['Topology'][:,0]) |  set(input.bonds['Topology'][:,1])
   
    selection = output.particles.create_property('Selection')
    for index in bonded_atoms:
        with selection:
            selection[index] = 1

In the script above, input.bonds['Topology'] contains all particle pairs that are connected by a bond, e.g. [0 5]. We then create a new particle property 'Selection' that takes values 0 or 1 and set it to 1 for every particle that appears in the list bonded_atoms.

Let me know if that works for you. Glad to hear that you enjoy OVITO.

-Constanze

Constanze Kalcher

  • Administrator
  • Full Member
  • *****
  • Posts: 119
Re: Select atoms at the interface of two materials
« Reply #2 on: August 03, 2018, 11:40:22 AM »
Hi Mike,

just for the sake of completeness, if you only have particles of type 1 and type 2 there is another alternative that only requires 1 step:
You could create a particle property "Selection" using the Compute property modifier where you use

Expression = ParticleType*NumNeighbors and Neighbor Expression = -ParticleType (see attached screenshot)

since this will be equal to zero only if all neighbor particles (within your chosen cutoff) are equal to the central particle.

-Constanze



mike.franky

  • Newbie
  • *
  • Posts: 4
Re: Select atoms at the interface of two materials
« Reply #3 on: August 04, 2018, 01:48:33 PM »
Hi Constanze,

Thanks very much for your response. Both these solutions look perfect. Indeed my system is currently composed of only  two types of atoms but I will move to more complicated systems in the near future.

I am currently away but I will test both these methods next week and will report back.

Thanks again

Cheers
Mike

mike.franky

  • Newbie
  • *
  • Posts: 4
Re: Select atoms at the interface of two materials
« Reply #4 on: August 09, 2018, 01:36:07 PM »
Hi Constanze,

Both your methods work very well. For your first method, I had to adapt the code as such
Code: [Select]
from ovito.data import *

def modify(frame, input, output):
  bonded_atoms = set(input['Bonds'].array[:,0]) | set(input['Bonds'].array[:,1])
  selection = output.create_user_particle_property('Selection', "int",1, 0)
  for index in bonded_atoms:
    selection.marray[index] = 1


I suppose some of the methods/properties must have changed across different versions?

The reason I wanted to get these particles is so that I can calculate the area of the interface between two materials. So, with the help of your script, as well as a few additional deletes, selections, etc., I am left with a single layer of atoms corresponding to the atoms of one of the materials at the interface. My overall goal is to use "Construct Surface Mesh" so that I can calculate the area of this interface. However, this is misbehaving (or more likely, I am using it incorrectly). For the probe radius, I use the location of the first peak of the radial distribution function g(r), as per the documentation. However, the created surface is tiny and hardly covers any atoms. I played around with the various parameters, with very little success. Any thoughts?

Thanks again for any help I get.

Cheers
Mike

Alexander Stukowski

  • Administrator
  • Hero Member
  • *****
  • Posts: 512
Re: Select atoms at the interface of two materials
« Reply #5 on: August 09, 2018, 02:50:05 PM »
Hi Mike,

yes, you're right. We wrongly assumed that you're already using OVITO 3.0, the current development version, but you are actually using OVITO 2.9.0. For future reference, in case you decide to switch to OVITO 3.0, all changes of the Python API are documented here: http://ovito.org/manual_testing/python/introduction/version_changes.html
One of the new features of OVITO 3.0 is that the Python programming interface gives you direct access to the vertices and triangles of a computed surface mesh (see here) --something that might be of interest to you.

However, there seems to be a misconception regarding the Construct Surface Mesh function. This function is designed to construct a surface around a group of atoms forming a three-dimensional solid. It does not construct a surface through the selected atoms. In your case, you are passing just the surface atoms to the function, which form a planar sheet. A two-dimensional sheet has no solid volume, that's why you don't get a proper surface mesh.

In other words, you went one step too far here. Instead of extracting the atoms at the interface between the two materials yourself, you could simply pass all atoms of one material to the Construct Surface Mesh function. To do that, first select all particles of one type, then activate the Use only selected particles in the Construct Surface Mesh panel.

-Alex

mike.franky

  • Newbie
  • *
  • Posts: 4
Re: Select atoms at the interface of two materials
« Reply #6 on: August 09, 2018, 04:28:36 PM »
Hi Alex,

Thanks for the response. You are absolutely right. If I I have one more plane in parallel, then the surface is formed correctly.

I am trying to calculate the area of a solid-liquid interface, which is not the same as the surface area of the solid. For example, the solid may have cavities which are too narrow for the liquid to intrude. This is why I am trying to find the atoms of the interface first; it will exclude any atoms that are part of the surface of the solid but are not in "contact" with the liquid. In VMD I used to do that using the Solvent Accessible Surface Area (SASA) algorithm available. Is there any similar functionality in OVITO?

Sorry for not being more explicit to begin with, and thanks a lot for the quick responses.

Cheers
Mike