moleculekit.smallmol.smallmollib module

class moleculekit.smallmol.smallmollib.SmallMolLib(libfile=None, removeHs=False, fixHs=True, sanitize=True)

Bases: object

Class to manage ligands databases (sdf). Ligands are stored as moleculekit.smallmol.smallmol.SmallMol objects and fields type in the sdf are stored in a list

Parameters
  • lib_file (str) – The sdf or smi file path

  • removeHs (bool) – If True, the hydrogens of the molecules will be removed

  • fixHs (bool) – If True, the hydrogens are added and optimized

Example

>>> import os
>>> from moleculekit.home import home
>>> lib = SmallMolLib(os.path.join(home(dataDir='test-smallmol'), 'fda_drugs_light.sdf'))
>>> lib.numMols
100

Methods

Attributes

numMols

Number of SmallMol molecules

Type

int

appendSmallLib(smallLib, strictField=False, strictDirection=1)

Merge two moleculekit.smallmol.smallmol.SmallMolLib objects

Parameters

smallLib (moleculekit.smallmol.smallmol.SmallMolLib) – The new SmallMolLib to merge

appendSmallMol(smallmolecule, strictField=False, strictDirection=0)

Adds a new moleculekit.smallmol.smallmol.SmallMol object in the current SmallMolLib object

Parameters

smallmol (moleculekit.smallmol.smallmol.SmallMol) – The SmallMol object to add

copy()

Returns a copy of the SmallMolLib object

depict(ids=None, sketch=True, filename=None, ipython=False, optimize=False, optimizemode='std', removeHs=True, legends=None, highlightAtoms=None, mols_perrow=3)

Depicts the molecules into a grid. It is possible to save it into an svg file and also generates a jupiter-notebook rendering

Parameters
  • ids (list) – The index of the molecules to depict

  • sketch (bool) – Set to True for 2D depiction

  • filename (str) – Set the filename for the svg file

  • ipython (bool) – Set to True to return the jupiter-notebook rendering

  • optimize (bool) – Set to True to optimize the conformation. Works only with 3D.

  • optimizemode (['std', 'mmff']) – Set the optimization mode for 3D conformation

  • removeHs (bool) – Set to True to hide hydrogens in the depiction

  • legends (str) – The name to used for each molecule. Can be ‘names’:the name of themselves; or ‘items’: a incremental id

  • highlightAtoms (list) – A List of atom to highligh for each molecule. It can be also a list of atom list, in this case different colors will be used

  • mols_perrow (int) – The number of molecules to depict per row of the grid

Returns

ipython_svg

Return type

SVG object if ipython is set to True

getMols(ids=None)

Returns the SmallMol objects that corresponds ot the indexes of the list passed

Parameters

ids (list) – The index list of the molecules to return

Returns

smallmollist – The list of SmallMol objects

Return type

list

Example

>>> lib2 = lib.getMols([1,2,3])
>>> len(lib2)
3
property numMols

Returns the number of molecules

removeMols(ids)

Removes the moleculekit.smallmol.smallmol.SmallMol object based on the indexes in the list

Parameters

ids (list) – The list of molecules index to remove from the SmallMolLib

toDataFrame(fields=None, molAsImage=True, sketch=True)

Returns a pandas.DataFrame of the SmallMolLib object.

Parameters
  • fields (list) – The list of fields to convert into a pandas DataFrame column

  • molAsImage (bool) – If True, the rdkit.Chem.rdchem.Mol is converted into an image

  • sketch (bool) – If True, the molecule are rendered to be 2D

Returns

dataframe – The pandas DataFrame

Return type

pandas.DataFrame

writeSdf(sdf_name, fields=None)

Writes an sdf file with molecules stored. Is it possible also to manage which field will be written

Parameters
  • sdf_name (str) – The ouput sdf filename

  • fields (list) – A list of the fields to write. If None all are saved

writeSmiles(smi_name, explicitHs=True, names=False, header=None)

Writes a smi file with molecules stored. Is it possible to specify the header of the smi file. The name of the ligands can be their ligand name or a sequential ID.

Parameters
  • smi_name (str) – The ouput smi filename

  • names (bool) – Set as True to use the own ligand name for each ligand. Otherwise a sequential ID will be used

  • header (str) – The header of the smi file. If is None the smi filename will be used.

moleculekit.smallmol.smallmollib.SmallMolStack

alias of moleculekit.smallmol.smallmollib.SmallMolLib

moleculekit.smallmol.smallmollib.sdfReader(file, removeHs, fixHs, sanitize, isgzip=False)
moleculekit.smallmol.smallmollib.smiReader(file, removeHs, fixHs, isgzip=False)