j < j_e, k_s\le k < k_e]\frac{\partial L}{\partial y_{rijk}} ,\\
&i_s =max \lbrace {0, \lfloor\frac{W_T-W_r}{2} \rfloor} \rbrace, i_e =i_s + min \lbrace  \lceil W_r\rceil, W_T \rbrace ,\\
&j_s =max \lbrace {0, \lfloor\frac{H_T-H_r}{2} \rfloor} \rbrace, j_e =j_s + min \lbrace  \lceil H_r\rceil, H_T \rbrace,\\
&k_s =max \lbrace {0, \lfloor\frac{L_T-L_r}{2} \rfloor} \rbrace, k_e =k_s + min \lbrace  \lceil L_r\rceil, L_T \rbrace,
\end{split}\label{eqn:aproi2}\end{aligned}$$ where $W_r, H_r,L_r$ are the size of the $r$-th RoI. $\partial L / \partial y_{rijk}$ denotes the partial derivative computed by the layer on top of the APRoI layer. Intuitively, only the previously valid locations will receive the gradients for back propagation, while the locations with padded zeros are simply ignored.

### Loss for amino acid detection

To predict the 3D box size, we follow previous work [@qi2017frustum] and use a mixture of both regression and classification formulations instead of directly regressing the 3D box size. Firstly, we specifically pre-define 20 template size with ($w^c, h^c, l^c$). Our model classifies each input into one type and then regresses the residual of the box sizes of the type with highest probability. While for box center regression, we parametrize a 3D ground truth box as $(x^g, y^g, z^g, w^g, h^g, l^g)$, where 