Skip to content

Commit

Permalink
Merge pull request #62 from molssi-seamm/dev
Browse files Browse the repository at this point in the history
Bugfix: charts with multiple exes, plus units for force constants
  • Loading branch information
seamm authored Aug 22, 2024
2 parents 77d391b + 1df4bf2 commit 66aaa3f
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 29 deletions.
4 changes: 4 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
=======
History
=======
2024.8.22 -- Bugfix: charts with multiple exes, plus units for force constants
* Add units for force constants (kJ/mol/Å^2,...)
* Fixed an issue naming axes in plots with multiple axes

2024.8.1 -- Added default units for viscosity and fixed a bug in handling dimensions
* Added more default units: dynamic viscosity (cP, etc) and kinematic viscosity
(cSt, etc)
Expand Down
28 changes: 17 additions & 11 deletions seamm_util/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,22 +301,29 @@ def dumps(self):
plot.bottom = bottom

# Number the axes sequentially and set their limits
axis_number = 1
axis_number = {"x": 0, "y": 0, "z": 0}
for plot in plots:
for axis in plot.axes:
xyz = axis.direction
axis_number[xyz] += 1
anum = axis_number[xyz]
axis.update(
{
"number": axis_number,
"name": xyz + "axis" + str(axis_number),
"short_name": xyz + str(axis_number),
"number": axis_number[xyz],
"name": xyz + "axis" + ("" if anum == 1 else str(anum)),
"short_name": xyz + ("" if anum == 1 else str(anum)),
}
)
if xyz == "x":
axis.update({"start": plot.left, "stop": plot.right})
length = plot.right - plot.left
left = plot.left + length * axis.start
right = plot.left + length * axis.stop
axis.update({"start": left, "stop": right})
elif xyz == "y":
axis.update({"start": plot.bottom, "stop": plot.top})
axis_number += 1
length = plot.top - plot.bottom
bottom = plot.bottom + length * axis.start
top = plot.bottom + length * axis.stop
axis.update({"start": bottom, "stop": top})

# Sort out any anchors between axes and get the data
axes = []
Expand All @@ -326,7 +333,6 @@ def dumps(self):
axis.update(anchor="free")
else:
axis.update(anchor=axis.anchor["short_name"])

axes.append(axis.to_dict())

# And, finally, set up the traces
Expand Down Expand Up @@ -441,7 +447,7 @@ class Axis(Dictionary):
for the axis.
"""

def __init__(self, direction, *args, anchor=None, **kwargs):
def __init__(self, direction, *args, anchor=None, start=0.0, stop=1.0, **kwargs):
"""Initialize an axis, optionally with data.
Parameters
Expand All @@ -459,10 +465,10 @@ def __init__(self, direction, *args, anchor=None, **kwargs):

self.anchor = anchor
self.direction = direction
self.start = start
self.stop = stop
self["label"] = ""
self["number"] = None
self["start"] = 0.0
self["stop"] = 1.0

self.update(*args, **kwargs)

Expand Down
9 changes: 9 additions & 0 deletions seamm_util/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@
"E_h/a_0",
"Ry/a_0",
],
"[mass] / [substance] / [time] ** 2": [
"kcal/mol/Å^2",
"kJ/mol/Å^2",
"eV/Å^2",
"E_h/Å^2",
"Ry/Å^2",
"E_h/a_0^2",
"Ry/a_0^2",
],
"[length] * [mass] / [time] ** 2": [
"kcal/mol/Å",
"kJ/mol/Å",
Expand Down
12 changes: 6 additions & 6 deletions tests/results/simple_plot.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
"type": "scatter",
"x0": 0,
"dx": 1.0,
"xaxis": "x1",
"xaxis": "x",
"y": [110.0, 111.0, 110.0, 109.0, 110.0],
"yaxis": "y2"
"yaxis": "y"
}
],
{
Expand All @@ -46,8 +46,8 @@
"text": "Simple plot",
"xanchor": "center"
},
"xaxis1": {
"anchor": "y2",
"xaxis": {
"anchor": "y",
"domain": [
0.0,
1.0
Expand All @@ -56,8 +56,8 @@
"text": "Time (ps)"
}
},
"yaxis2": {
"anchor": "x1",
"yaxis": {
"anchor": "x",
"domain": [
0.0,
1.0
Expand Down
24 changes: 12 additions & 12 deletions tests/results/two_plots.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
"type": "scatter",
"x0": 0,
"dx": 1.0,
"xaxis": "x1",
"xaxis": "x",
"y": [110.0, 111.0, 110.0, 109.0, 110.0],
"yaxis": "y2"
"yaxis": "y"
},
{
"hoverlabel": {
Expand All @@ -50,9 +50,9 @@
"type": "scatter",
"x0": 0,
"dx": 1.0,
"xaxis": "x3",
"xaxis": "x2",
"y": [10.0, 11.0, 10.0, 9.0, 10.0],
"yaxis": "y4"
"yaxis": "y2"
}
],
{
Expand All @@ -66,8 +66,8 @@
"text": "Two plots",
"xanchor": "center"
},
"xaxis1": {
"anchor": "y2",
"xaxis": {
"anchor": "y",
"domain": [
0.0,
0.6466666666666666
Expand All @@ -76,8 +76,8 @@
"text": "Time (ps)"
}
},
"yaxis2": {
"anchor": "x1",
"yaxis": {
"anchor": "x",
"domain": [
0.0,
1.0
Expand All @@ -86,8 +86,8 @@
"text": "Energy (kcal/mol)"
}
},
"xaxis3": {
"anchor": "y4",
"xaxis2": {
"anchor": "y2",
"domain": [
0.6666666666666666,
1.0
Expand All @@ -96,8 +96,8 @@
"text": "Time (ps)"
}
},
"yaxis4": {
"anchor": "x3",
"yaxis2": {
"anchor": "x2",
"domain": [
0.0,
0.48
Expand Down

0 comments on commit 66aaa3f

Please sign in to comment.