Skip to content
This repository has been archived by the owner on Apr 23, 2021. It is now read-only.

Commit

Permalink
Merge pull request #353 from simphony/remove-cuds-item
Browse files Browse the repository at this point in the history
Problem: CUDSItem enum is duplicate
  • Loading branch information
stefanoborini committed Nov 11, 2016
2 parents d82381e + 4c2ed5d commit bc4fb8a
Show file tree
Hide file tree
Showing 49 changed files with 324 additions and 346 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
exclude = doc/*

[build_meta]
repotag=6d1305a490d6b225cdb5233933a7b60cc84c2223
repotag=89797b0d85096c0119cab8ee6dfdf1ed66e6c930
18 changes: 7 additions & 11 deletions simphony/core/cuds_item.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
# code auto-generated by the cuba-generate.py script.
from enum import IntEnum, unique
import warnings

from . import CUBA as CUDSItem

@unique
class CUDSItem(IntEnum):

POINT = 0
PARTICLE = 1
BOND = 2
EDGE = 3
FACE = 4
CELL = 5
NODE = 6
warnings.warn("Deprecation warning: {}"
.format('CUDSItem is deprecated. Use CUBA instead.'))

# In order to maintain backward compatibility
__all__ = ['CUDSItem']
6 changes: 3 additions & 3 deletions simphony/cuds/abc_lattice.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from abc import abstractmethod

from ..core.cuds_item import CUDSItem
from ..core import CUBA
from .abc_dataset import ABCDataset
from .utils import deprecated

Expand Down Expand Up @@ -106,7 +106,7 @@ def iter(self, indices=None, item_type=None):
KeyError :
if any of the indices passed as parameters are not in the dataset.
"""
if item_type is not None and item_type != CUDSItem.NODE:
if item_type is not None and item_type != CUBA.NODE:
raise ValueError("item_type must be CUDSItem.NODE")

return self._iter_nodes(indices)
Expand Down Expand Up @@ -135,7 +135,7 @@ def __len__(self):
count : int
The number of items of item_type in the dataset.
"""
return self.count_of(CUDSItem.NODE)
return self.count_of(CUBA.NODE)

@deprecated
def get_node(self, index): # pragma: no cover
Expand Down
38 changes: 19 additions & 19 deletions simphony/cuds/abc_mesh.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import itertools
from abc import abstractmethod

from ..core.cuds_item import CUDSItem
from ..core import CUBA
from .abc_dataset import ABCDataset
from .utils import deprecated

Expand Down Expand Up @@ -180,13 +180,13 @@ def iter(self, uids=None, item_type=None):
KeyError :
if any of the ids passed as parameters are not in the dataset.
"""
if item_type == CUDSItem.POINT:
if item_type == CUBA.POINT:
return self._iter_points(uids)
elif item_type == CUDSItem.EDGE:
elif item_type == CUBA.EDGE:
return self._iter_edges(uids)
elif item_type == CUDSItem.FACE:
elif item_type == CUBA.FACE:
return self._iter_faces(uids)
elif item_type == CUDSItem.CELL:
elif item_type == CUBA.CELL:
return self._iter_cells(uids)
else:
if uids is None:
Expand Down Expand Up @@ -232,13 +232,13 @@ def has_type(self, item_type):
-------
True if the type is present, False otherwise.
"""
if item_type == CUDSItem.POINT:
if item_type == CUBA.POINT:
return self._has_points()
elif item_type == CUDSItem.EDGE:
elif item_type == CUBA.EDGE:
return self._has_edges()
elif item_type == CUDSItem.FACE:
elif item_type == CUBA.FACE:
return self._has_faces()
elif item_type == CUDSItem.CELL:
elif item_type == CUBA.CELL:
return self._has_cells()
else:
raise ValueError("Unknown item_type "
Expand All @@ -253,8 +253,8 @@ def __len__(self):
The number of items of item_type in the dataset.
"""
return sum(map(lambda x: self.count_of(x),
[CUDSItem.POINT, CUDSItem.EDGE,
CUDSItem.FACE, CUDSItem.CELL]))
[CUBA.POINT, CUBA.EDGE,
CUBA.FACE, CUBA.CELL]))

# Deprecated methods.

Expand Down Expand Up @@ -568,7 +568,7 @@ def iter_points(self, uids=None): # pragma: no cover
------
point : Point
"""
return self.iter(uids, CUDSItem.POINT)
return self.iter(uids, CUBA.POINT)

@deprecated
def iter_edges(self, uids=None): # pragma: no cover
Expand All @@ -590,7 +590,7 @@ def iter_edges(self, uids=None): # pragma: no cover
edge : Edge
"""
return self.iter(uids, CUDSItem.EDGE)
return self.iter(uids, CUBA.EDGE)

@deprecated
def iter_faces(self, uids=None): # pragma: no cover
Expand All @@ -612,7 +612,7 @@ def iter_faces(self, uids=None): # pragma: no cover
face : Face
"""
return self.iter(uids, item_type=CUDSItem.FACE)
return self.iter(uids, item_type=CUBA.FACE)

@deprecated
def iter_cells(self, uids=None): # pragma: no cover
Expand All @@ -634,7 +634,7 @@ def iter_cells(self, uids=None): # pragma: no cover
cell : Cell
"""
return self.iter(uids, item_type=CUDSItem.CELL)
return self.iter(uids, item_type=CUBA.CELL)

@deprecated
def has_points(self): # pragma: no cover
Expand All @@ -646,7 +646,7 @@ def has_points(self): # pragma: no cover
True of there are points inside the mesh,
False otherwise
"""
return self.has_type(CUDSItem.POINT)
return self.has_type(CUBA.POINT)

@deprecated
def has_edges(self): # pragma: no cover
Expand All @@ -658,7 +658,7 @@ def has_edges(self): # pragma: no cover
True of there are edges inside the mesh,
False otherwise
"""
return self.has_type(CUDSItem.EDGE)
return self.has_type(CUBA.EDGE)

@deprecated
def has_faces(self): # pragma: no cover
Expand All @@ -670,7 +670,7 @@ def has_faces(self): # pragma: no cover
True of there are faces inside the mesh,
False otherwise
"""
return self.has_type(CUDSItem.FACE)
return self.has_type(CUBA.FACE)

@deprecated
def has_cells(self): # pragma: no cover
Expand All @@ -682,7 +682,7 @@ def has_cells(self): # pragma: no cover
True of there are cells inside the mesh,
False otherwise
"""
return self.has_type(CUDSItem.CELL)
return self.has_type(CUBA.CELL)

# Private. Need to be reimplemented by subclasses
#
Expand Down
12 changes: 6 additions & 6 deletions simphony/cuds/abc_particles.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from abc import abstractmethod
import itertools

from ..core.cuds_item import CUDSItem
from ..core import CUBA
from .particles_items import Particle, Bond
from .abc_dataset import ABCDataset
from .utils import deprecated
Expand Down Expand Up @@ -219,9 +219,9 @@ def iter(self, uids=None, item_type=None):
part_container.update([particle])
"""

if item_type == CUDSItem.PARTICLE:
if item_type == CUBA.PARTICLE:
return self._iter_particles(uids)
elif item_type == CUDSItem.BOND:
elif item_type == CUBA.BOND:
return self._iter_bonds(uids)
else:
if uids is None:
Expand Down Expand Up @@ -270,7 +270,7 @@ def __len__(self):
The number of items in the dataset.
"""
return sum(map(lambda x: self.count_of(x),
[CUDSItem.PARTICLE, CUDSItem.BOND]))
[CUBA.PARTICLE, CUBA.BOND]))

# Deprecated API. Will go away. Uses the generic API instead of direct
# call to the internal methods to guarantee the behavior is unchanged
Expand Down Expand Up @@ -578,7 +578,7 @@ def iter_particles(self, uids=None): # pragma: no cover
>>> for particle in particles.iter_particles():
... #do stuff
"""
return self.iter(uids, item_type=CUDSItem.PARTICLE)
return self.iter(uids, item_type=CUBA.PARTICLE)

@deprecated
def iter_bonds(self, uids=None): # pragma: no cover
Expand Down Expand Up @@ -623,7 +623,7 @@ def iter_bonds(self, uids=None): # pragma: no cover
>>> for bond in particles.iter_bond():
... #do stuff; it will iterate over all the bond
"""
return self.iter(uids, item_type=CUDSItem.BOND)
return self.iter(uids, item_type=CUBA.BOND)

@deprecated
def has_particle(self, uid): # pragma: no cover
Expand Down
8 changes: 4 additions & 4 deletions simphony/cuds/lattice.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np

from ..core.cuds_item import CUDSItem
from ..core import CUBA
from ..core.data_container import DataContainer
from .abc_lattice import ABCLattice
from .lattice_items import LatticeNode
Expand Down Expand Up @@ -35,16 +35,16 @@ def __init__(self, name, primitive_cell, size, origin):
self._data = DataContainer()

self._items_count = {
CUDSItem.NODE: lambda: self._size
CUBA.NODE: lambda: self._size
}

def count_of(self, item_type):
""" Return the count of item_type in the container.
Parameters
----------
item_type : CUDSItem
The CUDSItem enum of the type of the items to return
item_type : CUBA
The CUBA enum of the type of the items to return
the count of.
Returns
Expand Down
14 changes: 7 additions & 7 deletions simphony/cuds/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import uuid

from ..core import data_container as dc
from ..core.cuds_item import CUDSItem
from ..core import CUBA
from .abc_mesh import ABCMesh
from .mesh_items import Edge, Face, Cell, Point

Expand Down Expand Up @@ -60,10 +60,10 @@ def __init__(self, name):
self._data = dc.DataContainer()

self._items_count = {
CUDSItem.POINT: lambda: self._points,
CUDSItem.EDGE: lambda: self._edges,
CUDSItem.FACE: lambda: self._faces,
CUDSItem.CELL: lambda: self._cells
CUBA.POINT: lambda: self._points,
CUBA.EDGE: lambda: self._edges,
CUBA.FACE: lambda: self._faces,
CUBA.CELL: lambda: self._cells
}

@property
Expand All @@ -79,8 +79,8 @@ def count_of(self, item_type):
Parameters
----------
item_type : CUDSItem
The CUDSItem enum of the type of the items to return the count of.
item_type : CUBA
The CUBA enum of the type of the items to return the count of.
Returns
-------
Expand Down
19 changes: 6 additions & 13 deletions simphony/cuds/meta/base_centered_monoclinic_lattice.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,29 @@ class BaseCenteredMonoclinicLattice(BravaisLattice):

def __init__(self,
primitive_cell,
origin,
description="",
name="",
lattice_parameter=None):
lattice_parameter=None,
size=None):

self._data = DataContainer()

self.origin = origin
self.primitive_cell = primitive_cell
if size is None:
self.size = [1, 1, 1]
if lattice_parameter is None:
self.lattice_parameter = [1.0, 1.0, 1.0]
self.name = name
self.description = description
# This is a system-managed, read-only attribute
self._definition = 'A base centered monoclinic lattice' # noqa
# This is a system-managed, read-only attribute
self._origin = None
# This is a system-managed, read-only attribute
self._size = [1, 1, 1]

@property
def definition(self):
return self._definition

@property
def origin(self):
return self._origin

@property
def data(self):
return DataContainer(self._data)
Expand All @@ -52,10 +49,6 @@ def uid(self):
self._uid = uuid.uuid4()
return self._uid

@property
def size(self):
return self._size

@classmethod
def supported_parameters(cls):
return (CUBA.DESCRIPTION, CUBA.LATTICE_PARAMETER, CUBA.NAME,
Expand Down
19 changes: 6 additions & 13 deletions simphony/cuds/meta/base_centered_orthorhombic_lattice.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,29 @@ class BaseCenteredOrthorhombicLattice(BravaisLattice):

def __init__(self,
primitive_cell,
origin,
description="",
name="",
lattice_parameter=None):
lattice_parameter=None,
size=None):

self._data = DataContainer()

self.origin = origin
self.primitive_cell = primitive_cell
if size is None:
self.size = [1, 1, 1]
if lattice_parameter is None:
self.lattice_parameter = [1.0, 1.0, 1.0]
self.name = name
self.description = description
# This is a system-managed, read-only attribute
self._definition = 'A base centered orthorhombic lattice' # noqa
# This is a system-managed, read-only attribute
self._origin = None
# This is a system-managed, read-only attribute
self._size = [1, 1, 1]

@property
def definition(self):
return self._definition

@property
def origin(self):
return self._origin

@property
def data(self):
return DataContainer(self._data)
Expand All @@ -52,10 +49,6 @@ def uid(self):
self._uid = uuid.uuid4()
return self._uid

@property
def size(self):
return self._size

@classmethod
def supported_parameters(cls):
return (CUBA.DESCRIPTION, CUBA.LATTICE_PARAMETER, CUBA.NAME,
Expand Down

0 comments on commit bc4fb8a

Please sign in to comment.