Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Constanze Kalcher

Pages: 1 ... 6 7 [8] 9
211
The OVITO 3 equivalent of the above Python script modifier would be :
Code: [Select]
from ovito.data import *
import numpy as np

def modify(frame, data):
    shear_strain = data.particles["Shear Strain"]
    selection = data.particles["Selection"]
    output.attributes["Average shear strain"] = np.mean( shear_strain[selection == 1] )

212
Let's say you want to calculate the average value of a particle property for only a subset of atoms, for example the shear strain.
First you may want to use one of the Selection modifiers, e.g., Expression select, Select particle type, Slice or Manual selection to select the atoms of interest.

Then, insert a Python script modifier that calculates the mean value of the per-atom shear strain of your selection and saves it as a global attribute.
Code: [Select]
from ovito.data import *
import numpy as np

def modify(frame, input, output):
    shear_strain = input.particle_properties["Shear Strain"].array
    selection = input.particle_properties["Selection"].array
    output.attributes["Average shear strain"] = np.mean( shear_strain[selection == 1] )

Global attributes can be exported as Calculation Results Text File output file format.

213
Support Forum / Re: Calculating the velocity of a, or group of atoms.
« on: September 14, 2018, 02:14:40 PM »
Hello,

the Compute Property Modifier only lets you reference the Particle Properties at the current frame, which appear in the Variables panel.
These particle properties are either part of your input data or the result of a modifier calculation you performed.

Have you considered using the Displacement vectors modifier to calculate the atomic displacements in reference to your initial frame? Then you will have access to these values in the Compute Property Modifier as "Displacement.X", etc.

-Constanze

214
Support Forum / Re: Shifting the System Along an Axis
« on: September 12, 2018, 07:06:03 AM »
Hi,

ok great! You can of course do it in OVITO 3.0, it's just that the Affine Transformation modifier looks slightly different there. You will find an "Operate on" panel at the bottom, where you need to select Particles and unselect Simulation cell.
Sorry for the confusion.

-Constanze

215
Support Forum / Re: Shifting the System Along an Axis
« on: September 10, 2018, 07:24:39 PM »
Hi jatin1990,

