|
| 1 | +from re import template |
| 2 | +import numpy as np |
| 3 | +#import scipy.special as sp |
| 4 | +import pandas as pd |
| 5 | +import plotly.graph_objects as go |
| 6 | + |
| 7 | +import util as util |
| 8 | + |
| 9 | + |
| 10 | +class Hydrogen_Wave: |
| 11 | + def __init__(self) -> None: |
| 12 | + pass |
| 13 | + |
| 14 | + def vizualise_wave(self, threshold, plot_kwargs): |
| 15 | + self.evaluate_points() |
| 16 | + self.apply_threshold(threshold=threshold) |
| 17 | + self.get_plot_kwargs(plot_kwargs) |
| 18 | + self.create_dataframe() |
| 19 | + self.create_plot() |
| 20 | + |
| 21 | + def set_quantum_number(self, n, l, m): |
| 22 | + """ |
| 23 | + Initialize the quantum numbers |
| 24 | + Parameters: |
| 25 | + ----------- |
| 26 | + n : int |
| 27 | + Principle number, in [0,1,2,...] |
| 28 | + l : int |
| 29 | + Azimuthal number, in [0,n-1] |
| 30 | + m : int |
| 31 | + Magnetic number, in [-l,l] |
| 32 | + """ |
| 33 | + self.n = n |
| 34 | + self.l = l |
| 35 | + self.m = m |
| 36 | + |
| 37 | + self.initialize_wave_function() |
| 38 | + |
| 39 | + def initialize_wave_function(self): |
| 40 | + self.wave_function = lambda x: ( |
| 41 | + util.wave_function( |
| 42 | + n=self.n, l=self.l, m=self.m, r=x[:, 0], theta=x[:, 1], phi=x[:, 2] |
| 43 | + ) |
| 44 | + ) |
| 45 | + |
| 46 | + def generate_data(self, n_points, low, high): |
| 47 | + data, r_theta_phi, x_y_z = util.generate_evaluation_points(n_points, low, high) |
| 48 | + self.r_theta_phi = r_theta_phi |
| 49 | + self.x_y_z = x_y_z |
| 50 | + self.data = data |
| 51 | + |
| 52 | + def evaluate_points(self): |
| 53 | + self.wav = self.wave_function(self.r_theta_phi) |
| 54 | + |
| 55 | + def apply_threshold(self, threshold): |
| 56 | + indices = np.where(np.abs(self.wav) > threshold) |
| 57 | + |
| 58 | + self.wav = self.wav[indices].reshape(-1, 1) |
| 59 | + self.x_y_z = self.x_y_z[indices] |
| 60 | + |
| 61 | + def create_dataframe(self): |
| 62 | + data = np.append(self.x_y_z, self.wav, axis=1) |
| 63 | + data = pd.DataFrame(data, columns=["x", "y", "z", "wav"]) |
| 64 | + self.data = data |
| 65 | + |
| 66 | + def get_plot_kwargs(self, plot_kwargs): |
| 67 | + self.opacity = plot_kwargs["opacity"] |
| 68 | + self.marker_size = plot_kwargs["marker_size"] |
| 69 | + self.colorscale = plot_kwargs["colorscale"] |
| 70 | + self.theme = plot_kwargs["theme"] |
| 71 | + |
| 72 | + def create_plot(self): |
| 73 | + fig = go.Figure( |
| 74 | + data=[ |
| 75 | + go.Scatter3d( |
| 76 | + x=self.data["x"], |
| 77 | + y=self.data["y"], |
| 78 | + z=self.data["z"], |
| 79 | + mode="markers", |
| 80 | + marker=dict( |
| 81 | + size=self.marker_size, |
| 82 | + color=self.data["wav"], |
| 83 | + colorscale=self.colorscale, |
| 84 | + opacity=self.opacity, |
| 85 | + ), |
| 86 | + ) |
| 87 | + ] |
| 88 | + ) |
| 89 | + fig.update_layout(margin=dict(l=0, r=0, b=0, t=0)) |
| 90 | + fig.update_layout(template=self.theme) |
| 91 | + fig.show() |
| 92 | + |
| 93 | + |
| 94 | +if __name__ == "__main__": |
| 95 | + print() |
| 96 | + print() |
| 97 | + print() |
| 98 | + themes = [ |
| 99 | + "plotly", |
| 100 | + "plotly_white", |
| 101 | + "plotly_dark", |
| 102 | + "ggplot2", |
| 103 | + "seaborn", |
| 104 | + "simple_white", |
| 105 | + "none", |
| 106 | + ] |
| 107 | + plot_kwargs = { |
| 108 | + "opacity": 1, |
| 109 | + "colorscale": "plasma", |
| 110 | + "marker_size": 2, |
| 111 | + "theme": "plotly_dark", |
| 112 | + } |
| 113 | + |
| 114 | + wave = Hydrogen_Wave() |
| 115 | + |
| 116 | + # n=4, l=2, m=0) |
| 117 | + wave.set_quantum_number(n=4, l=2, m=0) |
| 118 | + wave.generate_data(n_points=200000, low=-35, high=35) |
| 119 | + wave.vizualise_wave(threshold=0.01, plot_kwargs=plot_kwargs) |
| 120 | + |
| 121 | + # n=4, l=1, m=0 |
| 122 | + wave.set_quantum_number(n=4, l=1, m=0) |
| 123 | + wave.generate_data(n_points=600000, low=-50, high=50) |
| 124 | + wave.vizualise_wave(threshold=0.02, plot_kwargs=plot_kwargs) |
| 125 | + |
| 126 | + # n=4, l=3, m=2) |
| 127 | + wave.set_quantum_number(n=4, l=3, m=2) |
| 128 | + wave.generate_data(n_points=600000, low=-30, high=30) |
| 129 | + wave.vizualise_wave(threshold=0.01, plot_kwargs=plot_kwargs) |
| 130 | + |
| 131 | + # n=4, l=2, m=2 |
| 132 | + wave.set_quantum_number(n=4, l=2, m=2) |
| 133 | + wave.generate_data(n_points=600000, low=-35, high=35) |
| 134 | + wave.vizualise_wave(threshold=0.01, plot_kwargs=plot_kwargs) |
| 135 | + |
| 136 | + # n=4, l=2, m=2 |
| 137 | + wave.set_quantum_number(n=4, l=2, m=2) |
| 138 | + wave.generate_data(n_points=600000, low=-35, high=35) |
| 139 | + wave.vizualise_wave(threshold=0.01, plot_kwargs=plot_kwargs) |
| 140 | + |
| 141 | + # n=5, l=3, m=1 |
| 142 | + wave.set_quantum_number(n=5, l=3, m=1) |
| 143 | + wave.generate_data(n_points=600000, low=-50, high=50) |
| 144 | + wave.vizualise_wave(threshold=0.008, plot_kwargs=plot_kwargs) |
0 commit comments