Вы находитесь на странице: 1из 2

#Script to estimate the parameters of the Birch-Murnaghan equation of

state
library(readxl)
library(utils)
library(ggplot2)
setwd("C:/Users/RicardoGC/Box Sync/Clemson/Lab Research/2020/Gamma
Alumina/Validation")
#Validation=read_excel("C:/Users/RicardoGC/Box Sync/Clemson/Lab
Research/2020/Gamma Alumina/Validation/Pt Conventional Standard Cell
Optimization (Bulk).xlsx")
Validation=read_excel("Gamma Alumina Digner Slab a Lattice
Optimization.xlsx",sheet = "GO Point Lattice")
###Find closest
closestx=function(x,value) {
which(abs(x-value)==min(abs(x-value)))
return(x[which(abs(x-value)==min(abs(x-value)))])
}
closesty=function(x,y,value) {
which(abs(x-value)==min(abs(x-value)))
return(y[which(abs(x-value)==min(abs(x-value)))])
}
###
Validation=Validation[!is.na(Validation$`Energy/Atom (eV)`),]
Validation=Validation[Validation$`Energy/Atom (eV)`<=0,]
#Validation=Validation[Validation$`Energy/Atom (eV)`<=-4,]

#Constants=[E0,B0,B0p,V0]
Constants0=c(min(Validation$`Energy/Atom
(eV)`),1,1,min(Validation$`Volume/Atom (Å3)`))

BM=function(V,E0,B0,B0p,V0) {
#E0=Constants[1]
#B0=Constants[2]
#B0p=Constants[3]
#V0=Constants[4]
E=E0+9/16*V0*B0*(((V0/V)^(2/3)-1)^3*B0p+(((V0/V)^(2/3)-1)^2*(6-
4*(V0/V)^(2/3))))
return(E)
}

#Plot initial fit


y=Validation$`Energy/Atom (eV)`
x=Validation$`Volume/Atom (Å3)`
lo <- loess(y~x)
xl <- seq(min(x),max(x), (max(x) - min(x))/1000)
plot(Validation$`Volume/Atom (Å3)`,Validation$`Energy/Atom
(eV)`,cex=1.25,xlab = "Volume/Atom (A3/Atom)",ylab = "Energy per Atom
(eV/Atom)",main = "Lattice Optimization plot")
lines(xl, predict(lo,xl), col='darkblue', lwd=2)

#Fit model
E=y
V=x
model=nls(formula = E~BM(V,E0,B0,B0p,V0),start =
list(E0=Constants0[1],B0=Constants0[2],B0p=Constants0[3],V0=Constants0[4]
))
E_Predicted=predict(model)
Pearson_R2=cor(x = E_Predicted,y = E,method = c("pearson"))^2
Spearman_R2=cor(x = E_Predicted,y = E,method = c("spearman"))^2
Validation$E_Predicted=E_Predicted
OptimunLatticeParameter=summary(model)
$parameters[4,1]/closesty(x=Validation$`Lattice Factor`,y =
Validation$`Volume/Atom (Å3)`,value = 1)

cat("Statistics in Birch-Murnaghan equation of state\n")


summary(model)
cat("Pearson Coefficient of Determination:\n")
cat(Pearson_R2)
cat("Spearman Coefficient of Determination:\n")
cat(Spearman_R2)
cat("Optimun Lattice Parameter:\n")
cat(OptimunLatticeParameter)
p<-ggplot(Validation, aes(x=`Volume/Atom (Å3)`, y=`Energy/Atom (eV)`))
+geom_line(aes(x=`Volume/Atom (Å3)`,
y=E_Predicted),size=0.75,col="darkred",linetype="dashed")
+geom_point(col="navyblue",size=3)+theme(plot.title =
element_text(face="bold",hjust = 0.5),axis.title = element_text(face =
"bold",size = 11),panel.grid.major = element_blank(), panel.grid.minor =
element_blank(),panel.background = element_blank(),legend.key
=element_blank(), axis.line = element_line(colour = "black"))
+scale_color_manual(values=c("Navyblue", "#14681F", "#891313"))
+labs(y="Energy/Atom (eV)",x="Volume/Atom (Å3)",title ="Birch-Murnaghan
equation of state")+theme(plot.title = element_text(hjust =
0.5),axis.title = element_text(face = "bold",size = 11),strip.text =
element_text(hjust = 0.5,size = 11,face = "bold"),axis.text.x =
element_text(size=12),axis.text.y = element_text(size=12))+
theme(legend.position="bottom")+ theme(legend.title=element_blank())
+scale_x_continuous(breaks = seq(0,28,4),guide = guide_axis(n.dodge = 1))
#+scale_x_discrete(guide = guide_axis(n.dodge = 2))
p
ggsave(p,file="Birch-Murnaghan equation of state.png",dpi = 3000,width =
8,height = 5)

Вам также может понравиться