Cuds module

A module containing tvtk dataset wrappers to simphony CUDS containers.

Classes

VTKParticles(name[, data, data_set, mappings]) Constructor.
VTKMesh(name[, data, data_set, mappings]) Constructor.
VTKLattice(name, type_, data_set[, data]) Constructor.

Description

class simphony_mayavi.cuds.vtk_particles.VTKParticles(name, data=None, data_set=None, mappings=None)[source]

Bases: simphony.cuds.abstractparticles.ABCParticles

Constructor.

Parameters:
  • name (string) – The name of the container.
  • data (DataContainer) – The data attribute to attach to the container. Default is None.
  • data_set (tvtk.DataSet) – The dataset to wrap in the CUDS api. Default is None which will create a tvtk.PolyData
  • mappings (dict) – A dictionary of mappings for the particle2index, index2particle, bond2index and bond2element. Should be provided if the particles and bonds described in data_set are already assigned uids. Default is None and will result in the uid <-> index mappings being generated at construction.
add_bond(bond)[source]

Adds the bond to the container.

Also like with particles, if the bond has a defined uid, it won’t add the bond if a bond with the same uid already exists, and if the bond has no uid the particle container will generate an uid. If the user wants to replace an existing bond in the container there is an ‘update_bond’ method for that purpose.

Parameters:bond (Bond) – the new bond that will be included in the container.
Returns:uid (uuid.UID) – The uid of the added bond.
Raises:ValueError – When the new particle already exists in the container.

Examples

Add a bond to a Particles container.

>>> bond = Bond()
>>> particles = Particles(name="foo")
>>> particles.add_bond(bond)
add_particle(particle)[source]

Adds the particle to the container.

If the new particle has no uid, the particle container will generate a new uid for it. If the particle has already an uid, it won’t add the particle if a particle with the same uid already exists. If the user wants to replace an existing particle in the container there is an ‘update_particle’ method for that purpose.

Parameters:particle (Particle) – the new particle that will be included in the container.
Returns:uid (uuid.UUID) – The uid of the added particle.
Raises:ValueError – when the new particle already exists in the container.

Examples

Add a particle to a Particles container.

>>> particle = Particle()
>>> particles = Particles(name="foo")
>>> particles.add_particle(part)
bond2index = None

The mapping from uid to bond index

data

Easy access to the vtk CellData structure

data_set = None

The vtk.PolyData dataset

classmethod from_dataset(name, data_set, data=None)[source]

Wrap a plain dataset into a new VTKParticles.

The constructor makes some sanity checks to make sure that the tvtk.DataSet is compatible and all the information can be properly used.

Raises:TypeError – When the sanity checks fail.
classmethod from_particles(particles)[source]

Create a new VTKParticles copy from a CUDS particles instance.

get_bond(uid)[source]

Returns a copy of the bond with the ‘bond_id’ id.

Parameters:uid (uuid.UUID) – the uid of the bond
Raises:KeyError – when the bond is not in the container.
Returns:bond (Bond) – A copy of the internally stored bond info.
get_particle(uid)[source]

Returns a copy of the particle with the ‘particle_id’ id.

Parameters:uid (uuid.UUID) – the uid of the particle
Raises:KeyError – when the particle is not in the container.
Returns:particle (Particle) – A copy of the internally stored particle info.
has_bond(uid)[source]

Checks if a bond with the given uid already exists in the container.

has_particle(uid)[source]

Checks if a particle with the given uid already exists in the container.

index2bond = None

The reverse mapping from index to bond uid

index2particle = None

The reverse mapping from index to point uid

iter_bonds(uids=None)[source]

Generator method for iterating over the bonds of the container.

It can receive any kind of sequence of bond ids to iterate over those concrete bond. If nothing is passed as parameter, it will iterate over all the bonds.

