[Tex/LaTex] How to draw/annotate with TikZ on molecules drawn with chemfig package

chemfigtikz-pgf

I have just discovered the TikZ spin-off chemfig package for chemistry drawings. I just wanted to add some transparent box to highlight a certain region of the drawn molecule with some text using relative nodes with TikZ. The relativity is needed so that to keep everything in one piece when rotated. For this reason the molecule was drawn with relative angles instead of absolute ones. Another request, is how can I put large brackets instead of the shaded box idea, I mean just to put the shaded area in between two large brackets?
What I want looks like this image below:

enter image description here

Code for chemfig:

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{chemfig}
\begin{document}
\setatomsep{2em}

\chemfig{[:-30]*5(-(=O)-N(-O-[::60]([::-60]--[::60]--[::60]--[::60]-(=[::-60]O)-[::60]O-#(,7pt)[::-60]*5(N-(=O)---(=O)-#(0,5pt)) )=[::60]O)-(=O)--)}

\end{document}

Best Answer

This is not fully automatic (you need to specify the rotation for the molecule and the corresponding \chemmove command) and the TikZ code can most likely be improved but it may be a start. It places two invisible bonds where I've marked the respective ends with chemfigs @{<node name>} syntax. They are used to draw the rectangle later.

enter image description here

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{chemfig}

\begin{document}
\setatomsep{2em}

\chemfig{
  [:-30]*5(
    -(=O)-N(
      -O(-[::110,2,,,draw=none]@{a})
      -[::60](
        [::-60]--[::60]--[::60]--[::60]
        -(=[::-60]O)(-[::-50,2,,,draw=none]@{b})
        -[::60]O-#(,7pt)[::-60]
        *5(N-(=O)---(=O)-#(0,5pt))
      )=[::60]O
    )-(=O)--
  )
}
\chemmove[orientation/.style={rotate=0}]{
  \draw[orientation,draw=black,opacity=.2,fill=black!30]
    (a) -| (b) -| (a)
    node[pos=.25,above,opacity=1,orientation]{Some text here} ;
}

\chemfig{
  [:0]*5(
    -(=O)-N(
      -O(-[::110,2,,,draw=none]@{a})
      -[::60](
        [::-60]--[::60]--[::60]--[::60]
        -(=[::-60]O)(-[::-50,2,,,draw=none]@{b})
        -[::60]O-#(,7pt)[::-60]
        *5(N-(=O)---(=O)-#(0,5pt))
      )=[::60]O
    )-(=O)--
  )
}
\chemmove[orientation/.style={rotate=30}]{
  \draw[orientation,draw=black,opacity=.2,fill=black!30]
    (a) -| (b) -| (a)
    node[pos=.25,above,opacity=1,orientation]{Some text here} ;
}

\chemfig{
  [:-60]*5(
    -(=O)-N(
      -O(-[::110,2,,,draw=none]@{a})
      -[::60](
        [::-60]--[::60]--[::60]--[::60]
        -(=[::-60]O)(-[::-50,2,,,draw=none]@{b})
        -[::60]O-#(,7pt)[::-60]
        *5(N-(=O)---(=O)-#(0,5pt))
      )=[::60]O
    )-(=O)--
  )
}
\chemmove[orientation/.style={rotate=-30}]{
  \draw[orientation,draw=black,opacity=.2,fill=black!30]
    (a) -| (b) -| (a)
    node[pos=.25,above,opacity=1,orientation]{Some text here} ;
}

\end{document}
Related Question