From 9db58a5c3e503bdfe9fd733ea6f7f5be55c7604f Mon Sep 17 00:00:00 2001 From: Daniel Hollas Date: Wed, 11 Oct 2023 23:32:49 +0100 Subject: [PATCH] WIP: SmilesWidget: Use MMFF94 to optimize generated structure --- aiidalab_widgets_base/structures.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/aiidalab_widgets_base/structures.py b/aiidalab_widgets_base/structures.py index e5f5100b1..0aadd8bf2 100644 --- a/aiidalab_widgets_base/structures.py +++ b/aiidalab_widgets_base/structures.py @@ -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) @@ -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()