Complat software training 101
  • Introduction
  • Day 1
  • Day 2
  • TODO
  • Linear regression
  • Tmux
  • quick link
  • CLI more - 1
  • Vim more - 1
  • MQ
  • iv - 1
  • iv - 2
  • iv - 3
  • clear Arch
  • lv - array
  • INTERVIEW - JS
  • RDKit - read/write
  • RDKit - process
  • RDKit - transform
  • RDKit - rxn
  • SYSTEM DESIGN - Question
  • SYSTEM DESIGN - EX1
  • SYSTEM DESIGN - EX2
  • SYSTEM DESIGN - EX3
  • SYSTEM DESIGN - EX99
Powered by GitBook
On this page
  • Read a molecule
  • Read molecules
  • Write molecule
  • Molfile with coord
  • Chem vs AllChem

Was this helpful?

RDKit - read/write

Read a molecule

from rdkit import Chem

m = Chem.MolFromSmiles('Cc1ccccc1')
m = Chem.MolFromMolFile('data/input.mol')
mol_str=open('data/input.mol','r').read()
m = Chem.MolFromMolBlock(mol_str)

Read molecule will return <rdkit.Chem.rdchem.Mol object at 0x...> or None

Read molecules

mols = Chem.SDMolSupplier('data/5ht3ligs.sdf')

f = open('data/5ht3ligs.sdf','rb')
mols = Chem.ForwardSDMolSupplier(f)


for mol in mols:
    print(mol.GetNumAtoms())

Write molecule

m = Chem.MolFromMolFile('data/chiral.mol')
Chem.MolToSmiles(m) # 'C[C@H](O)c1ccccc1'
Chem.MolToSmiles(m,isomericSmiles=False) # 'CC(O)c1ccccc1'

Chem.MolToMolBlock(m2)
  • generic SMILES = no chiral or isotopic info

  • isomeric SMILES = with chiral & isotopic info

  • unique SMILES = canonicalized generic SMILES

  • absolute SMILES = unique isomeric SMILES

Output SMILES is canonical.

Molfile with coord

# 2D coordinates
from rdkit.Chem import AllChem

AllChem.Compute2DCoords(m)

#  4  4  0  0  0  0  0  0  0  0999 V2000
#    1.0607   -0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
#   -0.0000   -1.0607    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
#   -1.0607    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
#    0.0000    1.0607    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
# 3D coordinates
m = Chem.AddHs(m) # To get good 3D conformations, it’s almost always a good idea to add hydrogens to the molecule first
AllChem.EmbedMolecule(m)
m = Chem.RemoveHs(m)

#  4  4  0  0  0  0  0  0  0  0999 V2000
#    0.3497    0.9755   -0.2202 C   0  0  0  0  0  0  0  0  0  0  0  0
#    0.9814   -0.3380    0.2534 C   0  0  0  0  0  0  0  0  0  0  0  0
#   -0.3384   -1.0009   -0.1474 C   0  0  0  0  0  0  0  0  0  0  0  0
#   -0.9992    0.3532    0.1458 C   0  0  0  0  0  0  0  0  0  0  0  0

Chem vs AllChem

speed startup and lower import times

rdkit.Chem = basic func (reading/writing, substructure searching, cleanup, etc)

rdkit.Chem.AllChem = advanced

PreviousINTERVIEW - JSNextRDKit - process

Last updated 5 years ago

Was this helpful?