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
61
Support Forum / Re: Particles
« on: September 19, 2018, 01:36:58 PM »
OVITO currently has the following file export functions:

1) Either you can export a selection of particles along with their properties, like e.g. the atomic stresses. If you choose the *.dump or *.xyz format as export file format you can select which particle-properties you want to export, e.g. only the Stress Tensor (see screenshot 1).

2) Global attributes like the total strain and stress (which you probably first need to calculate using a Python script modifier as explained above) can be exported as well. Simply choose "Table of values" as export file format (see screenshot 2).

-Constanze

62
Support Forum / Re: Particles
« on: September 19, 2018, 12:06:26 PM »
Amir,
it's not clear what you mean by "tension in different strains" and "copy" the data. What you where trying to reference in your first screenshot as StressTensor.ZZ is a per-atom information, not the total stress.
If you're trying to calculate the total stress and strain you can do so, e.g. with a python script modifier. This has been explained here:

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

Still, the file-export is the way to go to export the time-evolution these quantities.

-Constanze




63
Support Forum / Re: Particles
« on: September 19, 2018, 11:46:23 AM »
Hi Amir,

have you considered using the File Export function?

-Constanze

64
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


65
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] )

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

67
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

68
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

69
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

70
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

71
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

72
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

73
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

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

75
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

76
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

77
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

78
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

79
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

80
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

81
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

82
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

83
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

84
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



85
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

86
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

87
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

88
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

89
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

90
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

Pages: 1 2 [3] 4