Polarimeteric Code
Published: 2023-10-30 04:40:00

Here in the continuum of my STEAM blog, I have attempted a try to write a polarimeteric analysis code. Recently India's Chandrayaan-3 went to the south pole of Moon and demonstrated soft landing capabilities of a humble space organization. This mission includes a very scientific analysis technique called polarimetry and it widely used in STEAM fields. 


> Whenever circular polarization effects are present in the sample, elliptical properties of the output light must be considered:

![Credit: SAGE Publications](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5na5zbbmij2v3gvc5n0h.png)




The following are the steps followed:

- Import the necessary libraries, numpy and matplotlib.pyplot.
- Define the wavelength of light used (in nm).
- Define the length of the sample cell (in cm).
- Read the optical rotation data from the polarimeter.
- Calculate the specific rotation (degrees per cm per g/mL).
- Calculate the optical rotation angle (degrees).
- Calculate the chirality (sign of specific rotation).
- Create a placeholder for the molecule structure.
- Create a placeholder for the impurities detection.
- Create a placeholder for the properties calculation.
- Plot the specific rotation vs. concentration.
- Plot the optical rotation angle vs. concentration.
- Plot the chirality vs. concentration.
- Plot the molecule structure vs. concentration.
- Plot the impurities vs. concentration.
- Plot the properties vs. concentration.

Sample Code:

```
import numpy as np
import matplotlib.pyplot as plt

##Define the wavelength of light used (in nm)
wavelength = 589.33

##Define the length of the sample cell (in cm)
length = 10.0

##Read the optical rotation data from the polarimeter
rotation_data = np.loadtxt("rotation_data.txt")

##Calculate the specific rotation (degrees per cm per g/mL)
specific_rotation = rotation_data / (length * 1.0)  ##Concentration is assumed to be 1.0 g/mL

##Calculate the optical rotation angle (degrees)
optical_rotation_angle = specific_rotation * wavelength

##Calculate the chirality (sign of specific rotation)
chirality = np.sign(specific_rotation)

##Concentration data (for illustration purposes)
concentration = np.linspace(0.1, 1.0, len(rotation_data))  ##Example concentration values

##Placeholder for molecule structure (replace with appropriate data)
structure = np.random.rand(len(rotation_data))  ##Replace with actual structure data

##Placeholder for impurities detection (replace with appropriate data)
impurities = np.random.rand(len(rotation_data))  ##Replace with actual impurities data

##Placeholder for properties calculation (replace with appropriate data)
properties = np.random.rand(len(rotation_data))  ##Replace with actual properties data

##Plot the specific rotation vs. concentration
plt.figure(figsize=(8, 6))
plt.plot(concentration, specific_rotation)
plt.xlabel("Concentration (g/mL)")
plt.ylabel("Specific Rotation (degrees per cm per g/mL)")
plt.title("Specific Rotation vs. Concentration")
plt.grid(True)
plt.show()

##Plot the optical rotation angle vs. concentration
plt.figure(figsize=(8, 6))
plt.plot(concentration, optical_rotation_angle)
plt.xlabel("Concentration (g/mL)")
plt.ylabel("Optical Rotation Angle (degrees)")
plt.title("Optical Rotation Angle vs. Concentration")
plt.grid(True)
plt.show()

##Plot the chirality vs. concentration
plt.figure(figsize=(8, 6))
plt.plot(concentration, chirality)
plt.xlabel("Concentration (g/mL)")
plt.ylabel("Chirality")
plt.title("Chirality vs. Concentration")
plt.grid(True)
plt.show()

##Placeholder for structure vs. concentration (replace with appropriate visualization)
plt.figure(figsize=(8, 6))
plt.plot(concentration, structure)
plt.xlabel("Concentration (g/mL)")
plt.ylabel("Structure (Placeholder)")
plt.title("Structure vs. Concentration")
plt.grid(True)
plt.show()

##Placeholder for impurities vs. concentration (replace with appropriate visualization)
plt.figure(figsize=(8, 6))
plt.plot(concentration, impurities)
plt.xlabel("Concentration (g/mL)")
plt.ylabel("Impurities (Placeholder)")
plt.title("Impurities vs. Concentration")
plt.grid(True)
plt.show()

##Placeholder for properties vs. concentration (replace with appropriate visualization)
plt.figure(figsize=(8, 6))
plt.plot(concentration, properties)
plt.xlabel("Concentration (g/mL)")
plt.ylabel("Properties (Placeholder)")
plt.title("Properties vs. Concentration")
plt.grid(True)
plt.show()

```