2.1.1.4.1.1. wc_utils.util.chem package

2.1.1.4.1.1.1. Submodules

2.1.1.4.1.1.2. wc_utils.util.chem.core module

Chemistry utilities

Author:Jonathan Karr <jonrkarr@gmail.com>
Date:2018-02-07
Copyright:2018, Karr Lab
License:MIT
class wc_utils.util.chem.core.EmpiricalFormula(value='')[source]

Bases: attrdict.default.AttrDefault

An empirical formula

__add__(other)[source]

Add two empirical formulae

Parameters:other (EmpiricalFormula or str) – another empirical formula
Returns:sum of the empirical formulae
Return type:EmpiricalFormula
__contains__(element)[source]
Parameters:element (str) – element symbol
Returns:True if the empirical formula contains the element
Return type:bool
__div__(quantity)[source]

Subtract two empirical formulae (for Python 2)

Parameters:quantity (float) –
Returns:division of the empirical formula by quantity
Return type:EmpiricalFormula
__hash__()[source]

Generate a hash

Returns:hash
Return type:int
__mul__(quantity)[source]

Subtract two empirical formulae

Parameters:quantity (float) –
Returns:multiplication of the empirical formula by quantity
Return type:EmpiricalFormula
__setitem__(element, coefficient)[source]

Set the count of an element

Parameters:
  • element (str) – element symbol
  • coefficient (float) – element coefficient
Raises:

ValueError – if the coefficient is not a float

__str__()[source]

Generate a string representation of the formula

__sub__(other)[source]

Subtract two empirical formulae

Parameters:other (EmpiricalFormula or str) – another empirical formula
Returns:difference of the empirical formulae
Return type:EmpiricalFormula
__truediv__(quantity)[source]

Subtract two empirical formulae

Parameters:quantity (float) –
Returns:division of the empirical formula by quantity
Return type:EmpiricalFormula
get_molecular_weight()[source]

Get the molecular weight

Returns:molecular weight
Return type:float
class wc_utils.util.chem.core.OpenBabelUtils[source]

Bases: object

classmethod export(mol, format, options=())[source]

Export an OpenBabel molecule to format

Parameters:
  • mol (openbabel.OBMol) – molecule
  • format (str) – format
  • options (list of str, optional) – export options
Returns:

format representation of molecule

Return type:

str

static get_formula(mol)[source]

Get the formula of an OpenBabel molecule

Parameters:mol (openbabel.OBMol) – molecule
Returns:formula
Return type:EmpiricalFormula
classmethod get_inchi(mol, options=('r', 'F'))[source]

Get the InChI-encoded structure of an OpenBabel molecule

Parameters:
  • mol (openbabel.OBMol) – molecule
  • options (list of str, optional) – export options
Returns:

InChI-encoded structure

Return type:

str

classmethod get_smiles(mol, options=())[source]

Get the SMILES-encoded structure of an OpenBabel molecule

Parameters:
  • mol (openbabel.OBMol) – molecule
  • options (list of str, optional) – export options
Returns:

SMILES-encoded structure

Return type:

str

wc_utils.util.chem.core.draw_molecule(structure, format, image_format='svg', atom_labels=None, atom_sets=None, bond_sets=None, show_atom_nums=False, width=200, height=200, include_xml_header=True)[source]

Draw an image of a molecule

Parameters:
  • structure (str) – chemical structure
  • format (str) – format of structure (e.g. ‘inchi’ or ‘smiles’)
  • image_format (str, optional) – format of generated image {emf, eps, jpeg, msbmp, pdf, png, or svg}
  • atom_labels (list of dict, optional) – list of atom labels (dictionaries with keys {position, element, label, color})
  • atom_sets (list of dict, optional) – list of atom sets (dictionaries with keys {positions, elements, color})
  • bond_sets (list of dict, optional) – list of bond sets (dictionaries with keys {positions, elements, color})
  • show_atom_nums (bool, optional) – if True, show the numbers of the atoms
  • width (int, optional) – width in pixels
  • height (int, optional) – height in pixels
  • include_xml_header (bool, optional) – if True, include XML header
Returns:

image of chemical structure

Return type:

str

wc_utils.util.chem.core.get_major_micro_species(structure_or_structures, in_format, out_format, ph=7.4, major_tautomer=False, keep_hydrogens=False, dearomatize=False)[source]

Get the major protonation state of one or more compounds at a specific pH.

Parameters:
  • structure_or_structures (str or list of str) – chemical structure or list of chemical structures
  • in_format (str) – format of structure_or_structures (e.g. ‘inchi’ or ‘smiles’)
  • out_format (str) – format of output (e.g. ‘inchi’ or ‘smiles’)
  • ph (float, optional) – pH at which to calculate major protonation microspecies
  • major_tautomer (bool, optional) – if True, use the major tautomeric in the calculation
  • keep_hydrogens (bool, optional) – if True, keep explicity defined hydrogens
  • dearomatize (bool, optional) – if True, dearomatize molecule
Returns:

protonated chemical structure or

list of protonated chemical structures

Return type:

str or list of str

2.1.1.4.1.1.3. Module contents