For high-accuracy template-based-modeling of CASP7 targets, we have applied a procedure based on the rigorous optimization of score functions at three stages: multiple alignment, chain building, and side-chain modeling. We applied the conformational space annealing method to a newly developed consistency based score function for multiple alignment. For chain building, we optimized the MODELLER energy function. For side-chain modeling, we optimized a SCWRL-like energy function using a rotamer library constructed specifically for a given target sequence. By rigorous optimization, we have achieved significant improvement in backbone as well as side-chain modeling for TBM and TBM/HA targets. For most TBM/HA targets (17/26), the predicted model was more accurate than the model one can construct from the best template in a posteriori fashion. It appears that the current method can extract relevant information out of multiple templates. Proteins 2007. © 2007 Wiley-Liss, Inc.