Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentes Révision précédente | Prochaine révisionLes deux révisions suivantes | ||
teaching:progappchim:elements_molecules [2014/02/11 03:10] – villersd | teaching:progappchim:elements_molecules [2020/03/09 11:38] – villersd | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
====== Éléments et molécules ====== | ====== Éléments et molécules ====== | ||
+ | |||
+ | ===== Librairies initiale de Christoph Gohlke (2005-2013) | ||
+ | |||
Les propriétés des éléments chimiques, de molécules peuvent être dressées, listées, | Les propriétés des éléments chimiques, de molécules peuvent être dressées, listées, | ||
- | [[http:// | + | [[http:// |
Voici deux exemples simples de programmes utilisant ces librairies : | Voici deux exemples simples de programmes utilisant ces librairies : | ||
- | <sxh python; title : molmass-elements-01.py> | + | <code python molmass-elements-01.py> |
# | # | ||
# -*- coding: utf-8 -*- | # -*- coding: utf-8 -*- | ||
# utilisations de elements.py & molmass.py | # utilisations de elements.py & molmass.py | ||
# source : http:// | # source : http:// | ||
+ | # mars 2020 : adaptation python 3 | ||
from elements import ELEMENTS | from elements import ELEMENTS | ||
Ligne 15: | Ligne 19: | ||
str(ELEMENTS[109]) | str(ELEMENTS[109]) | ||
ele = ELEMENTS[' | ele = ELEMENTS[' | ||
- | print ele.number, ele.symbol, ele.name, ele.eleconfig | + | print(ele.number, ele.symbol, ele.name, ele.eleconfig) |
- | print ele.eleconfig_dict | + | print(ele.eleconfig_dict) |
- | print sum(ele.mass for ele in ELEMENTS) | + | print(sum(ele.mass for ele in ELEMENTS)) |
for ele in ELEMENTS: | for ele in ELEMENTS: | ||
ele.validate() | ele.validate() | ||
ele = repr(ele) | ele = repr(ele) | ||
- | print ele, type(ele) | + | print(ele, type(ele)) |
- | | + | |
- | </sxh> | + | </code> |
- | <sxh python; title : molmass-elements-02.py> | + | <code python molmass-elements-02.py> |
# | # | ||
# -*- coding: utf-8 -*- | # -*- coding: utf-8 -*- | ||
# utilisations de elements.py & molmass.py | # utilisations de elements.py & molmass.py | ||
# source : http:// | # source : http:// | ||
+ | # mars 2020 : adaptation python 3 | ||
from molmass import Formula | from molmass import Formula | ||
Ligne 35: | Ligne 40: | ||
#f = Formula(" | #f = Formula(" | ||
- | print f.formula | + | print(f.formula) |
- | print f.empirical | + | print(f.empirical) |
- | print f.mass | + | print(f.mass) # average mass |
- | print f.isotope.massnumber | + | print(f.isotope.massnumber) # nominal mass |
- | print f.isotope.mass | + | print(f.isotope.mass) # monoisotopic mass |
- | print f.atoms | + | print(f.atoms) |
- | print f.composition() | + | print(f.composition()) |
- | print f.spectrum() | + | print(f.spectrum()) |
- | </sxh> | + | </code> |
Un autre programme, testant plus de possibilités : | Un autre programme, testant plus de possibilités : | ||
- | <sxh python; title : molmass-elements-03.py> | + | |
+ | <code python molmass-elements-03.py> | ||
# | # | ||
# -*- coding: utf-8 -*- | # -*- coding: utf-8 -*- | ||
Ligne 54: | Ligne 60: | ||
# source : http:// | # source : http:// | ||
# test des routines sur les formules chimiques | # test des routines sur les formules chimiques | ||
+ | # mars 2020 : adaptation python 3 | ||
from molmass import * | from molmass import * | ||
Ligne 62: | Ligne 69: | ||
methodList = [method for method in dir(object) if callable(getattr(object, | methodList = [method for method in dir(object) if callable(getattr(object, | ||
processFunc = collapse and (lambda s: " " | processFunc = collapse and (lambda s: " " | ||
- | print " | + | print(" |
(method.ljust(spacing), | (method.ljust(spacing), | ||
| | ||
- | for method in methodList]) | + | for method in methodList])) |
Ligne 73: | Ligne 80: | ||
line=' | line=' | ||
- | print line | + | print(line) |
- | print dir(f) | + | print(dir(f)) |
- | print line | + | print(line) |
- | print info(f) | + | print(info(f)) |
- | print line | + | print(line) |
- | print f.composition() | + | print(f.composition()) |
- | print line | + | print(line) |
- | print f.isotope | + | print(f.isotope) |
- | print line | + | print(line) |
- | print f.isotope.mass | + | print(f.isotope.mass) |
- | print line | + | print(line) |
- | print f.isotope.massnumber | + | print(f.isotope.massnumber) |
- | print line | + | print(line) |
- | print f.mass | + | print(f.mass) |
- | print line | + | print(line) |
- | print f.formula, f.gcd, f.empirical | + | print(f.formula, f.gcd, f.empirical) |
- | print line | + | print(line) |
- | print f.spectrum() | + | print(f.spectrum()) |
- | print line | + | print(line) |
- | print f.atoms | + | print(f.atoms) |
- | print line | + | print(line) |
- | print analyze (' | + | print(analyze (' |
- | print line | + | print(line) |
- | print f, type(f) | + | print(f, type(f)) |
- | print line | + | print(line) |
- | </sxh> | + | </code> |