generateIupacName method

Future<String?> generateIupacName(
  1. String smiles
)

Generates an IUPAC name from a SMILES notation using PubChem API.

Returns the IUPAC name as a string if successful. Returns null if an error occurs or the compound cannot be found.

Example:

final namer = IupacNaming();
final iupacName = await namer.generateIupacName('CCO');
print(iupacName); // 'ethanol'

Implementation

Future<String?> generateIupacName(String smiles) async {
  try {
    // Step 1: Convert SMILES to CID using PubChem API
    final cidList = await _getSmilesAsCid(smiles);
    if (cidList.isEmpty) {
      return null;
    }

    // Step 2: Get the compound properties using the first CID
    final cid = cidList.first;
    final properties = await _getCompoundProperties(cid);

    // Step 3: Extract and return the IUPAC name
    return properties['name'];
  } catch (e) {
    print('Error generating IUPAC name: $e');
    return null;
  }
}