forked from julienluzzatto/aKMC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LMP_EnergyEval3.jl
198 lines (158 loc) · 7.63 KB
/
LMP_EnergyEval3.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
## Functions to run energy evaluation in LAMMPS.jl
using LAMMPS
function startN_LAMMPS_instances(N::Int)
LMPvect=[ LMP(["-screen","none","-sf", "omp", "-pk", "omp 4"]) for i=1:N]
#LMPvect=[ LMP(["-sf", "omp", "-pk", "omp 4"]) for i=1:N]
return LMPvect
end
function MinimizeCoords(Full_LMPvect,OLatticeSites,HFLatticeSites,Temp,MD_timestep,SimDim,MinSteps,MDsteps)
command.(LMPvect,"clear")
OxygenAtoms=OLatticeSites[OLatticeSites[:,7].==1,:];
LMP_v=Full_LMPvect[1];
FinBaseCoords=[[Inf Inf Inf Inf] for ind=1:size(HFLatticeSites,1)];
FinOxyCoords=[[Inf Inf Inf Inf] for ind=1:size(OxygenAtoms,1)];
newOLatticeSites=[];
newHFLatticeSites=[];
#Basic LMP setup
try
command(LMP_v,"units metal");
command(LMP_v,"atom_style charge");
command(LMP_v,"dimension 3");
command(LMP_v,"boundary p p m");
command(LMP_v,"processors * * *");
#Setup Box
command(LMP_v,"region SimulationDomain block 0.0 " * string(SimDim[1]) * " 0.0 " * string(SimDim[2]) * " 0.0 " * string(SimDim[3]));
command(LMP_v,"create_box 4 SimulationDomain");
for jnd=1:size(HFLatticeSites,1)
command(LMP_v,"create_atoms " * string(floor(Int,HFLatticeSites[jnd,2])) * " single " * string(HFLatticeSites[jnd,4]) * " " * string(HFLatticeSites[jnd,5]) * " " * string(HFLatticeSites[jnd,6]) )
end
for knd=1:size(OxygenAtoms,1)
command(LMP_v,"create_atoms 4 single " * string(OxygenAtoms[knd,4]) * " " * string(OxygenAtoms[knd,5]) * " " * string(OxygenAtoms[knd,6]));
end
#Continue Setup
command(LMP_v,"group Hf-fixed type 1");
command(LMP_v,"group Hf-temp type 2");
command(LMP_v,"group Hf-nve type 3");
command(LMP_v,"group Oxygen type 4");
command(LMP_v,"group Hf-group type 1 2 3");
command(LMP_v,"mass 1 178.4900");
command(LMP_v,"mass 2 178.4900");
command(LMP_v,"mass 3 178.4900");
command(LMP_v,"mass 4 15.9990");
#Setup Potential
command(LMP_v,"pair_style comb");
command(LMP_v,"pair_coeff * * ffield.comb Hf Hf Hf O ");
command(LMP_v,"neighbor 2.0 bin");
command(LMP_v,"neigh_modify every 1 delay 0 check no");
command(LMP_v,"fix CombQEQ all qeq/comb 1 0.001");
#println("Set QEQcomb: minimize");
command(LMP_v,"timestep " * string(MD_timestep));
#Define Dynamics
command(LMP_v,"velocity all create " * string(Temp) * " " * string(abs.(rand(Int16,1))[1]) * " dist gaussian");
command(LMP_v,"fix 101 Hf-fixed move linear 0.0 0.0 0.0 units box ");
command(LMP_v,"fix 102 Hf-temp nvt temp " * string(Temp) * " " * string(Temp) * " " * string(100.0*MD_timestep));
command(LMP_v,"fix 103 Hf-nve nve");
command(LMP_v,"fix 104 Oxygen nve");
command(LMP_v,"delete_atoms overlap 0.5 all all")
command(LMP_v,"compute AtomPE all pe/atom ");
command(LMP_v,"compute AtomXYZ all property/atom x y z ");
command(LMP_v,"compute MyTestPE all reduce sum c_AtomPE");
command(LMP_v,"compute MyTestLoc all reduce sum c_AtomXYZ[1] c_AtomXYZ[2] c_AtomXYZ[3]");
command(LMP_v,"thermo 1");
command(LMP_v,"thermo_style custom step temp press etotal atoms c_MyTestPE spcpu");
command(LMP_v,"min_style sd");
command(LMP_v,"min_modify dmax 0.1");
command(LMP_v,"minimize 1.0e-10 1.0e-10 " * string(MinSteps) * " " * string(MinSteps));
command(LMP_v,"run " * string(MDsteps));
FinCoords=hcat(extract_atom(LMP_v,"type"),convert(Matrix,extract_atom(LMP_v,"x")'))
OxyKey=FinCoords[:,1].==4;
BaseKey=.!OxyKey;
newOLatticeSites=convert(Matrix{Any},hcat(1:sum(OxyKey),FinCoords[OxyKey,1],zeros(sum(OxyKey),1),FinCoords[OxyKey,2:4],ones(sum(OxyKey),1)));
newHFLatticeSites=convert(Matrix{Any},hcat(1:sum(BaseKey),FinCoords[BaseKey,1],zeros(sum(BaseKey),1),FinCoords[BaseKey,2:4],ones(sum(BaseKey),1)));
catch
newOLatticeSites=OLatticeSites;
newHFLatticeSites=HFLatticeSites;
println("Minimize Sim Failed");
end
return newOLatticeSites,newHFLatticeSites
end
function EnergyEvalSim(Full_LMPvect,OLatticeSites,HFLatticeSites,PossibleNeighbors,Temp,MD_timestep,SimDim)
command.(LMPvect,"clear")
OxygenAtoms=OLatticeSites[OLatticeSites[:,7].==1,:];
NumSites=size(PossibleNeighbors,1);
LMP_v=Full_LMPvect[1:NumSites];
EnergyVector=[Inf for ind=1:NumSites]
#Basic LMP setup
#Threads.@threads
for ind=1:NumSites
try
command(LMP_v[ind],"units metal");
command(LMP_v[ind],"atom_style charge");
command(LMP_v[ind],"dimension 3");
command(LMP_v[ind],"boundary p p m");
command(LMP_v[ind],"processors * * *");
#Setup Box
command(LMP_v[ind],"region SimulationDomain block 0.0 " * string(SimDim[1]) * " 0.0 " * string(SimDim[2]) * " 0.0 " * string(SimDim[3]));
command(LMP_v[ind],"create_box 5 SimulationDomain");
command(LMP_v[ind],"create_atoms 5 single " * string(PossibleNeighbors[ind,1]) * " " * string(PossibleNeighbors[ind,2]) * " " * string(PossibleNeighbors[ind,3]));
for jnd=1:size(HFLatticeSites,1)
command(LMP_v[ind],"create_atoms " * string(floor(Int,HFLatticeSites[jnd,2])) * " single " * string(HFLatticeSites[jnd,4]) * " " * string(HFLatticeSites[jnd,5]) * " " * string(HFLatticeSites[jnd,6]) )
end
for knd=1:size(OxygenAtoms,1)
command(LMP_v[ind],"create_atoms 4 single " * string(OxygenAtoms[knd,4]) * " " * string(OxygenAtoms[knd,5]) * " " * string(OxygenAtoms[knd,6]));
end
#Continue Setup
command(LMP_v[ind],"group Hf-fixed type 1");
command(LMP_v[ind],"group Hf-temp type 2");
command(LMP_v[ind],"group Hf-nve type 3");
command(LMP_v[ind],"group Oxygen type 4");
command(LMP_v[ind],"group OxygenTest type 5");
command(LMP_v[ind],"group Freeze type 1 2 3 4");
command(LMP_v[ind],"mass 1 178.4900");
command(LMP_v[ind],"mass 2 178.4900");
command(LMP_v[ind],"mass 3 178.4900");
command(LMP_v[ind],"mass 4 15.9990");
command(LMP_v[ind],"mass 5 15.9990");
#Setup Potential
command(LMP_v[ind],"pair_style comb");
command(LMP_v[ind],"pair_coeff * * ffield.comb Hf Hf Hf O O ");
command(LMP_v[ind],"neighbor 2.0 bin");
command(LMP_v[ind],"neigh_modify every 1 delay 0 check no");
command(LMP_v[ind],"fix CombQEQ all qeq/comb 1 0.001");
println("Set QEQcomb: sim" * string(ind));
command(LMP_v[ind],"timestep " * string(MD_timestep));
#println("Set timestep");
#Define Dynamics
#command(LMP_v[ind],"delete_atoms overlap 0.5 all all")
command(LMP_v[ind],"velocity all create " * string(Temp) * " " * string(abs.(rand(Int16,1))[1]) * " dist gaussian");
#println("Set velocity");
command(LMP_v[ind],"fix FreezeAtoms Freeze move linear 0.0 0.0 0.0 units box ");
command(LMP_v[ind],"fix 102 OxygenTest nve/limit 0.05");
#println("Set fix");
command(LMP_v[ind],"compute AtomPE OxygenTest pe/atom ");
command(LMP_v[ind],"compute AtomXYZ OxygenTest property/atom x y z ");
command(LMP_v[ind],"compute MyTestPE OxygenTest reduce sum c_AtomPE");
command(LMP_v[ind],"compute MyTestLoc OxygenTest reduce sum c_AtomXYZ[1] c_AtomXYZ[2] c_AtomXYZ[3]");
#println("Set compute");
command(LMP_v[ind],"thermo 1");
command(LMP_v[ind],"thermo_style custom step temp press etotal atoms c_MyTestPE spcpu");
command(LMP_v[ind],"min_style sd");
command(LMP_v[ind],"min_modify dmax 0.1");
#println("MINIMIZE Energy Eval")
command(LMP_v[ind],"minimize 1.0e-10 1.0e-10 15 15");
#println("MD Energy Eval")
command(LMP_v[ind],"run 10");
atomIDkey=extract_atom(LMP_v[ind],"type").==5
EnergyVector[ind]=extract_compute(LMP_v[ind],"AtomPE",LAMMPS.API.LMP_STYLE_ATOM,LAMMPS.API.LMP_TYPE_VECTOR)[atomIDkey][1]
catch
#println("Bad LAMMPS Sim Caught")
EnergyVector[ind]=Inf;
end
end
#display(FinCoords)
#display(EnergyVector)
command.(LMPvect,"clear")
#command.(LMP_v,"");
#command.(LMPvect,"clear")
return EnergyVector
end