~ubuntu-branches/ubuntu/saucy/pyacidobasic/saucy

« back to all changes in this revision

Viewing changes to .pc/debian-changes-0.1-3/acidebase.py

  • Committer: Bazaar Package Importer
  • Author(s): Georges Khaznadar
  • Date: 2010-08-15 19:34:00 UTC
  • Revision ID: james.westby@ubuntu.com-20100815193400-ywmgp5v7hv0dhexm
Tags: 0.1-6
* fixed the versionless GPL reference
* upgraded Standards-Version to 3.9.1
* first release to Debian. Closes: #593135

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#-*- coding: utf-8 -*-
 
2
 
 
3
 
 
4
licence="""
 
5
    file acidebase.py: part of the package pyacidobasic version %s:
 
6
 
 
7
    Copyright (C) 2010 Georges Khaznadar <georgesk@ofset.org>
 
8
 
 
9
    This program is free software: you can redistribute it and/or modify
 
10
    it under the terms of the GNU General Public License as published by
 
11
    the Free Software Foundation, either version 3 of the License, or
 
12
    (at your option) any later version.
 
13
 
 
14
    This program is distributed in the hope that it will be useful,
 
15
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
    GNU General Public License for more details.
 
18
 
 
19
    You should have received a copy of the GNU General Public License
 
20
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
21
"""
 
22
 
 
23
from PyQt4.QtCore import *
 
24
 
 
25
class acideBase:
 
26
    def __init__(self, formes=["AH","A<sup>-</sup>"], formeIndex=0, nom="acide générique", pK=[3.5], c=1.0, charge=0, v=0.0):
 
27
        """
 
28
        objet représentant un couple acido-basique
 
29
        @param formes la liste des formes acido-basiques conjuguées
 
30
        @param formeIndex la forme de base
 
31
        @param nom désignation de la forme de base
 
32
        @param pK liste des constantes d'acidité
 
33
        @param c concentration initiale en mol/L
 
34
        @param charge charge électrique de la forme acide en unité élémentaire
 
35
        @param v volume en mL
 
36
        """
 
37
        self.formes=formes
 
38
        self.formeIndex=formeIndex
 
39
        self.nom=nom
 
40
        self.pK=pK
 
41
        self.c=c
 
42
        self.charge=charge
 
43
        self.v=v
 
44
 
 
45
    def copie(self):
 
46
        return acideBase(self.formes, self.formeIndex, self.nom, self.pK,  self.c, self.charge, self.v)
 
47
 
 
48
    def __str__(self):
 
49
        return "%s;%s;%s;%s;%s;%s;%s" %(self.formes,
 
50
                                        self.formeIndex,
 
51
                                        self.nom,
 
52
                                        self.pK,
 
53
                                        self.c,
 
54
                                        self.charge,
 
55
                                        self.v)
 
56
    def chargeNette(self,pH):
 
57
        """
 
58
        Renvoie la charge électrique en Faraday en fonction du pH
 
59
        """
 
60
        concentrations=[1.0] # liste des concentrations des espèces
 
61
        total=1.0            # concentration totale
 
62
        for pK in self.pK:
 
63
            c=concentrations[-1]*10**(pH-pK)
 
64
            concentrations.append(c)
 
65
            total+=c
 
66
        # On normaliste pour que la concentration totale soit self.c
 
67
        concentrations=map(lambda c:c/total*self.c, concentrations)
 
68
        ch=self.charge # on considère la cahrge de l'espèce acide
 
69
        result=0.0
 
70
        # on calcule d'abord la concentration de charges
 
71
        for c in concentrations:
 
72
            result+=c*ch # on cumule la charge de l'espèce acide
 
73
            ch-=1        # et on passe à la base conjuguée
 
74
        # puis la charge en Faraday, en multipliant par le volume en mL.
 
75
        result*=self.v*1e-3   
 
76
        return result
 
77
    
 
78
def fromString(s):
 
79
    s=s.split(";")
 
80
    ab=acideBase()
 
81
    formes=s[0].split(',')
 
82
    ab.formes=[]
 
83
    for f in formes:
 
84
        f=unicode(f,"utf-8")
 
85
        ab.formes.append(QString(f))
 
86
    ab.formeIndex=   int(s[1])
 
87
    ab.nom=          QString(unicode(s[2],"utf-8"))
 
88
    pKs=s[3].split(",")
 
89
    ab.pK=[]
 
90
    for pK in pKs:
 
91
        ab.pK.append(float(pK))
 
92
    ab.c= float(s[4])
 
93
    ab.charge= int(s[5])
 
94
    return ab
 
95
 
 
96
def listFromString(s):
 
97
    liste=[]
 
98
    for ligne in s.split("\n"):
 
99
        try:
 
100
            acideOuBase=fromString(ligne)
 
101
            liste.append(acideOuBase)
 
102
        except:
 
103
            pass
 
104
    return liste
 
105
 
 
106
def listFromFile(fname):
 
107
    return listFromString(open(fname,"r").read(655360))
 
108
                
 
109