skchem.utils package

Submodules

skchem.utils.decorators module

skchem.utils.helpers module

skchem.utils.helpers

Module providing helper functions for scikit-chem

class skchem.utils.helpers.Defaults(defaults)[source]

Bases: object

get(val)[source]
skchem.utils.helpers.iterable_to_series(mols)[source]
skchem.utils.helpers.nanarray(shape)[source]

Produce an array of NaN in provided shape.

Parameters:shape (tuple) – The shape of the nan array to produce.
Returns:np.array
skchem.utils.helpers.optional_second_method(func)[source]
skchem.utils.helpers.squeeze(data, axis=None)[source]

Squeeze dimension for length 1 arrays.

Parameters:
  • data (pd.Series or pd.DataFrame or pd.Panel) – The pandas object to squeeze.
  • axis (int or tuple) – The axes along which to squeeze.
Returns:

pd.Series or pd.DataFrame

skchem.utils.io module

# skchem.utils.io

IO helper functions for skchem.

skchem.utils.io.json_dump(obj, target=None)[source]

Write object as json to file or stream, or return as string.

skchem.utils.io.line_count(filename)[source]

Quickly count the number of lines in a file.

Adapted from http://stackoverflow.com/questions/845058/how-to-get-line-count-cheaply-in-python

Parameters:filename (str) – The name of the file to count for.
skchem.utils.io.sdf_count(filename)[source]

Efficiently count molecules in an sdf file.

Specifically, the function counts the number of times ‘$$$$’ occurs at the start of lines in the file.

Parameters:filename (str) – The filename of the sdf file.
Returns:the number of molecules in the file.
Return type:int
skchem.utils.io.yaml_dump(obj, target=None)[source]

Write object as yaml to file or stream, or return as string.

skchem.utils.progress module

# skchem.utils.progress

Module implementing progress bars.

class skchem.utils.progress.DummyProgressBar(*args, **kwargs)[source]

Bases: object

finish()[source]
update(val)[source]
class skchem.utils.progress.NamedProgressBar(name=None, **kwargs)[source]

Bases: progressbar.bar.ProgressBar

default_widgets()[source]

skchem.utils.string module

skchem.utils.string.camel_to_snail(s)[source]

Convert CamelCase to snail_case.

skchem.utils.string.free_to_snail(s)[source]

Convert Free Case to snail_case.

skchem.utils.suppress module

skchem.utils.suppress

Class for suppressing C extensions output.

class skchem.utils.suppress.Suppressor[source]

Bases: object

A context manager for doing a “deep suppression” of stdout and stderr.

It will suppress all print, even if the print originates in a compiled C/Fortran sub-function.

This will not suppress raised exceptions, since exceptions are printed to stderr just before a script exits, and after the context manager has exited (at least, I think that is why it lets exceptions through).

null_fds = [4, 5]

Module contents

skchem.utils

Module providing utility functions for scikit-chem

class skchem.utils.Suppressor[source]

Bases: object

A context manager for doing a “deep suppression” of stdout and stderr.

It will suppress all print, even if the print originates in a compiled C/Fortran sub-function.

This will not suppress raised exceptions, since exceptions are printed to stderr just before a script exits, and after the context manager has exited (at least, I think that is why it lets exceptions through).

null_fds = [4, 5]
skchem.utils.camel_to_snail(s)[source]

Convert CamelCase to snail_case.

skchem.utils.free_to_snail(s)[source]

Convert Free Case to snail_case.

class skchem.utils.NamedProgressBar(name=None, **kwargs)[source]

Bases: progressbar.bar.ProgressBar

default_widgets()[source]
class skchem.utils.DummyProgressBar(*args, **kwargs)[source]

Bases: object

finish()[source]
update(val)[source]
skchem.utils.json_dump(obj, target=None)[source]

Write object as json to file or stream, or return as string.

skchem.utils.yaml_dump(obj, target=None)[source]

Write object as yaml to file or stream, or return as string.

skchem.utils.line_count(filename)[source]

Quickly count the number of lines in a file.

Adapted from http://stackoverflow.com/questions/845058/how-to-get-line-count-cheaply-in-python

Parameters:filename (str) – The name of the file to count for.
skchem.utils.sdf_count(filename)[source]

Efficiently count molecules in an sdf file.

Specifically, the function counts the number of times ‘$$$$’ occurs at the start of lines in the file.

Parameters:filename (str) – The filename of the sdf file.
Returns:the number of molecules in the file.
Return type:int
skchem.utils.iterable_to_series(mols)[source]
skchem.utils.nanarray(shape)[source]

Produce an array of NaN in provided shape.

Parameters:shape (tuple) – The shape of the nan array to produce.
Returns:np.array
skchem.utils.squeeze(data, axis=None)[source]

Squeeze dimension for length 1 arrays.

Parameters:
  • data (pd.Series or pd.DataFrame or pd.Panel) – The pandas object to squeeze.
  • axis (int or tuple) – The axes along which to squeeze.
Returns:

pd.Series or pd.DataFrame

skchem.utils.optional_second_method(func)[source]
class skchem.utils.Defaults(defaults)[source]

Bases: object

get(val)[source]