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évision | Révision précédente | ||
| teaching:progappchim:elements_molecules [2014/02/11 03:10] – villersd | teaching:progappchim:elements_molecules [2021/03/02 12:31] (Version actuelle) – [Librairie Mendeleev] villersd | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| ====== Éléments et molécules ====== | ====== Éléments et molécules ====== | ||
| - | Les propriétés des éléments chimiques, de molécules peuvent être dressées, listées, | + | |
| - | [[http://www.lfd.uci.edu/~gohlke/|Christoph Gohlke]] (University of California, Irvine), a écrit deux librairies, | + | Les propriétés des éléments chimiques, de molécules peuvent être dressées, listées, |
| + | |||
| + | ===== Librairie Mendeleev ===== | ||
| + | |||
| + | Consulter la page spécifique sur la [[mendeleev|librairie Mendeleev]] | ||
| + | |||
| + | La librairie [[https://pypi.org/ | ||
| + | * Package repository sur PyPI : [[https:// | ||
| + | * Page officielle, description et code source : [[https:// | ||
| + | * Documentation complète : [[https:// | ||
| + | * Tutoriels : [[https:// | ||
| + | * Notebook Jupyter | ||
| + | * [[https://nbviewer.jupyter.org/ | ||
| + | * [[https://nbviewer.jupyter.org/github/ | ||
| + | * [[https:// | ||
| + | * Installation via pip, ou la commande conda, ou l' | ||
| + | * pip install --user mendeleev | ||
| + | * conda install -c lmmentel mendeleev=0.6.0 | ||
| + | * Données utilisables, | ||
| + | * | ||
| + | ===== Librairie Molmass ===== | ||
| + | |||
| + | [[http:// | ||
| + | |||
| + | |||
| + | ==== Installation ==== | ||
| + | |||
| + | via la commande < | ||
| + | |||
| + | Dans jupyter | ||
| + | < | ||
| + | # Install a pip package in the current Jupyter kernel | ||
| + | import sys | ||
| + | !{sys.executable} -m pip install molmass | ||
| + | </ | ||
| + | |||
| + | ==== Exemples ==== | ||
| 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:// | ||
| - | from elements | + | # mars 2020 : adaptation python 3 |
| + | from molmass | ||
| len(ELEMENTS) | len(ELEMENTS) | ||
| 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 73: | ||
| #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 93: | ||
| # 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 102: | ||
| 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 113: | ||
| 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> |
| + | |||
| + | ==== Librairies initiales de Christoph Gohlke (2005-2013) | ||
| + | |||
| + | Les propriétés des éléments chimiques, de molécules peuvent être dressées, listées, | ||
| + | [[http:// | ||
| + | |||