uids : iterable of uuid.UUID, optional
sequence containing the id’s of the bond that will be iterated. When the uids are provided, then the bonds are returned in the same order the uids are returned by the iterable. If uids is None, then all bonds are returned by the interable and there is no restriction on the order that they are returned.
Yields:bond (Bond) – The next Bond item
Raises:KeyError – if any of the ids passed as parameters are not in the container.

Examples

It can be used with a sequence as parameter or without it:

>>> particles = Particles(name="foo")
>>> ...
>>> for bond in particles.iter_bonds([id1, id2, id3]):
        ...  #do stuff
        #take the bond back to the container so it will be updated
        #in case we need it
        particles.update_bond(bond)
>>> for bond in particles.iter_bond():
        ...  #do stuff; it will iterate over all the bond
        #take the bond back to the container so it will be updated
        #in case we need it
        particles.update_bond(bond)
iter_particles(uids=None)[source]

Generator method for iterating over the particles of the container.

It can receive any kind of sequence of particle uids to iterate over those concrete particles. If nothing is passed as parameter, it will iterate over all the particles.

uids : iterable of uuid.UUID, optional
sequence containing the uids of the particles that will be iterated. When the uids are provided, then the particles are returned in the same order the uids are returned by the iterable. If uids is None, then all particles are returned by the interable and there is no restriction on the order that they are returned.
Yields:particle (Particle) – The Particle item.
Raises:KeyError – if any of the ids passed as parameters are not in the container.

Examples

It can be used with a sequence as parameter or without it:

>>> particles = Particles(name="foo")
>>> ...
>>> for particle in particles.iter_particles([uid1, uid2, uid3]):
        ...  #do stuff
        #take the particle back to the container so it will be updated
        #in case we need it
        part_container.update_particle(particle)
>>> for particle in particles.iter_particles():
        ...  #do stuff; it will iterate over all the particles
        #take the particle back to the container so it will be updated
        #in case we need it
        particles.update_particle(particle)
particle2index = None

The mapping from uid to point index

remove_bond(uid)[source]

Removes the bond with the uid from the container.

The uid passed as parameter should exists in the container. If it doesn’t exists, nothing will happen.

Parameters:uid (uuid.UUID) – the uid of the bond to be removed.

Examples

Having an uid of an existing bond, pass it to the function.

>>> particles = Particles(name="foo")
>>> ...
>>> bond = particles.get_bond(uid)
>>> ...
>>> particles.remove_bond(bond.uid)
or
>>> particles.remove_bond(uid)
remove_particle(uid)[source]

Removes the particle with uid from the container.

The uid passed as parameter should exists in the container. Otherwise an exception will be raised.

Parameters:uid (uuid.UUID) – the uid of the particle to be removed.
Raises:KeyError – If the particle doesn’t exist.

Examples

Having an uid of an existing particle, pass it to the function.

>>> particles = Particles(name="foo")
>>> ...
>>> particle = particles.get_particle(uid)
>>> ...
>>> particles.remove_particle(part.uid)
or directly
>>> particles.remove_particle(uid)
supported_cuba = None

The currently supported and stored CUBA keywords.

update_bond(bond)[source]

Replaces an existing bond.

Takes the uid of ‘bond’ and searches inside the container for that bond. If the bond exists, it is replaced with the new bond passed as parameter. If the bond doesn’t exist, it will raise an exception.

Parameters:bond (Bond) – the bond that will be replaced.
Raises:ValueError – If the bond doesn’t exist.

Examples

Given a Bond that already exists in the Particles container (taken with the ‘get_bond’ method for example) just call the function passing the Bond as parameter.

>>> particles = Particles(name="foo")
>>> ...
>>> bond = particles.get_bond(uid)
>>> ... #do whatever you want with the bond
>>> particles.update_bond(bond)
update_particle(particle)[source]

Replaces an existing particle.

Takes the uid of ‘particle’ and searches inside the container for that particle. If the particle exists, it is replaced with the new particle passed as parameter. If the particle doesn’t exist, it will raise an exception.

Parameters:particle (Particle) – the particle that will be replaced.
Raises:ValueError – If the particle does not exist.

