xenopict.drawer module
Core drawing functionality for xenopict.
- class xenopict.drawer.Xenopict(input_mol, **kwargs)[source]
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
- align_to(template)[source]
Align this molecule to a template molecule using MCS.
This method aligns the current molecule to match the orientation of the template molecule by finding their maximum common substructure. The alignment is done in-place, modifying the current molecule’s coordinates.
- Parameters:
template (
Union[str,Mol,Xenopict]) – Template molecule to align to. Can be: - SMILES string - RDKit Mol object - Another Xenopict object- Return type:
- Returns:
self for method chaining
Examples
>>> from rdkit import Chem >>> # Create ethanol and align propanol to it >>> ethanol = Xenopict("CCO") >>> propanol = Xenopict("CCCO") >>> propanol.align_to(ethanol) # Aligns by OH group <xenopict.drawer.Xenopict ...>
-
cmap:
Union[str,Colormap] = 'xenosite'
-
diverging_cmap:
bool= False
-
down_scale:
float= 0.7
-
dummies_are_attachments:
bool= False
-
embed_script:
bool= False
- filter(atoms, bonds)[source]
Filter the molecule to show only the specified atoms and bonds.
- Return type:
- classmethod from_smarts(smarts, **kwargs)[source]
Create a Xenopict object from a SMARTS pattern.
- Parameters:
smarts (
str) – SMARTS pattern string**kwargs – Additional arguments passed to Xenopict constructor
- Return type:
- Returns:
Xenopict object initialized with the SMARTS pattern
-
groups:
dict[str,Element]
-
mark_down_scale:
float= 1.0
-
mol:
Mol
-
optimize_svg:
bool= True
-
scale:
float= 20
- set_backbone_color(color)[source]
Set the color of the molecule’s backbone and atom labels.
- Parameters:
color (
str) – Hex color code (e.g. ‘#FF0000’ for red)- Return type:
- Returns:
self for method chaining
- shade_substructure(substrs_by_atoms, shading, substrs_bonds=None)[source]
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.
- Parameters:
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
None. (to include for each substructure. Defaults to)
- Returns:
Modifies object in place, but returns copy of self to enable chaining.
- Return type:
-
shapely_resolution:
int= 6
- substructure_focus(atoms, substr_bonds=None)[source]
Focus on a substructure by dimming the rest of the molecule.
- Return type:
-
add_atom_indices: