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 2 [3] 4 5 6
31
Support Forum / Re: Particles
« on: September 19, 2018, 11:46:23 AM »
Hi Amir,

have you considered using the File Export function?

-Constanze

32
Support Forum / Re: Theta evolution vs. Frame
« on: September 18, 2018, 02:37:47 PM »
Hi Ali,

here is one possible example for an OVITO batch script that uses a python modifier function to calculate the angle between three specified particles at every simulation frame and saves that information as a global attribute. Finally the time evolution of the angle is saved in a textfile "theta.txt".
I'll leave it up to you to finish the part with the particle indices since I didn't know which of these atoms was supposed to be the central atom.

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

#User defined modifier funtion to calculate the angle between particles 3493, 1805 and 1813                                                                                                                                                                                                             
def compute_theta(frame, input, output):
   
    #Get particle indices from Particle Identifiers           
    particle_identifiers = input.particles["Particle Identifier"]                                                                                                                                                                   
    central_particle_index = np.where(particle_identifiers == 3493)[0][0]
    neighbor_1_index = ...
    neighbor_2_index = ...

    #Calculate the distance vectors                                                                                                                                                                 
    positions = input.particles['Position']
    dist_1 =  positions[neighbor_1_index] - positions[central_particle_index]
    dist_2 =  positions[neighbor_2_index] - positions[central_particle_index]

    #Get the angle                                                                                                                                                                                                                 
    cos_theta = np.dot(dist_1,dist_2)/np.linalg.norm(dist_1)/np.linalg.norm(dist_2)
    theta = np.arccos(cos_theta)

    #Save as global attribute                                                                                                                                                                                                     
    output.attributes['theta'] = np.degrees(theta)

# Load the simulation dataset to be analyzed.                                                                                                                                                                                     
pipeline = import_file("simulation.dump")
pipeline.modifiers.append(PythonScriptModifier(function = compute_theta))

# Export calculated theta values to a text file and let OVITO's data pipeline do the rest:                                                                                                                                           
export_file(pipeline, "theta.txt", format = "txt", columns = ["Timestep", "theta"], multiple_frames = True)

Let me know if that works for you and if you have questions.

Edit: Also note that I was assuming you're using OVITO3.

-Constanze


33
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, input, output):
    shear_strain = input.particles["Shear Strain"]
    selection = input.particles["Selection"]
    output.attributes["Average shear strain"] = np.mean( shear_strain[selection == 1] )

34
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.

35
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

36
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

37
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

38
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

39
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

40
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

41
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

42
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()

43
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

44
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

45
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

Pages: 1 2 [3] 4 5 6