Ergonomical cheminformatics library
Project description
ergochemics
Ergonomical cheminformatics library
Modules
ergochemics.draw| Convenient drawing functions for molecules and reactions.ergochemics.mapping| For mapping reaction rules to reactions, generating atom-mapped reactions, and extracting reaction centers.ergochemics.standardize| Customizable molecule and reaction standardization techniques.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
Release history Release notifications | RSS feed
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.2.0.tar.gz
(24.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ergochemics-0.2.0.tar.gz.
File metadata
- Download URL: ergochemics-0.2.0.tar.gz
- Upload date:
- Size: 24.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
476d9eb61b92db2ad3dda9d5d70f0664b04dc32baa3febbe3667419c8a66512c
|
|
| MD5 |
37bcadeb20dbc4d50f7f4daad83f1ef7
|
|
| BLAKE2b-256 |
2e9b7ab5bce83beb624ea1ddad1f81d31ae4dd658e2e05a0a16a9e679a29166a
|
File details
Details for the file ergochemics-0.2.0-py3-none-any.whl.
File metadata
- Download URL: ergochemics-0.2.0-py3-none-any.whl
- Upload date:
- Size: 22.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f5bceb9ceab73de6ca38b4254e15bc086c06054d1b8bd0a4ac857505e75d61e4
|
|
| MD5 |
d28371e6ac32c8e4f6e09aa040c6cf7e
|
|
| BLAKE2b-256 |
e15e4b2392175a68112c1e83188c8c703de5333b16742bb7af918961ce0a6004
|