Cheminformatics Tutorials - Herong's Tutorial Examples - v2.01, by Herong Yang
rdkit.Chem.rdchem.RWMol - The RWMol Class
This section provides a quick introduction of the rdkit.Chem.rdchem.RWMol class, which is a sub-class of rdkit.Chem.rdchem.Mol class with additional read and write functionalities.
What Is rdkit.Chem.rdchem.RWMol? - rdkit.Chem.rdchem.RWMol is the sub-class of rdkit.Chem.rdchem.Mol class located in the rdkit.Chem.rdchem module of the RDKit library.
rdkit.Chem.rdchem.RWMol represents a molecule class with additional read and write functionalities. Basically, you build a new molecule or modify a molecule represented by the RWMol sub-class.
Here are some useful methods provided in the RWMol sub-class.
m = rdkit.Chem.rdchem.RWMol() - Creates an empty molecule.
m.AddAtom(a) or rdkit.Chem.rdchem.RWMol.AddAtom(m, a) - Adds a given atom to the given molecule.
m.AddBond(i, j) or rdkit.Chem.rdchem.RWMol.AddBond(m, i, j) - Adds a bond from the i-th atom to the j-th atom in the given molecule.
m.RemoveAtom(i) or rdkit.Chem.rdchem.RWMol.RemoveAtom(m, i) - Removes the i-th atom from the given molecule.
m.RemoveBond(i) or rdkit.Chem.rdchem.RWMol.RemoveBond(m, i) - Removes the j-th bond from the given molecule.
m.ReplaceAtom(i, a) or rdkit.Chem.rdchem.RWMol.ReplaceAtom(m, i, a) - Replaces the i-th atom with a given atom in the given molecule.
m.ReplaceBond(i, b) or rdkit.Chem.rdchem.RWMol.ReplaceBond(m, i, b) - Replaces j-th bond with a given bond in the given molecule.
m.InsertMol(s) or rdkit.Chem.rdchem.RWMol.InsertMol(m, s) - Inserts another molecule into the given molecule.
rdkit.Chem.SanitizeMol(m) - Sanitizes the given molecule.
rdkit.Chem.MolToSmiles(m) - Returns the SMILES string of the given molecule.
rdkit.Chem.MolToMolBlock(m) - Returns the SDF string of the given molecule.
Here is an example session of using rdkit.Chem.rdchem.RWMol class to build molecules from scratch:
>>> import rdkit >>> water = rdkit.Chem.rdchem.RWMol() >>> O = rdkit.Chem.rdchem.Atom("O") >>> H = rdkit.Chem.rdchem.Atom("H") >>> >>> water.AddAtom(O) 0 >>> water.AddAtom(H) 2 >>> water.AddBond(0, 1, rdkit.Chem.rdchem.BondType.SINGLE) 1 >>> water.AddBond(0, 2, rdkit.Chem.rdchem.BondType.SINGLE) 2 >>> rdkit.Chem.SanitizeMol(water) rdkit.Chem.rdmolops.SanitizeFlags.SANITIZE_NONE >>> rdkit.Chem.MolToSmiles(water) '[H]O[H]' >>> ring = rdkit.Chem.rdchem.RWMol() >>> C = rdkit.Chem.rdchem.Atom("C") >>> ring.AddAtom(C) 0 >>> ring.AddAtom(C) 1 >>> ring.AddAtom(C) 2 >>> ring.AddAtom(C) 3 >>> ring.AddAtom(C) 4 >>> ring.AddBond(0, 1, rdkit.Chem.rdchem.BondType.SINGLE) 1 >>> ring.AddBond(1, 2, rdkit.Chem.rdchem.BondType.SINGLE) 2 >>> ring.AddBond(2, 3, rdkit.Chem.rdchem.BondType.SINGLE) 3 >>> ring.AddBond(3, 4, rdkit.Chem.rdchem.BondType.SINGLE) 4 >>> ring.AddBond(4, 0, rdkit.Chem.rdchem.BondType.SINGLE) 5 >>> rdkit.Chem.SanitizeMol(ring) rdkit.Chem.rdmolops.SanitizeFlags.SANITIZE_NONE >>> rdkit.Chem.MolToSmiles(ring) 'C1CCCC1'
Table of Contents
SMILES (Simplified Molecular-Input Line-Entry System)
Open Babel: The Open Source Chemistry Toolbox
Using Open Babel Command: "obabel"
Generating SVG Pictures with Open Babel
Substructure Search with Open Babel
Similarity Search with Open Babel
Fingerprint Index for Fastsearch with Open Babel
Stereochemistry with Open Babel
Command Line Tools Provided by Open Babel
RDKit: Open-Source Cheminformatics Software
►rdkit.Chem.rdchem - The Core Module
What Is rdkit.Chem.rdchem Module
rdkit.Chem.rdchem.Mol - The Molecule Class
rdkit.Chem.rdchem.Atom - The Atom Class
rdkit.Chem.rdchem.Bond - The Bond Class
►rdkit.Chem.rdchem.RWMol - The RWMol Class
rdkit.Chem.rdmolfiles - Molecular File Module
rdkit.Chem.rdDepictor - Compute 2D Coordinates
rdkit.Chem.Draw - Handle Molecule Images
Molecule Substructure Search with RDKit
rdkit.Chem.rdmolops - Molecule Operations
Daylight Fingerprint Generator in RDKit
Morgan Fingerprint Generator in RDKit
RDKit Performance on Substructure Search
Introduction to Molecular Fingerprints
OCSR (Optical Chemical Structure Recognition)
AlphaFold - Protein Structure Prediction