0% found this document useful (0 votes)
175 views2 pages

Birch-Murnaghan Equation of State

This document imports several Python libraries for tasks like file manipulation, regular expressions, and data analysis. It then sets the working directory and reads in experimental data on platinum crystal volumes and energies from an Excel file. Two equations of state, Murnaghan and Birch-Murnaghan, are defined to fit the data and their parameters are estimated using least squares optimization. The best fit is plotted along with the experimental data and saved as a figure.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
175 views2 pages

Birch-Murnaghan Equation of State

This document imports several Python libraries for tasks like file manipulation, regular expressions, and data analysis. It then sets the working directory and reads in experimental data on platinum crystal volumes and energies from an Excel file. Two equations of state, Murnaghan and Birch-Murnaghan, are defined to fit the data and their parameters are estimated using least squares optimization. The best fit is plotted along with the experimental data and saved as a figure.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

# -*- coding: utf-8 -*-

"""
Created on Fri May 29 16:53:17 2020

@author: RicardoGC
"""
# Folder & Files manipulation
import os # Miscellaneous operating system interfaces:
https://docs.python.org/3/library/os.html
import re # Regular expression operations:
https://docs.python.org/3/library/re.html
import sys # System-specific parameters and functions:
https://docs.python.org/3/library/sys.html
import subprocess # It allows to use shell commands:
https://docs.python.org/3/library/subprocess.html
import glob # Finds all the pathnames matching a specified
pattern according to Unix shell rules
import math
import csv
from pandas import ExcelWriter
from pandas import ExcelFile
import pandas as pd
import matplotlib.pyplot as plt
from scipy.optimize import leastsq
import numpy as np
import matplotlib.pyplot as plt
from sklearn.metrics import r2_score

###To change working directory


op=2
if op==1:
os.chdir("C:/Users/rachel_group/Google Drive/Clemson/Lab
Research/2020/Adsorbate Generation") #Set Working directory
else:
os.chdir("C:/Users/RicardoGC/Box Sync/Clemson/Lab Research/2020/Gamma
Alumina/Validation") #Set Working directory

#%% Scratch1

Validation=pd.DataFrame(pd.read_excel("Pt Conventional Standard Cell Optimization


(Bulk).xlsx","Lattice"))

Validation=Validation[Validation['Energy/Atom (eV)']<0] #Optional filter for


far values
Validation=Validation[Validation['Volume/Atom (Å3)']<30] #Optional filter for
far values
vols = Validation['Volume/Atom (Å3)']

energies = Validation['Energy/Atom (eV)']

def Murnaghan(parameters, vol):


'From Phys. Rev. B 28, 5480 (1983)'
E0, B0, BP, V0 = parameters
E = E0 + B0 * vol / BP * (((V0 / vol)**BP) / (BP - 1) + 1) - V0 * B0 / (BP -
1.0)
return E

def Birch_Murnaghan(parameters, vol):


'From Birch, Francis (1947). "Finite Elastic Strain of Cubic Crystals".
Physical Review. 71 (11): 809–824.'
E0, B0, BP, V0 = parameters
E = E0 + 9*V0*B0/16*(BP*((V0/vol)**(2/3)-1)**3+(((V0/vol)**(2/3)-1)**2*(6-
4*(V0/vol)**(2/3))))
return E

opp=2 #Select the state equation

if opp==1:
#Murnaghan equation
def objective(pars, y, x):
"""To minimize a function"""
err = y - Murnaghan(pars, x)
return err
x0 = [ -56.0, 0.54, 2.0, 16.5] #initial guess of parameters
elif opp==2:
#Birch Murnaghan equation
def objective(pars, y, x):
"""To minimize a function"""
err = y - Birch_Murnaghan(pars, x)
return err
x0 = [ energies.mean(), 1, 2.0, vols.mean()] #initial guess of parameters

plsq = leastsq(objective, x0, args=(energies, vols))


fit=Birch_Murnaghan(plsq[0], vols)
R2=r2_score(fit,energies)
print("Parameters: [E0, B0, BP, V0]")
print('Fitted parameters = {0}'.format(plsq[0]))
print("Pearson Coefficient of Determination (R2): {0}".format(R2))

plt.plot(vols,energies, 'ro')

#plot the fitted curve on top


x = np.linspace(min(vols), max(vols), 50)
y = Murnaghan(plsq[0], x)
plt.plot(x, y, 'k-',color='midnightblue')
plt.title('Birch Murnaghan Equation of State',fontweight="bold")
plt.xlabel('Volume/Atom (Å3)')
plt.ylabel('Energy/Atom (eV)')
plt.savefig('StateEquation.png',dpi=600)

You might also like