<jupyter_start><jupyter_text>Create Heater Thermal Profiles<jupyter_code>%matplotlib inline

import ipywidgets as widgets
from IPython.display import display
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

def PCR_thermal_cycle(filename):

    filename_text = widgets.Text(value=filename, description="Filename")

    heat_rate = widgets.FloatSlider(value = 0.31, min=0.1, max=2, step=0.01, description='Heat Rate')
    cool_rate = widgets.FloatSlider(value = 0.31, min=0.1, max=2, step=0.01, description='Cooling Rate')
    cycles = widgets.IntSlider(value=3, min=1, max=30, description="PCR Cycles")

    denaturation_label = widgets.Label('Denaturation', layout=widgets.Layout(width='80px'))
    denaturation_temp = widgets.FloatSlider(value=94, min=92, max=98, step=0.1, description='Temperature', readout_format='0.1f')
    denaturation_dur = widgets.BoundedIntText(value=90, min=60, max=120, step=1, description='Duration')
    denaturation = widgets.HBox([denaturation_label, denaturation_temp, denaturation_dur])

    annealing_label = widgets.Label('Annealing', layout=widgets.Layout(width='80px'))
    annealing_temp = widgets.FloatSlider(value=60, min=50, max=65, step=0.1, description='Temperature', readout_format='0.1f')
    annealing_dur = widgets.BoundedIntText(value=60, min=30, max=120, step=1, description='Duration')
    annealing = widgets.HBox([annealing_label, annealing_temp, annealing_dur])

    extension_label = widgets.Label('Extension', layout=widgets.Layout(width='80px'))
    extension_temp = widgets.FloatSlider(value=70, min=68, max=72, step=0.1, description='Temperature', readout_format='0.1f')
    extension_dur = widgets.BoundedIntText(value=90, min=30, max=180, step=1, description='Duration')
    extension = widgets.HBox([extension_label, extension_temp, extension_dur])
    
   
    def create_setpoint_trajectory(
            filename_text,
            heat_rate, cool_rate, cycles,
            denaturation_temp, denaturation_dur, 
            annealing_temp, annealing_dur,
            extension_temp, extension_dur,):
        Ta = 22
        tp = [0]
        Tp = [Ta]   

        for k in range(0, cycles):
            # denaturation
            tp.append(tp[-1] + (denaturation_temp - Tp[-1]) / heat_rate)
            Tp.append(denaturation_temp)
            tp.append(tp[-1] + denaturation_dur)
            Tp.append(denaturation_temp)

            # annealing
            tp.append(tp[-1] - (annealing_temp - denaturation_temp) / cool_rate)
            Tp.append(annealing_temp)
            tp.append(tp[-1] + annealing_dur)
            Tp.append(annealing_temp)

            # extension
            tp.append(tp[-1] + (extension_temp - annealing_temp) / heat_rate)
            Tp.append(extension_temp)
            tp.append(tp[-1] + extension_dur)
            Tp.append(extension_temp)
            
    

        tp.append(tp[-1] - (Ta - Tp[-1]) / cool_rate)
        Tp.append(Ta)
        fig, ax = plt.subplots(1, 1, figsize=(1 + max(tp)/500, 5))
        ax.plot(tp, Tp)
        ax.set_xlabel('time / sec')
        ax.set_ylabel('temperature / deg C')
        ax.set_title('PCR Temperature Program')
        ax.plot(tp, Tp, 'r.', ms=3)
        ax.grid(True)
        df = pd.DataFrame()
        df['tp'] = tp
        df['Tp'] = Tp
        df.to_csv(filename_text)

    display(filename_text)
    display(heat_rate)
    display(cool_rate)
    display(cycles)
    display(denaturation)
    display(annealing)
    display(extension)

    out = widgets.interactive_output(create_setpoint_trajectory, {
        'filename_text': filename_text,
        'heat_rate': heat_rate, 
        'cool_rate': cool_rate,
        'cycles': cycles,
        'denaturation_temp': denaturation_temp,
        'denaturation_dur': denaturation_dur,
        'annealing_temp': annealing_temp,
        'annealing_dur': annealing_dur,
        'extension_temp': extension_temp,
        'extension_dur': extension_dur,
        })

    display(out)<jupyter_output><empty_output><jupyter_text>Create Heater 1 Profile<jupyter_code>PCR_thermal_cycle('pcr/pcr1.csv')<jupyter_output><empty_output><jupyter_text>Create Heater 2 Profile<jupyter_code>PCR_thermal_cycle('pcr/pcr2.csv')<jupyter_output><empty_output><jupyter_text>Translate Requested Profiles to Setpoints<jupyter_code>import glob
import matplotlib.pyplot as plt
import pandas as pd

def get_data(file1, file2):
    fig, ax = plt.subplots(1,2, figsize=(7.5,2.5))
    if file1:
        df1 = pd.read_csv(file1)
        ax[0].plot(df1['tp'], df1['Tp'], 'b')
    if file2:
        df2 = pd.read_csv(file2)
        ax[0].plot(df2['tp'], df2['Tp'], 'r')
    ax[0].grid(True)
    ax[0].set_xlabel('time / sec')
    ax[0].set_ylabel('temperature / deg C')
    ax[0].set_title('PCR Temperature Program')
    if file1 and file2:
        tmax = max(df1['tp'].max(), df2['tp'].max())
        t = np.linspace(0, tmax, int(tmax+1))
        u1 = lambda t: np.interp(t, df1['tp'].to_numpy(), df1['Tp'].to_numpy())
        u2 = lambda t: np.interp(t, df2['tp'].to_numpy(), df2['Tp'].to_numpy())
        ax[1].plot(u1(t), u2(t))
        ax[1].axis('square')
        return t, u1, u2, tmax

t_ref, u1, u2, tmax = get_data('pcr/pcr1.csv', 'pcr/pcr2.csv')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13813414402432073, 'fraction_numerical': 0.029070872126163785, 'mean_word_length': 3.314754098360656, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '444044', 'license': 'MIT', 'n_tokens_mistral': 1968, 'n_tokens_neox': 1832, 'n_words': 312, 'path': 'Protocol UI - Final Project - Peter Werling.ipynb', 'repo_name': 'pawerling/PCR-Thermal-Cycler-Prototype', 'size': '5263'}