Code Monkey home page Code Monkey logo

ascii-phonons's Introduction

ascii-phonons

Visualisation of crystal vibrations with Blender.

DOI

Documentation Status

Visualisation is a powerful tool for the study of vibrations in the solid state. "Semi-automatic" animations have been generated for scientific publications, where they provide insight to spectroscopic observations.[1,2] (Images 1, 2.) In order to make this type of imagery more accessible, and add some visual interest to ajjackson's PhD thesis, a more convenient and automatic toolchain is desirable.

A presentation outlining some features and implementation details is available online.

Features

  • Ascii-phonons produces PNG and animated GIF files to illustrate phonon modes.
  • The output has an attractive "cartoon-like" visual style with flat colours and outlines.
  • A single mode may be visualised, or a tiled array of all modes labelled by frequency.
  • Arrows may also be used to indicate the atomic movements; this is vital for static images in printed publications.
  • Supercells are used to show the phase difference between neighbouring unit cells. A unit cell bounding box is shown and can be freely translated.
  • The camera angle is defined as a Miller index.
  • Mass-weighting may optionally be added if this was not done in the .ascii file construction.
  • The open-source graphics package Blender is used to render the images; it is also possible to open the Blender scenes for further adjustments before rendering. Experience with Blender is not required to use ascii-phonons.
  • Ascii-phonons is implemented in Python as a Blender addon and a library for convenient access. A GUI and a command-line interface are provided for easy accessibility and scripting potential. Python programming skills are not required.
  • The atomic positions, unit cell and phonon modes are imported from .ascii files. These can be generated with Phonopy. The format was originally specified for v_sim, a useful program and one of the only tools available for visualising non-Gamma-point phonons.
  • User settings can be saved to and loaded from simple config text files. Default parameters including atomic radii, masses and some colours are loaded from editable files in the same format.

Development

Development is in progress and hosted on Github. Please use the issue tracker for feature requests, bug reports and more general questions. For more information about the structure and goals of this project see the relevant section in the official documentation.

Setup

The simplest way to get up and running is

  1. Install Blender (available in all good package managers).
  2. Download the code:
    • either clone the repository with git clone [email protected]:ajjackson/ascii-phonons
    • or download the latest version as a zip file.

Requirements

  • Some means of generating .ascii files. We like Phonopy.
  • A recent version of Blender; development is currently with Blender 2.76 and later. At least version 2.70 is needed, which provides the wireframe modifier used to draw the bounding box. Note that the versions of Blender available in package managers such as apt-get are often quite dated. Installing the latest version for Linux is easy, however; just download the .tar.gz file, untar it and add the directory to your PATH.
  • Imagemagick tools (specifically "convert" and "montage") are used for image conversion and tiling. This is available in most package managers and may even be pre-installed with your Unix-like operating system.
  • The GUI uses Tkinter with the python image library. On Linux this is typically packaged as python-imaging-tk. Mac OSX and Windows Python distributions tend to include Tkinter, but it may be necessary to also install a PIL implementation such as Pillow.

Getting started

For those who would prefer to avoid working through the Python API, a command-line wrapper scripts/ascii-phonons and a graphical user intergace scripts/ascii-phonons-gui are available. Call the script with

ascii-phonons -h

for information about the numerous command-line arguments, or take a look at the online documentation.

If working on Mac OS X, you may need to specify the path to your Blender binary, which is tucked away in a .app package, using the -b flag. However, the script assumes you have Blender installed in a folder called "Blender" in the root Applications folder, and should find your binary in this case.

A typical call to the wrapper script would be something like:

ascii-phonons /path/to/my/phonons.ascii -m 5 --static --vectors -o pretty

which should write a static image pretty.png, illustrating mode 5 with arrows. To generate an animation, try

ascii-phonons /path/to/my/phonons.ascii -m 1 --gif -o pretty

which will use Imagemagick to generate pretty.gif. The --montage flag implements the tiled output; try something like

ascii-phonons /path/to/my/phonons.ascii --static --vectors --montage -o pretty

to generate a static image. Note that, while smaller images are rendered, this can take some time if your system has a large number of phonon modes.

