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 the BaseTrajectory’s add_filter() method before these are parsed.

BaseFilter

FilterByFunction

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

FilterByReducingToCOM

FilterByType

FixParticlePath

SubtractCOM

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

Bases: pybind11_builtins.pybind11_object

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

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.FilterByReducingToCOM(self: baggianalysis.core.FilterByReducingToCOM)None

Bases: baggianalysis.core.BaseFilter

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

Bases: baggianalysis.core.BaseFilter

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

Bases: baggianalysis.core.BaseFilter

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

Bases: baggianalysis.core.BaseFilter