Table Of Contents

Previous topic

ogl Package

Next topic

utils Package

This Page

pset Package

pset Package

particles_set Module

class pyparticles.pset.particles_set.ParticlesSet(size=1, dim=3, boundary=None, label=False, mass=True, velocity=True, charge=False, log_X=False, log_V=False, log_max_size=0)

Bases: object

The main class for storing the particles data set.

Constructor:

Parameters:
  • size – (default 1) Number of particles
  • dim – (default 3) dimensions of the system 2 or 3 ... 2D 3D
  • mass – (dafault True) if True the particles have a mass.
  • label – (default False) if true it’s possible to set a name for each particle
  • velocity – (dafault True) if true the particles has a velocity
  • charge – (default False) if true the particles have an electric charge.
  • log_X – (default False) if true it’s possible to logging the position
  • log_V – (default False) if true it’s possible to logging the velocity
  • log_max_size – (default 0) set the maximal size of the log queue

Note

The properties: position X and velocity V are mandatory.

M

return the reference to the array of the masses

Q

return the reference to the array of the charges

V

return the reference to the velocities array

X

return the reference to the array of the positions

add_clusters(Cs, n)
add_property_by_name(property_name, dim=None, model='numpy_array', to_type=<type 'numpy.float64'>)

Insert a new property by name. If the dim is not specified it uses the current dimension of the set.

If the model of the property is ‘list’ the dim is forced to 1

Parameters:
  • property_name – the name of the new property
  • dim – the dimension of the new property ( 2 = “2D , 3 = 3D ... )
  • model – ‘list’ or ‘numpy_array’
  • to_type – [np.float64] an array-numpy type for the model ‘numpy_array’ [ np.float64 , np.int64 ... ]

For example add ‘friction’ or ‘radius’:

# Add the friction to the particles set 
pset.add_property_by_name( "friction" , dim=1 , to_type=np.float32 )
pset.add_property_by_name( "radius" , dim=1 , to_type=np.float64 )
add_set_changed_listener(listener)

Add an object that contains a member methods called: particles_set_changed( pset ) that there will be called if the particle set will be modified.

append(p_dict)

Append the particle(s) described in the given dictionary

If the particle don’t contain every required data will be rejected.

The dictionary p_dict must contains the name of the property and it’s value, and it must include all property, also the user defined!

append_logger(logger, key=None)
boundary

return the reference to the boundary, None if the boundary are not set or open

centre_of_mass()

Return the stored center of mass.

Note

this function don’t compute the center of mass, but simply return the stored value.

close_log()

This function must be called after the end of the simulation for closing the log procedure.

dim

get the dim of the set

enable_log(log_X=True, log_V=False, sim_time=None, log_max_size=0)

Eanble the X and V logging:

Parameters:
  • log_X=True – log the positions
  • log_V=False – log the velocity
  • log_max_size – max size of the log queue
getM()
getQ()
getV()
getX()
get_boundary()
get_by_name(property_name)
Return a property reference by name:
for example ‘X’ , ‘V’ , ‘M’ , ‘Q’ ...
Parameters:property_name – The name of a property
# set to [1,2,3] the coordinates of the 10th particle
pset.get_by_name('X')[10,:] = [1,2,3]
get_dim()
get_label()
get_list(i, to=<type 'float'>)

return a list containing all data of the i-th particle TODO: adapt to property by name

get_log_V_enabled()
get_log_X_enabled()
get_log_array(i, log_X=True, log_V=False)
get_log_enabled()
get_log_indices_segments(full=False)
get_log_max_size()
get_log_size()
get_mass_unit()
get_properties_names()

Return a list of containing the names of all properties

get_size()
get_unit()
jump(indx)
label

return the reference to the label list

log()
If the log is enabled, save the current status in the log queue.
The last element of the queue will be removed if we reach the max allowed size
log_V_enabled

return true if the logging of the position is enabled

log_X_enabled

return true if the logging of the velocity is enabled

log_enabled

return true if the logging of position or velocity is enabled

log_max_size

set and get the max allowed size of the log

log_size
mass_unit

set the unit mass

notify_set_changed()

Call this methods when the particle set is modified.

read_log_array(i, ta, log_X=True, log_V=False)
realloc(size, dim, boundary=None, label=False, mass=True, velocity=True, charge=False, log_X=False, log_V=False, log_max_size=0)

Realloc the particle set, it uses the same args of the constructor,

Attention! this method remove the dictionary of the of the extra properties

resize(new_size)

Resize the particles set with the new_size.

If the new size is bigger the old data are copied in the new particles, according to the function numpy.resize if it is smaller it cancels the data.

