-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathase_plot_ir_activity
More file actions
executable file
·80 lines (54 loc) · 1.67 KB
/
ase_plot_ir_activity
File metadata and controls
executable file
·80 lines (54 loc) · 1.67 KB
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
#! /usr/bin/env python3
from pathlib import Path
import typer
from rich import print as echo
import numpy as np
def lorentzian(x, x0, gamma):
"""Simple normalized Lorentzian"""
return gamma / np.pi / ((x - x0) ** 2 + gamma**2)
def lorentzian2(x, x0, Gamma):
"""normalized Lorentzian with FWHM"""
gamma = Gamma / 2
return gamma / np.pi / ((x - x0) ** 2 + gamma**2)
def gaussian2(x, x0, Gamma):
"""normalized Gaussian with FWHM parameter"""
sigma = Gamma / np.sqrt(2 * np.log(16))
return np.exp(-((x - x0) ** 2) / 2 / sigma**2) / sigma / np.sqrt(2 * np.pi)
app = typer.Typer(pretty_exceptions_show_locals=False)
@app.command()
def main(
file: Path = "outfile.mode_activity.csv",
width: float = 10.0,
xmin: float = None,
xmax: float = None,
xpoints: int = 1001,
gaussian: bool = False,
outfile: Path = "outfile.mode_activity.pdf",
):
"""Plot IR activities"""
from matplotlib import pyplot as plt
import numpy as np
import pandas as pd
df = pd.read_csv(file)
x = df["frequency (cm^-1)"]
y = df["activity"]
if xmin is None:
xmin = x.min()
if xmax is None:
xmax = 1.2 * x.max()
xs = np.linspace(xmin, xmax, xpoints)
ys = []
for _x, _y in zip(x, y):
if gaussian:
ys.append(_y * gaussian2(xs, _x, width))
else:
ys.append(_y * lorentzian2(xs, _x, width))
ys = np.array(ys)
fig, ax = plt.subplots()
ax.plot(xs, ys.sum(axis=0), label="Total")
ax.set_xlabel("Frequency (cm$^{-1}$)")
ax.set_ylabel("Intensity")
echo(f'... save to "{outfile}"')
fig.savefig(outfile)
if __name__ == "__main__":
app()