diff --git a/src/AJ_analysis.py b/src/AJ_analysis.py index 093d39dee5a973b477c559fe8a8c2ef747322b76..29d4152a978b2c9bf639e8ccd2c4e1e12e37704c 100644 --- a/src/AJ_analysis.py +++ b/src/AJ_analysis.py @@ -290,7 +290,7 @@ def plot_3d_structure(filename): from PyQt5.QtWidgets import QMessageBox QMessageBox.critical(None, "Error", "Invalid structure: negative or zero box size computed. Please check your XYZ file.") return - + colors = [COLOR_MAP.get(label, 'gray') for label in labels] ax.scatter(positions[:, 0], positions[:, 1], positions[:, 2], @@ -300,6 +300,18 @@ def plot_3d_structure(filename): half = box_size / 2.0 cube_min = center - half cube_max = center + half + + # Set the axis limits to enforce a perfect cube + ax.set_xlim(cube_min[0], cube_max[0]) + ax.set_ylim(cube_min[1], cube_max[1]) + ax.set_zlim(cube_min[2], cube_max[2]) + + # Optionally, if using Matplotlib 3.3 or later, enforce equal aspect ratio: + try: + ax.set_box_aspect([1,1,1]) + except Exception: + pass + vertices = np.array([[cube_min[0], cube_min[1], cube_min[2]], [cube_min[0], cube_min[1], cube_max[2]], [cube_min[0], cube_max[1], cube_min[2]],