If the property is a list, the new elements will be filled with ‘None’ or empty string for the labels

The dim of the set will be not changed.

set_boundary(boundary)
set_default_logger(key)
set_log_max_size(log_max_size)
set_mass_unit(u)
set_unit(u)
size

get the size of the set

unit

set the unit length

update_boundary()

Update the particle set according to the boundary rule

update_centre_of_mass()

Compute and return the center of mass

logger Module

class pyparticles.pset.logger.Logger(pset, log_max_size, log_X=True, log_V=False, sim_time=None)

Bases: object

Class used for logging the status of the particles system, this class will be used by the ParticlesSet class. This class uses a matrix of size [ log_size by pasrticles_size by dim ] for saving the status.

Constructor

Parameters:
  • pset – A reference to the particles set to be logged.
  • log_max_size – The maximal size of the log
  • log_X – (default=True) log the positions
  • log_V – (default=False) log the velocities
  • sim_time – (default=None) log the simulation time
close_log()
get_log_V_enabled()
get_log_X_enabled()
get_log_array(i, log_X=True, log_V=False, log_time=False)

Return an numpy array containing the log if the i-th particles

Parameters:
  • i – Index (or indices) of the particles
  • log_X – (default=True) return the log of the positions
  • log_V – (default=False) return the log of the velocities
Returns:

A tuple containing the log arrays ( log_x , [log_V] )

get_log_indices_segments(full=False)
get_log_max_size()
get_log_size()
jump()
log()

Save the current status of the particles-set in the log queue. If the log queue is filled it removes the oldest status

log_V_enabled

return true if the logging of the position is enabled

log_X_enabled

return true if the logging of the velocity is enabled

log_max_size

get the max allowed size of the log

log_size
read_log_array(i, ta, log_X=True, log_V=False, log_time=False)

Write in the arrays stored in the tuple ta the log if the i-th particles

Parameters:
  • i – Index (or indices) of the particles
  • ta – A tuple with the reference to the target arrays ( X , V ). The size of X and V must be ( max_log_length by dim )
  • log_X – (default=True) return the log of the positions
  • log_V – (default=False) return the log of the velocities
Returns:

A tuple containing the log indices for using the segments array ( begin . end ).

resize(log_max_size)

boundary Module

class pyparticles.pset.boundary.Boundary

Bases: object

bound
boundary(p_set)
dim
get_bound()
get_dim()
set_boundary(bound=(-1, 1), dim=3)

cluster Module

class pyparticles.pset.cluster.Cluster

Bases: object

insert3(X, M=None, V=None)
write_out(X, M=None, V=None)

constrained_force_interactions Module

class pyparticles.pset.constrained_force_interactions.ConstrainedForceInteractions(pset=None)

Bases: pyparticles.pset.constraint.Constraint

add_connections(fc)

Adds the connections listed in fc . fc must be a list of list or a 2d array of pairs for example:

cfi = ConstrainedForceInteractions( pset )
a = [[1,1],[3,5]]
cfi.add_connections( a )
dense
Return the dense reppresentations of the connections matrix.
Don’t use this function in a loop, don’t use this function in a loop, but execute the conversion to a dense matix before the loop.
get_dense()

Return the dense reppresentations of the connections matrix. Don’t use this function in a loop, don’t use this function in a loop, but execute the conversion to a dense matix before the loop.

get_items()

list of the commection ((i,j), value) pairs, ...)

get_pset()
get_sparse()

Return the reference to the dok_matrix sparse matrix of the connections. For the operations with a dense matricies, don’t use this function in a loop, but execute the conversion to a dense matix before the loop.

items

list of the commection ((i,j), value) pairs, ...)

pset
remove_connections(fc)

Removes the connections listed in fc . fc must be a list of list or a 2d array of pairs for example:

cfi = ConstrainedForceInteractions( pset )
a = [[1,1],[3,5]]
cfi.remove_connections( a )
set_pset(pset)
sparse
Return the reference to the dok_matrix sparse matrix of the connections.
For the operations with a dense matricies, don’t use this function in a loop, but execute the conversion to a dense matix before the loop.

constrained_x Module

class pyparticles.pset.constrained_x.ConstrainedX(pset=None)

Bases: pyparticles.pset.constraint.Constraint

add_x_constraint(indx, constr)

Add new positional constraint and update the referenced particles set. constraints are concatenated to the stored constraints, we don’t tests the uniqueness of the indices. be careful with the double indices

Arguments  
indx indices of the new constraint
constr the new constraint

If constr is a slice the constraints will be constants

cX

return the constrained X elements

clear_all_x_constraint()

