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
31
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

32
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


33
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

34
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

35
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

36
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

37
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

38
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

39
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

40
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


41
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

42
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

43
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

44
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

45
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

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

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

48
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

49
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

50
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




51
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

52
Support Forum / Re: Loading the dump file error in python script
« on: September 28, 2018, 10:19:25 AM »
Quote
Additionally, is there a documentation explaining how to compile the ovitos in university cluster

There is no documentation for any specific cluster, however, this section in the manual describes how to compile ovito from source if necessary.
http://www.ovito.org/manual_testing/development.html
Quote
...or to access the dump files from cluster while running ovito python script in local machine?
Yes, when running on a local machine, the path to the file in the import_file() function can be a remote sftp:// URL. Have a look at the section about importing files from remote computers.

-Constanze

53
Support Forum / Re: Loading the dump file error in python script
« on: September 28, 2018, 09:44:39 AM »
Hi,

it looks like you copied that code snippet you posted here in a Python script modifier in the gui? This wouldn't work, since it's only meant to contain a single modifier function.
Note that what you wrote is a stand-alone batch script which you need to run from the command line, (see this section in the manual about running scripts http://ovito.org/manual/python/introduction/running.htm .

Code: [Select]
ovitos name_of_your_script.py
-Constanze

54
Support Forum / Re: Python Script Loop
« on: September 28, 2018, 09:29:50 AM »
Hi,
well you never calculated a global attribute "Displacement" that you're trying to export. You only created a selection based on the potential energy of the atoms. (This means that they now have a particle property "Selection" which is either 0 or 1. Again, what would you like to do with this selection?

-Constanze

55
Support Forum / Re: Python Script Loop
« on: September 26, 2018, 11:32:27 AM »
Hi,

I haven't gone through your whole script but the current error is definitely due to the naming of the variables in the expression select modifier. I tried with an expression select on an example file in the GUI version of ovito, where you can see the available particle properties in the "Variables" panel. 
You should try the following:

Code: [Select]
node.modifiers.append(SelectExpressionModifier(expression = 'c_disp_4_>0.8'))
This will select all atoms with displacement magnitudes larger than 0.8. What would you like to do with these atoms? Let me know if you need further help.

-Constanze

56
Support Forum / Re: Loading the dump file error in python script
« on: September 26, 2018, 11:17:52 AM »
Dear jatin1990,

the error message is telling you that there is no file called "dump.mix" in the folder where you're executing ovitos. Are you sure that's the correct name and location etc.?

-Constanze

57
Hi sairajdream,

I also tried and could open your file without any problem. Could you please upload your file here instead of just copying the text, because the latter one seems to be perfectly fine.

-Constanze

58
Support Forum / Re: Von Mises Stress
« on: September 20, 2018, 12:29:25 PM »
This doesn't answer my question. How do you want to save the information you calculated?

Besides, if your lammps command worked (I guess it's because the correct variable style should be atom not equal), the quantity VMS would also be a part of your dump file since it's a per-atom quantity. So now that you've calculated that with OVITO, why don't you append that new information as additional column to your .dump files?

However, the sum of all the per-atom values you compute for every snapshot and save as global attribute is something you could export as *.txt file, like you tried above.

59
Support Forum / Re: Von Mises Stress
« on: September 20, 2018, 11:50:22 AM »
That's what I meant with line 7 in your python script doesn't make much sense. Global attributes are not meant to save arrays.

Why don't you export the atomic von Mises stresses via the file-export formats *.dump"  or ".xyz"? Then you don't need that python script modifier at all.

Maybe you can explain how you want your output file to look like, because I'm having trouble understanding the issue.

60
Support Forum / Re: Von Mises Stress
« on: September 20, 2018, 10:51:50 AM »
If you want to sum up only the z-component of your stress tensor you can do:
Code: [Select]
numpy.sum( input.particles["Stress Tensor"][:,2] )

Pages: 1 [2] 3 4