rdkit

RDKit convert Mol file sdf v3000 to v2000


I have a Mol (sdf) file with a few chemicals in v3000 format. How do I convert it to Mol (sdf) file in v2000 format using RDKit?

Any help is appreciated.


Solution

  • RDKit will write v2000 format by default unless v3000 is specified, so you can just read in the SDF in v3000 format and write to v2000:

    from rdkit import Chem
    
    supplier = Chem.SDMolSupplier('v3000.sdf')
    writer = Chem.SDWriter('v2000.sdf')
    
    for molecule in supplier:
        writer.write(molecule)
    
    writer.close()
    

    Suppose you wanted to do the opposite:

    supplier = Chem.SDMolSupplier('v2000.sdf')
    writer = Chem.SDWriter('v3000.sdf')
    writer.SetForceV3000(True)
    
    for molecule in supplier:
        writer.write(molecule)
    
    writer.close()