When you are comfortable that the code works for you, the GUI (ascii-phonons-gui) offers an easy way to experiment with different settings and features. The "File" menu of the GUI allows you to save your settings to a .conf file, and to combine your settings with other .conf files including colour schemes. To use the resulting file with the CLI, use the --config flag.

ascii-phonons /path/to/my/phonons.ascii --config my_amazing.conf

Note that information about input and output files is contained within the .conf file, but that scripts/ascii-phonons always requires a .ascii file to be provided at the command line.

Implementation details

The default atomic radii are the covalent radii from Cordero et al (2008). The eigenvectors may be scaled by the square root of the relative atomic mass; the atomic mass data is from Coursey et al. (2015). (This is usually unnecessary as Phonopy applies this scaling when generating the .ascii file.)

Acknowledgements

Work on this package began while ajjackon was a PhD student funded by EPSRC through the Center for Sustainable Chemical Technologies (grant no. EP/G03768X/1) at the University of Bath. Further work to fix bugs and improve the documentation and useability has taken place as a Research Assistant in the same research group, while funded by the ERC (project 277757).

License

GNU GPL v3

Disclaimer

Use at your own risk. This project is not affiliated with Blender, Phonopy or v_sim.

ascii-phonons's People

Contributors

ajjackson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

ascii-phonons's Issues

FEATURE: tiled output

Tiled arrays of images are a major application of the code and this functionality should be made easily accessible. In the short term this will use Imagemagick.

FEATURE: tiled output

In the published images the phonon modes are displayed in a tiled array with their corresponding frequencies. This was does with a bit of scripting and imagemagick montage, but could be automated for convenience.

ENH: Tab completion

As there are a lot of command-line options and some are a bit verbose, tab-completion would be very handy. There looks to be a decent wrapper for adding tab-completion to argparse: https://github.com/kislyuk/argcomplete . As this is not widely installed, the dependency should be made optional if possible.

ENH: Possible performance improvement using duplication

One of the projects which inspired this is Clemens Barth's Atomic Blender packages, which renders animated .XYZ files in Blender. Instead of assigning unique meshes to each atom, they are grouped by type and specified as duplicates of a hidden reference atom.

This approach was originally avoided because it makes further modelling more complicated; however, if there is a significant performance advantage to be gained then this is worth doing.

ENH: Non-linear rescaling

The movement of light atoms such as hydrogen is much greater than that of heavier elements in modes that involve both atoms. While this is a physical effect, it can make it difficult to see coupling between atoms when the modes are visualised. An option to reduce the mass-weighting of phonon modes by rescaling the eigenvectors of lighter elements before normalisation would improve the legibility when illustrating systems such as hybrid organic-inorganic frameworks.

FEATURE: Select mode by q-point

While this is not done by Phonopy, the v_sim format supports multiple q-points in a single ascii file. The mode index should be for a given q-point.

  • CLI / python interface: If only a single q-point is present, use it. If more than one, raise a warning and default to first one.
  • GUI: provide a drop-down menu listing available q-points.

Backgrounding of render process from GUI

At the moment the GUI becomes non-responsive while rendering occurs. As it is possible to request an infeasibly complicated model, it would be nice if it could be cancelled from the GUI.

Requested by @aronwalsh

ENH: Miller indices for primitive cells

When a primitive cell is provided (as is typical for phonon calculations) the lattice vectors are usually not aligned with the conventional cell vectors. The .ascii format discards this information by using a 6-value unit cell description, but it might be recovered using the standard primitive cell vectors of a spacegroup.

Pros

More intuitive "Miller indices" can be used, default alignment will look better for primitive cells

Cons

Added spglib dependency (or need to integrate/re-implement spglib)

FEATURE: Crystallographic camera angles

Crystallographers don't think about cameras and raytracing, they think about crystallographic axes. It should be possible to select a sensible camera angle with "a" "b" or "c".

BONUS feature:
Accept a Miller index and face the camera to show the corresponding plane. Possibly use an orthographic lens (i.e. no perspective)?