clear all positional constraints

get_cX()
get_cx_free_indicies()

Return an array or if it’s possible a slice containing the not constrained indices

get_cx_indicies()

Return a copy of the constrained indices

get_pset()

Return the current constrained particles set

pset

get and set the particles set (pset)

remove_x_constraint(indxs)

Remove the element indexed in indxs from the constraints Arguments:

  1. indxs: an iterable containing the indices of the old constraints.
set_free_indicies(indx)
set_pset(pset)

set the particles set. And it sets the constrained values in the particles set pset

constraint Module

class pyparticles.pset.constraint.Constraint(pset=None)

Bases: object

get_pset()
pset
set_pset(pset)

file_cluster Module

class pyparticles.pset.file_cluster.FileCluster

Bases: object

Read the data from a csv formatted file:

The first row of the csv contains the size and the dim of the particles set.

The other rows are the data of the perticles in the order:

close()

Close the file

insert3(pset)

Insert the particles described in the file in the ParticlesSet pset

Parameters:pset – A reference to the particles set
open(cfile, mode='r')

Open the csv file named cfile.

Parameters:
  • cfile – The file name
  • mode – file mode (default reading)
write_out(pset)

Write out in the csv file the particles described in pset.

Parameters:pset – A reference to the particles set

octree Module

class pyparticles.pset.octree.OcTree

Bases: object

|OcTree particles container class

build_tree(pset)

Build the octree with the given particles set

Arguments  
pset a ParticlesSet object used to build the tree
centre_of_mass

return the centre of mass of the particles set

get_centre_of_mass()
print_tree()
search_neighbour(X, r)

return an array containing the indecies of the the particles included in the sheric region centred in X with a radius r

set_global_boundary(ref_vertex=array([ 0., 0., 0.]), edge_len=1.0)

Define the size of the octree cube

Arguments  
ref_vertex the ( down , near , left ) vertex
edge_len leght of the edge
class pyparticles.pset.octree.TreeElement

Bases: object

The element of a tree node

M

getter: return the total mass of the current element

add_sub_trees()
centre_of_mass

return the centre of mass of the particle

depth(d=1)

Compute and returns the maximal depth of the octree

down

relative domanin for the down ‘sub-space’

far

relative domanin for the far ‘sub-space’

getM()
get_centre_of_mass()
get_down()
get_far()
get_left()
get_max_vertex()
get_min_vertex()
get_near()
get_particle()
get_right()
get_up()

Z axis

insert_particle(pset, i)
insert_particle_mp(pset, i)
is_in(coord)
left

relative domanin for the left ‘sub-space’

max_vertex

get the maximal vertex of the cube

min_vertex

get the minimal vertex of the cube

near

relative domanin for the near ‘sub-space’

particle

Get the particle index of the tree element

print_tree(pset, d=1)

Print the structure of the tree and return the maximal depth

Args:
pset: the particles set d: current depth (1 for the first node)
right

relative domanin for the right ‘sub-space’

search_neighbour(cand_queue, res_list, pset, X, r)

Search the elements included in the volume centred in X with the radius r and append the results in the list res_list. res_list contains the indicies of the particles included in the the sphere.

set_local_boundary(ref_vertex, edge_len)
up

relative domanin for the up ‘sub-space’

periodic_boundary Module

class pyparticles.pset.periodic_boundary.PeriodicBoundary(bound=(-1, 1), dim=3)

Bases: pyparticles.pset.boundary.Boundary

boundary(p_set)

rand_cluster Module

class pyparticles.pset.rand_cluster.RandCluster

Bases: pyparticles.pset.cluster.Cluster

bomb_vel(X, V, start_indx=0, n=100, centre=(0.0, 0.0, 0.0), vel_rng=(0.5, 1.0), randg=<built-in method rand of mtrand.RandomState object at 0x3b47318>)
const_vel(X, V, start_indx=0, n=100, vel_rng=(0.5, 1.0), vel_dir=[1, 0, 0], randg=<built-in method rand of mtrand.RandomState object at 0x3b47318>)
insert3(X, M=None, V=None, start_indx=0, n=100, centre=(0.0, 0.0, 0.0), radius=1.0, mass_rng=(0.5, 1), vel_rng=(0.5, 1.0), vel_mdl=None, vel_dir=None, randg=<built-in method rand of mtrand.RandomState object at 0x3b47318>, r_min=0.0)

rebound_boundary Module

class pyparticles.pset.rebound_boundary.ReboundBoundary(bound=(-1, 1), dim=3)

Bases: pyparticles.pset.boundary.Boundary

boundary(p_set)
set_normals()