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' | ||
+ | ===== Pour les acides : ===== | ||
+ | <sxh python; title : representation_pH_acide.py> | ||
+ | # | ||
+ | # -*- 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= [' | ||
+ | listepka=[-8.6, | ||
+ | acideselect=listeacide.index(seltextacide) | ||
+ | pkaselect=listepka[acideselect] | ||
+ | label[' | ||
+ | |||
+ | def graphe_acide () : | ||
+ | """ | ||
+ | du pH de l' | ||
+ | fonction de sa concentration | ||
+ | """ | ||
+ | | ||
+ | indexacide=listbox1.curselection()[0] | ||
+ | seltextacide=listbox1.get(indexacide) | ||
+ | listeacide= [' | ||
+ | listepka=[-8.6, | ||
+ | acideselect=listeacide.index(seltextacide) | ||
+ | pkaselect=listepka[acideselect] | ||
+ | |||
+ | if pkaselect < 0: | ||
+ | x=[0.0001, | ||
+ | y=-log10(x) | ||
+ | l1=plt.semilogx(x, | ||
+ | lx=plt.xlabel(" | ||
+ | ly=plt.ylabel(" | ||
+ | t1=plt.title(" | ||
+ | plt.show() | ||
+ | |||
+ | elif pkaselect > 0: | ||
+ | x=[0.0001, | ||
+ | y=0.5*(pkaselect)-0.5*log10(x) | ||
+ | l1=plt.semilogx(x, | ||
+ | lx=plt.xlabel(" | ||
+ | ly=plt.ylabel(" | ||
+ | t1=plt.title(" | ||
+ | plt.show() | ||
+ | | ||
+ | |||
+ | #on crée un sample de données pour la listbox | ||
+ | str1= """ | ||
+ | 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' | ||
+ | #et le r veut dire ' | ||
+ | #si on mettait a, cela voudrait dire ' | ||
+ | fin = open(" | ||
+ | fin.write(str1) | ||
+ | fin.close() | ||
+ | |||
+ | #va lire le fichier .txt | ||
+ | fout = open(" | ||
+ | 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(" | ||
+ | |||
+ | #crée la listbox | ||
+ | listbox1 = tk.Listbox(root, | ||
+ | listbox1.grid(row=0, | ||
+ | |||
+ | #crée la scrollbar | ||
+ | yscroll = tk.Scrollbar(command=listbox1.yview, | ||
+ | yscroll.grid(row=0, | ||
+ | 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, | ||
+ | |||
+ | |||
+ | pka_corresp=tk.Label(root, | ||
+ | pka_corresp.grid(row=1, | ||
+ | #affiche le pKa correspondant, | ||
+ | listbox1.bind('< | ||
+ | label=tk.Label(root) | ||
+ | label.grid(row=2, | ||
+ | |||
+ | boutongraphe = tk.Button(root, | ||
+ | boutongraphe.grid(row=3, | ||
+ | |||
+ | root.mainloop() | ||
+ | </ | ||
+ | |||
+ | ===== Pour les bases : ===== | ||
+ | <sxh python; title : representation_pH_base.py> | ||
+ | # | ||
+ | # -*- 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= [' | ||
+ | listepka=[9.2, | ||
+ | baseselect=listebase.index(seltextbase) | ||
+ | pkaselect=listepka[baseselect] | ||
+ | label[' | ||
+ | |||
+ | def graphe_base () : | ||
+ | """ | ||
+ | du pH de l' | ||
+ | fonction de sa concentration | ||
+ | """ | ||
+ | | ||
+ | indexbase=listbox1.curselection()[0] | ||
+ | seltextbase=listbox1.get(indexbase) | ||
+ | listebase= [' | ||
+ | listepka=[9.2, | ||
+ | baseselect=listebase.index(seltextbase) | ||
+ | pkaselect=listepka[baseselect] | ||
+ | |||
+ | if pkaselect < 14: | ||
+ | x=[0.0001, | ||
+ | y=7+0.5*log10(x)+0.5*pkaselect | ||
+ | l1=plt.semilogx(x, | ||
+ | lx=plt.xlabel(" | ||
+ | ly=plt.ylabel(" | ||
+ | t1=plt.title(" | ||
+ | plt.show() | ||
+ | |||
+ | elif pkaselect > 14: | ||
+ | x=[0.0001, | ||
+ | y=14+log10(x) | ||
+ | l1=plt.semilogx(x, | ||
+ | lx=plt.xlabel(" | ||
+ | ly=plt.ylabel(" | ||
+ | t1=plt.title(" | ||
+ | plt.show() | ||
+ | | ||
+ | |||
+ | #on crée un sample de données pour la listbox | ||
+ | str1= """ | ||
+ | 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' | ||
+ | #et le r veut dire ' | ||
+ | fout = open(" | ||
+ | fout.write(str1) | ||
+ | fout.close() | ||
+ | |||
+ | #va lire le fichier .txt | ||
+ | fin = open(" | ||
+ | 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(" | ||
+ | |||
+ | #crée la listbox | ||
+ | listbox1 = tk.Listbox(root, | ||
+ | listbox1.grid(row=0, | ||
+ | |||
+ | #crée la scrollbar | ||
+ | yscroll = tk.Scrollbar(command=listbox1.yview, | ||
+ | yscroll.grid(row=0, | ||
+ | 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, | ||
+ | |||
+ | |||
+ | pka_corresp=tk.Label(root, | ||
+ | pka_corresp.grid(row=1, | ||
+ | #affiche le pKa correspondant, | ||
+ | listbox1.bind('< | ||
+ | label=tk.Label(root) | ||
+ | label.grid(row=2, | ||
+ | |||
+ | boutongraphe = tk.Button(root, | ||
+ | boutongraphe.grid(row=3, | ||
+ | |||
+ | root.mainloop() | ||
+ | |||
+ | </ |