fuellib.gcm.core.Decomposer

class fuellib.gcm.core.Decomposer(method, table_groups, first_order_groups)

Bases: object

Decompose molecules into groups for a Group Contribution Method.

Subclasses with second order groups should override second_order_counts.

Initialize the decomposer with a GCM’s group data.

Parameters:
  • method (str) – Display name of the GCM used in error messages.

  • table_groups (Index) – Group names that are columns of the GCM parameter table.

  • first_order_groups (Sequence[tuple[str, str]]) – (group name, SMARTS) pairs ordered by priority.

Methods

context

Build the shared prefix of every decomposition error message.

first_order_counts

Count first order groups, requiring that they cover every atom.

parse_smarts

Parse a SMARTS pattern used to decompose a molecule.

parse_smiles

Validate and parse a SMILES string.

second_order_counts

Count second order groups.

__init__(method, table_groups, first_order_groups)

Initialize the decomposer with a GCM’s group data.

Parameters:
  • method (str) – Display name of the GCM used in error messages.

  • table_groups (Index) – Group names that are columns of the GCM parameter table.

  • first_order_groups (Sequence[tuple[str, str]]) – (group name, SMARTS) pairs ordered by priority.

Return type:

None

context(smiles)

Build the shared prefix of every decomposition error message.

Parameters:

smiles (str) – The SMILES string being decomposed.

Returns:

The message prefix naming the method and SMILES string.

Return type:

str

first_order_counts(mol, smiles)

Count first order groups, requiring that they cover every atom.

Parameters:
  • mol (Mol) – The parsed molecule.

  • smiles (str) – The SMILES string being decomposed, used in error messages.

Returns:

A mapping of first order group name to its number of occurrences.

Raises:

ValueError – If a SMARTS pattern is invalid or any atom is not matched to a first order group.

Return type:

dict[str, int]

parse_smarts(smiles, smarts)

Parse a SMARTS pattern used to decompose a molecule.

Parameters:
  • smiles (str) – The SMILES string being decomposed, used in error messages.

  • smarts (str) – The SMARTS pattern to parse.

Returns:

The RDKit query molecule.

Raises:

ValueError – If the SMARTS pattern is invalid.

Return type:

Mol

parse_smiles(smiles)

Validate and parse a SMILES string.

Non-string values, such as the NaN pandas produces for a blank CSV cell, are rejected, as are empty strings (RDKit would parse those as an empty molecule).

Parameters:

smiles (str) – The SMILES string to parse.

Returns:

The parsed RDKit molecule.

Raises:

ValueError – If the SMILES is not a non-empty string or cannot be parsed.

Return type:

Mol

second_order_counts(mol, smiles)

Count second order groups.

Override in GCMs that define second order groups. The default has none.

Parameters:
  • mol (Mol) – The parsed molecule.

  • smiles (str) – The SMILES string being decomposed, used in error messages.

Returns:

A mapping of second order group name to its number of occurrences.

Return type:

dict[str, int]