cms_plots package

Submodules

cms_plots.dictionary module

Provides a Dictionary, identical to a dict, but which can be subclassed safely.

class cms_plots.dictionary.Dictionary(*args, ordered=False, **kwargs)[source]

Bases: MutableMapping

Class that acts like a dictionary, but can safely be subclassed.

The Dictionary class implements a dictionary-like class that other classes can inherit from. In addition, __init__ accepts a keyword ‘ordered’ specifying the use of an ordered dictionary.

copy()[source]

Return a shallow copy.

classmethod fromkeys(iterable, value=None)[source]

Create a new Dictionary with keys from iterable and values set to value.

cms_plots.electronic module

Methods for creating plots for electronic structure calculations

cms_plots.electronic.band_structure(Band_Structure, DOS=None, layout='3-panels', template='band_structure.html_template')[source]

Prepare the graph for the bandstructure

Parameters:
  • Band_Structure (pandas.DataFrame) – The band structure data in a standard Pandas dataframe.

  • DOS (pandas.DataFrame) – The DOS data in a standard Pandas dataframe.

  • layout (str) – For spin polarized calculations, use 3 (3-panels) or 2 panels.

  • template (str) – The template for the figure. Defaults to “line.html_template”

Returns:

A figure with the band structure plot.

Return type:

plotting.Figure

cms_plots.electronic.band_structure_plot(plot, Band_Structure)[source]

Prepare the graph for the band structure.

Parameters:
  • plot (plotting.Plot) – Plot object for the graphs

  • Band_Structure (pandas.DataFrame) – Standard dataframe containing the band structure

cms_plots.electronic.create_figure(jinja_env=None, title='', template='line.graph_template', module_path=None)[source]

Create a new figure.

Parameters:
  • title (str, optional)

  • template (str, optional) – The Jinja template for the desired graph. Defaults to ‘line.graph_template’

Return type:

plotting.Figure

cms_plots.electronic.dos(DOS, template='line.html_template')[source]

Prepare the graph for the density of states.

Parameters:
  • DOS (pandas.DataFrame) – The DOS data in a standard Pandas dataframe.

  • template (str) – The template for the figure. Defaults to “line.html_template”

Returns:

A figure with the DOS plot.

Return type:

plotting.Figure

cms_plots.electronic.dos_plot(plot, DOS, colors=('purple', 'green', 'cyan', 'gold', 'deeppink', 'turquoise', 'magenta'), dashes={'d': 'dashdot', 'f': 'longdashdot', 'p': 'dash', 's': 'dot'}, y_axis=None, orientation='horizontal', flipped='', spin=None)[source]

Prepare the plot of the density of states (DOS).

Parameters:
  • plot (plotting.Plot) – The Plot object for the graph.

  • DOS (pandas.DataFrame) – The DOS data in a standard form as a Pandas DataFrame.

  • colors ((str,)) – The colors to use for atom-projected DOS.

  • dashes ((str,)) – The dashes used to denote the shells in projected DOS

  • y_axis (plotting.Axis = None) – The y axis for shared plots, in e.g. the combo band structure - DOS plot.

  • orientation (str = "horizontal") – The orientation of the energy axis, horizontal or vertical.

  • flipped (str) – If this string contains “x” the energy in a veritcal graph increases to left.

  • spin (str = None) – If not None, only DOS with labels including this string are plotted. Intended to be e.g. “↑” or “↓” to pick out the spin-up or -down bands.

cms_plots.plotting module

A package for handling plotly plots.

A figure comprises one or more plots (or graphs) laid out in a grid. The datasets within a plot are represetned by traces, lines, scatter plots, pie chart elements, etc.

This package consists of a Figure class which is a container, a Plot class that handles the actual plotting, and a Trace class for the individual datasets and their graphical representations. The figure class uses a grid similar to the Tk grid to control the layout of the plots.

This package does not directly interact with plotly. Rather, it uses templates and Jinja to create the JSON, HTML or other representation of a plotly figure. The various containers in this package contain dictionaries of Jinja keys and the associated values. The keys needed are defined by the template used.

class cms_plots.plotting.Axis(direction, *args, anchor=None, **kwargs)[source]

Bases: Dictionary

Class to represent an axis in a plotly plot.

The Axis class defines an axis and the associated graphical control for how to display them. The class is a dict-like object where the elements of the dictionary are the control parameters for the axis.

to_dict()[source]

Return a dictionary representing the axis.

Returns:

A dictionary of the axis data, suitable for Jinja.

Return type:

dict

class cms_plots.plotting.Figure(*args, jinja_env=None, template=None, **kwargs)[source]

Bases: Dictionary

Holds one or more subplots and controls the layout.

add_plot(name, **kwargs)[source]

Create a new plot and return it.

Parameters:

name (str) – The name of the plot, which must be unique.

Return type:

The plot object.

dump(filename)[source]

Write the filled in template to disk as <filename>.

Parameters:

filename (str or filepath) – The name or path to the file to write.

Return type:

nothing

dumps()[source]

Return the filled in template document as a string.

Merge the layout data and the traces into the template document and return a string version of the document.

Returns:

The resulting document.

Return type:

str

get_plot(name)[source]

Return the named plot.

Parameters:

name (str) – The name of the plot, which must exist.

Return type:

The plot object.

grid_plots(*args, padx=0.02, pady=0.02)[source]

Define the layout of the plots.

When there is more than one plot, they need to be laid out in a grid. This method is called to define the layout, and will follow closely the approach used in Tk grid.

Parameters:
  • *args –

    Positional arguments specifying the layout of one or more rows. each row is given as a string composed of the following:

    <plot> :

    is the name of a plot.

    x :

    leaves an empty column between the plot on the left and the plot on the right.

    ^ :

    extends the row span of the plot above the ^’s in the grid. The number of ^’s in a row must match the number of columns spanned by the plot above it.

    • :

      increases the column span of the plot to the left. Several -‘s in a row will successively increase the number of columns spanned. A - may not follow a ^ or a x, nor may it be the first plot argument to grid configure.

  • **kwargs –

    Keyword arguments for options for the given rows:
    padxfloat, optional

    The fraction of space to leave between plots in a row. Defaults to 0.02.

    padyfloat, optional

    The fraction of space to leave between rows. Defaults to 0.02.

property template

The template to use for this figure.

class cms_plots.plotting.Plot(left=0, right=1, top=1, bottom=0, row=0, column=0, column_span=1, row_span=1)[source]

Bases: Dictionary

Class to represent a plotly plot.

The Plot class contains Axes and Traces, which represent the datasets being plotted. This class is a dict-like object where the elements of the dictionary are the traces.

add_axis(direction, anchor=None, **kwargs)[source]

Create a new axis and return it.

Parameters:

direction (str (one of 'x', 'y', or 'z')) – The direction of this axis.

Return type:

The axis object.

add_trace(name, x_axis=None, y_axis=None, z_axis=None, **kwargs)[source]

Create a new trace and return it.

Parameters:

name (str) – The name of the trace, which must be unique.

Return type:

The trace object.

property axes

The list of axes for this plot.

class cms_plots.plotting.Trace(x_axis=None, y_axis=None, z_axis=None, **kwargs)[source]

Bases: Dictionary

Class to represent a trace in a plotly plot.

The Trace class contains the datasets and associated graphical control for how to display them. The class is a dict-like object where the elements of the dictionary are the traces.

to_dict()[source]

Return a dictionary representing the trace.

Returns:

A dictionary of the trace data, suitable for Jinja.

Return type:

dict

Module contents

cms_plots Plots for computational materials/molecular science