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

62
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 ovito.data 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?

-Constanze

63
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
print(os.getcwd())
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.

-Constanze

64
Support Forum / Re: Quantum espresso files
« on: October 24, 2018, 01:24:42 PM »
Hi,
here's the list of file formats that can be imported in OVITO 3.0.
http://ovito.org/manual_testing/usage.import.html

-Constanze

65
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/Ovito.app/Contents/MacOS/ovitos <your-script.py>
Further, you can make your life easier by adding the following line to your "~/.bash_profile" file:
Code: [Select]
export PATH=/Applications/Ovito.app/Contents/MacOS/:$PATH so you won't have to type the whole path every time.

-Constanze

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

-Constanze

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

-Constanze

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

-Constanze

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

-Constanze

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

are you aware of the different Viewport overlays?
http://ovito.org/manual/viewport_overlays.html
You could for example use the Text label overlay or the Python Script overlay to label your hydrogen atom.

-Constanze

71
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 = np.dot(view_tm, 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.dot(proj_tm, 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(np.dot(args['view_tm'], world_pos), 1) # Transform to view space.
p1 = np.dot(args['proj_tm'], vp) # Project to screen space.
p1[0:3] /= p1[3]
vp += [0,r,0,0]
p2 = np.dot(args['proj_tm'], vp) # Project to screen space.
p2[0:3] /= p2[3]
return np.linalg.norm(p2-p1) * painter.window().height() / 2
else:
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 = np.dot(positions,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)
pen.setWidth(3)
pen.setColor(QColor(255,0,0))
painter.setPen(pen)
painter.setBrush(QColor(0,0,0))
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.

-Constanze


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

-Constanze

73
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)))



-Constanze

74
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]
#correct
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().

-Constanze

75
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.
https://support.microsoft.com/en-us/help/17205/windows-10-create-videos

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?

-Constanze

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

-Constanze

77
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:
http://ovito.org/manual/particles.modifiers.compute_property.html

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

-Constanze

78
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
https://docs.python.org/3/reference/lexical_analysis.html?highlight=indentation.
The problem is the leading whitespace, which you need to remove.

Maybe you'll find these python tutorials for beginners helpful:  https://www.python.org/about/gettingstarted/

-Constanze

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

-Constanze


80
Support Forum / Re: make movie with multiple active frames
« on: October 16, 2018, 11:48:36 AM »
Hello Reza,

there is no direct way to do this with OVITO. You can, however, render a series of *png files for the individual viewports and subsequently combine them to an animation using an external video encoding program. Could you tell me what operating system you are using, so I can give you a more specific answer.

-Constanze

81
Support Forum / Re: Dislocation in Tensile Test
« on: October 10, 2018, 12:03:12 PM »
Hi bity,

I don't have much experience with carbon nanotubes, so can you explain how dislocations in a carbon nanotube are defined? That might increase your chances that I or others can help you.

-Constanze

82
Support Forum / Re: Problem in executing OVITOS
« on: October 09, 2018, 05:26:45 PM »
Could you please upload your script for me, so I can try and reproduce what the problem is.
-Constanze

83
Support Forum / Re: Problem in executing OVITOS
« on: October 09, 2018, 04:02:08 PM »
Dear ad,

I don't really understand whats going on with the path you gave us. Do you really have another set of subfolders Ovito.app/Contents/MacOS/ in your folder  /usr/home/ad/ovito/Ovito.app/Contents/MacOS/ ?
Shouldn't it rather be:
Code: [Select]
/usr/home/ad/ovito/Ovito.app/Contents/MacOS/ovitos <name-of-your-script.py>
-Constanze

84
Support Forum / Re: Problem in executing OVITOS
« on: October 04, 2018, 07:26:43 PM »
Hi,
just to confirm, you followed these instructions?
Could you tell me how you ran the example script?

-Constanze

