bdld package

Subpackages

Submodules

bdld.analysis module

bdld.grid module

Custom grid class that holds also the data

class bdld.grid.Grid

Bases: object

Rectangular grid with evenly distributed points

Parameters:
  • _data – Values at the grid points

  • ranges – (min, max) of the grid points per dimension

  • stepsizes – stepsizes between grid points per dimension

  • n_points – number of points per dimension

axes()

Return list of grid axes per dimension

Return type:

List[ndarray]

copy_empty()

Get a new independent grid instance with the same points but without data

property data

Data values of the grid as numpy array

Setting data broadcasts the values to the shape given by n_points

exp()

Exponentiation of data, relies on numpy

interpolate(points, method='linear', fill_value=nan)

Interpolate grid data at the given points

The interpolation is done via scipy.interpolate.griddata, see there for details

Parameters:
  • points (Union[ndarray, Tuple[ndarray, …]]) – the desired points

  • method (str) – interpolation method to use, defaults to linear

  • fill_value – value for points outside the grid, defaults to nan

Return type:

ndarray

log()

Logarithm of data, relies on numpy

points()

Return all grid points as a array of shape (n_points, dim) in row-major order

Return type:

ndarray

set_from_func(func)

Set data by applying function to all points

The function must accept the input in

Return type:

None

write_to_file(filename, fmt='%.18e', header='')

Write the grid to file via numpy.savetxt

For 2d this will write the data in “plumed style”, i.e. in C-order with emtpy lines between the rows

Parameters:
  • filename (str) – Path to write to

  • fmt (str) – format of the data, see np.savetxt

  • header (str) – String for the header, must start with the appropriate comment char

Return type:

None

bdld.grid.convolve(g1, g2, mode='valid', method='auto')

Perform convolution between two grids via scipy.signal.convolve

Grids must have same dimensions and stepsizes. The convolution is also correctly normalized by the stepsizes.

Parameters:
  • g2 (g1,) – grids to convolute

  • mode (str) – convolution mode, see scipy.signal.convolve for details

  • method (str) – one of “direct”, “fft” or “auto” (the default)

Raises:
  • ValueError – if g1 and g2 have different stepsizes

  • NotImplementedError – if mode=”full”

Return grid:

New grid containing the convolutin

Return type:

Grid

bdld.grid.from_npoints(ranges, n_points)

Create grid from the number of points per direction

Parameters:
  • ranges (List[Tuple[float, float]]) – List with (min,max) positions of the grid

  • n_points (Union[List[int], int]) – Either list with points per dimension or single value for all

Raises:

ValueError – if dimensions of ranges and number of points do not match

Return grid:

empty grid with specified ranges and number of points

Return type:

Grid

bdld.grid.from_stepsizes(ranges, stepsizes, shrink=False)

Create grid from stepsizes between data points

If the stepsizes doesn’t exactly fit the ranges, the upper grid ranges are extended by default

Parameters:
  • ranges (List[Tuple[float, float]]) – List with (min,max) positions of the grid

  • stepsizes (Union[List[float], float]) – Either list with stepsizes per dimension or single value for all

  • shrink (bool) – Shrink ranges instead of expanding if stepsizes doesn’t fit exactly

Return type:

Grid

bdld.grid.sparsify(g, max_points, method='linear')

Return sparser version of grid (same range but fewer points)

If the specified number of points is larger than the datapoints in the original grid, this will leave the number of points unchanged

Parameters:
  • g (Grid) – grid to sparsify

  • max_points (List[int]) – desired number of points per dimension

  • method (str) – interpolation method to use, default “linear”

Return sparse_grid:

sparsified Grid instance

Return type:

Grid

bdld.grid.stepsizes_from_npoints(ranges, n_points)

Calculate the stepsizes from the number of points and ranges

Parameters:
  • ranges (List[Tuple[float, float]]) – Ranges of the grid

  • n_points (List[int]) – number of points per dimension

Return type:

List[float]

bdld.histogram module

Implement a simple histogramming class

class bdld.histogram.Histogram(n_bins, ranges)

Bases: Grid

