Dynamics simulation right after the Geometry Optimization

Dear all,

I'm having a difficulty with scripting.

I'm currently building a script that can simulate NVT and NPT.

I tried to put Geometry oprimization between those MD simulations as simply as below.

my \\\$results = \\\$module->Dynamics->Run(\\\$doc, ([ NumberOfSteps => \\\$numberSteps,

                          Ensemble3D => "NVT",

                          Temperature => "650",

                          Pressure => "-0.1",

                          TrajectoryFrequency => \\\$trajFrequency]));

my \\\$trajectory = \\\$results->Trajectory;

my \\\$trj = \\\$module->GeometryOptimization->Run(\\\$trajectory);

my \\\$trj->Trajectory->CurrentFrame = \\\$trj->Trajectory->EndFrame;

my \\\$results = \\\$module->Dynamics->Run(\\\$trj,     ([     NumberOfSteps => \\\$numberSteps,

                                                                         Ensemble3D => "NPT",

                                                                         Pressure => "-0.1",

                                                                         TrajectoryFrequency => \\\$trajFrequency]));

However, once the geometry optimization is done, MS always gives me the following error.

Unable to find the collection of objects in input (function/property "Run") at -e line 80.

Created initial documents

The script shown above is one of examples that I tried. I tried to save one frame or save as a file while any of those gave me the same error.

Please give me any hint.

Cheers

Jay