// Description: This component provides a user interface for validating and standardizing chemical structures using SMILES notation. It includes input handling, error checking, and displays results with appropriate messaging and styling for both light and dark themes. import { useState } from "react"; // Ensure all used icons are imported // Assuming these components are correctly implemented and styled for dark/light mode import SMILESInput from "../common/SMILESInput"; import MoleculeCard from "../common/MoleculeCard"; import { checkStructureErrors } from "../../services/chemService"; // Assuming this service exists import { AlertCircle, Check, Info, PencilLine, ShieldCheck, Loader2 } from "lucide-react"; import { ToolSkeleton } from "@/components/feedback/ToolSkeleton"; import { GlassErrorCard } from "@/components/feedback/GlassErrorCard"; import { EmptyState } from "@/components/feedback/EmptyState"; import { getErrorMessage } from "@/lib/error-messages"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; const StructureErrorView = () => { const [smiles, setSmiles] = useState(""); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const [result, setResult] = useState(null); // Stores { original: { smi, messages }, standardized: { smi, messages } } const [fix, setFix] = useState(true); // Option to attempt fixing issues // Handle form submission const handleSubmit = async (e) => { e.preventDefault(); const trimmedSmiles = smiles.trim(); if (!trimmedSmiles) { setError("Please enter a SMILES string."); setResult(null); // Clear previous results return; } setLoading(true); setError(null); setResult(null); // Clear previous results before fetching try { // Call the service function const validationResult = await checkStructureErrors(trimmedSmiles, fix); setResult(validationResult); // Optional: Check if standardized structure is same as original even if messages exist // if (fix && validationResult?.standardized?.smi === validationResult?.original?.smi) { // // Could set an info message here if desired // } } catch (err) { console.error("Structure check error:", err); // Log the error setError(getErrorMessage("chem", err)); setResult(null); // Ensure result is null on error } finally { setLoading(false); } }; // Render validation messages with appropriate styling const renderMessages = (messages) => { // Handle null or empty messages array if (!messages || messages.length === 0) { // Optionally return a default "No messages" state or null return (
This tool checks chemical structures for potential issues (e.g., incorrect valences, invalid aromaticity) using the ChEMBL structure curation pipeline.
Enable the "Attempt to fix" option to apply standardization rules (normalization, aromaticity perception, etc.) to resolve common problems and generate a standardized representation.