parse static method
- String smiles
Parses a SMILES string and returns structural information about the molecule.
Returns a map containing:
- atomCounts: Map of element symbols to counts
- bondCounts: Map of bond types to counts
- rings: Number of rings in the structure
- branches: Number of branches in the structure
- aromaticAtoms: Number of aromatic atoms
- molecularFormula: The molecular formula (if simple parsing is possible)
Implementation
static Map<String, dynamic> parse(String smiles) {
if (smiles.isEmpty) {
return {'error': 'Empty SMILES string'};
}
final result = <String, dynamic>{
'atomCounts': <String, int>{},
'bondCounts': <String, int>{
'single': 0,
'double': 0,
'triple': 0,
'aromatic': 0,
},
'rings': 0,
'branches': 0,
'aromaticAtoms': 0,
};
try {
_countAtoms(smiles, result);
_countBonds(smiles, result);
_countRings(smiles, result);
_countBranches(smiles, result);
_countAromaticAtoms(smiles, result);
return result;
} catch (e) {
return {'error': 'Failed to parse SMILES: $e'};
}
}