schrodinger.math.mathutils module

Contains math-related utility functions

Copyright Schrodinger, LLC. All rights reserved.

schrodinger.math.mathutils.round_value(val, precision=3, significant_figures=None)[source]

Return val as a string with the required precision or significant figures.

Either precision or significant_figures should be provided. Uses scientific notation for very large or small values, if the precision allows.

Parameters
  • val (float) – The value to round

  • precision (int) – The precision needed after rounding. A precision of 2 means two decimal places should be kept after rounding. A negative precision indicates how many digits can be replaced with zeros before the decimal point. -5 means that 123456 can be shown as 1e5, -3 means it can be shown as 1.23e5.

  • significant_figures (int) – The number of significant figures that should remain after rounding. If provided, determines the rounding precision.

Return type

str or None

Returns

A string with the required precision, or None if the input is a string

schrodinger.math.mathutils.deduplicate_xy_data(x_vals, y_vals)[source]

Remove duplicate x values by averaging the y values for them.

Parameters
  • x_vals (list) – The x values

  • y_vals (list) – The y values

Return type

list, list

Returns

The deduplicated xy data

class schrodinger.math.mathutils.Interpolate1D(source_vals, target_vals, log_interp=False)[source]

Bases: object

Creates a map between values in a source and a target axis, allowing to get the equivalent target point for each source point.

Wrapper around scipy.interpolate.interp1d to allow logarithmic interpolation or extrapolation.

__init__(source_vals, target_vals, log_interp=False)[source]

Create an instance.

Parameters
  • source_vals (tuple) – The values of points in the source range

  • target_vals (tuple) – The values of points in the target range

  • log_interp (bool) – Whether the interpolation is logarithmic. If False, linear interpolation will be used.

class schrodinger.math.mathutils.Interpolate2D(x_source_vals, x_target_vals, y_source_vals, y_target_vals, x_log_interp=False, y_log_interp=False)[source]

Bases: object

Creates two instances of Interpolate1D to map values between two source axes and two target axes. Example use case is mapping QGraphicsScene/QChart XY coordinates to a XY coordinate system being displayed in the scene/chart.

The two axes need to be independent.

__init__(x_source_vals, x_target_vals, y_source_vals, y_target_vals, x_log_interp=False, y_log_interp=False)[source]

Create an instance.

Parameters
  • x_source_vals (tuple) – The values of points in the X source range

  • x_target_vals (tuple) – The values of points in the X target range

  • y_source_vals (tuple) – The values of points in the Y source range

  • y_target_vals (tuple) – The values of points in the Y target range

  • x_log_interp (bool) – Whether the X axis interpolation is logarithmic

  • y_log_interp (bool) – Whether the Y axis interpolation is logarithmic