feature request: non-integer supercell indices / negative ones

  1. I think it would be beneficial allow to use non-integer supercell indices, e.g. for a large and/or messy cells where "1 1 1" cell is too small and "2 2 2" is too big.
    Also it seem like in case of "1 1 1" supercell any ions with coordinates containing full lattice translations (e.g. if I have ion in origin position, ions with coordinates "1 1 1", "1 0 0", etc.) are not shown , which makes the cell kinda asymmetric and little bit ugly.
  2. I think in many cases users (or at least me) would like to show the "1 1 1" supercell with ions close to outside cell in each direction, e.g. to fully reveal the structural groups.
    In VESTA we can use negative "supercell" indices to do it, e.g. show all from -0.3 -0.3 -0.3 to 1.3 1.3 1.3. Is it possible to add such a feature to ascii-phonons?
    I tried to tinker with the code by myself, but to no avail.

BUG: wireframe modifier required for Blender version < 2.70

The version of Blender packaged for Ubuntu 14.04 does not include the "WIREFRAME" modifier which is used by the new rendering engine. Requiring a more recent version of Blender is a "pain point". This can be worked around by either

a) using the older tracing engine with these versions of Blender, breaking consistency or
b) implementing a solid bounding-box generator in the code to avoid this dependency.

FEATURE: Orthographic projection

In many cases an orthographic projection is more useful than one with perspective.

  • Modify the camera creator to allow an orthographic view to be requested.
  • Add option to GUI, perhaps as a pre-ticked "perspective" checkbox

FEATURE: Save/Open options from GUI

There are two save/load options that would be useful from the GUI:

  • Loading a user-specific file with element settings (i.e. custom colours, radii...)
  • Saving the settings for the current render

The GUI is already a little cluttered in terms of buttons, so it might be beneficial to put these in an application File menu.

The file format would naturally be the same .conf files as found in addons/vsim2blender.
It isn't entirely clear how the two settings files should be related:

  • Does the "current render" conf remember the preferred element settings file?
  • Are the element settings dumped into the "current render" conf?

The difference between these in practice is what happens when the user saves a configuration and then modifies their personal elements conf.

ENH: Improved arrow scaling

Arrow scaling is very system-dependent. It would be helpful if an heuristic method could be used to set the initial scale factor, with the user control normalised to 1.0.

ENH: indicate axes

A little floating axis gizmo would help keep track of images with different projections.

error in python

I just use the example file, but it has a problem in python.

import sys
from os.path import pathsep

sys.path = ['D:\programFiles\ascii-phonons-master\addons'] + sys.path

import bpy
import vsim2blender
import vsim2blender.plotter

config = vsim2blender.read_config(user_config='C:\Users\JINHO-~1\AppData\Local\Temp\tmphryt1lxd')

Final line made the problem (SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape).

Disable mass-weighting

Eigenvectors from Phonopy for v_sim are already mass-weighted. At the moment, the mass-weighting is being exaggerated. This is unphysical and does not show the Gamma-point acoustic modes as rigid displacements, which they should be.

ENH: Eliminate Imagemagick dependency

In principle gif files and image arrays, provided by convert and montage respectively, can both be generated using the PIL tools which are already a project dependency.

FEATURE: Blender plug-in interface

While development has focussed on the command-line interface, this is largely implemented as Blender plug-ins, and an interactive control panel could be created for Blender.

At the moment this is not seen as a high priority as the majority of people computing phonons are not Blender users already, and the Blender GUI has a steep learning curve. If this is a feature you would like to see (or to work on!) please comment on this Issue.

ENH: Freestyle-based tracing

The Freestyle tools in Blender offer much more control over line tracing. However, they are not very compatible with the wireframe object currently used to display the bounding box.

For an attractive tracing setup:

  • enable Freestyle (SCENE.render.use_freestyle)
  • Setup two Freestyle line sets (one is created by default)
    • Atom outlines, using 'Silhouette' and 'Border' edge types and a thin (3pt) black line
    • Bounding box, using 'Edge Mark' edge type, round caps and a thicker (5pt) line
  • Bounding box line set should be above atom outlines
  • Make bounding box tracable
    • Instead of wireframe, use a regular solid material for bounding box
    • Create thin wireframe with wireframe modifier and apply to create new mesh
    • Select all edges of wireframe mesh and add Freestyle edge marks

