python-3.xdata-visualizationnetworkxchemistryxyz

Python Visualising a Graph of Atoms - How to use xyz2graph to visualise different atomic species as different colors?


This is the .xyz file that I want to visualise using xyz2graph:

18
Atoms. File created from networkx graph by get_decomposition_calc_SRO1.py_edited_by_hand
Ga 0.0 0.0 0.0
In 1.59 0.917986928012 2.583
In 0.0 0.0 5.166
Ga 1.59 0.917986928012 7.749
Ga 0.0 0.0 10.332
Ga 1.59 0.917986928012 12.915
Ga 1.59 2.75396078403 0.0
In 3.18 3.67194771205 2.583
Ga 1.59 2.75396078403 5.166
In 3.18 3.67194771205 7.749
Ga 1.59 2.75396078403 10.332
Ga 3.18 3.67194771205 12.915
Ga 3.18 5.50792156807 0.0
In 4.77 6.42590849608 2.583
In 3.18 5.50792156807 5.166
Ga 4.77 6.42590849608 7.749

This is a still image of the output: notice how all of the nodes (labelled In and Ga are the SAME color). InGaN snippet

The code being used to generate this image is copied directly from this website:

Exact code snippet shown here:

from xyz2graph import MolGraph, to_networkx_graph, to_plotly_figure
from plotly.offline import offline

# Create the MolGraph object
mg = MolGraph()

# Read the data from the .xyz file
mg.read_xyz('path/molecule.xyz')

# Create the Plotly figure object
fig = to_plotly_figure(mg)

# Plot the figure
offline.plot(fig)

How can I change the color of each atom in the chemical structure?


Solution

  • SOLUTION

    Open the package and edit the cpk_colors dictionary in helpers.py to include colors for the atomic species

    Why?

    The problem was that there was no default color associated with either Indium and Gallium atoms in helpers.py

    If we examine the source code there are two key files: xyz2graph.py and helpers.py

    xyz2graph.py contains the covalent radii of the two atoms in question, but helpers.py has no associated colors in thecpk_colors dict.