ccu.fancyplots.data¶
Classes for the storage of FancyPlots relevant data.
The class ccu.fancyplots.data.FancyCache describes how data is
imported to and exported from FancyPlots.
The class ccu.fancyplots.data.FEDData defines how free energy
diagram is stored.
The class ccu.fancyplots.data.FormattingParameters defines how
plot formatting parameters are stored.
The class ccu.fancyplots.data.Annotation defines how plot
annotations are stored.
Examples
The internal data from FancyPlots can be accessed via the attribute
ccu.fancyplots._gui.root.FancyPlotsGUI.cache and dumped into
a human-readable form via the following idiom:
>>> import json
>>> from pathlib import Path
>>> from ccu.fancyplots.data import DEFAULT_PARAMETERS
>>> from ccu.fancyplots.data import FancyCache
>>> data = {
... "energy_data": [
... [0, 0.2, 0.33, -0.5],
... [0, -0.1, 0.25, 0],
... "mechanism": ["*", "*CHOO", "*CO", "CO"],
... "legend_labels: ["Cu(111)", "Cu-NP"],
>>> annotations = []
>>> formatting_parameters = DEFAULT_PARAMETERS
>>> cache = FancyCache(
... formatting_parameters,
... diagram_data=data,
... annotations=annotations,
...)
>>> with Path("fancy.cache").open(
... mode="w", encoding="utf-8"
... ) as file:
... _ = json.dump(cache, file, indent=2)
The same file (fancy.cache) can be loaded into a convenient format for
FancyPlots via the following idiom:
>>> import json
>>> from pathlib import Path
>>> from ccu.fancyplots.data import FancyCache
>>> with Path("fancy.cache").open(
... mode="r", encoding="utf-8"
... ) as file:
... cache = FancyCache(**json.load(file))
- class ccu.fancyplots.data.Annotation(color: str = 'k', fontsize: float = 11.2, text: str = '', x: float = 0.0, y: float = 0.0)[source]¶
Bases:
NamedTupleA free energy diagram annotation.
- Variables:
Create new instance of Annotation(color, fontsize, text, x, y)
- _asdict()¶
Return a new dict which maps field names to their values.
- _field_defaults = {'color': 'k', 'fontsize': 11.2, 'text': '', 'x': 0.0, 'y': 0.0}¶
- _fields = ('color', 'fontsize', 'text', 'x', 'y')¶
- classmethod _make(iterable)¶
Make a new Annotation object from a sequence or iterable
- _replace(**kwds)¶
Return a new Annotation object replacing specified fields with new values
- ccu.fancyplots.data.DEFAULT_PARAMETERS = {'boxsize': (6, 4.5), 'colors': ('black', 'blue', 'red', 'lime', 'fuchsia'), 'dpi': 1200, 'font': 'Sans Serif', 'fontsize': 14, 'legend_loc': 'best', 'linewidth': 2.25, 'markeredgewidth': 0.3, 'markersize': 7, 'savename': 'fed.svg', 'tick_dec': 2, 'tick_double': False, 'tick_loc': 'out', 'tick_min': 0, 'title': '', 'xlabel': 'Reaction Coordinate', 'xlim': None, 'xscale': None, 'ylabel': '$\\Delta$G / eV', 'ylim': None, 'yscale': 'linear'}¶
The default formatting parameters for
FancyPlots
- class ccu.fancyplots.data.FEDData[source]¶
Bases:
TypedDictEnergies and metadata for a free energy diagram.
- Variables:
Valid
ccu.fancyplots.data.FEDDatainstances should satisfy the following condition for seamless use withFancyPlots:The lengths of each element in
ccu.fancyplots.data.FEDData.energy_datashould be equal to the lengths ofccu.fancyplots.data.FEDData.mechanismandccu.fancyplots.data.FEDData.legend_labels. This translates to the condition that the number of energies defined for each step should equal the number of steps in the mechanism.
- class ccu.fancyplots.data.FancyCache(style_parameters: FormattingParameters, diagram_data: FEDData, annotations: list[Annotation])[source]¶
Bases:
objectThe data model for caching/loading data into FancyPlots.
- Variables:
style_parameters (ccu.fancyplots.data.FormattingParameters) – The formatting parameters to use to plot the free energy diagram.
diagram_data (ccu.fancyplots.data.FEDData) – The energy data and metadata for plotting the free energy diagram.
annotations (list[ccu.fancyplots.data.Annotation]) – The annotations associated with the free energy diagram.
- annotations: list[Annotation]¶
- save(savename: str | Path = 'cache..fancy') None[source]¶
Save the FancyCache.
- Parameters:
savename – The filename in which to save the cache. Defaults to
f”cache.{FANCY_EXTENSION}”.
- style_parameters: FormattingParameters¶