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 ... 4 5 [6] 7 8 9
Support Forum / Re: Partial radial distribution function (RDF)
« on: November 13, 2018, 11:06:20 AM »
Hi Safy,

If you integrate the rdf between two values r1 and r2, you will get the number density of atoms in that shell, so you still have to multiply that by its volume. That's why I suggested to start from the unnormalized histogram of the bond lengths instead.

Yes, you could also use the Coordination analysis modifier. But this will give you the number of neighbors starting from r = 0 up to a certain cutoff value. But what you're asking for is the number of atoms in different coordination shells right? You could do that analysis from r0 to r1 and r0 to r2 and subtract the results of the inner shell from the outer one. However, the Coordination analysis modifier won't distinguish between different atom types.

But let me explain another way: What's probably easier for you is to use the Compute property modifier. Say you're examining atom type 1, this is how you would count the number of atoms of type 1 in an exemplary coordination shell between 2.5 and 4.0 (length units).

Neighbor Expression
(Distance >= 2.5) && (Distance =< 4.0) && (ParticleType == 1) && (@Particle Type == 1)

Note that  @... references the properties of the central particle, but this feature is not yet available in OVITO 2.9.

Support Forum / Re: Use bins to compute mass property
« on: November 13, 2018, 10:27:52 AM »
Hello ad,

I didn't understand yet what you are trying to do. Could you maybe explain a little bit more?


Support Forum / Re: Atoms Shifting to one end
« on: November 13, 2018, 10:15:34 AM »
yes, you could apply the Affine Transformation modifier to your data and then export the files via the File Export function.


Support Forum / Re: Partial radial distribution function (RDF)
« on: November 09, 2018, 04:30:30 PM »

why don't you use the information you already calculated in your script, i.e. when you calculate the histogram of the different bond lengths?
Code: [Select]
hist, bin_edges = np.histogram(output.bond_properties.length.array, bins=num_bins)

Support Forum / Re: Grab max z coordinate | python script
« on: November 08, 2018, 09:56:28 AM »
Hello ad,

have a look at this topic here, where someone had a similar question.


Hi Ali,

as explained above, the Slice modifier doesn't know about your crystal orientation, it uses spatial coordinates. However, for your given set of Miller-Bravais indices you can calculate the normal vector of the plane in spatial coordinates.


Support Forum / Re: Transformation to target box
« on: October 29, 2018, 10:55:40 AM »
Dear anurag,

this is how you would set the option "relative_mode" to False in the Affine Transformation modifier:

Code: [Select]
         relative_mode = False,
         #...other options )

Note that the relational operator "==" is not the same as "=", it compares the values on either sides of your expression and tells you the relation among them.
If the values of two operands are equal, then the condition becomes true.


Support Forum / Re: Quantum espresso files
« on: October 25, 2018, 01:42:02 PM »
As Alexander said, it would be helpful if you provide us with an example file. Then we can look into this.


Support Forum / Re: Problem in MSD results from ovito
« on: October 25, 2018, 12:10:52 PM »
Dear prash,

as far as I can see there's no issue with the way you calculate the MSD with OVITO, it's rather a problem with your reference structure. Are you sure that this is the correct reference file?

Note that the Displacement vectors modifier uses the Particle Identifiers and I found that you have different numbers of atoms in your reference and in your example frames. It seems that you were able to avoid this problem by deleting all particles of type 1. However, it appears that the Particle Identifiers of the atoms in your binary system do not correspond to their original ID's anymore. Can you explain how you inserted your second particle type in the reference structure?
Did you maybe not only change the atom type of some of your particles but also unintentionally their Particle Identifiers? And this is why you get these large displacements because you're actually comparing "different particles" so to say.

I'm also wondering, if you want the MSD of particle type 2 only, wouldn't it make more sense to use "frame 0" as a reference in the Displacement vectors modifier instead of the external reference structure, where these particles are not even present yet?
Hope that helps,


Support Forum / Re: How can we get a bond angle distribution in ovito?
« on: October 24, 2018, 04:50:13 PM »
Dear SC,

concerning the error message: did you just copy that code in a python script modifier in the GUI of OVITO? Note that this is a bash-script which is meant to be executed from the command line like this:
Code: [Select]
ovitos <>
See the documentation about running scripts.


Ah okay, I see. In principle you have three options: 1) Either you write a bash-script that takes care of everything and which you can execute from the command line like this:
Code: [Select]
ovitos <>but that will require some more python coding on your part. See the documentation about running scripts.

