xenopict package
Subpackages
Submodules
- xenopict.alignment module
- xenopict.colormap module
- xenopict.drawer module
XenopictXenopict.add_atom_indicesXenopict.add_bond_indicesXenopict.align_to()Xenopict.cmapXenopict.color_map()Xenopict.copy()Xenopict.diverging_cmapXenopict.down_scaleXenopict.draw_mol()Xenopict.dummies_are_attachmentsXenopict.embed_scriptXenopict.filter()Xenopict.from_smarts()Xenopict.get_cmap()Xenopict.groupsXenopict.halo()Xenopict.mark_atoms()Xenopict.mark_down_scaleXenopict.mark_substructure()Xenopict.molXenopict.optimize_svgXenopict.plot_dotXenopict.reframe()Xenopict.scaleXenopict.set_backbone_color()Xenopict.shade()Xenopict.shade_substructure()Xenopict.shapely_resolutionXenopict.substructure_focus()Xenopict.to_html()Xenopict.to_svg()
- xenopict.magic module
- xenopict.monkey module
- xenopict.plotdot module
Module contents
XenoPict: A library for molecular visualization with a focus on 2D depiction.
- class xenopict.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
-
mark_down_scale:
float= 1.0
-
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:
- xenopict.parse(spec)[source]
Parse a specification into a list of Xenopict objects.
This function serves as the main entry point for the declarative API. It accepts specifications in multiple formats and returns a list of Xenopict objects.
- Parameters:
spec (
Union[Dict[str,Any],XenopictSpec,str,Path]) – The specification for creating molecules. Can be one of: - A dict matching the XenopictSpec schema - A XenopictSpec instance - A JSON string matching the XenopictSpec schema - A Path to a JSON file containing a XenopictSpec- Return type:
List[Xenopict]- Returns:
List of Xenopict objects, one for each molecule in the specification
- Raises:
ValueError – If the input is invalid or required fields are missing
Examples
>>> # From a dict >>> spec = { ... "molecules": { ... "smiles": "CCO" ... } ... } >>> xenopicts = parse(spec) >>> len(xenopicts) 1
>>> # From a JSON string with marking >>> json_str = ''' ... { ... "molecules": [ ... { ... "smiles": "CCO", ... "mark": { ... "atoms": [0, 1] ... } ... }, ... { ... "smiles": "CCCO", ... "mark": { ... "substructure_atoms": [0, 1, 2] ... } ... } ... ] ... } ... ''' >>> xenopicts = parse(json_str) >>> len(xenopicts) 2
>>> # From a file path >>> from pathlib import Path >>> path = Path("molecules.json") >>> xenopicts = parse(path)