xenopict package
Submodules
xenopict.colormap module
- xenopict.colormap.install_colormaps() list[str]
xenopict.drawer module
- class xenopict.drawer.Xenopict(input_mol: Union[str, Mol, Xenopict], **kwargs)
Bases:
objectThis class draws an RDK molecule with sensible defaults, cleaning up the output SVG for easier modification and reduced size.
>>> from rdkit import Chem >>> import rdkit.Chem.rdPartialCharges >>> diclofenac = mol = Chem.MolFromSmiles('O=C(O)Cc1ccccc1Nc1c(Cl)cccc1Cl') >>> rdkit.Chem.rdPartialCharges.ComputeGasteigerCharges(mol)
Partial charge (scaled to be in [-1, 1])
>>> shading = np.array([a.GetDoubleProp("_GasteigerCharge") for a in mol.GetAtoms()]) >>> shading = shading / abs(shading).max()
SVG of molecule shaded by partial charge,
>>> drawer = Xenopict(mol) >>> drawer.shade(shading) <xenopict.drawer.Xenopict ...> >>> str(drawer) '<...>'
Atoms can also be annotated with a circle,
>>> drawer.mark_atoms([1, 2]) <xenopict.drawer.Xenopict ...>
The underlying svg dom (xml.dom.minidom) is accessible:
>>> drawer.svgdom <xml.dom.minidom.Document ...>
- add_atom_indices: bool = False
- add_bond_indices: bool = False
- cmap: Union[str, Colormap] = 'xenosite'
- color_map(color)
- diverging_cmap: bool = False
- down_scale: float = 0.7
- draw_mol(mol: Optional[Mol] = None)
- dummies_are_attachments: bool = False
- embed_script: bool = False
- get_cmap() Colormap
- mark_down_scale: float = 1.0
- mark_substructure(atoms: Sequence[int], substr_bonds: Optional[Sequence[Sequence[int]]] = None) Xenopict
- optimize_svg: bool = True
- scale: float = 20
- shade(atom_shading: Optional[Sequence[float]] = None, bond_shading: Optional[tuple[collections.abc.Sequence[int], collections.abc.Sequence[int], collections.abc.Sequence[float]]] = None) Xenopict
- shade_substructure(substrs_by_atoms: Sequence[Sequence[int]], shading: Sequence[float], substrs_bonds: Optional[Sequence[Optional[Sequence[Sequence[int]]]]] = None) Xenopict
shade_substructure shades a list of substruture, each one defined as a list of atom idxs.
By default, all the bonds connecting these structures are included. Optionally, a list of bonds can be provided instead.
- Args:
substrs_by_atoms (Sequence[Sequence[AtomIdx]]): A list of substructures, each one defined as a list of atoms.
shading (Sequence[float]): A list of shading intensities, one for each substructure.
substrs_bonds (Optional[Sequence[Sequence[AtomIdx]]], optional): Optionally specify the bonds to include for each substructure. Defaults to None.
- Returns:
Xenopict: Modifies object in place, but returns copy of self to enable chaining.
- shapely_resolution: int = 6
- substructure_focus(atoms: Sequence[int], substr_bonds: Optional[Sequence[Sequence[int]]] = None) Xenopict
- to_html(svg_datauri=False) str
Return the HTML string depicting the molecule, embedding the SVG element within a white-background styled div. Optionally, the SVG can be placed into an img tag’s datauri isntead.
- to_svg(uniquify_internal_refs: bool = True, hash_length: int = 10, svg_attributes: dict = {})
Convert Xenopict into an svg. By default, this function will uniquify all id/hrefs int the svg with the same md5 hash. This prevents id clashes in any documents into which svgs are embedded.
- xenopict.drawer.shaded_svg(mol, atom_shading: Optional[Sequence[float]] = None, bond_shading: Optional[tuple[collections.abc.Sequence[int], collections.abc.Sequence[int], collections.abc.Sequence[float]]] = None, **kwargs)
Functional interface to shade a molecule.
This is a simple functional interface to shading. More complex depictions should work directly with
Xenopict.>>> import rdkit.Chem.rdPartialCharges >>> from rdkit import Chem >>> diclofenac = mol = rdkit.Chem.MolFromSmiles('O=C(O)Cc1ccccc1Nc1c(Cl)cccc1Cl')
>>> rdkit.Chem.rdPartialCharges.ComputeGasteigerCharges(mol) >>> shading = np.array([a.GetDoubleProp("_GasteigerCharge") for a in mol.GetAtoms()]) >>> shading = shading / abs(shading).max() # partial charge (scaled to [-1, 1])
>>> shaded_svg(mol, shading) '<...>'
- Args:
- mol (RDKMol):
Rdkit molecule,
- atom_shading (AtomShading | None, optional):
Sequence of floats [-1,1] corresopnding to atom shades. Defaults to None.
- bond_shading (BondShading | None, optional):
Sequence of floats [-1,1]. Defaults to None.
- Returns:
SVG: SVG of the drawing.
xenopict.magic module
- xenopict.magic.install()
- xenopict.magic.patch_pandas()
- xenopict.magic.patch_rdkit()
- xenopict.magic.register_list_mol()
- xenopict.magic.register_minidom()
- xenopict.magic.register_rdkit()
xenopict.monkey module
- exception xenopict.monkey.BoostError
Bases:
RuntimeError
- class xenopict.monkey.BoostModulePatcher(mod=None, wrappers=None, depth=15)
Bases:
Patcher- after_call(result, args: tuple, kwargs: dict, func: Callable)
- before_call(args: tuple, kwargs: dict, func: Callable) tuple[tuple, dict]
- boost_wrapper(func)
- on_throw(func: Callable, args: tuple, kwargs: dict, exec_info)
- register_before_call(callback: Callable[[tuple, dict, Callable], tuple[tuple, dict]])
- exception xenopict.monkey.BoostTypeError
Bases:
TypeError
- class xenopict.monkey.Patcher(patches: Optional[list[xenopict.monkey.Patch]] = None)
Bases:
Patch- install()
- replace(obj, attr, new)
- uninstall()