BestFitPlane normal vector by time

Dear Material Studio users,

I have a system that includes several 6-rings. Following MD simulations, I aimed to conduct post-processing analyses, one of which requires obtaining the normal vectors of each 6-ring plane versus time.


So, I made BestFitPlane out of all 6-rings (please see the attached figure) and then wrote the following code:


#!perl

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

my \\\$doc = \\\$Documents{"new0.xtd"};
my \\\$std = Documents->New("NormaleVectors.std");
\\\$std->ColumnHeading(0) = "Nx";
\\\$std->ColumnHeading(1) = "Ny";
\\\$std->ColumnHeading(2) = "Nz"
my \\\$bestFitPlane = \\\$doc->DisplayRange->BestFitPlane;
my \\\$planes = \\\$bestFitPlane->BestFitPlane;
for (my \\\$frame=1; \\\$frame<=\\\$doc->Trajectory->NumFrames; ++\\\$frame){
\\\$doc->Trajectory->CurrentFrame = \\\$frame;
my \\\$BFPCounter = 0;
my \\\$i=0
foreach my \\\$plane (@{\\\$doc->DisplayRange->BestFitPlane}){{++\\\$BFPCounter}  
\\\$std->Cell(\\\$i,0+(\\\$frame-1)*3) = \\\$plane->UnitNormalVector->X;
\\\$std->Cell(\\\$i,1+(\\\$frame-1)*3) = \\\$plane->UnitNormalVector->Y;
\\\$std->Cell(\\\$i,2+(\\\$frame-1)*3) = \\\$plane->UnitNormalVector->Z;
\\\$i++;} 
}

However, upon running the code, I got this error:

"There is more than one object in the "BestFitPlane"s collection (function/property "BestFitPlane") at -e line 13."

Would you be able to kindly advise me on what I have missed in the code? Thank you, SJ

Answers 2
SJ
SJ 2023-09-21

When I changed BestFitPlane to BestFitPlanes, I received this error: There is no function or property named "UnitNormalVector" on type "Object" at -e line 21. 

After selecting one of the bestfitplane, in the properties explorer, one can see in he BestFitPlane row: something like  r.(aa,bb,cc)=cc. I suppose aa,bb, and cc should be the bestfitplane vector elements. How can we reformulate the code to get these values? Many Thanks, SJ

SJ
SJ 2023-09-21

I just changes the the code as follows: 

 

#!perl

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

my $doc = $Documents{"new0.xtd"};
my $std = Documents->New("NormaleVectors.std");
   $std->ColumnHeading(0) = "Nx";
   $std->ColumnHeading(1) = "Ny";
   $std->ColumnHeading(2) = "Nz";
  
my $bestFitPlane = $doc->UnitCell->BestFitPlanes;
my $planes = $bestFitPlane->BestFitPlanes;
for (my $frame=1; $frame<=$doc->Trajectory->NumFrames; ++$frame){
       $doc->Trajectory->CurrentFrame = $frame;
       my $BFPCounter = 0;
       my $i=0;
 
       foreach my $plane (@{$doc->UnitCell->BestFitPlanes}){{++$BFPCounter}      
        $std->Cell($i,0+($frame-1)*3) = $plane->BestFitPlane->UnitNormalVector->X;
        $std->Cell($i,1+($frame-1)*3) = $plane->BestFitPlane->UnitNormalVector->Y;
        $std->Cell($i,2+($frame-1)*3) = $plane->BestFitPlane->UnitNormalVector->Z;
        $i++;} 
}

 

And it worked.

Please feel free to advise me if you see any issue in the code

Thanks, SJ

 

​​​​​​​