The result of this is that the bounding box is stroked twice, with the thicker box line settings hiding the thin outline. Atoms are stroked once, with a configurable line thickness and colour.

TypeError: Converting py args to operator properties: enum "SUBSURF" not found in ()

Hello there.

I'm trying to run ascii-phonons 1.0 on the following scenario:
OS = centos 6.5 x86_64
CC = gcc 5.3.0
Python = 3.5.5
Numpy = 1.14.2
Requests = 2.18.4
Blender = 2.79b compiled with the following options: (output from cmake -L)

CMAKE_BUILD_TYPE:STRING=RelWithDebInfo
WITH_ALEMBIC:BOOL=OFF
WITH_ALEMBIC_HDF5:BOOL=OFF
WITH_BOOST:BOOL=OFF
WITH_BUILDINFO:BOOL=ON
WITH_BULLET:BOOL=ON
WITH_CODEC_AVI:BOOL=ON
WITH_CODEC_FFMPEG:BOOL=OFF
WITH_CODEC_SNDFILE:BOOL=OFF
WITH_COMPOSITOR:BOOL=ON
WITH_CYCLES:BOOL=OFF
WITH_CYCLES_CUDA_BINARIES:BOOL=OFF
WITH_CYCLES_OPENSUBDIV:BOOL=OFF
WITH_CYCLES_OSL:BOOL=OFF
WITH_CYCLES_STANDALONE:BOOL=OFF
WITH_CYCLES_STANDALONE_GUI:BOOL=OFF
WITH_DOC_MANPAGE:BOOL=OFF
WITH_FFTW3:BOOL=OFF
WITH_FREESTYLE:BOOL=ON
WITH_GAMEENGINE:BOOL=ON
WITH_GAMEENGINE_DECKLINK:BOOL=ON
WITH_GHOST_XDND:BOOL=ON
WITH_GTESTS:BOOL=OFF
WITH_IK_ITASC:BOOL=ON
WITH_IK_SOLVER:BOOL=ON
WITH_IMAGE_CINEON:BOOL=ON
WITH_IMAGE_DDS:BOOL=ON
WITH_IMAGE_FRAMESERVER:BOOL=ON
WITH_IMAGE_HDR:BOOL=ON
WITH_IMAGE_OPENEXR:BOOL=OFF
WITH_IMAGE_OPENJPEG:BOOL=ON
WITH_IMAGE_TIFF:BOOL=ON
WITH_INPUT_NDOF:BOOL=ON
WITH_INSTALL_PORTABLE:BOOL=ON
WITH_INTERNATIONAL:BOOL=ON
WITH_JACK:BOOL=OFF
WITH_JACK_DYNLOAD:BOOL=OFF
WITH_LIBMV:BOOL=ON
WITH_LLVM:BOOL=OFF
WITH_LZMA:BOOL=ON
WITH_LZO:BOOL=ON
WITH_MOD_FLUID:BOOL=ON
WITH_MOD_OCEANSIM:BOOL=OFF
WITH_MOD_REMESH:BOOL=ON
WITH_MOD_SMOKE:BOOL=ON
WITH_OPENAL:BOOL=ON
WITH_OPENCOLLADA:BOOL=OFF
WITH_OPENCOLORIO:BOOL=OFF
WITH_OPENGL_DRAW_TESTS:BOOL=OFF
WITH_OPENGL_RENDER_TESTS:BOOL=OFF
WITH_OPENIMAGEIO:BOOL=ON
WITH_OPENMP:BOOL=ON
WITH_OPENSUBDIV:BOOL=OFF
WITH_OPENVDB:BOOL=OFF
WITH_OPENVDB_BLOSC:BOOL=OFF
WITH_PLAYER:BOOL=OFF
WITH_PYTHON_INSTALL:BOOL=ON
WITH_PYTHON_INSTALL_NUMPY:BOOL=ON
WITH_PYTHON_INSTALL_REQUESTS:BOOL=ON
WITH_PYTHON_MODULE:BOOL=OFF
WITH_RAYOPTIMIZATION:BOOL=ON
WITH_SDL:BOOL=OFF
WITH_SDL_DYNLOAD:BOOL=OFF
WITH_STATIC_LIBS:BOOL=OFF
WITH_SYSTEM_EIGEN3:BOOL=OFF
WITH_SYSTEM_GLES:BOOL=OFF
WITH_SYSTEM_GLEW:BOOL=OFF
WITH_SYSTEM_LZO:BOOL=OFF
WITH_SYSTEM_OPENJPEG:BOOL=OFF
WITH_X11_ALPHA:BOOL=ON
WITH_X11_XF86VMODE:BOOL=ON
WITH_X11_XFIXES:BOOL=ON
WITH_X11_XINPUT:BOOL=ON

