Author Topic: How to use result of SelectionExpressionModifier in ClusterAnalysisModifier ?  (Read 1822 times)

Xtof

  • Jr. Member
  • **
  • Posts: 68
Dear all,

I wrote a Python script to determine from a LAMMPS dump file where interstitials and vacancies are:

Code: [Select]
# import the cascade file
node = import_file("cascade_MD.xyz")

# Construct the modifier for Wigner Seitz analysis of SIA and V
modws = WignerSeitzAnalysisModifier(eliminate_cell_deformation = True)
modws.reference.load("crystal_eq.xyz")

# Add the modifier to the modification pipeline
node.modifiers.append(modws)

# Performs computation
output = node.compute()


It works well. I get 41 SIA and V.
Now, I would like to determine how vacancies are clustered. My idea is to select from all atoms, those that have an occupancy = 0 (definition of vac). I thus used the SelectExpressionModifier as follows:

Code: [Select]
mod2 = SelectExpressionModifier(expression = 'Occupancy == 0')
node.modifiers.append(mod2)

selection_vacancies = node.compute()

However, when I check the number of particles in selection_vacancies (selection_vacancies.number_of_particles) I find that all atoms from the initial data file are there, whereas I expected that only vacancies would be selected. But if I check selection_vacancies.attributes['SelectExpression.num_selected'], I get the right number of vacancies. I guess there is something I misunderstood.

How can I isolate vacancies and use them with ClusterAnalysisModifier ?

A possible solution I guess would be to select particles with occupancy > 0 (others than vacancies) and delete them with the DeleteSelectedParticleModifier. Is that correct ? If so, how then could I reverse it and select only interstitials and do the same exercice if they are already deleted ?

Many thanks in advance for any suggestion.
Christophe

Alexander Stukowski

  • Administrator
  • Hero Member
  • *****
  • Posts: 638
Note that SelectExpressionModifier only selects particles. That is, it sets the Selection property of certain particles to 1, but it doesn't remove the other particles. That's why the total number of particles is still the same.

Thus, in addition to the SelectExpressionModifier, you need to add a DeleteSelectedParticleModifier. And since you want to keep the sites with occupancy == 0, the selection must be inverted first (or you simply invert the selection expression):

Code: [Select]
node.modifiers.append(SelectExpressionModifier(expression = 'Occupancy == 0'))
node.modifiers.append(InvertSelectionModifier())
node.modifiers.append(DeleteSelectedParticlesModifier())
vacancies = node.compute()

Xtof

  • Jr. Member
  • **
  • Posts: 68
That works. Thanks. I got the same result using 'Occupancy > 0' + DeleteSelectedParticlesModifier().

But now, what I do not know how to do is, after selecting the vacancies, do the same thing for interstitials. If all particles that do not fullfill 'Occupancy ==0' have been deleted (with InvertSelectionModifier() + DeletedSelectedParticlesModifier()), how can I select interstitials ('Occupancy == 2') ? Is there a way to undelete particles ?

Christophe

Alexander Stukowski

  • Administrator
  • Hero Member
  • *****
  • Posts: 638
The idea to change the data pipeline, i.e. modifiers can be added/removed/changed as needed later on. Exactly as in the graphical program. For example, you can change the existing SelectExpressionModifier and rcompute:

Code: [Select]
select_point_defects = SelectExpressionModifier(expression = 'Occupancy == 0')
node.modifiers.append(select_point_defects)
node.modifiers.append(InvertSelectionModifier())
node.modifiers.append(DeleteSelectedParticlesModifier())

vacancies = node.compute()
... Do somthing with the vacancies (e.g. export to file)

select_point_defects.expression = 'Occupancy > 1'
interstitials = node.compute()
... Do somthing with the interstitials (e.g. export to file)

Modifiers also have an 'enabled' attribute, which allows you to temporarily disable a modifier. Or you can permanently remove a modifier from the pipeline again using the Python 'del' statement.

Xtof

  • Jr. Member
  • **
  • Posts: 68
It works ! Thanks a lot !
I thought that once the particles are deleted, they are really deleted.

I did not find the description of expression member of the modifier in the manual. I just found enabled. However, when I am in the console mode and I explore the members of select_point_defects with the tab, a list appears, among which expression.

I played with enabled attribute and put it to False and recomputed, it works well.

However I did not understand how to delete permanently a modifier from the pipeline with del statement from Python.

But I succeeded to delete the modifier select_point_defects from the pipeline with node.modifiers.remove(selec_point_defects). Is that correct that way ?

Christophe


Alexander Stukowski

  • Administrator
  • Hero Member
  • *****
  • Posts: 638
Particles never get permanently deleted. OVITO always keeps two copies of the data in memory: the original dataset loaded from the input file and the cached results from the data pipeline. Whenever you modify the data pipeline, OVITO recalculates the results. Most of this is described here.

The expression field is documented for the SelectExpressionModifier class. This modifier class inherits the enabled field from the Modifier base class.

Using node.modifiers.remove(select_point_defects) to remove the modifier from the pipeline is actually the best solution. In general the ObjectNode.modifiers field behaves like a standard Python list. That means you can also delete entries by index using the standard del statement:

Code: [Select]
del node.modifiers[0]