Or  2) if you prefer using the graphical user interface, you could calculate the center of mass of your cluster for every frame, where the atoms are aggregated and save that information in a global attribute (it will also appear in the Data Inspector.) The time-series of a global attribute can be exported using the File-Export function Table of Values.

If you like, try the following: First, apply the Cluster analysis modifier. Then, you should assign masses to your atoms via the Compute property modifier. For example if your particles of type 1 and 2 have masses of 0.5 and 1.1 you can use the expression shown in the screen shot. Then, add the following Python script modifier to your pipeline:
Code: [Select]
from import *
import numpy as np
def modify(frame, input, output):
    #get the particle property "Cluster", "Position" and "Mass"
    cluster = input.particles['Cluster']
    positions = input.particles['Position']
    masses = input.particles['Mass']
    #Perform calculation only if all particles are aggregated in 1 cluster
    #(i.e. no Cluster-ID higher than 1 is allowed)
    if np.max(cluster) == 1:
        sum = 0
        for i in range(len(positions)):
            sum += masses[i]*positions[i]
        com = sum/np.sum(masses)
        output.attributes["CenterofMass"] = com
        output.attributes["CenterofMass"] = "Nan"

If you export that data as explained above, you will get a table with the position of the center of mass of the cluster for every frame. In frames, where there's more than 1 cluster, you'll have an entry "Nan" instead. You can then further post-process your file and calculate the displacements and from that the MSD etc.

Edit: Note, that the above script is just meant as starting point for you. You should probably also add a part that takes care of the periodic boundary conditions and use the minimum image convention for calculating the position of the center of mass. 

3) What you could also do is export a series of dump or data files, where you pretend your center of mass is a "particle". If you reimport that data into Ovito, you could simply use the Displacement vectors modifier or even the Generate particle trajectories modifier to visualize the movement of the center of mass.


Support Forum / Re: Problem in MSD results from ovito
« on: October 24, 2018, 03:01:32 PM »
The script doesn't seem to be the issue.

Dear prash,

I have had a look at the data files you uploaded. So as a starting point, here is how you would use the Python script modifier (OVITO 3.0 syntax) to identify frames where the particles are aggregated in 1 cluster only (Note that you need to perform the Cluster analysis before, see attached screenshot).

Code: [Select]
from import *
import numpy as np
def modify(frame, input, output):
    #get the particle property "Cluster"
    cluster = input.particles['Cluster']
    #Perform calculation only if all particles are aggregated in 1 cluster
    #(i.e. no Cluster-ID higher than 1 is allowed)
    if np.max(cluster) == 1:
        print("Found 1 cluster in frame {}".format(frame))
        #...continue here

What I don't quite understand yet is what these 4 particles represent. I noticed they have different particle identifiers in every frame and sometimes different particle types. So I couldn't use the Displacement vectors modifier, since there's no reference structure that contains all present particle identifiers.

If you need further help, maybe you could explain, what displacements you're trying to calculate? Individual particle displacements to some reference (you didn't include in your example files?) or the displacement of the center of mass of the whole cluster?


Support Forum / Re: Partial radial distribution function (RDF)
« on: October 24, 2018, 02:11:14 PM »
Hi Kyu,
you're right. With these two lines you can print the current working directory:
Code: [Select]
import os
Under MacOS it turns out to be "/", where you typically don't have write permission.
So on the Mac, you need to give a file path as well, when you're trying to save a file with
numpy.savetxt() from within the python modifier in the GUI.

However, in a future release, there will be a more intuitive way to export that data such that you can simply use the "File Export" function.


Support Forum / Re: Quantum espresso files
« on: October 24, 2018, 01:24:42 PM »
here's the list of file formats that can be imported in OVITO 3.0.


Support Forum / Re: Problem in executing OVITOS
« on: October 23, 2018, 04:07:59 PM »
Dear ad,

in that case you don't have to build it from source. The python scripting interface comes with the OVITO package.
That means, on your Mac you can simply drag and drop the OVITO package into your Applications folder (like how you usually install programs). Then you can call ovitos like this:

Code: [Select]
/Applications/ <>
Further, you can make your life easier by adding the following line to your "~/.bash_profile" file:
Code: [Select]
export PATH=/Applications/$PATH so you won't have to type the whole path every time.


Dear prash,

without seeing (at least an example of) your simulation data it's very difficult for me to help you. That also goes for the other topic you opened on this board. If you like, you can upload an example of your trajectory, then I and other users can look into it your problem.


Dear prash,

that sounds like it could be achieved by using the Cluster analysis modifier in conjunction with a user defined function in a python script modifier.


