Skip to content

Commit 9db58a5

Browse files
committed
WIP: SmilesWidget: Use MMFF94 to optimize generated structure
1 parent ccfcf80 commit 9db58a5

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

aiidalab_widgets_base/structures.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -737,8 +737,8 @@ def _rdkit_opt(self, smiles, steps):
737737
if mol is None:
738738
# Something is seriously wrong with the SMILES code,
739739
# just return None and don't attempt anything else.
740-
self.output.value = "RDKit ERROR: Invalid SMILES string"
741-
return None
740+
msg = "Invalid SMILES"
741+
raise ValueError(msg)
742742
mol = Chem.AddHs(mol)
743743

744744
conf_id = AllChem.EmbedMolecule(mol, maxAttempts=20, randomSeed=42)
@@ -751,12 +751,16 @@ def _rdkit_opt(self, smiles, steps):
751751
mol, maxAttempts=20, useRandomCoords=True, randomSeed=422
752752
)
753753
if conf_id < 0:
754-
self.output.value = "RDKit ERROR: Could not generate conformer"
755-
return None
756-
if AllChem.UFFHasAllMoleculeParams(mol):
754+
msg = "RDKit could not generate conformer"
755+
raise ValueError(msg)
756+
757+
if AllChem.MMFFHasAllMoleculeParams(mol):
758+
# TODO: Check the return value!
759+
AllChem.MMFFOptimizeMolecule(mol, maxIters=steps)
760+
elif AllChem.UFFHasAllMoleculeParams(mol):
757761
AllChem.UFFOptimizeMolecule(mol, maxIters=steps)
758762
else:
759-
self.output.value = "RDKit WARNING: Missing UFF parameters"
763+
self.output.value = "RDKit WARNING: Missing MMFF/UFF parameters"
760764

761765
positions = mol.GetConformer().GetPositions()
762766
natoms = mol.GetNumAtoms()

0 commit comments

Comments
 (0)