85
Support Forum / Re: Loading the dump file error in python script
« on: October 04, 2018, 05:14:17 PM »
My guess is that "ovito.py" is a script you wrote and it's in the same folder as "velocity.py"? If that's the case, note that this file might be mistaken for the actual ovito module when you call
Code: [Select]
import ovitoand that's what causes the error. (Read more on python modules here).
You should better rename it to something else.

86
Support Forum / Re: Average Quaternions for Each Grain
« on: October 04, 2018, 05:00:57 PM »
Thank you Peter!  :)

87
Support Forum / Re: Loading the dump file error in python script
« on: October 04, 2018, 02:03:44 PM »
Hello jatink,

as for your previous reply, yes in principle you're right, except for the part about not being able to load input data when invoking "Run python script" from the GUI, but you would need to call add_to_scene() to make it appear in your viewports. More on this in the first highlighted box in this Manual entry about importing files:
http://ovito.org/manual_testing/python/introduction/file_io.html.

I can't really make sense of your error message though. Did you maybe accidentally install several instances of OVITO? Also can you tell me what this file is?
Quote
/Users/kashyap/Google_Drive/NJIT/prof_singh/test/ovito.py

-Constanze

88
Support Forum / Re: Trying to find Certain types of structure in the cell
« on: October 04, 2018, 01:27:34 PM »
Hi Nirmal,

what you're asking for is actually available as an example script in the manual, so you should give a try:
http://ovito.org/manual/python/introduction/examples.html.

-Constanze

89
Support Forum / Re: Loading the dump file error in python script
« on: October 03, 2018, 08:24:54 PM »
Hello jatink,

you don't have to build it from source. The python scripting interface comes with the OVITO package.
From your error message I can see you're using MacOS. If you right click on the OVITO-icon in your applications folder and choose "Show package Content", you can see that "ovitos" is in the subfolder "MacOS".

So from the terminal, you can call it like this:

Code: [Select]
/Applications/Ovito.app/Contents/MacOS/ovitos
or you can make your life easier by adding the following line to your "~/.bash_profile" file:
Code: [Select]
export PATH=/Applications/Ovito.app/Contents/MacOS/:$PATH so you won't have to type the whole path every time.

Edit: If you're not really familiar with the Terminal app, I think this might be helpful:
https://developer.apple.com/library/archive/documentation/OpenSource/Conceptual/ShellScripting/CommandLInePrimer/CommandLine.html

-Constanze




90
Support Forum / Re: Python Script Loop
« on: September 29, 2018, 09:55:38 AM »
Hi jhart,
Quote
it is based on displacement distance
yes you're right, my mistake.

Quote
I want to calculate the number of atoms displaced by more than 0.8 Angstroms.
Then you could count them and save them as global attribute -  basically what you already did in your previous script.

I added this as line 5 to your script below:

Code: [Select]
for file in sorted(glob.glob('../*.dump')):
    node = import_file(file, multiple_frames=True)
    node.modifiers.append(SelectExpressionModifier(expression = 'c_disp_4_>0.8'))
    data = node.compute()
    node.output.attributes['n_atoms'] = np.count_nonzero(data.particle_properties["Selection"].array)
    export_file(
node, "natoms_{}.txt".format(file[-10:-7]), "txt",
columns=['Timestep', 'n_atoms'],
multiple_frames=True
    )

The Select expression modifier, however, already creates a global attribute 'SelectExpression.num_selected',
(see scripting manual of the Select expression modifier). So you could also just reference that:
Code: [Select]
for file in sorted(glob.glob('../*.dump')):
    node = import_file(file, multiple_frames=True)
    node.modifiers.append(SelectExpressionModifier(expression = 'c_disp_4_>0.8'))
    node.compute()
    export_file(
node, "natoms_{}.txt".format(file[-10:-7]), "txt",
columns=['Timestep', 'SelectExpression.num_selected'],
multiple_frames=True
    )

Does that work for you?
-Constanze

Pages: 1 2 [3] 4 5 6