Support Forum / Re: Problem in MSD results from ovito
« on: October 23, 2018, 02:20:19 PM »
Dear prash,

I'm afraid you will need to get more specific for people to be able to help you, i.e. show us the python script modifier you are using and the MSD graph. If your trajectory is not too large it would be helpful if you uploaded it here too.


Support Forum / Re: Partial radial distribution function (RDF)
« on: October 23, 2018, 10:43:51 AM »
Hi Safy,
the answer depends on what version of OVITO you're using. In the latest developer version, you can already see the plot under "Data Plots" in the Data Inspector (see attached screenshot).

In OVITO 2.9, you can add two lines of code to your python script modifier using numpy.savetxt()

Code: [Select]
result = np.column_stack((radii,rdf))
np.savetxt("partial_rdf_%s.dat" % frame, result)
to export your data to a text file (labeled by number of the current frame) and then plot it with your favorite plotting program.


Support Forum / Re: Name on the particle
« on: October 22, 2018, 06:23:02 PM »

are you aware of the different Viewport overlays?
You could for example use the Text label overlay or the Python Script overlay to label your hydrogen atom.


Support Forum / Re: Drawing border around circles
« on: October 18, 2018, 07:34:59 PM »
So as a starting point, here's how you draw black circles with red borders for every atom (I also attached a picture of the result to compare with the previous version)

Code: [Select]
import ovito
import numpy as np
from PyQt5.QtCore import *
from PyQt5.QtGui import *
import ovito.vis

# This helper function projects a point from 3d space to
# 2d window coordinates.
def project_point(xyz, painter, args):
view_tm = args['view_tm'] # 3x4 matrix
proj_tm = args['proj_tm'] # 4x4 matrix
world_pos = np.append(xyz, 1) # Convert to 4-vector.
view_pos =, world_pos) # Transform to view space.
# Check if point is behind the viewer. If yes, stop here.
if args['is_perspective'] and view_pos[2] >= 0.0: return None
# Project to screen space:
screen_pos =, np.append(view_pos, 1))
screen_pos[0:3] /= screen_pos[3]
win_rect = painter.window()
x = win_rect.left() + win_rect.width() * (screen_pos[0] + 1) / 2
y = win_rect.bottom() - win_rect.height() * (screen_pos[1] + 1) / 2 + 1
return (x,y)

# This helper function projects a distance or radius from 3d space to
# 2d window coordinates.
def project_radius(xyz, r, painter, args):
if args['is_perspective']:
world_pos = np.append(xyz, 1) # Convert to 4-vector.
vp = np.append(['view_tm'], world_pos), 1) # Transform to view space.
p1 =['proj_tm'], vp) # Project to screen space.
p1[0:3] /= p1[3]
vp += [0,r,0,0]
p2 =['proj_tm'], vp) # Project to screen space.
p2[0:3] /= p2[3]
return np.linalg.norm(p2-p1) * painter.window().height() / 2
return r / args['fov'] * painter.window().height() / 2

def render(painter, **args):

# Access current particle positions.
node = ovito.dataset.selected_node
positions = node.compute().particle_properties.position.array

#Sort particles by distance viewer depending on camera view
vp = ovito.dataset.viewports.active_vp
projected_pos =,vp.camera_dir)
sorted_indices = np.argsort(projected_pos)[::-1]

# Project center point of first particle.
for particle_index in sorted_indices:
xy = project_point(positions[particle_index], painter, args)
if xy is None: return

# Get particle display radius.
radius = node.source.particle_properties.position.display.radius

# Calculate screen-space size of particle in pixels.
screen_radius = project_radius(positions[0], radius, painter, args)

# Draw circles instead of particles.
pen = QPen(Qt.SolidLine)
painter.drawEllipse(QPointF(xy[0], xy[1]), screen_radius, screen_radius)

If you like, copy that code and try it out in the python script overlay. I'll leave the part about drawing bonds up to you. Let me know if you have questions.

Edit: I added another 3 lines of code that sort the particles by "distance from the viewer" depending on the viewing direction of the active viewport. Otherwise the circles might not be plotted in the right order.


Support Forum / Re: Drawing border around circles
« on: October 18, 2018, 07:06:41 PM »
Dear Aldo,

just to clarify, I created the picture I uploaded with OVITO. Depending on the "stacking sequence" of your different bonds and particles, I guess it should in principle be be possible to hide the bonds behind the "border". Also, the Affine Transformation could be adapted to follow any viewing direction. By the way, the whole procedure can be made a little bit less painful by using the "Pipeline cloning" functionality in OVITO 3, but I do get your point.