you could use the Affine Transformation modifier in conjunction with the Wrap at periodic boundaries modifier. (This is in case you're using OVITO 2.9).

You can translate the atoms only with the Affine Transformation modifier: Choose Transform particle positions and unselect Transform simulation cell. The Wrap at periodic boundaries modifier will then map those atoms back into the simulation cell that you moved out of your cell.

Does that work for you?
-Constanze

216
Dear Shuai,

I suggest you to have a look at this section in the manual about running scripts.
In short, if you're using the GUI, simply use a Python script modifier and copy-paste the code example.

-Constanze

217
Support Forum / Re: CNA and bond-angle analysis criterion
« on: September 05, 2018, 03:05:33 PM »
I assumed you are using the latest version of OVITO 3, where the python API has been updated, as explained here:
http://ovito.org/manual_testing/python/introduction/version_changes.html.

If you'd rather use OVITO 2.9, you need to adapt line 5 like this:
Code: [Select]
output.attributes["my_fcc_count"] = np.count_nonzero(input.particle_properties["Selection"])

The Data inspector panel is only available in OVITO 3, however, in OVITO2.9 the global attribute "my_fcc_count" will be visible under Attributes to Export when you choose the file format "Calculation Results File" in the Export File function.

-Constanze

218
Support Forum / Re: CNA and bond-angle analysis criterion
« on: September 05, 2018, 01:43:56 PM »
Hi Theo,

alright, in that case you could add a Python Script modifier after the Expand Selection modifier. The following modifier function counts the number of selected atoms (=fcc atoms + 12 nearest neighbors of each fcc atom) and adds a global attribute "my_fcc_count" to your data collection.
Code: [Select]
from ovito.data import *
import numpy as np

def modify(frame, input, output):
    output.attributes["my_fcc_count"] = np.count_nonzero(input.particles["Selection"])

Global attributes appear in the Attributes Section in the Data Inspector and  can be exported using the Export File - Table of Values Option. Does that work for you?

-Constanze

219
Support Forum / Re: CNA and bond-angle analysis criterion
« on: September 05, 2018, 12:05:00 PM »
Dear Theo,

could you please give us a little bit more context what you are trying to do. It is not yet clear to us what question you are trying to answer. What is your setup? Do you have more than these two surface atoms? And what would  a "softer" criterium be in your case, e.g. only being a neighbor to 8 fcc atoms?

I'm happy to help with the python script then.

-Constanze

220
Support Forum / Re: LAMMPS input file with atomic mass information?
« on: September 03, 2018, 12:50:50 PM »
Alternatively,
if you only have the two particle types 1 and 6 in your system using the Compute Property Modifier as suggested by Alex will work as well:

Code: [Select]
pipeline.modifiers.append(ComputePropertyModifier(output_property = 'Mass', expressions = ['(ParticleType == 1) ? 1.008 : 12.011'] ))
pipeline.compute()

221
Support Forum / Re: LAMMPS input file with atomic mass information?
« on: September 03, 2018, 11:21:44 AM »
Hi RU,

here is an example how you would do it in the scripting interface of OVITO 3 with a Python script modifier that uses the user-defined function "assign_mass". Note, that you need to invoke pipeline.compute() to make the particle property "mass" part of your pipeline.

Code: [Select]
from ovito.data import *
from ovito.modifiers import PythonScriptModifier

# Load some input data:
pipeline = import_file("input/simulation.data")

def assign_mass(frame, input, output):
    p_types = input.particles['Particle Type']
    mass = output.particles.create_property('Mass')
    with mass:
        mass[(p_types == 1)] = 1.008
        mass[(p_types == 6)] = 12.011

pipeline.modifiers.append(PythonScriptModifier(function = assign_mass))

# Evaluate data pipeline. This will result in a call to assign_mass() from above.
data = pipeline.compute()

-Constanze

222
Support Forum / Re: Define a new properties
« on: August 27, 2018, 06:06:32 PM »
Dear Ali,

write-access to particle properties was done differently in OVITO 2.9.

In that case, instead of using a with statement in your "lines 81-82" you need to access your particle property "xyz_prime" like this

Code: [Select]
xyz_prime.marray[particle_index] = 1
xyz_prime.changed()

as described in more detail in this Section in the Manual.
Does this solve your problem?

-Constanze

223
Support Forum / Re: Save the distance between two particles
« on: August 27, 2018, 01:53:44 PM »
Hi ramonjgt,

you could use a Python script modifier to calculate the distance between the two particles, e.g. between particle 1 and 2
Code: [Select]
from ovito.data import *
import numpy as np
def modify(frame, input, output):
    distance = np.linalg.norm( input.particles["Position"][1]-input.particles["Position"][2] )
    print (distance)
    output.attributes["Distance"] = distance

and save that information as a global attribute.
Then this information is available in the Text label overlay function as [Distance].

-Constanze

224
Dear Ali,

are you using the GUI of OVITO or is your code snippet part of a larger batch script?
Also can you explain a little bit more on what bonds we are looking at here and how you generate them. It is not yet clear to me which atoms you would like to color code.   A bond angle is defined by three atoms, so which of these three should it be?

-Constanze

225
Support Forum / Re: total strain
« on: August 15, 2018, 05:36:34 PM »
Hi Bahman,

so I assume you have a non-periodic cell where you can't just calculate the total strain from the length change?
Then you could have a look at this topic http://forum.ovito.org/index.php?topic=330.0 ,
where an example is given how to calculate the average value of any particle property using a  Python script modifier. This should answer your question.

Cheers,
Constanze

226
Support Forum / Re: How to coloring particles by its properties
« on: August 09, 2018, 02:30:36 PM »
Hi,
I removed the attached file in Alexander's post.
Best,
Constanze

227
Support Forum / Re: visualization of vectors by arrows
« on: August 07, 2018, 03:29:11 PM »
Hi Ilya,

could you send us a screenshot or even better upload the .ovito state file so we can understand what you're doing.

Best,
Constanze

228
In that case, just change the line where you calculate the Voronoi polyhedra.
Code: [Select]
voro_indices = input.particles['Voronoi Index']
to this:
Code: [Select]
voro_indices = input.particles['Voronoi Index'][ input.particles['Particle Type'] == 1 ]

-Constanze

229
First of all, you made a mistake when you copy-pasted Alexander's example script again. You should remove the first 6 lines.
Moreover, you need to be more clear in your wording. What do you mean by "Voronoi index of certain particle"?

Do you want to know the Voronoi index of a certain particle? Or are you asking how to get the distribution of Voronoi-indices for a certain particle type?
Those are two different things.

-Constanze

230
Support Forum / Re: Select atoms at the interface of two materials
« 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



231
Hi,
let me try to answer your questions in the order you posted them.  :)

