Chython [ˈkʌɪθ(ə)n]

Library for processing molecules and reactions in python way.

Features:
  • Read/write/convert formats: MDL .RDF (.RXN) and .SDF (.MOL), .MRV, SMILES, INCHI (inchi-trust library), .XYZ, .PDB

  • Standardize molecules and reactions and valid structures checker

  • Supported python-magic

  • Tetrahedron, Allene and CIS-TRANS stereo supported

  • Perform subgraph search

  • Build/edit molecules and reactions with Python API

  • Produce template based reactions and molecules

  • Atom-to-atom mapping, checking and rule-based fixing

  • Perform MCS search

  • 2d coordinates generation (based on SmilesDrawer)

  • 2d/3d depiction with Jupyter support

  • SMARTS parser with restrictions

  • Protective groups remover

  • Common reaction templates collection

Full documentation can be found here.

CGRtools

Chython is fork of CGRtools.

Install

Only python 3.8+.

Note: for using clean2d install NodeJS into system.

  • stable version available through PyPI:

    pip install chython
    
  • Install chython library DEV version for features that are not well tested:

    pip install -U git+https://github.com/chython/chython.git@master#egg=chython
    

Contributors

CGRtools contributors are included too.

Chython package API

chython. pickle_cache = True - Store cached attributes in pickle. Effective for multiprocessing.

chython. torch_device = ‘cpu’ - Atom-to-Atom mapping model device in torch notation. Change before first reset_mapping call!

chython.depict_settings(*, carbon: bool = False, aam: bool = True, monochrome: bool = False, bond_color: str = 'black', aam_color: str = '#0305A7', atoms_colors: tuple = ('#909090', '#D9FFFF', '#CC80FF', '#C2FF00', '#FFB5B5', '#101010', '#3050F8', '#FF0D0D', '#90E050', '#B3E3F5', '#AB5CF2', '#8AFF00', '#BFA6A6', '#F0C8A0', '#FF8000', '#C6C600', '#1FF01F', '#80D1E3', '#8F40D4', '#3DFF00', '#E6E6E6', '#BFC2C7', '#A6A6AB', '#8A99C7', '#9C7AC7', '#E06633', '#F090A0', '#50D050', '#C88033', '#7D80B0', '#C28F8F', '#668F8F', '#BD80E3', '#FFA100', '#A62929', '#5CB8D1', '#702EB0', '#00FF00', '#94FFFF', '#94E0E0', '#73C2C9', '#54B5B5', '#3B9E9E', '#248F8F', '#0A7D8C', '#006985', '#C0C0C0', '#FFD98F', '#A67573', '#668080', '#9E63B5', '#D47A00', '#940094', '#429EB0', '#57178F', '#00C900', '#70D4FF', '#FFFFC7', '#D9FFC7', '#C7FFC7', '#A3FFC7', '#8FFFC7', '#61FFC7', '#45FFC7', '#30FFC7', '#1FFFC7', '#00FF9C', '#00E675', '#00D452', '#00BF38', '#00AB24', '#4DC2FF', '#4DA6FF', '#2194D6', '#267DAB', '#266696', '#175487', '#D0D0E0', '#FFD123', '#B8B8D0', '#A6544D', '#575961', '#9E4FB5', '#AB5C00', '#754F45', '#428296', '#420066', '#007D00', '#70ABFA', '#00BAFF', '#00A1FF', '#008FFF', '#0080FF', '#006BFF', '#545CF2', '#785CE3', '#8A4FE3', '#A136D4', '#B31FD4', '#B31FBA', '#B30DA6', '#BD0D87', '#C70066', '#CC0059', '#D1004F', '#D90045', '#E00038', '#E6002E', '#EB0026', '#EB0026', '#EB0026', '#EB0026', '#EB0026', '#EB0026', '#EB0026', '#EB0026', '#EB0026', '#EB0026'), bond_width: float = 0.04, wedge_space: float = 0.08, dashes: Tuple[float, float] = (0.2, 0.1), aromatic_dashes: Tuple[float, float] = (0.15, 0.05), dx_ci: float = 0.05, dy_ci: float = 0.2, dx_m: float = 0.05, dy_m: float = 0.2, span_dy: float = 0.15, double_space: float = 0.06, triple_space: float = 0.13, aromatic_space: float = 0.14, atom_radius: float = 0.2, bond_radius=0.02, font_size: float = 0.5, other_size: float = 0.3, span_size: float = 0.35, aam_size: float = 0.25, symbols_font_style: str = 'sans-serif', other_font_style: str = 'monospace', other_color: str = 'black', mapping_font_style: str = 'monospace')

Settings for depict of chemical structures

