9
$\begingroup$

I found plenty of packages that open .nc files but all specifically catered to climate (meteorological) and geo-maps data. I would like to get suggestions of software that can open .nc (NetCDF), which are either generic, or cater to matter modeling.

I have files related to condensed matter results such as electrostatic potential surfaces (with the structure information too).

$\endgroup$
4
  • 1
    $\begingroup$ +1 Since h5py and MATLAB can open HDF5 files, I'd assume python and MATLAB can open NetCDF, but I'll look into it later. $\endgroup$ Dec 8 '21 at 17:36
  • $\begingroup$ @NikeDattani my concern is that will work for generic data, not for matter simulation. $\endgroup$
    – Camps
    Dec 8 '21 at 17:40
  • 1
    $\begingroup$ What matter simulation software are you considering? h5py and netCDF4 from python works well for the nc files produced by quantum espresso, yambo, .... $\endgroup$ Dec 8 '21 at 18:29
  • $\begingroup$ @XiaomingWang I am using SIESTA. $\endgroup$
    – Camps
    Dec 9 '21 at 12:29
9
$\begingroup$

Python libraries: xarray and hvplot

This is a rather generic answer for opening and quickly visualizing a netCFD file with python. It is not specific to condensed matter, but can be used for it (I personally use it to explore properties computed during MD simulations).

xarray is a python library for handling labelled multi-dimensional arrays, primarily stored as netCFD files

import xarray as xr
ds = xr.open_dataset("saved_on_disk.nc") # read
ds.to_netcdf("saved_on_disk.nc") # write

It comes with its own built-in plotting methods, but an easier way to explore the data is to use the hvPlot library. It creates customizable and interactive graphs that fit nicely in jupyter notebooks. Here's an overview of how it can be used to explore an xarray file.

import hvplot.xarray  # noqa
ds.hvplot()
Example with Siesta ElectrostaticPotential grid

Using one of the example files provided by Camps, this plot was obtained with the following code:

ds = xr.open_dataset('ElectrostaticPotential.grid.nc')
ds.gridfunc.isel(n3=0).hvplot.contour() # plot gridfunc dataarray for first n3 coordinate

enter image description here

Exploring all the n3 coordinates can be done using an interactive widget:

import panel.widgets as pnw
ds.gridfunc.interactive().sel(spin=0, n3=pnw.DiscreteSlider).hvplot(x='n1', y ='n2', kind='contour')
$\endgroup$
2
  • $\begingroup$ it just killed the kernel ;(. Here are some examples of my NetCDF files. $\endgroup$
    – Camps
    Dec 9 '21 at 18:16
  • 1
    $\begingroup$ @Camps I've made an edit with one of your example files taken at random (I didn't try to plot anything relevant, just showed some functionalities) $\endgroup$
    – Hebo
    Dec 10 '21 at 10:56
8
$\begingroup$

This problem is generically problematic for different software packages since there is no standardized format for storing grid values.

In my software package sisl the interaction with Siesta grid output files is seamless and converts between the most common formats, cube and xsf files.

For instance to convert the Rho.grid.nc to a cube or xsf file, simply do:

sgrid Rho.grid.nc Rho.cube

Generally a cube file also needs to know the geometry to see it in visualization, so one needs to attach the geometry as well. Additionally one can compute differences (say spin), here is an example:

sgrid Rho.grid.nc{0} --geometry RUN.fdf --diff Rho.grid.nc{1} diff_up-down.cube

which takes the difference between the 1st and 2nd spin-components and stores them in diff_up_down.cube.

All of the above commands also works for the binary .VT etc. files that siesta outputs.

They can also be used for VASP, although there are probably some corner case files that I haven't thought about.

$\endgroup$
7
$\begingroup$

Adding to @nickpapior answer, the sisl python package also includes intrinsic visualization tools that can help you visualize grids (in this case, stored in .nc files). It is as easy as, in python:

import sisl
import sisl.viz

grid_plot = sisl.get_sile("myfile.nc").plot()

There are lots of things you can tweak on a grid plot directly from python, starting from visualizing things in 3D, 2D and 1D and hiding/showing the structure. Here's a page where the options are displayed in an illustrative way: https://zerothi.github.io/sisl/visualization/viz_module/showcase/GridPlot.html

A cool thing is that the sisl visualization framework is agnostic on the particular plotting framework that renders the plots, so using the same settings you can see the display in any of the supported backends (currently plotly, matplotlib and blender).

Here's some brief introduction to the framework: https://zerothi.github.io/sisl/visualization/viz_module/index.html

And here's a quick tutorial to get started plotting your things in blender: https://zerothi.github.io/sisl/visualization/viz_module/blender/Getting%20started.html

There is no problem with the size of the grids, I use grid sizes like this or more all the time, so I doubt it will kill the kernel, unless your computer has a very small memory.

If you have specific doubts about the usage or suggestions you can use the discord channels.

$\endgroup$
5
$\begingroup$

I don't know if you used VMD. In general, if you didn't use VMD. It is one of the best to visualize and there are a lot of options that you can use to analysis if you need. It is available to win and Linux, and I recommend you to use Linux Version.

All you need to upload the parameter of your structure or the format you have, depend on your calculation and then load the NetCDF file over the parameter.

enter image description here

enter image description here

$\endgroup$
8
  • $\begingroup$ I tried your suggestion. When loading the `.nc' file, it claims Unable to load molecule. Here are some examples of NetCD files. $\endgroup$
    – Camps
    Dec 9 '21 at 17:43
  • $\begingroup$ @Camps You have only the nc file . Don't you have topology(top) file or parm file ? $\endgroup$ Dec 9 '21 at 19:32
  • $\begingroup$ There isn't topology/parm files. Just the XYZ with the system structure. $\endgroup$
    – Camps
    Dec 9 '21 at 20:15
  • 1
    $\begingroup$ Yes, it will show, but you can't load nc. the parm file contains the type of each atom, the angle, the dihedral, proper etc. and when you load nc over the parm, now you can see each frame and the change of the angle and so $\endgroup$ Dec 9 '21 at 20:55
  • 1
    $\begingroup$ If the chat gets too long, I recommend the HPC chatroom. $\endgroup$ Dec 10 '21 at 14:21
3
$\begingroup$

NetCDF

According to the NetCDF homepage

NetCDF (Network Common Data Form) is a set of software libraries and machine-independent data formats that support the creation, access, and sharing of array-oriented scientific data. It is also a community standard for sharing scientific data. The Unidata Program Center supports and maintains netCDF programming interfaces for C, C++, Java, and Fortran. Programming interfaces are also available for Python, IDL, MATLAB, R, Ruby, and Perl.

Since this is a general format which can be used for any kind of data, and you did not specify what files you are actually interested in, I would recommend using the NetCDF library to open and handle NetCDF files that you encounter anywhere.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.