I want to graft the loop from some other protein taken from pdb to my
protein structure.
You could use multiple-template modeling to achieve this. Alternatively,
you could manually combine the two PDB files, using a PDB viewer or even
by editing the files in a text editor.
I tried modeling it on my own but some parts of the
secondary structure (beta sheet) also change into loop while loop
modeling ..
That is hardly surprising - loop modeling does not use any information
from the template.
So I want to fix those two ends of the beta sheet where the
loop is present so that these end should not change to loop region.
If you don't want to subject the beta sheet to loop modeling, simply
don't select those residues in the select_loop_atoms function: