harmonic_fit_rot.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. #print ("Numeric ", k_numeric, nu_numeric, zpve_numeric)
  57. #print ("Force constants for ", scan_var)
  58. #print ("Analytic_derivative ==", k_analytic, "Hartree/Radian^2")
  59. #print ("Numeric_derivative ==", k_numeric, "Hartree/Ang^2")
  60. plt.plot(X, Y, 'bo')
  61. plt.plot(X, f2(X), 'b-')
  62. plt.plot(X, f2(X, 1), 'rx--')
  63. plt.plot(X, f2(X, 2), 'co--')
  64. plt.legend(['Points', 'Cubic Spline', r'dV/d${\theta}$', r"d2V/d${\theta}^{2}$"], fontsize = 12)
  65. plt.xlabel(r"$\theta$", fontsize = 16)
  66. plt.ylabel("E(a.u) and higher derivs", fontsize = 16)
  67. plt.savefig(pltFileName)