Add External Force to Two Sets of Molecules

Dear all,
In my MD simulation system, I have 2 sets of moleculse that need to added a external force, how to deal with that, can I write such a perl script as below?

#!perl

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

my \$doc = \$Documents{"MFI5.xsd"};

my \$totalTime = 400;
my \$interval = 4;
my \$period = 800;
my \$forceAmplitude = 69.92; # kcal/mol/A

my \$forcite = Modules->Forcite;
my \$dynamics = \$forcite->Dynamics;

Modules->Forcite->ChangeSettings([Ensemble3D => "NVT",
Temperature => 348, 
TimeStep=> 2, 
EnergyDeviation=> 500000,
 NumberOfSteps=>2000,
 TrajectoryFrequency=>500,
 Thermostat=>"Berendsen",
 CurrentForcefield=>"Dreiding",
 Quality=>"Coarse",
 ChargeAssignment=>"Use current",
 "3DPeriodicElectrostaticSummationMethod"=>"Atom based",
 ]);

my \$xtd = \$dynamics->Run(\$doc, Settings(NumberOfSteps => 1))->Trajectory;

Modules->Forcite->ChangeSettings(Settings(
    TrajectoryRestart => "Yes", 
    AppendTrajectory => "Yes"));

for(my \$time = 0; \$time < \$totalTime; \$time += \$interval)
{
    my \$force = \$forceAmplitude*sin(\$time/\$period*2*pi);
    

    my \$externalForceStrength = \$force ;
    
    my \$results = \$dynamics->Run(\$xtd, Settings(
        ExternalForceSet => "Top",  
        ExternalForceStrength => \$externalForceStrength, 
        ExternalForceX=>0,
        ExternalForceY=>-1,
        ExternalForceZ=>0,
        ExternalForceSet => "Bottom",  
        ExternalForceStrength => \$externalForceStrength, 
        ExternalForceX=>0,
        ExternalForceY=>1,
        ExternalForceZ=>0,

    ));
}

Thank.
Best regards,
Yours
CHENG Xu