1. Yes, but it's not the script that controls that, it's the Voronoi analysis modifier. You can simply use the Select type modifier in conjunction with the option "Use only selected particles" in the Voronoi analysis modifier.

2. No you don't need to. It's up to you. If you don't use that option then all particles will be treated as if they have the same size during the Voronoi tesselation. Otherwise, bigger atoms will take more space so to say.

3. In a non-interactive batch script (=outside the graphical user interface) you import your data from an external file (as shown below) to start the pipeline and then you add all your modifiers similarly to what you would do in the graphical user interface.

The python script modifier in the graphical user interface is only meant to define modifier functions
Code: [Select]
def modify(frame, input, output):
    ....
and is part of the pipeline. It gets the your imported data as input. That's why it failed when you tried to import your data (twice).
Code: [Select]
node = import_file("C:/Users/wai/Desktop/example.cfg.cfg")

4. Well, that's what the function called "modify" your using here does, right?
Code: [Select]
unique_indices, counts = row_histogram(voro_indices)

-Constanze

232
Support Forum / Re: How to coloring particles by its properties
« on: August 03, 2018, 10:51:12 AM »
Hi eason1021,

it would be a lot easier to help you if you uploaded your code here. Then I can understand what you're trying to do.

-Constanze

233
Hi,
in principle you were only missing a loop over all your frames, which I added in the end. Also I removed a couple of node.compute()'s from your code. You don't need to apply it after every modifier addition. You can just do it after you set up your modification pipeline. :)

