Skip to main content

Ergonomical cheminformatics library

Project description

ergochemics

Ergonomical cheminformatics library

Modules

  1. ergochemics.draw | Convenient drawing functions for molecules and reactions.
  2. ergochemics.mapping | For mapping reaction rules to reactions, generating atom-mapped reactions, and extracting reaction centers.
  3. ergochemics.standardize | Customizable molecule and reaction standardization techniques.
  4. ergochemics.similarity | Featurization and similarity for molecules and reactions.

Basic Usage

Full example notebooks available here.

from ergochemics.draw import draw_molecule, draw_reaction
from ergochemics.mapping import operator_map_reaction, get_reaction_center
from ergochemics.standardize import (
    standardize_mol,
    standardize_smiles,
    standardize_reaction,
    hash_molecule,
    hash_reaction
)
from ergochemics.similarity import (
    MorganFingerprinter,
    ReactionFingerprinter,
    MolFeaturizer,
)
from IPython.display import SVG, display
from rdkit import Chem

Draw molecules

glutamic_acid_smi = 'C(CC(=O)[O-])[C@@H](C(=O)O)N'
glutamic_acid_mol = Chem.MolFromSmiles(glutamic_acid_smi)
glutamic_acid_mol.GetAtomWithIdx(4).SetProp('atomNote', ' pKa=4.15')
display(
    SVG(
        draw_molecule(
            molecule=glutamic_acid_mol,
            size=(400, 250),
            highlight_atoms=(0, 5, 6, 9),
            draw_options={
                'addAtomIndices': True, # Example of a property set to `True`
                'addBondIndices': False, # Example of a property set to `False`
                'setHighlightColour': (0.2, 0.8, 0.2, 0.9), # Example of a callable that takes a tuple argument; pass a tuple
                'useBWAtomPalette': None, # Example of a callable that takes no arguments; pass `None`
                'addStereoAnnotation': True

            },
            legend="L-Glutamate (chiral tetrahedral highlighted in green)"
        )
    )
)

Draw reactions

decarboxylation = 'C(CC(=O)[O-])[C@@H](C(=O)O)N>>C(CC(=O)[O-])CN.O=C=O'
display(
    SVG(
        draw_reaction(
            rxn=decarboxylation,
            sub_img_size=(300, 200),
            draw_options={
                'addAtomIndices': True,
                'comicMode': True,
            },
        )
    )
)

Map rules to reactions

rule = "[O:1][C:2][C:3][N:4]>>[C:3][N:4].[O:1]=[C:2]"
res = operator_map_reaction(rxn=decarboxylation, operator=rule)
print(f"Did the rule map the reaction?  {res.did_map}")
print(f"Atom mapped reaction: {res.atom_mapped_smarts}")
print(f"Indices of the atoms that matched the rule's template: {res.template_aidxs}")

Output:

>>>Did the rule map the reaction?  True
>>>Atom mapped reaction: [NH2:2][CH:1]([CH2:3][CH2:4][C:5](=[O:6])[OH:7])[C:9](=[O:10])[OH:8]>>[NH2:2][CH2:1][CH2:3][CH2:4][C:5](=[O:6])[OH:7].[O:8]=[C:9]=[O:10]
>>>Indices of the atoms that matched the rule's template: (((9, 7, 1, 0),), ((0, 1), (0, 1)))

Get reaction center

print(f"Separate: {get_reaction_center(res.atom_mapped_smarts, mode="separate")}")
print(f"Combined: {get_reaction_center(res.atom_mapped_smarts, mode="combined")}")
>>>Separate: (((1, 7, 9),), ((1,), (0, 1)))
>>>Combined: ((1, 7, 9), (1, 7, 8))

Standardize molecules

std_mol = standardize_mol(glutamic_acid_mol)
std_mol_w_stereo = standardize_mol(glutamic_acid_mol, do_remove_stereo=False)
size = (400, 200)
display(SVG(draw_molecule(glutamic_acid_mol, size=size, legend="Original")))
display(SVG(draw_molecule(std_mol_w_stereo, size=size, legend="Standardized (stereo kept)")))
display(SVG(draw_molecule(std_mol, size=size, legend="Standardized (stereo removed)")))

Customizable Morgan fingerprints

def constant_atom_featurizer(atom: Chem.Atom) -> list[float | int]:
    return [1.0]

std_mol = Chem.MolFromSmiles(standardize_smiles(glutamic_acid_smi))
gcc = Chem.MolFromSmiles('CC(=C)CCC(C)C(=C)C')

display(
    SVG(
        draw_molecule(
            gcc,
            size=(300, 200),
            legend="Glutamate's carbonaceous cousin"
        )
    )
)

topology_featurizer = MolFeaturizer(
    atom_featurizer=constant_atom_featurizer
)

topo_mfper = MorganFingerprinter(
    radius=2,
    length=1024,
    mol_featurizer=topology_featurizer
)

gcc_topo_mfp = topo_mfper.fingerprint(gcc)
glutamate_topo_mfp = topo_mfper.fingerprint(std_mol)

assert np.allclose(gcc_topo_mfp, glutamate_topo_mfp)

Reaction-center-sensitive reaction fingerprints

rxn_mfper = ReactionFingerprinter(
    radius=2,
    length=1024,
    mol_featurizer=MolFeaturizer()
)

rxnfp_w_rc_loc = rxn_mfper.fingerprint(am_rxn, use_rc=True)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ergochemics-0.1.2.tar.gz (23.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ergochemics-0.1.2-py3-none-any.whl (22.1 kB view details)

Uploaded Python 3

File details

Details for the file ergochemics-0.1.2.tar.gz.

File metadata

  • Download URL: ergochemics-0.1.2.tar.gz
  • Upload date:
  • Size: 23.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.21

File hashes

Hashes for ergochemics-0.1.2.tar.gz
Algorithm Hash digest
SHA256 8d9a0eb643c44bf929e2c31faa21142ae0d74ae248808d98de9283120a90faf2
MD5 f65bd4d007f0ed49369d61eee63817c5
BLAKE2b-256 fa9ac441e42656ef523b1297faa47f92b4b513b804ba6c54e4a8aac178e807d3

See more details on using hashes here.

File details

Details for the file ergochemics-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for ergochemics-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 07b0a54bfd586132d8204e8f60bfc1cc006b02e47c9050846897babeac424e83
MD5 164f3f03554cabc84e3842f751d8dd0c
BLAKE2b-256 e9f3eed35cdaa28bb1b7602e47b2db8527bb25e8748cc83e3ee899d6232aec1d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page