Skip to content

API Reference

LipidConverter

pylipidparse.converter.LipidConverter

Convert lipid shorthand notation to molecular structures.

This is the main public class. It wraps a cached pygoslin parser and dispatches to the appropriate structure builder for each lipid class.

Parameters

dialect : str Parsing dialect for pygoslin. Options: "LipidMaps" (default), "Goslin", "SwissLipids", "HMDB". cache_size : int Maximum number of parsed molecules to keep in the LRU cache. Set to 0 to disable caching (useful for memory-constrained environments).

Examples

from pylipidparse import LipidConverter conv = LipidConverter() conv.to_smiles("FA 18:1(9Z)") 'CCCCCCCC/C=C\CCCCCCCC(=O)O' conv.to_inchikey("PC 16:0/18:1(9Z)") 'XXXXXXXXXXXXXX-XXXXXXXXXX-N'

to_mol(lipid_name)

Convert a lipid name to an RDKit Mol object.

The returned molecule is sanitized and has stereochemistry assigned, but does NOT have 2D coordinates. Use :meth:to_mol_file or :meth:to_sdf for a molecule with 2D layout.

Parameters

lipid_name : str Lipid shorthand notation, e.g. 'PC 16:0/18:1(9Z)'.

Returns

Chem.Mol Sanitized RDKit molecule.

Raises

LipidParseError If the name cannot be parsed. UnsupportedLipidClassError If the lipid class is not yet supported. InsufficientStructuralDetailError If the input is species-level (sum composition). StructureGenerationError If molecule assembly fails.

to_smiles(lipid_name)

Convert a lipid name to a canonical SMILES string.

Parameters

lipid_name : str Lipid shorthand notation.

Returns

str Canonical SMILES string (RDKit canonical form).

to_inchi(lipid_name)

Convert a lipid name to an InChI string.

Parameters

lipid_name : str Lipid shorthand notation.

Returns

str or None InChI string, or None if InChI generation failed.

to_inchikey(lipid_name)

Convert a lipid name to an InChIKey string.

Parameters

lipid_name : str Lipid shorthand notation.

Returns

str or None InChIKey string (27-character hash), or None if generation failed.

to_mol_file(lipid_name, path, add_hydrogens=False)

Write a lipid structure to a MOL file (with 2D coordinates).

Parameters

lipid_name : str Lipid shorthand notation. path : str Output file path (should end in .mol). add_hydrogens : bool If True, add explicit hydrogens before writing.

to_sdf(lipid_names, path, add_hydrogens=False)

Write one or more lipid structures to an SDF file.

Each molecule in the SDF has the following properties: - _Name: lipid shorthand name - SMILES: canonical SMILES - InChIKey: InChIKey

Parameters

lipid_names : str or list of str Lipid shorthand notation(s). path : str Output file path (should end in .sdf). add_hydrogens : bool If True, add explicit hydrogens before writing.

clear_cache()

Clear the molecule cache.

Exceptions

pylipidparse.exceptions.PyLipidParseError

Bases: Exception

Base exception for all PyLipidParse errors.

pylipidparse.exceptions.LipidParseError

Bases: PyLipidParseError

Raised when pygoslin cannot parse the input lipid string.

pylipidparse.exceptions.UnsupportedLipidClassError

Bases: PyLipidParseError

Raised when the lipid class is recognized but not yet supported.

pylipidparse.exceptions.InsufficientStructuralDetailError

Bases: PyLipidParseError

Raised when the input is species-level (sum composition) and a unique structure cannot be generated.

Example: 'PC 34:1' without explicit chain breakdown cannot produce a unique SMILES. Use full structural notation like 'PC 16:0/18:1(9Z)' instead.

pylipidparse.exceptions.StructureGenerationError

Bases: PyLipidParseError

Raised when the molecular structure cannot be assembled (invalid chemistry).