diff --git a/spatialpy/core/domain.py b/spatialpy/core/domain.py index cdb033bf..7efb50a5 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: @@ -906,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") @@ -964,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")