I have been doing separate optimization steps on selected region where i
experienced that certain residue(ARG,LYS,TYR) atoms get distorted (like
bonds between two atoms were distorted). So is their anyway to control the
random deviation of certain residues atoms.
You can't control how they are moved during optimization (since that's a
function of the first derivatives) but you can certainly control how
much they're initially randomized by. Just make separate selections and
randomize them differently (or not at all, potentially).
For example:
# all atoms for optimization
all_sel = selection(...)
# subset of these atoms in 'certain residues'
badres = all_sel.only_residue_types('ARG LYS TYR')
# remaining subset
goodres = all_sel - badres
# randomize bad residues less than good ones
goodres.randomize_xyz(deviation=10.0)
badres.randomize_xyz(deviation=1.0)
Note that randomize_xyz() already does something similar for residues
containing rings to avoid this issue: