harmonic_fit_rot_phi.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #! /usr/bin/env python
  2. import subprocess, re, os, time, random
  3. #from harmonic_fit import comp_k_analytic
  4. import sys
  5. import csv
  6. import numpy as np
  7. import matplotlib.pyplot as plt
  8. import math
  9. #from mpl_toolkits.mplot3d import axes3d
  10. from scipy.interpolate import interp1d, CubicSpline
  11. plt.rcParams['font.family'] = 'sans-serif'
  12. plt.rcParams['font.family'] = 'Times New Roman'
  13. plt.rcParams['axes.edgecolor']='#333F4B'
  14. plt.rcParams['axes.linewidth']=0.8
  15. plt.rcParams['xtick.color']='#333F4B'
  16. plt.rcParams['ytick.color']='#333F4B'
  17. plt.rcParams["axes.prop_cycle"]
  18. # Read CSV
  19. csvFileName = sys.argv[1]
  20. scan_var = csvFileName.split('.')[0]
  21. pltFileName = scan_var + '.png'
  22. csvData = []
  23. with open(csvFileName, 'r') as csvFile:
  24. csvReader = csv.reader(csvFile, delimiter = ' ')
  25. for csvRow in csvReader:
  26. csvData.append(csvRow)
  27. # Get X, Y and store in np array
  28. csvData = np.array(csvData)
  29. csvData = csvData.astype(np.float)
  30. X, Y = csvData[:,0], csvData[:,1]
  31. au_to_kJpmol = 2625.5
  32. # convert kJpmol to au
  33. Y = np.array([y/au_to_kJpmol for y in Y])
  34. def comp_k_analytic(X,Y):
  35. """
  36. Compute the analytic force constant given X, and V(X)
  37. """
  38. N = X.size
  39. eq = 0
  40. f2 = CubicSpline(X,Y)
  41. k_analytic = f2(X, 2)[0]
  42. return k_analytic, f2
  43. def convert_k_to_cminv_rotor(k):
  44. """
  45. Convert force constant in Hartree/Radian^2 to cm-1
  46. this is for h2
  47. """
  48. I = 1948.37443393238771437461228584
  49. nu = 1/(2*np.pi)*math.sqrt(k/I)*(1/(137*5.29*10**-9))
  50. return nu
  51. #k_numeric = comp_k_numeric(X, Y)
  52. k_analytic, f2 = comp_k_analytic(X, Y)
  53. nu_analytic = convert_k_to_cminv_rotor(k_analytic)
  54. zpve_analytic = nu_analytic/2
  55. print (scan_var, "Analytic", k_analytic, nu_analytic, zpve_analytic)
  56. #k_numeric = comp_k_numeric(X, Y)
  57. #k_analytic, f2 = comp_k_analytic(X, Y)
  58. #print ("Force constants for ", scan_var)
  59. #print ("Analytic_derivative ==", k_analytic, "Hartree/Ang^2")
  60. #print ("Numeric_derivative ==", k_numeric, "Hartree/Ang^2")
  61. plt.plot(X, Y, 'bo')
  62. plt.plot(X, f2(X), 'b-')
  63. plt.plot(X, f2(X, 1), 'rx--')
  64. plt.plot(X, f2(X, 2), 'co')
  65. plt.legend(['Points', 'Cubic Spline', r'dV/d${\phi}$', r"d2V/d${\phi}^{2}$"], fontsize = 12)
  66. plt.xlabel(r"$\phi$", fontsize = 16)
  67. plt.ylabel("E(a.u) and higher derivs", fontsize = 16)
  68. plt.savefig(pltFileName)