Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: SmilesWidget: Use MMFF94 to optimize generated structures #525

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions aiidalab_widgets_base/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,8 +737,8 @@ def _rdkit_opt(self, smiles, steps):
if mol is None:
# Something is seriously wrong with the SMILES code,
# just return None and don't attempt anything else.
self.output.value = "RDKit ERROR: Invalid SMILES string"
return None
msg = "Invalid SMILES"
raise ValueError(msg)
mol = Chem.AddHs(mol)

conf_id = AllChem.EmbedMolecule(mol, maxAttempts=20, randomSeed=42)
Expand All @@ -751,12 +751,16 @@ def _rdkit_opt(self, smiles, steps):
mol, maxAttempts=20, useRandomCoords=True, randomSeed=422
)
if conf_id < 0:
self.output.value = "RDKit ERROR: Could not generate conformer"
return None
if AllChem.UFFHasAllMoleculeParams(mol):
msg = "RDKit could not generate conformer"
raise ValueError(msg)

if AllChem.MMFFHasAllMoleculeParams(mol):
# TODO: Check the return value!
AllChem.MMFFOptimizeMolecule(mol, maxIters=steps)
elif AllChem.UFFHasAllMoleculeParams(mol):
AllChem.UFFOptimizeMolecule(mol, maxIters=steps)
else:
self.output.value = "RDKit WARNING: Missing UFF parameters"
self.output.value = "RDKit WARNING: Missing MMFF/UFF parameters"

positions = mol.GetConformer().GetPositions()
natoms = mol.GetNumAtoms()
Expand Down