(how) can you build a mesostructure template with the perl script?

I am writing a script in MaterialsStudio 2023 and I need to build a mesostructure with a certain cell length, which I calculate previously. The system should contain 2 slabs as filler. Does anyone has a suggestion for the perl code?
scriptperlmesostructuretemplate 

Answers 6
JW
JW 2025-05-20 Best Answer

Hi Marek, 

This will not help you to use Materials Studio 2023, but for the record this functionality was added in the latest MS2025 release so scripts like this (taken from the Help) are now possible. 

my $template = Documents->New("membrane template.msd"); 
my $water = $Documents{"beadW.xsd"}; 
my $lipid = $Documents{"beadLipid.xsd"}; 

my $templateBuilder = Tools->MesostructureBuilder->MesostructureTemplate; 
$templateBuilder->AddFormer($template, "System", "Solvent", [ ExtentZ => 75 ]);
$templateBuilder->AddFormer($template, "Slab", "Membrane",                            [ FractionalPositionZ => 0.5,                              Orientation => "Along Z",                              EnableSurfacePacking => "Yes",                              SlabPackingSurface => "Both" ]);
Tools->MesostructureBuilder->ChangeSettings([Density => 0.7,                      RigidBodyPacking => "Yes"]);

 my $mesostructureBuilder = Tools->MesostructureBuilder->Mesostructure; $mesostructureBuilder->ClearComponents;
 $mesostructureBuilder->AddComponent($water, "Solvent"); $mesostructureBuilder->RelativeAmount($water, "Solvent") = 1;
 $mesostructureBuilder->AddComponent($lipid, "Membrane"); $mesostructureBuilder->RelativeAmount($lipid, "Membrane") = 1;
 my $structure = $mesostructureBuilder->Build($template);
 
Hopefully you can upgrade to MS2025 at some point to make use of this helpful new feature!
best regards,
James

CM
CM 2025-05-16

Did you already have a look at the copy-script functionality in Materials Studio?

Please search the Materials Studio help for "Generating scripts" (with  quotation marks).

MS
MS 2025-05-19

In this case, there is no option to copy the script (at least with MS 2023). Also in the help I cannot find any information about a command to execute “Build mesoscale Template” using a script. 

JD
JD 2025-05-19

Hi Marek, Mesostructure templates are not supported in scripting as you can see by the lack of those objects (template, filler, former, etc) in the API help. Nevertheless, a little experimentation offers what might be a workaround. You could read in an existing template and then modify it. I find this test works in MS2025:

my $msd = $Documents{"test.msd"};
$msd->SystemFormer->SystemExtentX = 200;
 

MS
MS 2025-05-19

Thank you very much for this suggestion. I will try it this way

CM
CM 2025-05-20

A colleague mailed me some further info. The copy-script functionality was indeed not there in Materials Studio 2023.

I do not have a Materials Studio 2023 right now search the help myself.
What do you get when you search the help for "MesostructureBuilder MesostructureTemplate task" (with quotation marks).

At least in Materials Studio 2025 there is some nice help and an example script for this.