mordred package

modred descriptor calculator.

class mordred.Result(mol, r, d)[source]

Result type.

fill_missing(value=nan)[source]

Replace missing value to “value”.

Parameters:

value – value that missing value is replaced

Returns:

Result

drop_missing()[source]

Delete missing value.

Returns:

Result

items()[source]

Get items.

Returns:

Iterable[(Descriptor, value)]

keys()[source]

Get descriptors instances.

Returns:

Iterable[Descriptor]

values()[source]

Get descriptor values.

Returns:

Iterable[value]

asdict(rawkey=False)[source]

Convert Result to dict.

Parameters:

rawkey (bool) –

  • True: dict key is Descriptor instance

  • False: dict key is str

Returns:

dict

property ix

Access descriptor value by index.

>>> from mordred import Calculator, Lipinski
>>> from rdkit import Chem
>>> result = Calculator(Lipinski.Lipinski)(Chem.MolFromSmiles("C1CCCCC1"))
>>> result.ix[0]
True
property name

Access descriptor value by descriptor name or instance.

>>> from mordred import Calculator, descriptors
>>> from rdkit import Chem
>>> result = Calculator(descriptors)(Chem.MolFromSmiles("C1CCCCC1"))
>>> result.name["C2SP3"]
6
class mordred.Descriptor[source]

Abstract base class of descriptors.

mol

target molecule

Type:

rdkit.Mol

classmethod preset(version)[source]

Generate preset descriptor instances.

Returns:

preset descriptors

Return type:

Iterable[Descriptor]

abstract parameters()[source]

[abstractmethod] get __init__ arguments of this descriptor instance.

this method used in pickling and identifying descriptor instance.

Returns:

tuple of __init__ arguments

Return type:

tuple

to_json()[source]

Convert to json serializable dictionary.

Returns:

dictionary of descriptor

Return type:

dict

abstract calculate()[source]

[abstractmethod] calculate descriptor value.

Returns:

rtype

dependencies()[source]

Descriptor dependencies.

Returns:

dict[str, Descriptor or None] or None

property as_argument

Argument representation of descriptor.

Returns:

any

property mol

Get molecule.

Returns:

rdkit.Mol

property coord

Get 3D coordinate.

Returns:

coordinate matrix

Return type:

numpy.array[3, N]

fail(exception)[source]

Raise known exception and return missing value.

Raises:

MissingValueException

rethrow_zerodiv()[source]

[contextmanager] treat zero div as known exception.

rethrow_na(exception)[source]

[contextmanager] treat any exceptions as known exception.

classmethod from_json(obj)

Create Descriptor instance from json dict.

Parameters:

obj (dict) – descriptor dict

Returns:

descriptor

Return type:

Descriptor

class mordred.Calculator(descs=None, version=None, ignore_3D=False, config=None)[source]

descriptor calculator.

Parameters:
  • descs – see Calculator.register() method

  • ignore_3D – see Calculator.register() method

classmethod from_json(obj)[source]

Create Calculator from json descriptor objects.

Parameters:

obj (list or dict) – descriptors to register

Returns:

calculator

Return type:

Calculator

register_json(obj)[source]

Register Descriptors from json descriptor objects.

Parameters:

obj (list or dict) – descriptors to register

to_json()[source]

Convert descriptors to json serializable data.

Returns:

descriptors

Return type:

list

config(**configs)[source]

Set global configuration.

property descriptors

All descriptors.

you can get/set/delete descriptor.

Returns:

registered descriptors

Return type:

tuple[Descriptor]

register(desc, version=None, ignore_3D=False)[source]

Register descriptors.

Descriptor-like:
  • Descriptor instance: self

  • Descriptor class: use Descriptor.preset() method

  • module: use Descriptor-likes in module

  • Iterable: use Descriptor-likes in Iterable

Parameters:
  • desc (Descriptor-like) – descriptors to register

  • version (str) – version

  • ignore_3D (bool) – ignore 3D descriptors

echo(s, file=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, end='\n')[source]

Output message.

Parameters:
  • s (str) – message to output

  • file (file-like) – output to

  • end (str) – end mark of message

Returns:

None

map(mols, nproc=None, nmols=None, quiet=False, ipynb=False, id=-1)[source]

Calculate descriptors over mols.

Parameters:
  • mols (Iterable[rdkit.Mol]) – moleculars

  • nproc (int) – number of process to use. default: multiprocessing.cpu_count()

  • nmols (int) – number of all mols to use in progress-bar. default: mols.__len__()

  • quiet (bool) – don’t show progress bar. default: False

  • ipynb (bool) – use ipython notebook progress bar. default: False

  • id (int) – conformer id to use. default: -1.

Returns:

Iterator[Result[scalar]]

pandas(mols, nproc=None, nmols=None, quiet=False, ipynb=False, id=-1)[source]

Calculate descriptors over mols.

Returns:

pandas.DataFrame

mordred.get_descriptors_in_module(mdl, submodule=True)[source]

Get descriptors in module.

Parameters:
  • mdl (module) – module to search

  • submodule (bool) – search recursively

Returns:

Iterator[Descriptor]