Filters

Filters take a system as input and generate a new system according to some user-defined criteria. There are filters that remove particles of a given type (or types), filters that remove the centre-of-mass-position from the particles, filters that include or exclude particles according to a user-defined function and more.

Once a filter has been created, it can be applied to single systems like this::

new_system = my_filter.filter(old_system)

In addition, filters can be applied to whole trajectories by using BaseTrajectory’s add_filter() method before these are parsed.

BaseFilter

The interface from which filters should inherit.

FilterByFunction

A filter that uses a user-provided callable to choose which particles will be included in the new system.

FilterById

A filter that builds a new system by including only those particles whose index is in the list provided by the user.

FilterByReducingToCOM

A filter that builds a new system containing a single particle whose position and velocity are the position and velocity of the centre of mass of the input system.

FilterByType

A filter that builds a new system by including only those particles whose type is in the list provided by the user.

FixParticlePath

A filter that attempts to reconstruct the trajectories of particles subject to periodic boundary conditions.

MapParticles

A filter that reduces the number of particles in a configuration by averaging the position and velocity of sets of particles.

MolecularCOMs

A filter that takes each molecule of the given system and adds it as a particle in the new system using the molecule’s centre of mass, velocity, charge and mass.

SubtractCOM

A filter that removes the centre of mass position and velocity from each particle.

class baggianalysis.core.BaseFilter(self: baggianalysis.core.BaseFilter)None

Bases: pybind11_builtins.pybind11_object

The interface from which filters should inherit. This is a pure virtual class and child classes should overload the filter() method.

filter(self: baggianalysis.core.BaseFilter, system: baggianalysis.core.System)baggianalysis.core.System

Returns a copy of the given system, filtered according to some criterion. This method should be overridden by child classes.

Parameters

system (System) – The input system.

Returns

A system that has the same timestep and box size of the input one but different particles, depending on the type of filter applied.

Return type

System

class baggianalysis.core.FilterByFunction(self: baggianalysis.core.FilterByFunction, arg0: Callable[[baggianalysis.core.Particle], bool])None

Bases: baggianalysis.core.BaseFilter

A filter that uses a user-provided callable to choose which particles will be included in the new system.

As an example, the following snippet creates a filter that will include in the new system only those particles whose type is different from “2” and whose position along the x coordinate is larger than 5:

my_filter = ba.FilterByFunction(lambda p: p.type != "2" and p.position[0] > 5)

The same effect can be achieved without using a lambda function:

def filter_func(p):
    return p.type != "2" and p.position[0] > 5

my_filter = ba.FilterByFunction(filter_func)

The constructor takes as a parameter a callable that will be used to decided which particles will be included in the new system.

Parameters

function (callable) – A callable that takes a particle and returns True if the particle should be included in the new system, False otherwise.

class baggianalysis.core.FilterById(self: baggianalysis.core.FilterById, arg0: List[int])None

Bases: baggianalysis.core.BaseFilter

A filter that builds a new system by including only those particles whose index is in the list provided by the user.

As an example, the following snippet creates a filter that will include in the new system only particles with index 1, 13 and 102:

allowed_ids = [1, 13, 102]
my_filter = ba.FilterById(allowed_ids)

The constructor takes a list of indexes as its only parameter.

Parameters

allowed_ids (List(int)) – The list of particle indexes that should be included in the new system.

class baggianalysis.core.FilterByReducingToCOM(self: baggianalysis.core.FilterByReducingToCOM)None

Bases: baggianalysis.core.BaseFilter

A filter that builds a new system containing a single particle whose position and velocity are the position and velocity of the centre of mass of the input system.

The constructor does not take any parameters.

class baggianalysis.core.FilterByType(self: baggianalysis.core.FilterByType, arg0: List[str])None

Bases: baggianalysis.core.BaseFilter

A filter that builds a new system by including only those particles whose type is in the list provided by the user.

As an example, the following snippet creates a filter that will include in the new system only particles of type “0” and “3”:

allowed_types = ["0", "3"]
my_filter = ba.FilterByType(allowed_types)

The constructor takes a list of particle types as its only parameter.

Parameters

allowed_types (List(str)) – The list of particle types that should be included in the new system.

class baggianalysis.core.FixParticlePath(self: baggianalysis.core.FixParticlePath)None

Bases: baggianalysis.core.BaseFilter

A filter that attempts to reconstruct the trajectories of particles subject to periodic boundary conditions.

This filter assumes that configurations are sorted in time and will silently fail its job if particles move more than the length of a box side between two consecutive configurations.

The constructor does not take any parameters.

class baggianalysis.core.MapParticles(self: baggianalysis.core.MapParticles, arg0: List[List[int]])None

Bases: baggianalysis.core.BaseFilter

A filter that reduces the number of particles in a configuration by averaging the position and velocity of sets of particles.

As an example, the following snippet creates a filter that will include in the new system two particles whose position and velocity will be computed by averaging the positions and velocities of particles with index 0 and 3 and 2, 5 and 6, respectively:

id_lists = [[0, 3], [2, 5, 6]]
my_filter = ba.MapParticles(id_lists)

The constructor takes a list of index lists used to construct the new particles.

Parameters

id_lists (List(List(int))) – A list of lists containing the indexes of the particles that should be averaged over to build the new particles.

class baggianalysis.core.SubtractCOM(self: baggianalysis.core.SubtractCOM)None

Bases: baggianalysis.core.BaseFilter

A filter that removes the centre of mass position and velocity from each particle.

The constructor does not take any parameters.