teaching:progappchim:ph_acides_bases_2013

no way to compare when less than two revisions

Différences

Ci-dessous, les différences entre deux révisions de la page.


teaching:progappchim:ph_acides_bases_2013 [2013/11/29 11:16] (Version actuelle) – créée villersd
Ligne 1: Ligne 1:
 +====== Représentation de pH d'acides et de bases ======
  
 +===== Pour les acides : =====
 +<sxh python; title : representation_pH_acide.py>
 +#!/usr/bin/env python
 +# -*- coding: utf-8 -*-
 +# travail de QD et TB, ba2 chimie 2012-2013
 +
 +import Tkinter as tk
 +from numpy import *
 +import matplotlib.pyplot as plt
 +
 +def get_acide(event):
 +    """
 +    fonction pour lire la séléction dans la listbox
 +    et afficher le pKa correspondant
 +    """
 +    indexacide=listbox1.curselection()[0]
 +    seltextacide=listbox1.get(indexacide)
 +    listeacide= ['HClO4','HCl', 'HI', 'HNO3', 'H3O+', 'HF', 'HSO4-', 'HBr', 'HClO2', 'HNO2']
 +    listepka=[-8.6,-6,-10,-1.3,-1.74,3.2,1.9,-9,1.93,3.29]
 +    acideselect=listeacide.index(seltextacide)
 +    pkaselect=listepka[acideselect]
 +    label['text']=pkaselect
 +
 +def graphe_acide () :
 +    """ foncton pour tracer le graphe
 +    du pH de l'acide sélectionné en
 +    fonction de sa concentration
 +    """
 +    
 +    indexacide=listbox1.curselection()[0]
 +    seltextacide=listbox1.get(indexacide)
 +    listeacide= ['HClO4','HCl', 'HI', 'HNO3', 'H3O+', 'HF', 'HSO4-', 'HBr', 'HClO2', 'HNO2']
 +    listepka=[-8.6,-6,-10,-1.3,-1.74,3.2,1.9,-9,1.93,3.29]
 +    acideselect=listeacide.index(seltextacide)
 +    pkaselect=listepka[acideselect]
 +
 +    if pkaselect < 0:
 +        x=[0.0001,0.001,0.01,0.1,1]
 +        y=-log10(x)
 +        l1=plt.semilogx(x,y,color='m',linewidth=2)
 +        lx=plt.xlabel("Concentration")
 +        ly=plt.ylabel("pH")
 +        t1=plt.title("pH d'un acide fort en fonction de la concentration")
 +        plt.show()
 +
 +    elif pkaselect > 0:
 +        x=[0.0001,0.001,0.01,0.1,1]
 +        y=0.5*(pkaselect)-0.5*log10(x)
 +        l1=plt.semilogx(x,y,color='#DAB30A',linewidth=2)
 +        lx=plt.xlabel("Concentration")
 +        ly=plt.ylabel("pH")
 +        t1=plt.title("pH d'un acide faible en fonction de la concentration")
 +        plt.show()
 +    
 +
 +#on crée un sample de données pour la listbox
 +str1= """HClO4 
 +HCl 
 +HI 
 +HNO3 
 +H3O+ 
 +HF 
 +HSO4-          
 +HBr 
 +HClO2
 +HNO2"""
 +
 +#va écrire un fichier .txt dans lequel on met le sample
 +#fout -->file output et fin --> file input sont des
 +#fonctions d'édition de fichiers. Ici, le w veut dire 'writing'
 +#et le r veut dire 'reading'
 +#si on mettait a, cela voudrait dire 'appending'
 +fin = open("chem_data_acide.txt", "w")
 +fin.write(str1)
 +fin.close()
 + 
 +#va lire le fichier .txt
 +fout = open("chem_data_acide.txt", "r")
 +chem_list = fout.readlines()
 +fout.close()
 +
 +#rtstrip pour recopier les éléments de chem_list
 +c2=[chem for chem in chem_list]
 +chem_list = [chem.rstrip() for chem in chem_list]
 +print chem_list
 +print c2
 +#crée la fenêtre Tk
 +root = tk.Tk()
 +root.title("Graphique Acide")
 +
 +#crée la listbox
 +listbox1 = tk.Listbox(root, width=35, height=6)
 +listbox1.grid(row=0, column=1)
 + 
 +#crée la scrollbar
 +yscroll = tk.Scrollbar(command=listbox1.yview, orient=tk.VERTICAL)
 +yscroll.grid(row=0, column=0, sticky=tk.N+tk.S)
 +listbox1.configure(yscrollcommand=yscroll.set)
 +
 +
 +#insère les éléments de chem_list dans la listbox
 +for item in chem_list:
 +    listbox1.insert(tk.END, item)
 + 
 +
 +pka_corresp=tk.Label(root, text='pKa correspondant:')
 +pka_corresp.grid(row=1,column=1)
 +#affiche le pKa correspondant, à chaque cliq
 +listbox1.bind('<ButtonRelease-1>', get_acide)
 +label=tk.Label(root)
 +label.grid(row=2,column=1)
 +
 +boutongraphe = tk.Button(root, text="Tracer le graphe!", command=graphe_acide)
 +boutongraphe.grid(row=3, column=1)
 +
 +root.mainloop()
 +</sxh>
 +
 +===== Pour les bases : =====
 +<sxh python; title : representation_pH_base.py>
 +#!/usr/bin/env python
 +# -*- coding: utf-8 -*-
 +# travail de QD et TB, ba2 chimie 2012-2013
 +
 +import Tkinter as tk
 +from numpy import *
 +import matplotlib.pyplot as plt
 +
 +def get_base(event):
 +    """
 +    fonction pour lire la séléction dans la listbox
 +    et afficher le pKa correspondant
 +    """
 +    indexbase=listbox1.curselection()[0]
 +    seltextbase=listbox1.get(indexbase)
 +    listebase= ['NH3','Aniline (C6H5NH2)', 'Benzylamine (C6H5CH2NH2)', 'n-Butylamine (CH3CH2CH2CH2NH2)', 'Diethylamine (CH3CH2NHCH2CH3)', 'Pyridine (C5H5N)', 'CH3-', 'NH2-', 'OH-']
 +    listepka=[9.2, 4.62, 9.33, 10.59, 11.68, 5.21, 48, 23, 24]
 +    baseselect=listebase.index(seltextbase)
 +    pkaselect=listepka[baseselect]
 +    label['text']=pkaselect
 +
 +def graphe_base () :
 +    """ foncton qui va tracer le graphe
 +    du pH de l'acide sélectionné en
 +    fonction de sa concentration
 +    """
 +    
 +    indexbase=listbox1.curselection()[0]
 +    seltextbase=listbox1.get(indexbase)
 +    listebase= ['NH3','Aniline (C6H5NH2)', 'Benzylamine (C6H5CH2NH2)', 'n-Butylamine (CH3CH2CH2CH2NH2)', 'Diethylamine (CH3CH2NHCH2CH3)', 'Pyridine (C5H5N)', 'CH3-', 'NH2-', 'OH-']
 +    listepka=[9.2, 4.62, 9.33, 10.59, 11.68, 5.21, 48, 23, 24]
 +    baseselect=listebase.index(seltextbase)
 +    pkaselect=listepka[baseselect]
 +
 +    if pkaselect < 14:
 +        x=[0.0001,0.001,0.01,0.1,1]
 +        y=7+0.5*log10(x)+0.5*pkaselect
 +        l1=plt.semilogx(x,y,color='m',linewidth=2)
 +        lx=plt.xlabel("Concentration")
 +        ly=plt.ylabel("pH")
 +        t1=plt.title("pH d'une base faible en fonction de la concentration")
 +        plt.show()
 +
 +    elif pkaselect > 14:
 +        x=[0.0001,0.001,0.01,0.1,1]
 +        y=14+log10(x)
 +        l1=plt.semilogx(x,y,color='m',linewidth=2)
 +        lx=plt.xlabel("Concentration")
 +        ly=plt.ylabel("pH")
 +        t1=plt.title("pH d'une base forte en fonction de la concentration")
 +        plt.show()
 +    
 +
 +#on crée un sample de données pour la listbox
 +str1= """NH3
 +Aniline (C6H5NH2)
 +Benzylamine (C6H5CH2NH2)
 +n-Butylamine (CH3CH2CH2CH2NH2)
 +Diethylamine (CH3CH2NHCH2CH3)
 +Pyridine (C5H5N)
 +CH3-
 +NH2-
 +OH-"""
 +
 +#va écrire un fichier .txt dans lequel on met le sample
 +#fout -->file output et fin --> file input sont des
 +#fonctions d'édition de fichiers. Ici, le w veut dire 'writing'
 +#et le r veut dire 'reading'
 +fout = open("chem_data_base.txt", "w")
 +fout.write(str1)
 +fout.close()
 + 
 +#va lire le fichier .txt
 +fin = open("chem_data_base.txt", "r")
 +chem_list = fin.readlines()
 +fin.close()
 +
 +#rtstrip pour recopier ce qu'il y a
 +chem_list = [chem.rstrip() for chem in chem_list]
 +
 +#crée la fenêtre Tk
 +root = tk.Tk()
 +root.title("Graphique Base")
 +
 +#crée la listbox
 +listbox1 = tk.Listbox(root, width=35, height=6)
 +listbox1.grid(row=0, column=0)
 + 
 +#crée la scrollbar
 +yscroll = tk.Scrollbar(command=listbox1.yview, orient=tk.VERTICAL)
 +yscroll.grid(row=0, column=1, sticky=tk.N+tk.S)
 +listbox1.configure(yscrollcommand=yscroll.set)
 +
 +
 +#insère les éléments de chem_list dans la listbox
 +for item in chem_list:
 +    listbox1.insert(tk.END, item)
 + 
 +
 +pka_corresp=tk.Label(root, text='pKa correspondant:')
 +pka_corresp.grid(row=1,column=0)
 +#affiche le pKa correspondant, à chaque cliq
 +listbox1.bind('<ButtonRelease-1>', get_base)
 +label=tk.Label(root)
 +label.grid(row=2,column=0)
 +
 +boutongraphe = tk.Button(root, text="Tracer le graphe!", command=graphe_base)
 +boutongraphe.grid(row=3, column=0)
 +
 +root.mainloop()
 +
 +</sxh>
  • teaching/progappchim/ph_acides_bases_2013.txt
  • Dernière modification : 2013/11/29 11:16
  • de villersd