Histogram data into grid bins by using numpy’s histogramdd

This uses the Grid class for underlying structure and adds some histogram functions The main difference is that the Histogram stores values for the intervals between the grid points instead of the values at the grid points. Note that this is actually a bad way to do it from an OOP perspective (–> Liskov broken) Also explicitely stores the bin edges (as opposed to only the n_points of the Grid class)

Also allows histogramming over time, i.e. adding more data to the existing histogram

Parameters:
  • n_points – number of bins for histogramming per dimension

  • histo_ranges – extent of histogram (min, max) per dimension

  • bins – bin edges of the histogram per dimension

  • data – histogram data

add(data)

Add data to histogram

Parameters:

data (list (1d), list of lists or numpy.ndarrays (arbitrary dimensions)) – The values to add to the histogram, see numpy’s histogramdd for details

Return type:

None

axes()

Overwrite function from base class: Axes should return the bin centers

The base function would return them with points at the borders

bin_centers()

Calculate the centers of the histogram bins from the bin edges

Return centered_bins:

the centers of the histogram bins

clear()

Reset all counts to zero

Return type:

None

bdld.inputparser module

Input class and helpers to parse input from file

The configparser parses only simple items (str, float, int, bool), this was extended to also allow comma separated list of values. More complicated syntax like nested lists makes the writing and parsing of input files more error-prone.

The downside is that some of the options might need transforming. This is not done directly but some helper functions to do it are provided in this file.

class bdld.inputparser.Condition(function, desc)

Bases: object

Combine a string description with the evaluating function of a condition

class bdld.inputparser.Input(filename)

Bases: object

Class that parses the input file

Each section of the config is parsed in a seperate function defining the individual InputOption objects. The parsed options are then stored in one dictionary per section.

all_positive = <bdld.inputparser.Condition object>
at_most_3dim = <bdld.inputparser.Condition object>
parse_all()

Read input file and make sure the compulsory sections are included

Does then launch the config for the individual sections

Return type:

None

parse_birth_death(section)

Define and parse the options of the potential

Return type:

None

parse_delta_f(section)

Define and parse if delta f should be calculated section

Return type:

None

parse_fes(section)

Define and parse the fes section

Return type:

None

parse_histogram(section)

Define and parse the options for histogramming the trajectories

Return type:

None

parse_ld(section)

Define and parse the options of the langevin dynamics

Return type:

None

parse_particle_distribution(section)

Define and parse if statistics about particles should be printed periodically

Return type:

None

parse_particles(section)

Parse the number of particles and initial distribution

Return type:

None

parse_potential(section)

Define and parse the options of the potential

Return type:

None

static parse_section(section, options)

Parse all options of a section

Parameters:
  • section (SectionProxy) – section to parse

  • options (List[InputOption]) – list of InputOption to parse

Return type:

Dict[str, Union[str, float, int, bool, List[Union[str, float, int, bool]], None]]

parse_trajectories(section)

Define and parse the options for trajectory output

Return type:

None

positive = <bdld.inputparser.Condition object>
positive_or_zero = <bdld.inputparser.Condition object>
class bdld.inputparser.InputOption(key, keytype, compulsory=False, condition=None, default=None)

Bases: object

Bundle information about a config option into class

Parameters:
  • key (str) – keyword in config

  • keytype (Union[Type[Union[str, float, int, bool]], List[Type[Union[str, float, int, bool]]]]) – expected type (one of OptionType)

  • compulsory (bool) – if the key is required

  • condition (Optional[Condition]) – optional Condition the value must satisfy

  • default (Union[str, float, int, bool, List[Union[str, float, int, bool]], None]) – optional default value

parse(section)

Parse option from section in exception save way

Returns either the option as the desired type or None if the key is not found

Return type:

Union[str, float, int, bool, List[Union[str, float, int, bool]], None]

exception bdld.inputparser.OptionError(message, key, section)

Bases: Exception

Custom error message if option missing or could not be parsed

exception bdld.inputparser.SectionError(section)

Bases: Exception

Error if section is missing

bdld.inputparser.get_all_numbered_values(section, prefix='', suffix='')

