scikit-chem is first and formost a wrapper around rdkit to make it more Pythonic, and more intuitive to a user familiar with other libraries in the Scientific Python Stack. The package implements a core Mol class, physically representing a molecule. It is a direct subclass of the rdkit.Mol class:
In [1]:
import rdkit.Chem
issubclass(skchem.Mol, rdkit.Chem.Mol)
Out[1]:
As such, it has all the methods available that an rdkit.Mol class has, for example:
In [2]:
hasattr(skchem.Mol, 'GetAromaticAtoms')
Out[2]:
Constructors are provided as classmethods on the skchem.Mol object, in the same fashion as pandas objects are constructed. For example, to make a pandas.DataFrame from a dictionary, you call:
In [3]:
df = pd.DataFrame.from_dict({'a': [10, 20], 'b': [20, 40]}); df
Out[3]:
Analogously, to make a skchem.Mol from a smiles string, you call;
In [4]:
mol = skchem.Mol.from_smiles('CC(=O)Cl'); mol
Out[4]:
The available methods are:
In [5]:
[method for method in skchem.Mol.__dict__ if method.startswith('from_')]
Out[5]:
When a molecule fails to parse, a ValueError is raised:
In [6]:
skchem.Mol.from_smiles('NOTSMILES')
Atoms and bonds are accessible as a property:
In [7]:
mol.atoms
Out[7]:
In [8]:
mol.bonds
Out[8]:
These are iterable:
In [9]:
[a for a in mol.atoms]
Out[9]:
subscriptable:
In [10]:
mol.atoms[3]
Out[10]:
sliceable:
In [11]:
mol.atoms[:3]
Out[11]:
indexable:
In [19]:
mol.atoms[[1, 3]]
Out[19]:
and maskable:
In [18]:
mol.atoms[[True, False, True, False]]
Out[18]:
Properties on the rdkit objects are accessible through the props property:
In [11]:
mol.props['is_reactive'] = 'very!'
In [12]:
mol.atoms[1].props['kind'] = 'electrophilic'
mol.atoms[3].props['leaving group'] = 1
mol.bonds[2].props['bond strength'] = 'strong'
These are using the rdkit property functionality internally:
In [13]:
mol.GetProp('is_reactive')
Out[13]:
The properties of atoms and bonds are accessible molecule wide:
In [14]:
mol.atoms.props
Out[14]:
In [15]:
mol.bonds.props
Out[15]:
These can be exported as pandas objects:
In [16]:
mol.atoms.props.to_frame()
Out[16]:
Molecules are exported and/or serialized in a very similar way in which they are constructed, again with an inspiration from pandas.
In [17]:
df.to_csv()
Out[17]:
In [18]:
mol.to_inchi_key()
Out[18]:
The total available formats are:
In [19]:
[method for method in skchem.Mol.__dict__ if method.startswith('to_')]
Out[19]: