Skip to content

Commit

Permalink
WIP: SmilesWidget: Use MMFF94 to optimize generated structure
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhollas committed Oct 11, 2023
1 parent ccfcf80 commit 9db58a5
Showing 1 changed file with 10 additions and 6 deletions.
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

0 comments on commit 9db58a5

Please sign in to comment.