Skip to content

Commit

Permalink
improved xyzFromSmiles.py
Browse files Browse the repository at this point in the history
  • Loading branch information
kumaranu committed May 1, 2024
1 parent f5abc8c commit ec5fdc5
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions src/MolecularDockingKit/xyzFromSmiles.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
import numpy as np
from rdkit import Chem
from rdkit.Chem import AllChem

###########################################################
# #
# This program generates the xyz coordinates for the #
# molecules using SMILES. It tries for upto 20 iterations #
# inside the rdkit MM force field optimizer and only #
# returns a geometry if converged. Most of the molecules #
# were converged with an exception of four to five. #
# #
###########################################################
def xyzFromSmiles(smiles, fileName):

def xyz_from_smiles(smiles: str, file_name: str) -> None:
"""
Generates the xyz coordinates for molecules using SMILES.
Parameters:
smiles (str): The SMILES string of the molecule.
file_name (str): The name of the output file to save the molecule coordinates.
Returns:
None. Saves the coordinates to a file in SD format.
"""

# Convert SMILES to RDKit molecule object
mol = Chem.MolFromSmiles(smiles)

# Add hydrogen atoms to the molecule
mol = Chem.AddHs(mol)

# Embed the molecule and optimize using the MMFF force field
AllChem.EmbedMolecule(mol, useRandomCoords=True)
try:
AllChem.MMFFOptimizeMolecule(mol, maxIters=20)
writer = Chem.rdmolfiles.SDWriter(fileName + '.sd')

# Write the molecule to an SD file
writer = Chem.rdmolfiles.SDWriter(file_name + '.sd')
writer.write(mol)
except:
print('Skipping ', fileName)
print('Skipping ', file_name)
return

0 comments on commit ec5fdc5

Please sign in to comment.