Try the following code (it's still OVITO 2 syntax) which calculates the average hydrogen coordination number of your selected particle and let me know if you have questions:

Code: [Select]
from ovito.io import import_file
from ovito.modifiers import *
import numpy as np

#Step 1: Setting up the pipeline
# Load in the data file
node = import_file("1.dump", multiple_frames = True)

# Output the number of atoms and frames
print("Number of atoms = %i" % node.source.number_of_particles)
print("Number of frames = %i" % node.source.num_frames)

node.modifiers.append(SelectExpressionModifier(expression = 'ParticleIdentifier == 18267'))

# Calculate the coordination number of the hydrocarbon system, build neighbour C-H bonds
modifier = ComputePropertyModifier()
modifier.cutoff_radius = 1.30
modifier.output_property = "Coordination"
modifier.expressions = ["0"]
modifier.neighbor_mode = True
modifier.neighbor_expressions = ["ParticleType==2?1:0"]
modifier.only_selected=True
node.modifiers.append(modifier)

n_hydrogen = []
# Step 2: Evaluating the same pipeline for different input frames:                                                                                                                                                                 
for frame in range(node.source.num_frames):
        data = node.compute(frame)
        coordination = data.particle_properties["Coordination"].array
        selection = data.particle_properties["Selection"].array
        n_hydrogen.append( coordination[ (selection == 1) ]  )

print("average hydrogen coordination number of selected particle: %.2f" % np.mean(n_hydrogen))

-Constanze

234
Dear RMCtestFYP,

you can't run whole batch scripts from within a python script modifier in the graphical user interface (GUI) of OVITO.
Have a look at the documentation part about running scripts.

So either you execute the voronoi example script from within the terminal, e.g.
Code: [Select]
ovitos voronoi.py

or you follow the GUI procedure which I explained in my previous post. Note that if you want to reproduce what's happening in the example batch script, you need to activate
Use particle radii in the Voronoi analysis modifier.

The particle radii can be edited when you click on -> Particle Types in the Data source panel (see screenshot).

Concerning your results I can only suggest you to consult the literature. My expertise is mostly on CuZr metallic glasses.

-Constanze

235
Hi,

actually, here you calculate the number of neighbors of type 2 within a cutoff of 1.3 for every atom.
Quote
Code: [Select]
modifier = ComputePropertyModifier()
modifier.cutoff_radius = 1.30
modifier.output_property = "Coordination"
modifier.expressions = ["0"]
modifier.neighbor_mode = True
modifier.neighbor_expressions = ["ParticleType==2?1:0"]
node.modifiers.append(modifier)

If you only need that information for the particle you previously selected you also need to use
Code: [Select]
only_selected = True in your Compute Property modifier.
In that case, the particles will have a particle property called "Coordination" which only for the selected particle should be equal to the number of type2 neighbors (within that cutoff) and zero for all other particles.

Then in the following part of your script you count the number of all hydrogen atoms that have exactly one hydrogen neighbor. What were you trying to achieve here?
Quote
Code: [Select]
def count_coordinated_particles(frame, input, output):
   n_hydrogen = (input.particle_properties['Particle Type'].array == 2) & (input.particle_properties['Coordination'].array == 1)
   output.attributes['coordinated_particles'] = np.count_nonzero(n_hydrogen)

-Constanze

236
Support Forum / Re: Select atoms at the interface of two materials
« 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

237
Hi,

there are some changes in the python programming interface of OVITO 3.0 as compared to OVITO 2.X and you're using the example script from the OVITO 2.X manual.
Let me refer you to the updated script in the OVITO 3.0 documentation.

However, from your screen-shot I can see that you're using the graphical user interface, where you can make your life a lot easier by calculating the Voronoi indices by inserting
the Voronoi analysis modifier in the modification pipeline (see attached screen-shot). Afterwards, you can still use a python script modifier function to print the 10 most frequent Voronoi motifs, e.g. like this:

Code: [Select]
from ovito.data import *
import numpy

def row_histogram(a):
    ca = numpy.ascontiguousarray(a).view([('', a.dtype)] * a.shape[1])
    unique, indices, inverse = numpy.unique(ca, return_index=True, return_inverse=True)
    counts = numpy.bincount(inverse)
    sort_indices = numpy.argsort(counts)[::-1]
    return (a[indices[sort_indices]], counts[sort_indices])

def modify(frame, input, output):
   
    voro_indices = input.particles['Voronoi Index']
    # Compute frequency histogram.
    unique_indices, counts = row_histogram(voro_indices)
    # Print the ten most frequent histogram entries.
    for i in range(10):
        print("%s \t %i \t (%.1f %%)" % (tuple(unique_indices[i]), counts[i], 100.0*float(counts[i])/len(voro_indices)))
   

-Constanze


238
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



239
Support Forum / Re: How to coloring particles by its properties
« on: July 30, 2018, 09:51:16 AM »
Yes, it needs to be a particle property.
Let's say the output of your method is called "results" and you want to store these values in a new particle property "myproperty".
This is how you can do this:

Code: [Select]
data.particles.create_property('myproperty', data=results)

240
Support Forum / Re: How to coloring particles by its properties
« on: July 29, 2018, 12:05:06 PM »
Have a look at this topic, where I explained how to use your own color map in the Color Coding modifier. This gives you more control over the color coding.
In the python scripting interface you can import an image file of your own custom color gradient like this:

Code: [Select]
pipeline.modifiers.append(ColorCodingModifier(
    property = ... ',
    gradient = ColorCodingModifier.Custom("<image file>")
))

Let me know if that works for you.
-Constanze

Pages: 1 ... 6 7 [8] 9