getRelevantSmiles method

Future<List<String>> getRelevantSmiles(
  1. String description
)

Uses Google Gemini AI to suggest relevant SMILES patterns based on the given application description.

Returns a list of valid SMILES strings.

Implementation

Future<List<String>> getRelevantSmiles(String description) async {
  final prompt =
      '''I'm a student that is very passion with chemistry and i hope that you will help me in the following task.
  Given the application: "$description", suggest 3-10 SMILES patterns representing
  key functional groups or structural motifs relevant to this application.
  Return ONLY valid SMILES strings, one per line, with no additional text.
  Example:
  C(=O)O
  c1ccccc1
  NC(=O)N
  ''';
  String systemInstruction =
      '''If a question is not related to organic chemistry of a specific application, respond with:
  "I specialize in organic chemistry. Please ask questions related to that field."''';

  final response = await generateContent(prompt, systemInstruction);

  // Extract SMILES using regex pattern
  final RegExp smilesRegex =
      RegExp(r'^[A-Za-z0-9@+\-\[\]\(\)\\/=#$.]+$', multiLine: true);
  final matches = smilesRegex.allMatches(response);

  if (matches.isEmpty) {
    throw Exception('No valid SMILES found in AI response');
  }

  return matches.map((m) => m.group(0)!).toList();
}