xenopict.declarative package
Submodules
Module contents
Declarative API for xenopict.
This module provides a high-level interface for creating molecule visualizations using JSON-like specifications. It supports both single and multiple molecule visualizations with automatic alignment.
- xenopict.declarative.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)