generated from Quantum-Accelerators/template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
23 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|