Skip to content

Commit

Permalink
Merge pull request #203 from StochSS/repo-restucture
Browse files Browse the repository at this point in the history
Repo restructure
  • Loading branch information
seanebum authored Nov 29, 2021
2 parents 0036155 + b1b0508 commit 3d4ef8f
Show file tree
Hide file tree
Showing 109 changed files with 978 additions and 364 deletions.
14 changes: 5 additions & 9 deletions spatialpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,9 @@
import sys
if (sys.version_info < (3,0)):
raise Exception("SpatialPy only works in Python 3.0 and higher")
from .__version__ import __version__, __title__, __description__, __url__
from .__version__ import __author__, __email__
from .__version__ import __license__, __copyright__

from spatialpy.Model import *
from spatialpy.Solver import *
from spatialpy.Geometry import *
from spatialpy.Domain import *
from spatialpy.DataFunction import DataFunction
from spatialpy.InitialCondition import *
from spatialpy.BoundaryCondition import BoundaryCondition
from spatialpy.VTKReader import *
from spatialpy.cleanup import *
from spatialpy.core import *
from spatialpy.solvers import *
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
'''

import numpy
from spatialpy.Model import ModelError

from spatialpy.core.spatialpyError import BoundaryConditionError


class BoundaryCondition():
Expand Down Expand Up @@ -102,9 +103,9 @@ def expression(self):
:rtype: str
"""
if( self.species is not None and self.property is not None):
raise ModelError("Can not set both species and property")
raise BoundaryConditionError("Can not set both species and property")
if self.value is None:
raise ModelError("Must set value")
raise BoundaryConditionError("Must set value")
cond=[]
if(self.xmin is not None): cond.append("(me->x[0] >= {0})".format(self.xmin))
if(self.xmax is not None): cond.append("(me->x[0] <= {0})".format(self.xmax))
Expand All @@ -113,14 +114,14 @@ def expression(self):
if(self.zmin is not None): cond.append("(me->x[2] >= {0})".format(self.zmin))
if(self.zmax is not None): cond.append("(me->x[2] <= {0})".format(self.zmax))
if(self.type_id is not None): cond.append("(me->type == {0})".format(int(self.type_id)))
if(len(cond)==0): raise ModelError('need at least one condition on the BoundaryCondition')
if(len(cond)==0): raise BoundaryConditionError('need at least one condition on the BoundaryCondition')
bcstr = "if(" + '&&'.join(cond) + "){"
if self.species is not None:
if self.deterministic:
s_ndx = self.model.species_map[self.model.listOfSpecies[self.species]]
bcstr += "me->C[{0}] = {1};".format(s_ndx,self.value)
else:
raise Exception("BoundaryConditions don't work for stochastic species yet")
raise BoundaryConditionError("BoundaryConditions don't work for stochastic species yet")
elif self.property is not None:
if(self.property == 'v'):
for i in range(3):
Expand All @@ -130,6 +131,6 @@ def expression(self):
elif(self.property == 'rho'):
bcstr+= "me->rho={0};".format(self.value)
else:
raise Exception("Unable handle boundary condition for property '{0}'".format(self.property))
raise BoundaryConditionError("Unable handle boundary condition for property '{0}'".format(self.property))
bcstr+= "}"
return bcstr
6 changes: 3 additions & 3 deletions spatialpy/DataFunction.py → spatialpy/core/DataFunction.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''

from spatialpy.core.spatialpyError import DataFunctionError

class DataFunction():
""" Abstract class used to constuct the data function. """
Expand All @@ -24,7 +24,7 @@ def __init__(self, name=None):
if name is not None:
self.name = name
if self.name is None:
raise Exception("DataFunction must have a 'name'")
raise DataFunctionError("DataFunction must have a 'name'")

def map(self, x):
"""
Expand All @@ -39,6 +39,6 @@ def map(self, x):
:returns: value of function at this spatial location.
:rtype: float
"""
raise Exception("DataFunction.map() must be implemented.")
raise DataFunctionError("DataFunction.map() must be implemented.")


11 changes: 3 additions & 8 deletions spatialpy/Domain.py → spatialpy/core/Domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
import numpy
from scipy.spatial import KDTree

from spatialpy.Result import _plotly_iterate

from spatialpy.core.spatialpyError import DomainError

class Domain():
""" Domain class for SpatialPy. A domain defines points and attributes of a regional space for simulation.
Expand Down Expand Up @@ -360,6 +359,7 @@ def plot_types(self, width=None, height=None, colormap=None, size=5, title=None,
:param use_matplotlib: Whether or not to plot the proprties results using matplotlib.
:type use_matplotlib: bool
'''
from spatialpy.core.Result import _plotly_iterate

if use_matplotlib:
width = 6.4 if width in (None, "auto") else width
Expand Down Expand Up @@ -557,7 +557,7 @@ def read_stochss_subdomain_file(self, filename):
(ndx,type_id) = line.rstrip().split(',')
self.type[int(ndx)] = int(type_id)
except ValueError as e:
raise ModelError(f"Could not read in subdomain file, error on line {ln}: {line}")
raise DomainError(f"Could not read in subdomain file, error on line {ln}: {line}")


@classmethod
Expand Down Expand Up @@ -751,8 +751,3 @@ def create_2D_domain(cls, xlim, ylim, nx, ny, type_id=1, mass=1.0, nu=1.0, rho=N

# return model ref
return obj



class DomainError(Exception):
pass
3 changes: 2 additions & 1 deletion spatialpy/Geometry.py → spatialpy/core/Geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''
from spatialpy.core.spatialpyError import GeometryError

class Geometry:
""" Geometry class provides a method for tagging parts of the spatial domain as separate parts"""
Expand All @@ -23,7 +24,7 @@ def __init__(self):
pass

def inside(self, x, on_boundary):
raise Exception("Subclasses of spatialpy.Geometry must implement the inside() method")
raise GeometryError("Subclasses of spatialpy.Geometry must implement the inside() method")


class GeometryAll(Geometry):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
'''

import numpy
from spatialpy.Model import ModelError

from spatialpy.core.spatialpyError import InitialConditionError


class InitialCondition():
Expand All @@ -27,7 +28,7 @@ class InitialCondition():
"""

def apply(self, model):
raise ModelError("spatialpy.InitialCondition subclasses must implement apply()")
raise InitialConditionError("spatialpy.InitialCondition subclasses must implement apply()")

#TODO: implement InitialConditionFromResult()

Expand Down Expand Up @@ -102,7 +103,7 @@ def apply(self, model):
if model.domain.type[i] in self.types:
allowed_voxels.append(i)
nvox = len(allowed_voxels)
if nvox==0: raise ModelError("ScatterInitialCondition has zero voxels to scatter in. Species={0} count={1} types={2}".format(self.species.name, self.count, self.types))
if nvox==0: raise InitialConditionError("ScatterInitialCondition has zero voxels to scatter in. Species={0} count={1} types={2}".format(self.species.name, self.count, self.types))
for mol in range(self.count):
v_ndx = numpy.random.randint(0, nvox)
vtx = allowed_voxels[v_ndx]
Expand Down
Loading

0 comments on commit 3d4ef8f

Please sign in to comment.