##Instruction:
Database: toxicology
Total Tables: 4
Total Columns: 11

Table Schemas:

Database: toxicology
Total Tables: 4
Total Columns: 11

Table Schemas:

Table: atom (3 columns)
-----------------------
• atom_id (text): the unique id of atoms
• molecule_id (text): identifying the molecule to which the atom belongs
  Values: commonsense evidence:
TRXXX_i represents ith atom of molecule TRXXX
• element (text): the element of the toxicology
  Values:  cl: chlorine
 c: carbon
 h: hydrogen
 o: oxygen
 s: sulfur
 n: nitrogen
 p: phosphorus
 na:...

Table: bond (3 columns)
-----------------------
• bond_id (text): unique id representing bonds
  Values: TRxxx_A1_A2:
TRXXX refers to which molecule
A1 and A2 refers to which atom
• molecule_id (text): identifying the molecule in which the bond appears
• bond_type (text): type of the bond
  Values: commonsense evidence:
-: single bond
'=': double bond
'#': triple bond

Table: connected (3 columns)
----------------------------
• atom_id (text): id of the first atom
• atom_id2 (text): id of the second atom
• bond_id (text): bond id representing bond between two atoms

Table: molecule (2 columns)
---------------------------
• molecule_id (text): unique id of molecule
  Values: "+" --> this molecule / compound is carcinogenic
'-' this molecule is not / compound carcinogenic
• label (text): whether this molecule is carcinogenic or not

##Evidence:
TR000_2 refers to atom_id2; bond classification includes 'Contains Chlorine' for bonds with chlorine atoms, 'Carbon-Carbon Bond' for bonds between two carbon atoms, and 'Other Bond Type' for remaining bonds

##Role Access Policy (Column-Level):
Role: MolecularViewer
Accessible Columns: molecule: ALL COLUMNS; atom: atom_id, element; bond: bond_id, bond_type

Based on the above schema and your role's column-level access policy, generate a SQL query to answer the question. If your role does not have access to the required columns, respond with: "Sorry, I cannot answer."


Question: For all bonds connected to atom TR000_2, what are the bond details including the connected atoms, their elements, bond types, bond classifications, and the molecule's atom and bond counts?
Evidence: TR000_2 refers to atom_id2; bond classification includes 'Contains Chlorine' for bonds with chlorine atoms, 'Carbon-Carbon Bond' for bonds between two carbon atoms, and 'Other Bond Type' for remaining bonds
Answer: Sorry, I cannot answer.
Permission: denied (Missing column permissions: connected: atom_id, atom_id2, bond_id; bond: molecule_id; atom: molecule_id)
Gold SQL: WITH MoleculeInfo AS (
    SELECT 
        m.molecule_id,
        m.label,
        COUNT(DISTINCT a.atom_id) AS atom_count,
        COUNT(DISTINCT b.bond_id) AS bond_count
    FROM 
        molecule m
    LEFT JOIN 
        atom a ON m.molecule_id = a.molecule_id
    LEFT JOIN 
        bond b ON m.molecule_id = b.molecule_id
    GROUP BY 
        m.molecule_id, m.label
),
AtomConnections AS (
    SELECT 
        c.bond_id,
        c.atom_id,
        c.atom_id2,
        a1.element AS element1,
        a2.element AS element2,
        b.bond_type,
        b.molecule_id,
        ROW_NUMBER() OVER (PARTITION BY b.molecule_id ORDER BY c.bond_id) AS connection_rank
    FROM 
        connected c
    JOIN 
        atom a1 ON c.atom_id = a1.atom_id
    JOIN 
        atom a2 ON c.atom_id2 = a2.atom_id
    JOIN 
        bond b ON c.bond_id = b.bond_id
    WHERE 
        c.atom_id2 = 'TR000_2'
)
SELECT 
    ac.bond_id,
    ac.atom_id AS connected_from,
    ac.atom_id2 AS connected_to,
    ac.element1 || '-' || ac.element2 AS connection_elements,
    ac.bond_type,
    mi.label AS molecule_label,
    CASE 
        WHEN ac.element1 = 'cl' OR ac.element2 = 'cl' THEN 'Contains Chlorine'
        WHEN ac.element1 = 'c' AND ac.element2 = 'c' THEN 'Carbon-Carbon Bond'
        ELSE 'Other Bond Type'
    END AS bond_classification,
    mi.atom_count,
    mi.bond_count,
    ac.connection_rank
FROM 
    AtomConnections ac
JOIN 
    MoleculeInfo mi ON ac.molecule_id = mi.molecule_id
ORDER BY 
    ac.molecule_id, ac.connection_rank;