| 1 | package Physics::CVD::Film; | ||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 4 | 1 | ▶ | use Carp; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 5 | 1 | ▶ | use List::Util qw(sum max min); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 6 | |||||||||||||||||||||||
| 7 | # ═══════════════════════════════════════════════════════════════════════════════ | ||||||||||||||||||||||
| 8 | # Film analysis for CVD-grown films | ||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||
| 10 | # Computes: | ||||||||||||||||||||||
| 11 | # - Thickness, roughness, density, porosity | ||||||||||||||||||||||
| 12 | # - Composition profile (depth-resolved) | ||||||||||||||||||||||
| 13 | # - Stoichiometry analysis | ||||||||||||||||||||||
| 14 | # - Export to XYZ and LAMMPS formats | ||||||||||||||||||||||
| 15 | # ═══════════════════════════════════════════════════════════════════════════════ | ||||||||||||||||||||||
| 16 | |||||||||||||||||||||||
| 17 | 1 | ▶ | sub new { | ||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.7
Pod
undocumented
| |||||||||||||||||||||||
| 18 | 1 | my ($class, %opts) = @_; | |||||||||||||||||||||
| 19 | my $self = bless { | ||||||||||||||||||||||
| 20 | lattice => $opts{lattice}, | ||||||||||||||||||||||
| 21 | surface => $opts{surface}, | ||||||||||||||||||||||
| 22 | site_species => $opts{site_species}, | ||||||||||||||||||||||
| 23 | lattice_size => $opts{lattice_size} // [30, 30, 20], | ||||||||||||||||||||||
| 24 | 1 | ▶ | lattice_const => $opts{lattice_const} // 3.0, # Angstrom | ||||||||||||||||||||
|
Condition50%2/4
$opts{"lattice_size"} // [30, 30, 20]
$opts{"lattice_const"} // 3
MC/DC0%0/1
$opts{"lattice_size"} // [30, 30, 20]
$opts{"lattice_size"}
MC/DC0%0/1
$opts{"lattice_const"} // 3
$opts{"lattice_const"}
Truth table50%1/2
A
A= $opts{"lattice_size"}
Truth table50%1/2
A
A= $opts{"lattice_const"}
| |||||||||||||||||||||||
| 25 | }, $class; | ||||||||||||||||||||||
| 26 | 1 | return $self; | |||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||
| 28 | |||||||||||||||||||||||
| 29 | 1 | ▶ | sub thickness { | ||||||||||||||||||||
|
Subroutine
thickness: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||
| 30 | 1 | my ($self) = @_; | |||||||||||||||||||||
| 31 | 1 | my ($nx, $ny) = @{$self->{lattice_size}}; | |||||||||||||||||||||
| 32 | 1 | my $sum = 0; | |||||||||||||||||||||
| 33 | 1 | for my $x (0 .. $nx-1) { | |||||||||||||||||||||
| 34 | 15 | for my $y (0 .. $ny-1) { | |||||||||||||||||||||
| 35 | 225 | $sum += $self->{surface}[$x][$y]; | |||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||
| 38 | 1 | my $avg_layers = $sum / ($nx * $ny); | |||||||||||||||||||||
| 39 | 1 | return $avg_layers * $self->{lattice_const} / 10.0; # nm | |||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||
| 41 | |||||||||||||||||||||||
| 42 | 0 | ▶ | sub roughness { | ||||||||||||||||||||
|
Subroutine
roughness: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||
| 43 | 0 | my ($self) = @_; | |||||||||||||||||||||
| 44 | 0 | my ($nx, $ny) = @{$self->{lattice_size}}; | |||||||||||||||||||||
| 45 | 0 | my $sum = 0; | |||||||||||||||||||||
| 46 | 0 | my $sum2 = 0; | |||||||||||||||||||||
| 47 | 0 | my $n = $nx * $ny; | |||||||||||||||||||||
| 48 | 0 | for my $x (0 .. $nx-1) { | |||||||||||||||||||||
| 49 | 0 | for my $y (0 .. $ny-1) { | |||||||||||||||||||||
| 50 | 0 | my $h = $self->{surface}[$x][$y]; | |||||||||||||||||||||
| 51 | 0 | $sum += $h; | |||||||||||||||||||||
| 52 | 0 | $sum2 += $h * $h; | |||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||
| 55 | 0 | my $mean = $sum / $n; | |||||||||||||||||||||
| 56 | 0 | my $var = $sum2 / $n - $mean * $mean; | |||||||||||||||||||||
| 57 | 0 | ▶ | $var = 0 if $var < 0; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 58 | 0 | return sqrt($var) * $self->{lattice_const} / 10.0; # nm | |||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||
| 60 | |||||||||||||||||||||||
| 61 | 0 | ▶ | sub density { | ||||||||||||||||||||
|
Subroutine
density: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||
| 62 | 0 | my ($self) = @_; | |||||||||||||||||||||
| 63 | 0 | my ($nx, $ny, $nz) = @{$self->{lattice_size}}; | |||||||||||||||||||||
| 64 | 0 | my $max_z = 0; | |||||||||||||||||||||
| 65 | 0 | for my $x (0 .. $nx-1) { | |||||||||||||||||||||
| 66 | 0 | for my $y (0 .. $ny-1) { | |||||||||||||||||||||
| 67 | 0 | $max_z = max($max_z, $self->{surface}[$x][$y]); | |||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||
| 70 | 0 | ▶ | return 0 if $max_z == 0; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 71 | |||||||||||||||||||||||
| 72 | 0 | my $occupied = 0; | |||||||||||||||||||||
| 73 | 0 | my $total = $nx * $ny * $max_z; | |||||||||||||||||||||
| 74 | 0 | for my $x (0 .. $nx-1) { | |||||||||||||||||||||
| 75 | 0 | for my $y (0 .. $ny-1) { | |||||||||||||||||||||
| 76 | 0 | for my $z (0 .. $max_z-1) { | |||||||||||||||||||||
| 77 | 0 | ▶ | $occupied++ if $self->{lattice}[$x][$y][$z]; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||
| 81 | 0 | return $occupied / $total; | |||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||
| 83 | |||||||||||||||||||||||
| 84 | 0 | ▶ | sub porosity { return 1.0 - $_[0]->density } | ||||||||||||||||||||
|
Subroutine
porosity: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||
| 85 | |||||||||||||||||||||||
| 86 | # Composition analysis: count each species type | ||||||||||||||||||||||
| 87 | 0 | ▶ | sub composition { | ||||||||||||||||||||
|
Subroutine
composition: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||
| 88 | 0 | my ($self) = @_; | |||||||||||||||||||||
| 89 | 0 | my ($nx, $ny, $nz) = @{$self->{lattice_size}}; | |||||||||||||||||||||
| 90 | 0 | my %counts; | |||||||||||||||||||||
| 91 | 0 | my $total = 0; | |||||||||||||||||||||
| 92 | 0 | for my $x (0 .. $nx-1) { | |||||||||||||||||||||
| 93 | 0 | for my $y (0 .. $ny-1) { | |||||||||||||||||||||
| 94 | 0 | for my $z (0 .. $nz-1) { | |||||||||||||||||||||
| 95 | 0 | ▶ | next unless $self->{lattice}[$x][$y][$z]; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 96 | 0 | ▶ | my $sp = $self->{site_species}[$x][$y][$z] // 'unknown'; | ||||||||||||||||||||
|
Condition0%0/2
$self->{"site_species"}[$x][$y][$z] // "unknown"
MC/DC0%0/1
$self->{"site_species"}[$x][$y][$z] // "unknown"
$self->{"site_species"}[$x][$y][$z]
Truth table0%0/2
A
A= $self->{"site_species"}[$x][$y][$z]
| |||||||||||||||||||||||
| 97 | 0 | $counts{$sp}++; | |||||||||||||||||||||
| 98 | 0 | $total++; | |||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||
| 102 | # Convert to fractions | ||||||||||||||||||||||
| 103 | 0 | my %fractions; | |||||||||||||||||||||
| 104 | 0 | for my $sp (keys %counts) { | |||||||||||||||||||||
| 105 | 0 | ▶ | $fractions{$sp} = $counts{$sp} / $total if $total > 0; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||
| 107 | 0 | return { counts => \%counts, fractions => \%fractions, total => $total }; | |||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||
| 109 | |||||||||||||||||||||||
| 110 | # Depth-resolved composition profile | ||||||||||||||||||||||
| 111 | 0 | ▶ | sub composition_profile { | ||||||||||||||||||||
|
Subroutine
composition_profile: not called CC=11 SCAR=48.8
Pod
undocumented
| |||||||||||||||||||||||
| 112 | 0 | my ($self, %opts) = @_; | |||||||||||||||||||||
| 113 | 0 | ▶ | my $bin_size = $opts{bin_size} // 1; # layers per bin | ||||||||||||||||||||
|
Condition0%0/2
$opts{"bin_size"} // 1
MC/DC0%0/1
$opts{"bin_size"} // 1
$opts{"bin_size"}
Truth table0%0/2
A
A= $opts{"bin_size"}
| |||||||||||||||||||||||
| 114 | 0 | my ($nx, $ny, $nz) = @{$self->{lattice_size}}; | |||||||||||||||||||||
| 115 | |||||||||||||||||||||||
| 116 | 0 | my @profile; | |||||||||||||||||||||
| 117 | 0 | ▶ | for (my $z = 0; $z < $nz; $z += $bin_size) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 118 | 0 | my %counts; | |||||||||||||||||||||
| 119 | 0 | my $total = 0; | |||||||||||||||||||||
| 120 | 0 | for my $x (0 .. $nx-1) { | |||||||||||||||||||||
| 121 | 0 | for my $y (0 .. $ny-1) { | |||||||||||||||||||||
| 122 | 0 | for my $dz (0 .. $bin_size-1) { | |||||||||||||||||||||
| 123 | 0 | my $zz = $z + $dz; | |||||||||||||||||||||
| 124 | 0 | ▶ | last if $zz >= $nz; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 125 | 0 | ▶ | next unless $self->{lattice}[$x][$y][$zz]; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 126 | 0 | ▶ | my $sp = $self->{site_species}[$x][$y][$zz] // 'unknown'; | ||||||||||||||||||||
|
Condition0%0/2
$self->{"site_species"}[$x][$y][$zz] // "unknown"
MC/DC0%0/1
$self->{"site_species"}[$x][$y][$zz] // "unknown"
$self->{"site_species"}[$x][$y][$zz]
Truth table0%0/2
A
A= $self->{"site_species"}[$x][$y][$zz]
| |||||||||||||||||||||||
| 127 | 0 | $counts{$sp}++; | |||||||||||||||||||||
| 128 | 0 | $total++; | |||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||
| 132 | 0 | ▶ | last if $total == 0; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 133 | 0 | my %fracs; | |||||||||||||||||||||
| 134 | 0 | for my $sp (keys %counts) { | |||||||||||||||||||||
| 135 | 0 | $fracs{$sp} = $counts{$sp} / $total; | |||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||
| 137 | push @profile, { | ||||||||||||||||||||||
| 138 | 0 | depth_nm => $z * $self->{lattice_const} / 10.0, | |||||||||||||||||||||
| 139 | total => $total, | ||||||||||||||||||||||
| 140 | fractions => \%fracs, | ||||||||||||||||||||||
| 141 | }; | ||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||
| 143 | 0 | return \@profile; | |||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||
| 145 | |||||||||||||||||||||||
| 146 | # Stoichiometry ratio (e.g., Si:O ratio for SiO₂) | ||||||||||||||||||||||
| 147 | 0 | ▶ | sub stoichiometry { | ||||||||||||||||||||
|
Subroutine
stoichiometry: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||
| 148 | 0 | my ($self, $elem_a, $elem_b) = @_; | |||||||||||||||||||||
| 149 | 0 | my $comp = $self->composition; | |||||||||||||||||||||
| 150 | 0 | ▶ | my $ca = $comp->{counts}{$elem_a} // 0; | ||||||||||||||||||||
|
Condition0%0/2
$comp->{"counts"}{$elem_a} // 0
MC/DC0%0/1
$comp->{"counts"}{$elem_a} // 0
$comp->{"counts"}{$elem_a}
Truth table0%0/2
A
A= $comp->{"counts"}{$elem_a}
| |||||||||||||||||||||||
| 151 | 0 | ▶ | my $cb = $comp->{counts}{$elem_b} // 0; | ||||||||||||||||||||
|
Condition0%0/2
$comp->{"counts"}{$elem_b} // 0
MC/DC0%0/1
$comp->{"counts"}{$elem_b} // 0
$comp->{"counts"}{$elem_b}
Truth table0%0/2
A
A= $comp->{"counts"}{$elem_b}
| |||||||||||||||||||||||
| 152 | 0 | ▶ | return ($cb > 0) ? $ca / $cb : 0; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||
| 154 | |||||||||||||||||||||||
| 155 | # Export film to XYZ format | ||||||||||||||||||||||
| 156 | 0 | ▶ | sub export_xyz { | ||||||||||||||||||||
|
Subroutine
export_xyz: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||
| 157 | 0 | my ($self, $filename) = @_; | |||||||||||||||||||||
| 158 | 0 | ▶ | $filename //= 'cvd_film.xyz'; | ||||||||||||||||||||
|
Condition0%0/2
$filename //= "cvd_film.xyz"
MC/DC0%0/1
$filename //= "cvd_film.xyz"
$filename
Truth table0%0/2
A
A= $filename
| |||||||||||||||||||||||
| 159 | 0 | my ($nx, $ny, $nz) = @{$self->{lattice_size}}; | |||||||||||||||||||||
| 160 | 0 | my $a = $self->{lattice_const}; | |||||||||||||||||||||
| 161 | |||||||||||||||||||||||
| 162 | 0 | my @atoms; | |||||||||||||||||||||
| 163 | 0 | for my $x (0 .. $nx-1) { | |||||||||||||||||||||
| 164 | 0 | for my $y (0 .. $ny-1) { | |||||||||||||||||||||
| 165 | 0 | for my $z (0 .. $nz-1) { | |||||||||||||||||||||
| 166 | 0 | ▶ | next unless $self->{lattice}[$x][$y][$z]; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 167 | 0 | ▶ | my $sp = $self->{site_species}[$x][$y][$z] // 'X'; | ||||||||||||||||||||
|
Condition0%0/2
$self->{"site_species"}[$x][$y][$z] // "X"
MC/DC0%0/1
$self->{"site_species"}[$x][$y][$z] // "X"
$self->{"site_species"}[$x][$y][$z]
Truth table0%0/2
A
A= $self->{"site_species"}[$x][$y][$z]
| |||||||||||||||||||||||
| 168 | 0 | push @atoms, [$sp, $x*$a, $y*$a, $z*$a]; | |||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||
| 172 | |||||||||||||||||||||||
| 173 | 0 | ▶ | open my $fh, '>', $filename or croak "Cannot write $filename: $!"; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 174 | 0 | printf $fh "%d\n", scalar @atoms; | |||||||||||||||||||||
| 175 | 0 | printf $fh "CVD film: %s\n", join(', ', map { $_->[0] } @atoms[0..min(2,$#atoms)]); | |||||||||||||||||||||
| 176 | 0 | for my $atom (@atoms) { | |||||||||||||||||||||
| 177 | 0 | printf $fh "%-4s %10.4f %10.4f %10.4f\n", @$atom; | |||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||
| 179 | 0 | close $fh; | |||||||||||||||||||||
| 180 | 0 | return scalar @atoms; | |||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||
| 182 | |||||||||||||||||||||||
| 183 | # Export to LAMMPS data format | ||||||||||||||||||||||
| 184 | 0 | ▶ | sub export_lammps_data { | ||||||||||||||||||||
|
Subroutine
export_lammps_data: not called CC=10 SCAR=47.0
Pod
undocumented
| |||||||||||||||||||||||
| 185 | 0 | my ($self, $filename) = @_; | |||||||||||||||||||||
| 186 | 0 | ▶ | $filename //= 'cvd_film.data'; | ||||||||||||||||||||
|
Condition0%0/2
$filename //= "cvd_film.data"
MC/DC0%0/1
$filename //= "cvd_film.data"
$filename
Truth table0%0/2
A
A= $filename
| |||||||||||||||||||||||
| 187 | 0 | my ($nx, $ny, $nz) = @{$self->{lattice_size}}; | |||||||||||||||||||||
| 188 | 0 | my $a = $self->{lattice_const}; | |||||||||||||||||||||
| 189 | |||||||||||||||||||||||
| 190 | # Collect atoms and unique species | ||||||||||||||||||||||
| 191 | 0 | my @atoms; | |||||||||||||||||||||
| 192 | my %type_map; | ||||||||||||||||||||||
| 193 | 0 | my $type_id = 0; | |||||||||||||||||||||
| 194 | 0 | for my $x (0 .. $nx-1) { | |||||||||||||||||||||
| 195 | 0 | for my $y (0 .. $ny-1) { | |||||||||||||||||||||
| 196 | 0 | for my $z (0 .. $nz-1) { | |||||||||||||||||||||
| 197 | 0 | ▶ | next unless $self->{lattice}[$x][$y][$z]; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 198 | 0 | ▶ | my $sp = $self->{site_species}[$x][$y][$z] // 'X'; | ||||||||||||||||||||
|
Condition0%0/2
$self->{"site_species"}[$x][$y][$z] // "X"
MC/DC0%0/1
$self->{"site_species"}[$x][$y][$z] // "X"
$self->{"site_species"}[$x][$y][$z]
Truth table0%0/2
A
A= $self->{"site_species"}[$x][$y][$z]
| |||||||||||||||||||||||
| 199 | 0 | ▶ | $type_map{$sp} //= ++$type_id; | ||||||||||||||||||||
|
Condition0%0/2
$type_map{$sp} //= ++$type_id
MC/DC0%0/1
$type_map{$sp} //= ++$type_id
$type_map{$sp}
Truth table0%0/2
A
A= $type_map{$sp}
| |||||||||||||||||||||||
| 200 | 0 | push @atoms, [$type_map{$sp}, $x*$a, $y*$a, $z*$a]; | |||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||
| 204 | |||||||||||||||||||||||
| 205 | 0 | ▶ | open my $fh, '>', $filename or croak "Cannot write $filename: $!"; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 206 | 0 | printf $fh "CVD Film - LAMMPS data file\n\n"; | |||||||||||||||||||||
| 207 | 0 | printf $fh "%d atoms\n", scalar @atoms; | |||||||||||||||||||||
| 208 | 0 | printf $fh "%d atom types\n\n", $type_id; | |||||||||||||||||||||
| 209 | 0 | printf $fh "0.0 %.4f xlo xhi\n", $nx * $a; | |||||||||||||||||||||
| 210 | 0 | printf $fh "0.0 %.4f ylo yhi\n", $ny * $a; | |||||||||||||||||||||
| 211 | 0 | printf $fh "0.0 %.4f zlo zhi\n", $nz * $a; | |||||||||||||||||||||
| 212 | 0 | printf $fh "\nAtoms\n\n"; | |||||||||||||||||||||
| 213 | 0 | for my $i (0 .. $#atoms) { | |||||||||||||||||||||
| 214 | 0 | printf $fh "%d %d %.4f %.4f %.4f\n", $i+1, @{$atoms[$i]}; | |||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||
| 216 | 0 | close $fh; | |||||||||||||||||||||
| 217 | 0 | return scalar @atoms; | |||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||
| 219 | |||||||||||||||||||||||
| 220 | 1 | 1; | |||||||||||||||||||||