CVD/Interface/LAMMPS.pm

filter: Statementstmt 19.7% 13 / 66 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 28 MC/DCmcdc 0.0% 0 / 15 Subroutinesub 44.4% 4 / 9 Podpod 0.0% 0 / 5 totaltotal 11.8% 17 / 143 CC 24 SCAR 38.3
CC
24
Cov
11%
parse_log
90.0
generate_surface_reaction
56.0
run
30.0
CRAP 46.0
« CVD/Film.pm ↑ Summary CVD/Chemistry.pm »
1 package Physics::CVD::Interface::LAMMPS;
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 File::Path qw(make_path);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 # ═══════════════════════════════════════════════════════════════════════════════
8 # LAMMPS interface for CVD surface reaction MD
9 #
10 # Generates scripts for:
11 # - Reactive MD with ReaxFF for CVD surface chemistry
12 # - Precursor adsorption/decomposition studies
13 # - Film stress and relaxation
14 # ═══════════════════════════════════════════════════════════════════════════════
15  
16 0 ▶sub new {
Subroutine new: not called CC=4 SCAR=30.0
Pod undocumented
17 0 my ($class, %opts) = @_;
18 my $self = bless {
19 work_dir => $opts{work_dir} // './lammps_cvd',
20 0 ▶ executable => $opts{executable} // 'lmp',
Condition0%0/4
$opts{"work_dir"} // "./lammps_cvd"
l!l
00
$opts{"executable"} // "lmp"
l!l
00
MC/DC0%0/1
$opts{"work_dir"} // "./lammps_cvd"
$opts{"work_dir"}
MC/DC0%0/1
$opts{"executable"} // "lmp"
$opts{"executable"}
Truth table0%0/2
A
A= $opts{"work_dir"}
Aresult
11
00
Truth table0%0/2
A
A= $opts{"executable"}
Aresult
11
00
21 }, $class;
22 0 ▶ make_path($self->{work_dir}) unless -d $self->{work_dir};
Branch: 1 branch
BranchTrueFalseTotal
unless -d $self->{"work_dir"} 0 0 0
23 0 return $self;
24 }
25  
26 # Generate a ReaxFF CVD surface reaction script
27 0 ▶sub generate_surface_reaction {
Subroutine generate_surface_reaction: not called CC=7 SCAR=40.3
Pod undocumented
28 0 my ($self, %opts) = @_;
29 0 ▶ my $substrate = $opts{substrate} // 'Si';
Condition0%0/2
$opts{"substrate"} // "Si"
l!l
00
MC/DC0%0/1
$opts{"substrate"} // "Si"
$opts{"substrate"}
Truth table0%0/2
A
A= $opts{"substrate"}
Aresult
11
00
30 0 ▶ my $precursor = $opts{precursor} // 'SiH4';
Condition0%0/2
$opts{"precursor"} // "SiH4"
l!l
00
MC/DC0%0/1
$opts{"precursor"} // "SiH4"
$opts{"precursor"}
Truth table0%0/2
A
A= $opts{"precursor"}
Aresult
11
00
31 0 ▶ my $T = $opts{temperature} // 700;
Condition0%0/2
$opts{"temperature"} // 700
l!l
00
MC/DC0%0/1
$opts{"temperature"} // 700
$opts{"temperature"}
Truth table0%0/2
A
A= $opts{"temperature"}
Aresult
11
00
32 0 ▶ my $potential = $opts{potential} // 'ffield.reax.cho';
Condition0%0/2
$opts{"potential"} // "ffield.reax.cho"
l!l
00
MC/DC0%0/1
$opts{"potential"} // "ffield.reax.cho"
$opts{"potential"}
Truth table0%0/2
A
A= $opts{"potential"}
Aresult
11
00
33 0 ▶ my $n_precursor = $opts{n_molecules} // 20;
Condition0%0/2
$opts{"n_molecules"} // 20
l!l
00
MC/DC0%0/1
$opts{"n_molecules"} // 20
$opts{"n_molecules"}
Truth table0%0/2
A
A= $opts{"n_molecules"}
Aresult
11
00
34  
35 0 my $script = <<EOF;
36 # LAMMPS ReaxFF CVD surface reaction — $precursor on $substrate
37 # Generated by Physics::CVD
38  
39 units real
40 atom_style charge
41 boundary p p f
42  
43 # Read substrate
44 read_data substrate.data
45  
46 # ReaxFF potential
47 pair_style reaxff NULL
48 pair_coeff * * $potential Si O H N C
49  
50 # Groups
51 group substrate type 1
52 group precursor type 2 3 4
53  
54 # Fix bottom layer
55 region bottom block INF INF INF INF INF 3.0
56 group frozen region bottom
57 fix freeze frozen setforce 0.0 0.0 0.0
58  
59 # Thermostat for substrate surface
60 fix nvt_sub substrate nvt temp $T $T 100.0
61  
62 # Integration
63 timestep 0.5
64 fix nve_prec precursor nve
65  
66 # Charge equilibration
67 fix qeq all qeq/reaxff 1 0.0 10.0 1.0e-6 reaxff
68  
69 # Reflecting wall
70 fix wall all wall/reflect zhi EDGE
71  
72 # Output
73 thermo 100
74 thermo_style custom step temp pe ke etotal press atoms
75 dump traj all custom 500 dump.cvd.lammpstrj id type x y z q
76  
77 # Insert precursor molecules
78 molecule prec_mol precursor.mol
79 region insert_region block INF INF INF INF 30.0 40.0
80 fix depo precursor deposit $n_precursor 0 200 12345 &
81 region insert_region mol prec_mol near 3.0 &
82 vz -5.0 -3.0
83  
84 # Run deposition
85 run 50000
86  
87 # Relaxation
88 unfix depo
89 run 20000
90  
91 write_data final_cvd.data
92 EOF
93  
94 0 my $filename = "$self->{work_dir}/in.cvd_reaction";
95 0 ▶ open my $fh, '>', $filename or croak "Cannot write $filename: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $filename or croak("Cannot write ${filename}: $!") 0 0 0
96 0 print $fh $script;
97 0 close $fh;
98 0 return $filename;
99 }
100  
101 # Generate film stress analysis script
102 0 ▶sub generate_stress_analysis {
Subroutine generate_stress_analysis: not called CC=3 SCAR=24.8
Pod undocumented
103 0 my ($self, %opts) = @_;
104 0 ▶ my $T = $opts{temperature} // 300;
Condition0%0/2
$opts{"temperature"} // 300
l!l
00
MC/DC0%0/1
$opts{"temperature"} // 300
$opts{"temperature"}
Truth table0%0/2
A
A= $opts{"temperature"}
Aresult
11
00
105  
106 0 my $script = <<EOF;
107 # LAMMPS CVD film stress analysis
108 # Generated by Physics::CVD
109  
110 units metal
111 atom_style atomic
112 boundary p p f
113  
114 read_data cvd_film.data
115  
116 pair_style tersoff
117 pair_coeff * * SiO.tersoff Si O
118  
119 # NPT relaxation to find equilibrium stress
120 fix relax all npt temp $T $T 0.1 x 0.0 0.0 1.0 y 0.0 0.0 1.0
121  
122 thermo 100
123 thermo_style custom step temp press pxx pyy pzz lx ly lz
124  
125 # Compute per-atom stress
126 compute stress all stress/atom NULL
127 dump stress all custom 1000 dump.stress id type x y z &
128 c_stress[1] c_stress[2] c_stress[3]
129  
130 run 10000
131 write_data relaxed_film.data
132 EOF
133  
134 0 my $filename = "$self->{work_dir}/in.stress";
135 0 ▶ open my $fh, '>', $filename or croak "Cannot write $filename: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $filename or croak("Cannot write ${filename}: $!") 0 0 0
136 0 print $fh $script;
137 0 close $fh;
138 0 return $filename;
139 }
140  
141 0 ▶sub run {
Subroutine run: not called CC=5 SCAR=34.0
Pod undocumented
142 0 my ($self, %opts) = @_;
143 0 ▶ my $input = $opts{input} // 'in.cvd_reaction';
Condition0%0/2
$opts{"input"} // "in.cvd_reaction"
l!l
00
MC/DC0%0/1
$opts{"input"} // "in.cvd_reaction"
$opts{"input"}
Truth table0%0/2
A
A= $opts{"input"}
Aresult
11
00
144 0 ▶ my $np = $opts{processors} // 1;
Condition0%0/2
$opts{"processors"} // 1
l!l
00
MC/DC0%0/1
$opts{"processors"} // 1
$opts{"processors"}
Truth table0%0/2
A
A= $opts{"processors"}
Aresult
11
00
145 0 my $dir = $self->{work_dir};
146 0 my $exe = $self->{executable};
147  
148 0 ▶ my $cmd = ($np > 1)
Branch: 1 branch
BranchTrueFalseTotal
$np > 1 ? : 0 0 0
149 ? "cd $dir && mpirun -np $np $exe -in $input > log.lammps 2>&1"
150 : "cd $dir && $exe -in $input > log.lammps 2>&1";
151  
152 0 ▶ system($cmd) == 0 or carp "LAMMPS run failed";
Branch: 1 branch
BranchTrueFalseTotal
system($cmd) == 0 or carp("LAMMPS run failed") 0 0 0
153 0 return $self;
154 }
155  
156 # Parse LAMMPS log for thermo data
157 0 ▶sub parse_log {
Subroutine parse_log: not called CC=9 SCAR=45.0
Pod undocumented
158 0 my ($self, $logfile) = @_;
159 0 ▶ $logfile //= "$self->{work_dir}/log.lammps";
Condition0%0/2
$logfile //= qq[$self->{"work_dir"}/log.lammps]
l!l
00
MC/DC0%0/1
$logfile //= qq[$self->{"work_dir"}/log.lammps]
$logfile
Truth table0%0/2
A
A= $logfile
Aresult
11
00
160 0 ▶ open my $fh, '<', $logfile or croak "Cannot read $logfile: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $logfile or croak("Cannot read ${logfile}: $!") 0 0 0
161  
162 0 my @data;
163 0 my $in_thermo = 0;
164 0 my @headers;
165 0 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
166 0 ▶ if (/^Step\s/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^Step\s/) 0 0 0
167 0 $in_thermo = 1;
168 0 @headers = split;
169 0 next;
170 }
171 0 ▶ if ($in_thermo && /^Loop time/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_thermo and /^Loop time/) 0 0 0
Condition0%0/3
$in_thermo and /^Loop time/
!ll&&!rl&&r
000
MC/DC0%0/2
$in_thermo and /^Loop time/
$in_thermo /^Loop time/
Truth table0%0/3
A and B
A= $in_thermoB= /^Loop time/
ABresult
0X0
100
111
172 0 $in_thermo = 0;
173 0 next;
174 }
175 0 ▶ if ($in_thermo && /^\s*\d/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_thermo and /^\s*\d/) 0 0 0
Condition0%0/3
$in_thermo and /^\s*\d/
!ll&&!rl&&r
000
MC/DC0%0/2
$in_thermo and /^\s*\d/
$in_thermo /^\s*\d/
Truth table0%0/3
A and B
A= $in_thermoB= /^\s*\d/
ABresult
0X0
100
111
176 0 my @vals = split;
177 0 my %row;
178 0 @row{@headers} = @vals;
179 0 push @data, \%row;
180 }
181 }
182 0 close $fh;
183 0 return \@data;
184 }
185  
186 1 1;
« CVD/Film.pm ↑ Summary CVD/Chemistry.pm »