The blender executable is found by *which blender, but when trying to execute both ascii-phonons or ascii-phonons-gui it barfs the same error message:

[user@machine examples]$ ascii-phonons -o kesterite kesterite.ascii
Color management: using fallback mode for management
found bundled python: /path/to/blender/2.79/2.79/python
addon not found: 'cycles'
Traceback (most recent call last):
  File "/home/user/ascii-phonons-1.0.0/examples/tmpzvyuxsz5.py", line 14, in <module>
    vsim2blender.plotter.setup_render_freestyle(**{'output_file': 'kesterite', 'input_file': '/home/user/ascii-phonons-1.0.0/examples/kesterite.ascii'})
  File "/path/to/blender/2.79/2.79/python/lib/python3.5/site-packages/vsim2blender/plotter.py", line 508, in setup_render_freestyle
    bpy.ops.object.modifier_add(type='SUBSURF')
  File "/path/to/blender/2.79/2.79/scripts/modules/bpy/ops.py", line 189, in __call__
    ret = op_call(self.idname_py(), None, kw)
TypeError: Converting py args to operator properties:  enum "SUBSURF" not found in ()
Blender quit

I had to compile blender because the binary release segfaults even when using 2.19 libc shared libraries via LD_PRELOAD.

Any clue where the error might be?

Thanks for any help,
Fabricio

Issues with ascii-phonons

I want to simply visualize the ascii files printed by phonopy.

I am using ./ascii-phonons -b /Applications/Blender.app/Contents/MacOS/Blender ../../animations/animation_G.ascii .

The call breaks giving the error

Blender 3.4.1 (hash 55485cb379f7 built 2022-12-20 00:48:52)
Read prefs: "/Application Support/Blender/3.4/config/userpref.blend
Error: Python: Traceback (most recent call last):
  File "/phonons/ascii-phonons/scripts/tmpojzggnou.py", line 13, in <module>
    vsim2blender.plotter.open_mode(**{'input_file': 'phonons/animations/animation_G.ascii', 'blender_bin': '/Applications/Blender.app/Contents/MacOS/Blender'})
  File "/phonons/ascii-phonons/addons/vsim2blender/plotter.py", line 359, in open_mode
    draw_bounding_box(lattice_vectors, offset=bbox_offset)
  File "/phonons/ascii-phonons/addons/vsim2blender/plotter.py", line 37, in draw_bounding_box
    cart_offset = offset * Matrix(cell)
TypeError: Element-wise multiplication: not supported between 'Vector' and 'Matrix' types

Blender quit

I am trying to figure if there is a way out around this?

Thanks!

FEATURE: Eliminate YAML dependency

YAML is slow and is an annoying dependency to add on systems that don't otherwise use Python 3 for anything. A simpler text format using a default parser would be fine. Configparser looks like the way to go

There aren't many users at the moment, so we can probably afford to make the change now. If made later, a script should probably be provided to migrate existing YAML files to the new format.

FEATURE: GUI

If you're looking at this on GitHub you probably already know that command line interfaces are a superior way to interact with most non-interactive programs ;-) Nonetheless, a simple GUI would make this more accessible and would also make the features more discoverable.

This feature request refers to a standalone GUI which would still call Blender in batch mode.

ENH: Vectors with phase contribution

At the moment only the real part of the displacement vector is used when displaying arrows. This is useful in combination with animated atoms as it helps show how the phase difference leads to different positions on the same trajectory. However, for static images it would be useful to incorporate this information into the arrows.

  • This could be enabled automatically for single-frame images
  • The arrow-head tracks the position of displaced atoms corresponding to the current frame

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.