Examples

Given a Particle that already exists in the Particles container (taken with the ‘get_particle’ method for example), just call the function passing the Particle as parameter.

>>> part_container = Particles(name="foo")
>>> ...
>>> part = part_container.get_particle(uid)
>>> ... #do whatever you want with the particle
>>> part_container.update_particle(part)
class simphony_mayavi.cuds.vtk_mesh.VTKMesh(name, data=None, data_set=None, mappings=None)[source]

Bases: simphony.cuds.abstractmesh.ABCMesh

Constructor.

Parameters:
  • name (string) – The name of the container
  • data (DataContainer) – The data attribute to attach to the container. Default is None.
  • data_set (tvtk.DataSet) – The dataset to wrap in the CUDS api. Default is None which will create a tvtk.UnstructuredGrid.
  • mappings (dict) – A dictionary of mappings for the point2index, index2point, element2index and index2element. Should be provided if the points and elements described in data_set are already assigned uids. Default is None and will result in the uid <-> index mappings being generated at construction.
add_cell(cell)[source]
add_edge(edge)[source]
add_face(face)[source]
add_point(point)[source]
data

Easy access to the vtk PointData structure

data_set = None

The vtk.PolyData dataset

element2index = None

The mapping from uid to bond index

element_data = None

Easy access to the vtk CellData structure

classmethod from_dataset(name, data_set, data=None)[source]

Wrap a plain dataset into a new VTKMesh.

The constructor makes some sanity checks to make sure that the tvtk.DataSet is compatible and all the information can be properly used.

Raises:TypeError – When the sanity checks fail.
classmethod from_mesh(mesh)[source]

Create a new VTKMesh copy from a CUDS mesh instance.

get_cell(uid)[source]
get_edge(uid)[source]
get_face(uid)[source]
get_point(uid)[source]
has_cells()[source]
has_edges()[source]
has_faces()[source]
index2element = None

The reverse mapping from index to bond uid

index2point = None

The reverse mapping from index to point uid

iter_cells(uids=None)[source]
iter_edges(uids=None)[source]
iter_faces(uids=None)[source]
iter_points(uids=None)[source]
point2index = None

The mapping from uid to point index

supported_cuba = None

The currently supported and stored CUBA keywords.

update_cell(element)
update_edge(element)
update_face(element)
update_point(point)[source]
class simphony_mayavi.cuds.vtk_lattice.VTKLattice(name, type_, data_set, data=None)[source]

Bases: simphony.cuds.abstractlattice.ABCLattice

Constructor.

Parameters:
  • name (string) – The name of the container.
  • type_ (string) – The type of the container.
  • data_set (tvtk.DataSet) – The dataset to wrap in the CUDS api
  • data (DataContainer) – The data attribute to attach to the container. Default is None.
base_vect
data

The container data

classmethod empty(name, type_, base_vector, size, origin, data=None)[source]

Create a new empty Lattice.

classmethod from_dataset(name, data_set, data=None)[source]

Create a new Lattice and try to guess the type.

classmethod from_lattice(lattice)[source]

Create a new Lattice from the provided one.

get_coordinate(index)[source]

Get coordinate of the given index coordinate.

index : int[3]
node index coordinate
Returns:

coordinates : float[3]

get_node(index)[source]

Get the lattice node corresponding to the given index.

index : int[3]
node index coordinate
Returns:node (LatticeNode)
iter_nodes(indices=None)[source]

Get an iterator over the LatticeNodes described by the indices.

indices : iterable set of int[3], optional
When indices (i.e. node index coordinates) are provided, then nodes are returned in the same order of the provided indices. If indices is None, there is no restriction on the order the nodes that are returned.
Returns:
iterator:
An iterator over LatticeNode objects
origin
point_data = None

Easy access to the vtk PointData structure

size
supported_cuba = None

The currently supported and stored CUBA keywords.

type
update_node(node)[source]

Update the corresponding lattice node.

Parameters:node (LatticeNode) –