Collision under periodical boundary condition

Hi everyone
I have a script to make two molecules collsion,it works when there is no periodical bondary condition.However it does not work when the periodical boundary condition is imposed.I do not know why,please help me out.
Sincerely 
Li

#!perl

use strict;
use Getopt::Long;
use MaterialsScript qw(:all);

my \$name = "fei relaxed";
#my settings
my \$settings = Settings(Quality =>"Fine",
                        Ensemble =>"NVE",                
                        NumberOfSteps =>30000,
                        TrajectoryFrequency =>100,
                        CurrentForcefield =>"pcff",
                        InitialVelocities => "Current",
                        Temperature =>1600,
                        PeriodicElectrostaticSummationMethod =>"Atom based",
                        PeriodicvdWSummationMethod=>"Atom based",
                        PeriodicvdWAtomTruncationMethod =>"Cubic spline",
                        );

# load my documents
my \$doc = \$Documents{"\$name.xsd"}; 
my \$collision_Doc = Documents->New("collision.xsd");
   \$collision_Doc->CopyFrom(\$doc); 


# get both molecules
my \$molecules = \$collision_Doc->UnitCell->Molecules;
my \$molecule1 = \$molecules->Item(0);
my \$molecule2 = \$molecules->Item(1);
my \$velocity = 3.864*0.6;    #A/ps,60% of most probale velocity


# make sure we are moving molecules towards each other
my \$X1 = \$molecule1->CenterOfMass->X;
my \$X2 = \$molecule2->CenterOfMass->X;
\$velocity *= -1 if \$X2 < \$X1;

print "\$velocity";

# apply velocities to molecule 1 
my \$atoms1 = \$molecule1->Atoms; 
foreach my \$atom (@\$atoms1)
{
      my \$v = \$atom->Velocity;
      \$atom->Velocity = Point(
           X=>\$v->X+\$velocity,
           Y=>\$v->Y,
           Z=>\$v->Z);
}
my \$w = \$molecule1->NetVelocity;
# apply velocities on molecule 2 
my \$atoms2 = \$molecule2->Atoms; 
foreach my \$atom (@\$atoms2)
{
      my \$v = \$atom->Velocity;
      \$atom->Velocity = Point(
           X=>\$v->X-\$velocity,
           Y=>\$v->Y,
           Z=>\$v->Z);
}
my \$results= Modules->Forcite->Dynamics->Run(\$collision_Doc,\$settings);