Parameters:
  • carbon – if True, depict atom C

  • font_size – font size

  • aam_size – atom-to-atom mapping font size

  • span_size – font size for hydrogen count

  • other_size – isotope, radical, charges, neighbors and hybridization symbols size

  • bond_width – bond width

  • bond_color – color of bonds

  • aam_color – atom-to-atom mapping color

  • atoms_colors – atom colors where key is atomic number - 1, value is atom color (str)

  • other_color – color for charges, radicals, isotopes

  • symbols_font_style – font style for atom symbols

  • other_font_style – font style for charges, radicals, isotopes, hybridization and neighbors

  • aam – if True, depict mapping

  • monochrome – if True, colors of items in molecule not used

  • dashes – first value is long of visible line, second is long of invisible line

  • aromatic_space – space between simple and aromatic bonds

  • triple_space – space between simple and triple bonds

  • double_space – space between simple and double bonds

  • aromatic_dashes – first value is long of visible line, second is long of invisible line

  • atom_radius – radius of atoms spheres in depict3d. if negative is multiplier to covalent radii

  • bond_radius – radius of bonds spheres in depict3d

  • dx_ci – x-axis offset relative to the center of the atom symbol for radical, charges, isotope

  • dy_ci – y-axis offset relative to the center of the atom symbol for radical, charges, isotope

  • dx_m – x-axis offset relative to the center of the atom symbol for atom-to-atom mapping

  • dy_m – y-axis offset relative to the center of the atom symbol for atom-to-atom mapping

  • span_dy – y-axis offset relative to the center of the atom symbol for hydrogen count

  • mapping_font_style – font style for mapping

  • wedge_space – wedge bond width

chython.inchi(data, /, *, ignore_stereo: bool = False, _cls=<class 'chython.containers.molecule.MoleculeContainer'>) MoleculeContainer

INCHI string parser

chython.mdl_mol(data: str, /, *, ignore=True, calc_cis_trans=False, ignore_stereo=False, remap=False, ignore_bad_isotopes=False, _cls=<class 'chython.containers.molecule.MoleculeContainer'>) MoleculeContainer

Parse string with mol file.

chython.smarts(data: str)

Parse SMARTS string.

  • stereo ignored.

  • only D, a, h, r and !R atom primitives supported.

  • bond order list and not bond supported.

  • [not]ring bond supported only in combination with explicit bonds, not bonds and bonds orders lists.

  • mapping, charge and isotopes supported.

  • list of elements supported.

  • A - treats as any element. <A> primitive (aliphatic) ignored.

  • M - treats as any metal..

  • <&> logic operator unsupported.

  • <;> logic operator is mandatory except (however preferable) for charge, isotope, stereo marks.

  • CXSMARTS radicals supported.

  • hybridization and heteroatoms count in CXSMARTS atomProp notation coded as <hyb> and <het> keys.

  • masked atom - chython.Reactor specific mark for masking reactant atoms from deletion.

    Coded in CXSMARTS atomProp as <msk> key with any value.

For example:

[C;r5,r6;a]-;!@[C;h1,h2] |^1:1,atomProp:1.hyb.24:1.het.0| - aromatic C member of 5 or 6 atoms ring
connected with non-ring single bond to aromatic or SP2 radical C with 1 or 2 hydrogens.

Alternative hybridization, heteroatoms and masks coding:

  • primitive <xN> - heteroatoms (e.g. x2 - two heteroatoms)

  • primitive <zN> - hybridization (N = 1 - sp3, 2 - sp2, 3 - sp, 4 - aromatic)

  • primitive <M> - masked atom

Note: atom numbers greater than 10 ** 9 forbidden for usage and reserved for masked atoms numbering. In multiprocess mode has potential bugs in reaction enumeration task then used templates prepared from components from different processes. For avoiding, prepare templates on single process and then share it.

chython.smiles(data, /, *, ignore: bool = True, remap: bool = False, ignore_stereo: bool = False, ignore_bad_isotopes: bool = False, keep_implicit: bool = False, ignore_carbon_radicals: bool = False, ignore_aromatic_radicals: bool = True, _r_cls=<class 'chython.containers.reaction.ReactionContainer'>, _m_cls=<class 'chython.containers.molecule.MoleculeContainer'>) MoleculeContainer | ReactionContainer

SMILES string parser

Parameters:
  • ignore – Skip some checks of data or try to fix some errors.

  • remap – Remap atom numbers started from one.

  • ignore_stereo – Ignore stereo data.

  • keep_implicit – keep given in smiles implicit hydrogen count, otherwise ignore on valence error.

  • ignore_bad_isotopes – reset invalid isotope mark to non-isotopic.

  • ignore_carbon_radicals – fill carbon radicals with hydrogen (X[C](X)X case).

  • ignore_aromatic_radicals – don’t treat aromatic tokens like c[c]c as radicals.

chython.xyz(matrix: ~typing.Sequence[~typing.Tuple[str, float, float, float]], charge=0, radical=0, radius_multiplier=1.25, atom_charge: ~typing.Sequence[int] | None = None, _cls=<class 'chython.containers.molecule.MoleculeContainer'>) MoleculeContainer

Subpackages

Notebooks