From 7ac0d8edcc32911a7d5a35d3392f5cd6fb3a6b21 Mon Sep 17 00:00:00 2001 From: shervinea Date: Wed, 8 Sep 2021 22:59:49 -0700 Subject: [PATCH 1/6] Fix the issue 'Axes3D currently only supports the aspect argument 'auto'' --- enzynet/visualization.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/enzynet/visualization.py b/enzynet/visualization.py index 052342c..4ab2f14 100644 --- a/enzynet/visualization.py +++ b/enzynet/visualization.py @@ -52,7 +52,11 @@ def plot_volume(vol: np.ndarray, pdb_id: Text, v_size: int, num: int, plt.rc('font', family='serif') fig = plt.figure(figsize=(4,4)) ax = fig.gca(projection='3d') - ax.set_aspect('equal') + + # Reproduces the functionality of ax.set_aspect('equal'). + # Source: https://github.com/matplotlib/matplotlib/issues/17172#issuecomment-830139107 + ax.set_box_aspect( + [ub - lb for lb, ub in (getattr(ax, f'get_{a}lim')() for a in 'xyz')]) # Parameters. len_vol = vol.shape[0] From 5e72ee0ba2ac46ad133a59a6b89e0b91c95e8b56 Mon Sep 17 00:00:00 2001 From: shervinea Date: Wed, 8 Sep 2021 23:04:34 -0700 Subject: [PATCH 2/6] Fix the issue 'AttributeError: 'list' object has no attribute 'ndim'' --- enzynet/visualization.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/enzynet/visualization.py b/enzynet/visualization.py index 4ab2f14..3a867a9 100644 --- a/enzynet/visualization.py +++ b/enzynet/visualization.py @@ -119,7 +119,7 @@ def plot_volume(vol: np.ndarray, pdb_id: Text, v_size: int, num: int, def cuboid_data( pos: Tuple[float, float, float], size: Tuple[int, int, int]=(1,1,1) -) -> Tuple[List[List[float]], List[List[float]], List[List[float]]]: +) -> Tuple[np.ndarray, np.ndarray, np.ndarray]: """Gets coordinates of cuboid.""" # Gets the (left, outside, bottom) point. o = [a - b / 2 for a, b in zip(pos, size)] @@ -136,7 +136,7 @@ def cuboid_data( [o[2], o[2], o[2] + h, o[2] + h, o[2]], [o[2], o[2], o[2] + h, o[2] + h, o[2]]] - return x, y, z + return np.array(x), np.array(y), np.array(z) def plot_cube_at(pos: Tuple[float, float, float] = (0,0,0), From 4cac1ce15e71555e72212205fbbdd1971097d0ec Mon Sep 17 00:00:00 2001 From: shervinea Date: Wed, 8 Sep 2021 23:06:30 -0700 Subject: [PATCH 3/6] Fix issue 'TypeError: 'float' object is not subscriptable' --- enzynet/visualization.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/enzynet/visualization.py b/enzynet/visualization.py index 3a867a9..a50c481 100644 --- a/enzynet/visualization.py +++ b/enzynet/visualization.py @@ -98,9 +98,9 @@ def plot_volume(vol: np.ndarray, pdb_id: Text, v_size: int, num: int, ax.zaxis._axinfo["grid"]['linewidth'] = 0.1 # Change thickness of ticks. - ax.xaxis._axinfo["tick"]['linewidth'] = 0.1 - ax.yaxis._axinfo["tick"]['linewidth'] = 0.1 - ax.zaxis._axinfo["tick"]['linewidth'] = 0.1 + ax.xaxis._axinfo["tick"]['linewidth'][True] = 0.1 + ax.yaxis._axinfo["tick"]['linewidth'][True] = 0.1 + ax.zaxis._axinfo["tick"]['linewidth'][True] = 0.1 # Change tick placement. ax.xaxis._axinfo['tick']['inward_factor'] = 0 From b7675322990f50399c4595077546bc9ab20ea1cb Mon Sep 17 00:00:00 2001 From: shervinea Date: Wed, 8 Sep 2021 23:07:31 -0700 Subject: [PATCH 4/6] Remove superfluous import --- enzynet/visualization.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/enzynet/visualization.py b/enzynet/visualization.py index a50c481..677ab0e 100644 --- a/enzynet/visualization.py +++ b/enzynet/visualization.py @@ -5,7 +5,7 @@ # MIT License -from typing import List, Optional, Text, Tuple +from typing import Optional, Text, Tuple import numpy as np import matplotlib.pyplot as plt From da0fd61cd5398c838a68c759a5aec7c096c640dc Mon Sep 17 00:00:00 2001 From: shervinea Date: Wed, 8 Sep 2021 23:10:23 -0700 Subject: [PATCH 5/6] Mimic previous light source by adjusting parameters accordingly --- enzynet/visualization.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/enzynet/visualization.py b/enzynet/visualization.py index 677ab0e..9a28669 100644 --- a/enzynet/visualization.py +++ b/enzynet/visualization.py @@ -8,6 +8,7 @@ from typing import Optional, Text, Tuple import numpy as np +import matplotlib.colors as mcolors import matplotlib.pyplot as plt from enzynet import pdb @@ -142,9 +143,11 @@ def cuboid_data( def plot_cube_at(pos: Tuple[float, float, float] = (0,0,0), ax: Optional[plt.gca] = None) -> None: """Plots a cube element at position pos.""" + lightsource = mcolors.LightSource(azdeg=135, altdeg=0) if ax != None: X, Y, Z = cuboid_data(pos) - ax.plot_surface(X, Y, Z, color='g', rstride=1, cstride=1, alpha=1) + ax.plot_surface(X, Y, Z, color='g', rstride=1, cstride=1, alpha=1, + lightsource=lightsource) def plot_cube_weights_at(pos: Tuple[float, float, float] = (0, 0, 0), From 17f142af730a9f48552e28f394e4586af0ae64d9 Mon Sep 17 00:00:00 2001 From: shervinea Date: Wed, 8 Sep 2021 23:13:25 -0700 Subject: [PATCH 6/6] Indicate working matplotlib version with the current state of the visualization code --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 62e9d69..5dc43c5 100755 --- a/requirements.txt +++ b/requirements.txt @@ -6,7 +6,7 @@ keras tensorflow # Plot -matplotlib +matplotlib==3.4.1 # Biology biopython