From 801bcf2942df04d7bed94b2e7fb148dd7b569ec6 Mon Sep 17 00:00:00 2001 From: Bryan Rumsey Date: Mon, 11 Jul 2022 11:23:39 -0400 Subject: [PATCH 1/2] Add check to properly raise error when attempting to plot and empty domain. --- spatialpy/core/domain.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spatialpy/core/domain.py b/spatialpy/core/domain.py index cdb033bf..f7529929 100644 --- a/spatialpy/core/domain.py +++ b/spatialpy/core/domain.py @@ -571,6 +571,9 @@ def plot_types(self, width=None, height=None, colormap=None, size=None, title=No :returns: Plotly figure of domain types if, use_matplotlib=False and return_plotly_figure=True :rtype: None or dict ''' + if len(self.vertices) == 0: + raise DomainError("The domain does not contain particles.") + from spatialpy.core.result import _plotly_iterate # pylint: disable=import-outside-toplevel if not use_matplotlib: From 25c11e9aa82f2bec60af9d6ec8b4e92ccfe081a6 Mon Sep 17 00:00:00 2001 From: Bryan Rumsey Date: Mon, 11 Jul 2022 12:39:34 -0400 Subject: [PATCH 2/2] Fixed total volume calculation in 2D and 3D domain creation. --- spatialpy/core/domain.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spatialpy/core/domain.py b/spatialpy/core/domain.py index f7529929..7efb50a5 100644 --- a/spatialpy/core/domain.py +++ b/spatialpy/core/domain.py @@ -909,7 +909,7 @@ def create_3D_domain(cls, xlim, ylim, zlim, nx, ny, nz, type_id=1, mass=1.0, x_list = numpy.linspace(xlim[0], xlim[1], nx) y_list = numpy.linspace(ylim[0], ylim[1], ny) z_list = numpy.linspace(zlim[0], zlim[1], nz) - totalvolume = (xlim[1] - xlim[0]) * (ylim[1] - ylim[0]) * (zlim[1] - zlim[0]) + totalvolume = abs(xlim[1] - xlim[0]) * abs(ylim[1] - ylim[0]) * abs(zlim[1] - zlim[0]) vol = totalvolume / numberparticles if vol < 0: raise DomainError("Paritcles cannot have 0 volume") @@ -967,7 +967,7 @@ def create_2D_domain(cls, xlim, ylim, nx, ny, type_id=1, mass=1.0, # Vertices x_list = numpy.linspace(xlim[0], xlim[1], nx) y_list = numpy.linspace(ylim[0], ylim[1], ny) - totalvolume = (xlim[1] - xlim[0]) * (ylim[1] - ylim[0]) + totalvolume = abs(xlim[1] - xlim[0]) * abs(ylim[1] - ylim[0]) vol = totalvolume / numberparticles if vol < 0: raise DomainError("Paritcles cannot have 0 volume")