sisl.shape.Shape

class sisl.shape.Shape(center=(0, 0, 0))

Bases: _Dispatchs

Baseclass for all shapes. Logical operations are implemented on this class.

This class must be sub classed.

Also all the required methods are predefined although they issue an error if they are not implemented in the sub-classed class.

There are a few routines that are necessary when implementing an inherited class:

center

return the geometric center of the shape.

within

Returns a boolean array which defines whether a coordinate is within or outside the shape.

within_index

Equivalent to within, however only the indices of those within are returned.

copy

Create a new identical shape.

The minimal requirement a shape can have are the above attributes.

Subclassed shapes may have additional methods by which they are defined.

Any Shape may be used to construct other shapes by applying set operations. Currently implemented binary operators are:

__or__/__add__ : set union, either | or + operator (not or)

__and__ : set intersection, & operator (not and)

__sub__ : set complement, - operator

__xor__ : set disjunctive union, ^ operator

Parameters:

center ((3,)) – the center of the shape

Methods

copy()

Create a new copy of this object.

scale(scale)

Return a new Shape with scaled size

toCuboid(*args, **kwargs)

Create a cuboid which is surely encompassing the full shape

toEllipsoid(*args, **kwargs)

Create an ellipsoid which is surely encompassing the full shape

toSphere(*args, **kwargs)

Create a sphere which is surely encompassing the full shape

translate(xyz)

Translate the center of the shape by xyz.

within(other, *args, **kwargs)

Return True if other is fully within self

within_index(other, *args, **kwargs)

Return indices of the elements of other that are within the shape

center

The geometric center of the shape

to

A dispatcher for classes, using __get__ it converts into ObjectDispatcher upon invocation from an object, or a TypeDispatcher when invoked from a class

__init__(center=(0, 0, 0))[source]
property center

The geometric center of the shape

copy()[source]

Create a new copy of this object.

scale(scale)[source]

Return a new Shape with scaled size

to

A dispatcher for classes, using __get__ it converts into ObjectDispatcher upon invocation from an object, or a TypeDispatcher when invoked from a class

This is a class-placeholder allowing a dispatcher to be a class attribute and converted into an ObjectDispatcher when invoked from an object.

If it is called on the class, it will return a TypeDispatcher.

This class should be an attribute of a class. It heavily relies on the __get__ special method.

Parameters:
  • name (str) – name of the attribute in the class

  • dispatchs (dict, optional) – dictionary of dispatch methods

  • obj_getattr (callable, optional) – method with 2 arguments, an obj and the attr which may be used to control how the attribute is called.

  • instance_dispatcher (AbstractDispatcher, optional) – control how instance dispatchers are handled through __get__ method. This controls the dispatcher used if called from an instance.

  • type_dispatcher (AbstractDispatcher, optional) – control how class dispatchers are handled through __get__ method. This controls the dispatcher used if called from a class.

Examples

>>> class A:
...   new = ClassDispatcher("new", obj_getattr=lambda obj, attr: getattr(obj.sub, attr))

The above defers any attributes to the contained A.sub attribute.

toCuboid(*args, **kwargs)[source]

Create a cuboid which is surely encompassing the full shape

toEllipsoid(*args, **kwargs)[source]

Create an ellipsoid which is surely encompassing the full shape

toSphere(*args, **kwargs)[source]

Create a sphere which is surely encompassing the full shape

translate(xyz: Sequence[float])[source]

Translate the center of the shape by xyz.

Parameters:

xyz (Sequence[float])

within(other, *args, **kwargs)[source]

Return True if other is fully within self

If other is an array, an array will be returned for each of these.

Parameters:
  • other (array_like) – the array/object that is checked for containment

  • *args – passed directly to within_index

  • **kwargs – passed directly to within_index

within_index(other, *args, **kwargs)[source]

Return indices of the elements of other that are within the shape