Skip to content

Instantly share code, notes, and snippets.

@bdrown
Created May 13, 2020 13:22
Show Gist options
  • Save bdrown/9686c3201826a5ccd50f074f6b017eb9 to your computer and use it in GitHub Desktop.
Save bdrown/9686c3201826a5ccd50f074f6b017eb9 to your computer and use it in GitHub Desktop.
Short python script for guessing the 3D structure of a molecule from a smiles string and writing out to mol file
# smiles_to_mol.py
__doc__ = """Guesses the initial geometry of a molecule based on SMILES string
"""
###############################
from rdkit import Chem
from rdkit.Chem import AllChem
import sys
###############################
# Get parameters
smiles = sys.argv[1]
mol_out = sys.argv[2]
m = Chem.MolFromSmiles(smiles)
m2 = Chem.AddHs(m)
# Generate initial guess
AllChem.EmbedMolecule(m2,AllChem.ETKDG())
AllChem.MMFFOptimizeMolecule(m2)
# Write mol file
print(Chem.MolToMolBlock(m2),file=open(mol_out,'w'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment