Author Topic: color coding as a function of liquid density  (Read 115 times)

dhuang2

  • Newbie
  • *
  • Posts: 5
color coding as a function of liquid density
« on: March 26, 2019, 06:48:38 PM »
Dear all,
I would like to know how to display the color as a function of the liquid density?
Is ovito able to do that?
I am simulating a heated nanoparticle immersed inside a pool of liquid, I am able to see the density decrease around the nanoparticle by post processing the 1d and 2d density profile.
It would be great to use ovito to do the color coding as a function of the liquid density.
Regards,

Dezhao Huang
3rd year Ph.D student
University of Notre Dame
Department of Aerospace and Mechanical engineering
B14 Fitzpatrick Hall
Notre Dame, IN 46556-5710
Tel: (573)-578-0869
dhuang2@nd.edu
« Last Edit: March 26, 2019, 06:51:33 PM by dhuang2 »

Constanze Kalcher

  • Administrator
  • Full Member
  • *****
  • Posts: 233
Re: color coding as a function of liquid density
« Reply #1 on: March 27, 2019, 10:46:53 AM »
Dear Dezhao,

what exactly would you like to color? Do you only need to color the atoms in the liquid phase or are you trying to overlay a density plot from your external data? The latter could possibly be done with a little work around.

Could you send me an example of your data, and also the density profiles? If you don't want to upload it here you can use the official mail support.

Just in case you didn't know, OVITO also has a Spatial binning modifier,
https://ovito.org/manual_testing/particles.modifiers.bin_and_reduce.html
It creates so-called Voxel grids
http://ovito.org/manual_testing/python/modules/ovito_data.html#ovito.data.VoxelGrid
which can be used by the Create Isosurface modifier
http://ovito.org/manual_testing/python/modules/ovito_modifiers.html#ovito.modifiers.CreateIsosurfaceModifier
to render iso-level surfaces for any grid field you computed/imported. Maybe that could be of interest to you.

Edit: I attached to two example pictures for you so it's easier to understand what OVITO can do. For the first one I used the spatial binning modifier (on an artificially created particle property that's radially increasing) and then added several isosurfaces. In the second one the color coding modifier was used.

-Constanze
« Last Edit: March 27, 2019, 11:39:48 AM by Constanze Kalcher »

dhuang2

  • Newbie
  • *
  • Posts: 5
Re: color coding as a function of liquid density
« Reply #2 on: March 28, 2019, 05:47:03 AM »
Hi Constanze,
Thank you very much for your detailed reply! I really appreciated it.
I have already figured out this problem by post-processing the 3d density profile generated by lammps using the MATLAB isosurface functionality. I was able to locate the critical density isosurface and distinguish the liquid/vapor interface. Since my density profile file is around several Gbs, I will not put that in the attachment. It is generated by the lammps fix ave/chunk 2d command.
I have also tried to use Ovito to do the same thing by following your explanations, right now, I only have one quick question about the ovito. How do we define our own computing property in Ovito and output the 3d binning profile?
Thank you very much!
Regards,
Dezhao

Constanze Kalcher

  • Administrator
  • Full Member
  • *****
  • Posts: 233
Re: color coding as a function of liquid density
« Reply #3 on: March 28, 2019, 02:58:47 PM »
Hi Dezhao,

ah okay, yes of course that makes sense. Thank you for your explanations.

Concerning your questions, there are two ways to create new particle properties, you can either use the Compute property modifier
https://ovito.org/manual_testing/particles.modifiers.compute_property.html
or a Python script modifier
http://ovito.org/manual_testing/particles.modifiers.python_script.html

As a very simple example, say the particle masses you need to calculate the density are not part of your input data (as is e.g. the case for a lammps dump file). Then we could create a new particle property called "Mass". Let's assume you have 2 particle types (e.g. Cu and Zr) with type ID's 1 and 2 and their masses are 63.5u and 91.2u. This is how you would go about this then:

Approach 1) Compute property modifier
Output property -> Mass
Expression -> ParticleType == 1? 63.5:91.2

Approach 2) Python script modifier
Code: [Select]
from ovito.data import *

def modify(frame, data):
    #create a standard particle property
    my_prop = data.particles_.create_property('Mass')
    ptypes = data.particles["Particle Type"]

    with my_prop:
        my_prop[(ptypes == 1)] = 63.5
        my_prop[(ptypes == 2)] = 91.3

You can use that newly created particle property "Mass" in the Spatial binning modifier to calculate the density.
Note that at the moment there is no direct export function to export the grid you computed. However, with the help of a
small python script modifier (which you would insert on top of you pipeline/ after the Spatial binning modifier) you can do it.

Example for a 2D - grid:
Code: [Select]
grid = data.grids['binning[Mass]']
        array = grid['Mass']
        array_2d = np.reshape(array, grid.shape)
        numpy.savetxt("My_array.txt", array_2d)

Example to export a 3D grid:
Code: [Select]
    import numpy as np
    grid = data.grids['binning[Mass]']
    array = grid['Mass']
    array_2d = np.reshape(array, grid.shape)
    print(array_2d.shape)
    with open("outfile.txt", "w") as out:
        for i in range(0,array_2d.shape[0]):
            for j in range(0,array_2d.shape[1]):
                for k in range(array_2d.shape[2]):
                    out.write( "{:f} \t {:f} \t {:f} \t {:.4f} \n".format( i, j, k, array_2d[i][j][k] ))

To visualize this a trick that I sometimes use is to make the export format match the extended-xyz  or dump file format so I can reimport it with OVITO (You can add the additional data as a second pipeline, slice it, add some color coding and change the "particle shape" to cubes or squares).
See attached pictures.

-Constanze
« Last Edit: March 28, 2019, 05:45:09 PM by Constanze Kalcher »

dhuang2

  • Newbie
  • *
  • Posts: 5
Re: color coding as a function of liquid density
« Reply #4 on: March 30, 2019, 02:11:52 AM »
Thank you very much, Constanze!
This is really helpful!
Regards,
Dezhao