luna.mol.features module

class ChemicalFeature(name)[source]

Bases: object

Define chemical features as for example pharmacophore properties.

Parameters

name (str) – The chemical feature name.

format_name(case_func='sentencecase')[source]

Convert chemical feature names to another string case.

Parameters

name (str) – The name of a string case function from luna.util.stringcase.

class FeatureExtractor(feature_factory)[source]

Bases: object

Perceive chemical features from molecules.

Parameters

feature_factory (MolChemicalFeatureFactory) – An RDKit feature factory.

Examples

First, let’s read a molecule (glutamine).

>>> from luna.wrappers.base import MolWrapper
>>> mol = MolWrapper.from_smiles("N[C@@H](CCC(N)=O)C(O)=O").unwrap()

Now, create a feature factory and instantiate a new FeatureExtractor object.

>>> from luna.util.default_values import ATOM_PROP_FILE
>>> from rdkit.Chem import ChemicalFeatures
>>> from luna.mol.features import FeatureExtractor
>>> feature_factory = ChemicalFeatures.BuildFeatureFactory(ATOM_PROP_FILE)
>>> feature_extractor = FeatureExtractor(feature_factory)

Finally, you can extract features by group or atom.

>>> features = feature_extractor.get_features_by_atoms(mol)
>>> features = feature_extractor.get_features_by_groups(mol)
get_features_by_atoms(mol_obj, atm_map=None)[source]

Perceive chemical features from the molecule mol_obj by atom.

Parameters
  • mol_obj (MolWrapper, rdkit.Chem.rdchem.Mol, or openbabel.pybel.Molecule) – The molecule.

  • atm_map (dict) – A dictionary to map an atom’s index to a different value.

Returns

atm_features – Chemical features by atoms that are represented by their index or by a value from atm_map.

Return type

dict of {int : list of ChemicalFeature}

get_features_by_groups(mol_obj, atm_map=None)[source]

Perceive chemical features from the molecule mol_obj by atom groups.

Parameters
  • mol_obj (MolWrapper, rdkit.Chem.rdchem.Mol, or openbabel.pybel.Molecule) – The molecule.

  • atm_map (dict) – A dictionary to map an atom’s index to a different value.

Returns

grp_features – Chemical features by groups. Each dictionary value is defined as follows:

  • atm_ids (list): list of atoms represented by their index or by a value from atm_map ;

  • features (list of ChemicalFeature): list of chemical features.

Return type

dict of {str : dict}

class OBMolChemicalFeature(family, atom_ids)[source]

Bases: object

Mimic rdkit.Chem.rdMolChemicalFeatures.MolChemicalFeature for Open Babel.

Parameters
  • family (str) – The family name, which is the term used by RDKit for chemical features.

  • atom_ids (list) – List of atom identifiers.

GetAtomIds()[source]

Get the IDs of the atoms that participate in the feature.

GetFamily()[source]

Get the family to which the feature belongs (e.g., donor, acceptor, etc.)