mordred Documentation

repository·develop·Indexed 19 days ago

https://github.com/mordred-descriptor/mordred

A molecular descriptor calculator for cheminformatics used to compute a wide range of 2D and 3D molecular descriptors for chemical structures. It provides a Python library featuring the Calculator, Descriptor, and Result classes, as well as a CLI tool for processing SMILES, SDF, and MOL files. The package includes matrix aggregating methods for spectral, eigenvector, and vibrational/ring properties.

Tokens
1.7K
Snippets
5
Records
10
Agent score
67%

What's inside mordred

  1. Core classes in the mordred package

    develop

    The mordred package provides the primary interfaces for molecular descriptor calculation:

    • mordred.Calculator: The main engine used to compute descriptors for molecules.
    • mordred.Descriptor: Represents an individual molecular descriptor.
    • mordred.Result: Represents the outcome of a descriptor calculation for a specific molecule.
  2. How the Calculator class works

    develop

    The Calculator class is the primary interface for computing molecular descriptors.

    • Initialization: You pass a collection of descriptors (usually the descriptors object) to the constructor.
    • 3D Descriptors: By default, Calculator may include 3D descriptors. To restrict to 2D descriptors, use ignore_3D=True. To explicitly use 3D descriptors, ensure your input molecules have 3D coordinates (from SDF or MOL files) and use the -3 flag in CLI or appropriate settings in the library.
    • Output Formats: When used as a library, the calculator can return results as a list/sequence or directly as a pandas.DataFrame using the .pandas(mols) method.
  3. Install mordred via pip

    develop

    To install via pip, you must first install the rdkit python package. You can then install mordred either with extra requirements (recommended for full functionality) or as a standard package.

    # Install with extra requirements
    $ pip install 'mordred[full]'
    
    # Or standard install
    $ pip install mordred
  4. Install mordred via conda

    develop

    The recommended way to install mordred is using conda. Ensure you have miniconda or anaconda installed first, then run the following command to install mordred from the mordred-descriptor channel.

    $ conda install -c rdkit -c mordred-descriptor mordred
  5. Use mordred as a Python library

    develop

    To use mordred in your code, import Calculator and descriptors. You typically initialize a Calculator with a set of descriptors and then pass RDKit molecule objects to it.

    from rdkit import Chem
    from mordred import Calculator, descriptors
    
    # Create a calculator (ignore_3D=True for 2D descriptors)
    calc = Calculator(descriptors, ignore_3D=True)
    
    # Calculate descriptors for a single molecule
    mol = Chem.MolFromSmiles('c1ccccc1')
    results = calc(mol)
    print(results[:3])  # Access first 3 descriptors
    
    # Calculate descriptors for multiple molecules
    mols = [Chem.MolFromSmiles(smi) for smi in ['c1ccccc1Cl', 'c1ccccc1O', 'c1ccccc1N']]
    results_list = calc.pandas(mols)
    print(results_list['SLogP'])
  6. Retrieve descriptors from modules

    develop

    Use the following functions to discover and collect descriptors available within specific Python modules:

    • get_descriptors_in_module(module): Retrieves descriptors contained within a given module.
    • get_descriptors_from_module(module): Retrieves descriptors from a specified module.
  7. Matrix aggregating methods reference

    develop

    Mordred includes several matrix aggregating methods used to derive descriptors from eigenvalues ($\lambda_i$) and eigenvectors ($\ell_i$). These methods are categorized into spectral properties (Sp), eigenvector properties (VE), and vibrational/ring properties (VR).

    Spectral Properties

    • SpAbs: Sum of absolute eigenvalues: $\sum |\lambda_i|$
    • SpMax: Maximum eigenvalue: $\max \lambda_i$
    • SpDiam: Spectral diameter: $\text{SpMax} - \text{SpMin}$
    • SpAD: Sum of absolute deviations from the mean eigenvalue: $\sum |\lambda_i - \bar{\lambda}|$
    • SpMAD: Mean absolute deviation: $\text{SpAD} / A$ (where $A$ is the number of atoms)
    • LogEE: Log-sum-exp of eigenvalues: $\log(\sum \exp(\lambda_i))$
    • SM1: Sum of eigenvalues: $\sum \lambda_i$

    Eigenvector Properties

    • VE1: Sum of absolute elements of the eigenvector corresponding to the leading eigenvalue: $\sum |\ell_i|$
    • VE2: Normalized VE1: $\text{VE1} / A$
    • VE3: Log-scaled VE1: $\log(\frac{A}{10} \cdot \text{VE1})$. Returns NaN if $\text{VE1} = 0$.

    Vibrational/Ring Properties

    • VR1: Sum of inverse square roots of products of eigenvector elements for bonded atoms: $\sum_{(i, j) \in \text{bonds}} (\ell_i \cdot \ell_j)^{-1/2}$
    • VR2: Normalized VR1: $\text{VR1} / A$
    • VR3: Log-scaled VR1: $\log(\frac{A}{10} \cdot \text{VR1})$. Returns NaN if $\text{VR1} = 0$.
  8. mordred CLI options reference

    develop

    The following flags are available when running python -m mordred:

    FlagDescription
    -h, --helpShow this help message and exit
    --versionShow version
    -t, --type {auto,sdf,mol,smi}Input filetype (default: auto)
    -o OUTPUT, --output OUTPUTOutput file path (default: stdout)
    -p PROCESSES, --processes PROCESSESNumber of processes (default: number of logical processors)
    -q, --quietHide progress bar
    -s, --streamStream read (low memory)
    -d DESC, --descriptor DESCDescriptors to calculate (default: all)
    -3, --3DUse 3D descriptors (requires sdf or mol file)
    -v, --verbosityVerbosity level
  9. Use mordred as a CLI tool

    develop

    You can use mordred directly from the command line to calculate descriptors for molecules provided in files (SMILES, SDF, or MOL).

    # Calculate all descriptors for a SMILES file
    $ python -m mordred example.smi
    
    # Save results to a CSV file
    $ python -m mordred example.smi -o example.csv
    
    # Stream read (low memory usage, no molecule count info)
    $ python -m mordred example.smi -s -o example.csv
    
    # Calculate specific descriptors (e.g., ABCIndex)
    $ python -m mordred example.smi -d ABCIndex
    
    # Calculate multiple descriptors (e.g., ABCIndex and AcidBase)
    $ python -m mordred example.smi -d ABCIndex -d AcidBase
    
    # Process multiple input files
    $ python -m mordred example.smi example2.smi -d ABCIndex