Use script to mutate amino acid but structure twisted

Dear all:

Please help me to solve my problem as below:

I want to mutate amino acid on the protein structure.

When amino acid 177 was mutated as W (trp) , I find W structure twisted.

But I use clean button on Discovery Studio Client. It is OK.

Why I use my script to mutate amino acid structure twisted from ALA to TRP ??

Is my Clean function wrong ???

Please help me to check my script as below:

#! /usr/bin/perl -w

# usage: \\\$DS25HOME/bin/perl.bat resid(seperated by ,) mutateAA(one codon) (MS)

# \\\$DS25HOME/bin/perl.sh resid(seperated by ,) mutateAA (Linux)

# example: \\\$DS25HOME/bin/perl.bat 177,178 WF

# example: \\\$DS25HOME/bin/perl.bat 177,W

use strict;

use DSCommands;

use MdmCommands;

use MdmDiscoveryScript;

use ProteinDiscoveryScript;

my \\\$document = DiscoveryScript::Open("D:/Accelrys_debug/1mfb.pdb");

my \\\$aminoAcids = \\\$document->AminoAcids;

my @resid = split (/,/, \\\$ARGV[0]);

my @mutant = split (//, \\\$ARGV[1]);

die "resid ne mutate residues" if (\\\$#resid != \\\$#mutant);

# mutate AA

for (my \\\$i = 0; \\\$i <= \\\$#resid; \\\$i++){

my \\\$residuetomutate = \\\$aminoAcids->Item((\\\$resid[\\\$i]-1));

print 'Amino acid name before the mutation: '. \\\$residuetomutate->Name() . "\\n";

my \\\$mutate = codonChang(lc(\\\$mutant[\\\$i]));

\\\$document->MutateAminoAcid( \\\$residuetomutate, \\\$mutate);

print 'Amino acid name after the mutation: '. \\\$residuetomutate->Name() . "\\n";

}

# select area for minimization

my \\\$protein = FilterByString( \\\$document, "L:177:*" ); #

SetSelection(\\\$document,\\\$protein);

AddHydrogens(\\\$document);

\\\$document->Clean();

\\\$document->DeselectAll();

RemoveHydrogens(\\\$document);

# save minimized PDB

\\\$document->Save( "D:/Accelrys_debug/1mfb_mini.pdb", 'pdb' );

\\\$document->Close();

sub codonChang{

my \\\$oneCodon = \\\$_[0];

my %one2Three =

('a' => Mdm::ala, 'c' => Mdm::cys, 'd' => Mdm::asp, 'y' => Mdm::tyr,

'e' => Mdm::glu, 'f' => Mdm::phe, 'g' => Mdm::gly, 'h' => Mdm::his,

'i' => Mdm::ile, 'k' => Mdm::lys, 'l' => Mdm::leu, 'm' => Mdm::met,

'n' => Mdm::asn, 'p' => Mdm::pro, 'q' => Mdm::gln, 'r' => Mdm::arg,

's' => Mdm::ser, 't' => Mdm::thr, 'v' => Mdm::val, 'w' => Mdm::trp,

);

return \\\$one2Three{\\\$oneCodon};

}