Here's another idea: Are you aware of the code examples given in the documentation about Viewport overlays? You could use a Python script overlay that's based on "Example: Viewport projection" and add a function that draws the bonds as well. The learning curve will be steep, but you'll have more flexibility there.


Support Forum / Re: How to save data as a txt file?
« on: October 18, 2018, 03:26:14 PM »
Ah okay I see, the problem is that np.savetxt(...) is missing a couple of whitespaces in the beginning of the line. You need to make it match the indentation level of the previous lines, so it's part of the modify function:

Code: [Select]
def modify(frame, input, output):
hist, bin_edges = np.histogram(input.bond_properties.length.array, bins=num_bins)

rho = input.number_of_particles / input.cell.volume
factor = 4./3. * np.pi * rho * input.number_of_particles

radii = bin_edges[:-1]
radii_right = bin_edges[1:]
rdf = hist / (factor * (radii_right**3 - radii**3))
np.savetxt("partial_rdf.dat", np.column_stack((radii,rdf)))


Support Forum / Re: How to save data as a txt file?
« on: October 18, 2018, 01:30:23 PM »
Dear SC,

to me it looked like there was a leading whitespace at the beginning of your source code which needs to be removed.

Code: [Select]
np.savetxt("partial_rdf.dat", np.column_stack((radii,rdf)))
#here you need to remove the leading white space
 np.savetxt("partial_rdf.dat", np.column_stack((radii,rdf)))

Sorry for the confusion, in case there is none, can you copy the whole code here? Maybe the indentation level of the previous lines doesn't match your last line.
In any case, you don't need to modify the RDF by doing this RDF.strip().


Support Forum / Re: make movie with multiple active frames
« on: October 18, 2018, 12:28:01 PM »
Hello Reza,

I have never done it using Windows 10, but the Windows support suggests that the Photos app or the Movie Maker can do this.

Blender could be an alternative. It's free and open source, but I think it will take some time to learn.

You could also do it from the command line using ffmpeg.

Maybe other Windows users have better suggestions?


Support Forum / Re: Drawing border around circles
« on: October 18, 2018, 12:07:19 PM »
Dear Aldo,

I think the easiest solution is to follow your strategy but repeating it one more time.
First, load in your dataset, plot the particles (as circles) and bonds (with shading mode = flat) with the "bordering" color.
Then load in the dataset one more time, create thinner bonds with your desired "inner" bond color, but this time deactivate Particles under "Display". Now also use the Affine-Transformation modifier and shift these bonds a little towards the viewing direction so that they are on top.
Finally, load the dataset one last time, shift the atoms using the Affine Transformation modifier and plot only the particles as smaller circles and use the fill color of your choice.

I attached a screenshot of an example structure. Might be that you need to add fourth step if you don't want to have "closed" circles around your atoms.
Anyways, I hope that helps. Let me know if that was what you're aiming at.


Support Forum / Re: Property specific to a particle ID.
« on: October 18, 2018, 11:11:33 AM »
Hi Shamail,

the Compute property modifier lets you use conditional assigments, see the section about Conditional assignments in the documenation:

As an example, say you want to assign a charge of 0.5 to particle type 1 and a charge of 1.1 to particle type 2. The corresponding expression for the Compute property modifier "charge" would then be

(ParticleType == 1 ) ? 0.5 : 1.1


Support Forum / Re: How to save data as a txt file?
« on: October 18, 2018, 11:03:01 AM »
Dear SC,

indentation matters in python, see e.g. here
The problem is the leading whitespace, which you need to remove.

Maybe you'll find these python tutorials for beginners helpful:


Dear jatink,

we are looking forward to you contacting us directly. But in the meantime here's an idea of how you could track the x-coordinate of the particle with the highest z-coordinate as a function of simulation time. As you already noted, the Displacement vectors modifier is not the right tool to achieve this.
However, here's how you could adapt your python script: Use numpy.argmax() to find the index of the particle with the highest z-coordinate and use that index to look up its x-coordinate.
Code: [Select]
import numpy
node = import_file(...)

def compute_max_z(frame, input, output):
    #Find the index of the particle with the highest z-coordinate and look up its x-coordinate                                                                                                                                                                     
    positions = input.particles["Position"]
    output.attributes["x_coord"] = positions[ np.argmax(positions[:,2]) ][0]
export_file(node, "max_z.txt", "txt", columns=["Frame", "x_coord"], multiple_frames = True)

This gives you the x-coordinate of the maximum of your "wrinkle" as a function of simulation time. You could then use that data to fit the velocity. Let me know if that was what you had in mind.


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