From 3997c1c09d14af2ae2e3522c06a9ff072827f56f Mon Sep 17 00:00:00 2001 From: nbrosse <31697743+nbrosse@users.noreply.github.com> Date: Mon, 13 May 2024 10:57:01 +0200 Subject: [PATCH] get_flexible_torsions, keep track of the central bond. (#221) Co-authored-by: nicolas.brosse --- unimol/unimol/utils/conformer_model.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/unimol/unimol/utils/conformer_model.py b/unimol/unimol/utils/conformer_model.py index 7b1218a..50c12ed 100644 --- a/unimol/unimol/utils/conformer_model.py +++ b/unimol/unimol/utils/conformer_model.py @@ -99,9 +99,12 @@ def get_flexible_torsions(mol: Chem.Mol) -> th.Tensor: i_, l_ = (dist_mat.triu() == 3).bool().nonzero().T.tolist() # Shortest path, where rotatable bond in the middle is a torsion flex_unique_torsions = [] + central_bond_torsions = set() for i, l in zip(i_, l_): i, j, k, l = Chem.GetShortestPath(mol, i, l) - if {(j, k), (k, j)}.intersection(matches): + if {(j, k), (k, j)}.intersection(matches) and (j, k) not in central_bond_torsions: + # Register the central bond + central_bond_torsions.update([(j, k), (k, j)]) # torsion in the direction that leaves lesser atoms to later rotate: towards the periphery if (dist_mat[j] < dist_mat[k]).sum() > (dist_mat[j] > dist_mat[k]).sum(): flex_unique_torsions.append([i, j, k, l])