#
# Purpose: Introduces substitutional disorder by replacing a percentage of atoms with another element.
# If this is a zeolite, Lowenstein's rule can be used to avoid too many substitutions.
# Note. When calculating the number of atoms to change, this number is rounded up. This can
# be changed by modifing the line containing $numToChange.
use strict;
use warnings;
use List::Util qw(shuffle); # Allows randomizing of the atoms in an array
use POSIX; # Allows use of ceil to round-up numbers
use MaterialsScript qw(:all);
# Lowenstein's rule applies to substitution of Aluminium in zeolite and states that no two
# Al atoms can share a common oxygen.
sub CheckLowenstein {
my ($atom) = @_;
#Rule states that Al-O-Al linkages are forbidden
my $attached = $atom->AttachedAtoms;
foreach my $firstAtom (@$attached) {
#Only care about oxygens
if($firstAtom->ElementSymbol eq "O" {
my $oxyAttached = $firstAtom->AttachedAtoms;
foreach my $secondAtom (@$oxyAttached) {
if($secondAtom->ElementSymbol eq "Al" {
return 0; #Lowenstein broken
}
}
}
}
return 1; #Lowenstein satisfied
}
# Main routine to substitute atoms
sub SubstituteAtoms {
my ($doc, $pcChange, $original, $new, $lowenstein)= @_;
# Stop if atom is still undefined as this means Lowensteins rule has been broken
if(!$atom) {
print "Unable to satisfy Lowenstein's rule\n";
# Count the number of atoms changed and report this.
my $modAtoms = 0;
foreach my $at (@{$doc->UnitCell->Atoms}) {
if ($at->ElementSymbol eq "$new" { ++$modAtoms;}
}
print "$modAtoms atoms have been modified to $new element\n";
return;
} else {
#Change the element and display style
$atom->ElementSymbol = "$new";
$atom->Style = "Ball and Stick";
}
}
}
# Specify the input document and percentage number of silicons to change
my $xsd = $Documents{"FAU.xsd"};# Structure name
my $percentChange = 11; # Percentage of atoms of original element to change
my $originalElement = "Si"; # Original element to change to new element
my $newElement = "Al"; # New element
my $obeyLowenstein = "Yes"; # Whether to obey Lowenstein's for zeolites