Returns all numbered options with the given key name

Parameters:
  • section (Union[SectionProxy, Dict[str, Union[str, float, int, bool, List[Union[str, float, int, bool]], None]]]) – section/dict to search

  • prefix (str) – prefix of option key (string before number)

  • suffix (str) – suffix of option key (string after number)

Return type:

List[Union[str, float, int, bool, List[Union[str, float, int, bool]], None]]

bdld.inputparser.min_max_to_ranges(min_list, max_list)

Transform the max and min lists to a list of lists of tuples for the states

The min_list and max_list have one point per entry, i.e. for more than 1D they are also lists. This also checks that all min and max values have the same dimension

The output list contains one list for every range. The list then contains a tuple with (min, max) value for every dimension.

Parameters:
  • min_list (Union[List[float], List[List[float]]]) – list with all minimum points of the intervals

  • max_list (Union[List[float], List[List[float]]]) – list with all maximum points of the intervals

Raises:
  • ValueError – when the length of the lists do not match

  • ValueError – when the dimensions of any min-max pair don’t match

Return type:

List[List[Tuple[float, float]]]

bdld.inputparser.numbered_state_options(section)

Return list with ‘state{i}_min’ & ‘state{i}_max’ InputOptions in section

This reads the keys of a section and adds two new options for each found state The state InputOptions are lists regardless of dimensions

Parameters:

section (SectionProxy) – section of configparser to search through

Raises:
  • OptionError – if number of min and max options don’t match

  • OptionError – if no min and max actions were found

Return type:

List[InputOption]

bdld.main module

Class that takes care about running and analysing a simulation

bdld.main.bd_prob_density(pot, bd_bw, kt)

Return probability density grid needed for BirthDeath

This is usually a unknown quantity, so this has to be replaced by an estimate in the future. E.g. enforce usage of the histogram and use that as estimate at current time with iterative updates

Because of the current free choice of points, we use rather a lot and make sure the Kernel grid will have at least 20 points per dimension within 5 sigma

Return prob_grid:

Grid of the probability density

Return type:

Grid

bdld.main.init_logger(level_str)

Set up logger with specified level

Parameters:

level_str (str) – string with the level

Return type:

Logger

bdld.main.init_particles(options, ld)

Add particles to ld with the given algorithm

random-global: distribute randomly on full range of potential random-pos: distribute randomly on the given positions fractions-pos: distribute with given fractions on the given positions

Return type:

None

bdld.main.main()

Main function of simulation

Does these things (in order):

  1. parse cli args

  2. get input from file

  3. set up all actions

  4. run the main loop for the desired time steps

  5. run final actions

Return type:

None

bdld.main.setup_birth_death(options, ld)

Setup BirthDeath instance from options

Currently this requires to get the true probability density values from the potential for the corrections of the algorithm, so this is also set up here

Return type:

BirthDeath

bdld.main.setup_delta_f(options, fes_action)

Setup FesAction on HistogramAction with given options

Return type:

DeltaFAction

bdld.main.setup_fes(options, histo_action)

Setup FesAction on HistogramAction with given options

Return type:

FesAction

bdld.main.setup_histogram(options, traj_action)

Setup HistogramAction on TrajectoryAction with given options

Return type:

HistogramAction

bdld.main.setup_ld(options, pot)

Return Langevin Dynamics with given options on the potential

Return type:

Union[BussiParinelloLD, OverdampedLD]

bdld.main.setup_particle_distribution(options, ld)

Setup analysis of particle distribution of LD

Return type:

ParticleDistributionAction

bdld.main.setup_potential(options)

Return potential from given options

Return type:

Potential

bdld.main.setup_trajectories(options, ld)

Setup TrajectoryAction on ld with given options

Return type:

TrajectoryAction

bdld.particle module

MD particle class

class bdld.particle.Particle(pos, mom=None, mass=1.0)

Bases: object

Simple particle class

Parameters:
  • pos (numpy.array) – position

  • mom (numpy.array) – momentum

  • mass (float) – mass of particle

init_momentum(mom=None)

Initialize momentum to either given value or zero array of correct size

Module contents