Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente Prochaine révisionLes deux révisions suivantes | ||
teaching:progappchim:openbabel_jmol [2014/02/18 10:05] – créée villersd | teaching:progappchim:openbabel_jmol [2014/02/28 12:26] – [OpenBabel] villersd | ||
---|---|---|---|
Ligne 5: | Ligne 5: | ||
* Site officiel : [[http:// | * Site officiel : [[http:// | ||
* Interfaçage en Python : [[http:// | * Interfaçage en Python : [[http:// | ||
+ | |||
+ | Pour utiliser OpenBabel en python, il faut installer au préalable ces outils. Sous Linux (Debian, Ubuntu, | ||
===== Jmol ===== | ===== Jmol ===== | ||
Ligne 15: | Ligne 17: | ||
===== Exemple de programme Python ===== | ===== Exemple de programme Python ===== | ||
- | En construction... | + | <sxh python; title : generate_alcohols-01.py> |
+ | #! / | ||
+ | # -*- coding: utf-8 -*- | ||
+ | # génération à partir du code smile d' | ||
+ | # et de fichiers | ||
+ | # références : | ||
+ | # http:// | ||
+ | # http:// | ||
+ | # http:// | ||
+ | # https:// | ||
+ | # http:// | ||
+ | |||
+ | import openbabel | ||
+ | |||
+ | def OBMolMinimize(mol): | ||
+ | """ | ||
+ | """ | ||
+ | ff = openbabel.OBForceField.FindForceField(" | ||
+ | ff.Setup(mol) | ||
+ | ff.ConjugateGradients(100, | ||
+ | ff.GetCoordinates(mol) | ||
+ | return mol | ||
+ | |||
+ | def OBStructureFromSmiles(smilesstring, | ||
+ | mol = openbabel.OBMol() | ||
+ | obConversion = openbabel.OBConversion() | ||
+ | obConversion.SetInAndOutFormats(" | ||
+ | obConversion.ReadString(mol, | ||
+ | mol.AddHydrogens() | ||
+ | builder = openbabel.OBBuilder() | ||
+ | builder.Build(mol) | ||
+ | mol = OBMolMinimize(mol) | ||
+ | if filename is None: return mol | ||
+ | # save structures in subfolder molecules | ||
+ | obConversion.WriteFile(mol, | ||
+ | |||
+ | def getAlcohols(): | ||
+ | molecules = dict() | ||
+ | molecules[' | ||
+ | molecules[' | ||
+ | molecules[' | ||
+ | molecules[' | ||
+ | molecules[' | ||
+ | molecules[' | ||
+ | molecules[' | ||
+ | molecules[' | ||
+ | molecules[' | ||
+ | return molecules | ||
+ | |||
+ | if __name__ == ' | ||
+ | |||
+ | etab = openbabel.OBElementTable() | ||
+ | dico = getAlcohols() | ||
+ | for elem in dico: | ||
+ | OBStructureFromSmiles(dico[elem], | ||
+ | |||
+ | # Determine the charge of a molecule | ||
+ | for file_in in dico: | ||
+ | obConversion = openbabel.OBConversion() | ||
+ | obConversion.SetInFormat(" | ||
+ | mol = openbabel.OBMol() | ||
+ | obConversion.ReadFile(mol, | ||
+ | # get the charges of the atoms | ||
+ | charge_model = openbabel.OBChargeModel.FindType(" | ||
+ | charge_model.ComputeCharges(mol) | ||
+ | partial_charges = charge_model.GetPartialCharges() | ||
+ | print file_in, '- Formula = ', mol.GetFormula() | ||
+ | print 'mol wt = ', mol.GetMolWt(), | ||
+ | for atom in openbabel.OBMolAtomIter(mol): | ||
+ | z=atom.GetAtomicNum() | ||
+ | v3=atom.GetVector() | ||
+ | print atom.GetAtomicMass(), | ||
+ | print ' | ||
+ | print 'total charge = ', " | ||
+ | print ' | ||
+ | |||
+ | </ | ||
+ | Pour le méthanol, ce programme sort ces informations : | ||
+ | < | ||
+ | methanol - Formula = CH4O | ||
+ | mol wt = 32.04186 - Numb atoms = 6 - Numb bonds = 5 | ||
+ | 12.0107 6 C x= 0.956 y= -0.086 z= -0.056 | ||
+ | 15.9994 8 O x= 0.488 y= -1.374 z= 0.299 | ||
+ | 1.00794 1 H x= 0.587 y= 0.64 z= 0.672 | ||
+ | 1.00794 1 H x= 0.584 y= 0.177 z= -1.05 | ||
+ | 1.00794 1 H x= 2.049 y= -0.08 z= -0.052 | ||
+ | 1.00794 1 H x= 0.831 y= -1.996 z= -0.365 | ||
+ | partial charges = (0.28, -0.68, 0.0, 0.0, 0.0, 0.4) | ||
+ | total charge = 0 | ||
+ | </ | ||
+ | |||
+ | ===== References ===== | ||
+ | * [[http:// |