@@ -451,12 +451,15 @@ def modify(
451451 mol , ghosts0 , modifications , skip_ghosts = linearised0 , is_lambda1 = False
452452 )
453453
454- # Remove angles that span ring-making bonds in the state where those
455- # bonds do not yet exist.
454+ # Remove angles and dihedrals that span ring-making bonds in the state
455+ # where those bonds do not yet exist.
456456 if _ring_making_bonds :
457457 mol = _remove_cross_bond_angles (
458458 mol , _ring_making_bonds , modifications , is_lambda1 = False
459459 )
460+ mol = _remove_cross_bond_dihedrals (
461+ mol , _ring_making_bonds , modifications , is_lambda1 = False
462+ )
460463
461464 # Soften any surviving mixed ghost/physical dihedrals.
462465 mol = _soften_mixed_dihedrals (
@@ -572,12 +575,15 @@ def modify(
572575 mol , ghosts1 , modifications , skip_ghosts = linearised1 , is_lambda1 = True
573576 )
574577
575- # Remove angles that span ring-breaking bonds in the state where those
576- # bonds no longer exist.
578+ # Remove angles and dihedrals that span ring-breaking bonds in the state
579+ # where those bonds no longer exist.
577580 if _ring_breaking_bonds :
578581 mol = _remove_cross_bond_angles (
579582 mol , _ring_breaking_bonds , modifications , is_lambda1 = True
580583 )
584+ mol = _remove_cross_bond_dihedrals (
585+ mol , _ring_breaking_bonds , modifications , is_lambda1 = True
586+ )
581587
582588 # Soften any surviving mixed ghost/physical dihedrals.
583589 mol = _soften_mixed_dihedrals (
@@ -2508,6 +2514,88 @@ def _remove_cross_bond_angles(mol, changing_bonds, modifications, is_lambda1=Fal
25082514 return mol
25092515
25102516
2517+ def _remove_cross_bond_dihedrals (mol , changing_bonds , modifications , is_lambda1 = False ):
2518+ r"""
2519+ Remove dihedral terms whose central bond spans a ring-making or
2520+ ring-breaking bond in the end state where that bond does not exist.
2521+ Such dihedrals encode the bonded geometry and couple atoms across the
2522+ missing bond, causing poor overlap between adjacent lambda windows.
2523+
2524+ A - B ~~~ C - D
2525+ (missing bond)
2526+
2527+ If the B-C bond is absent in this end state, the dihedral A-B-C-D
2528+ is removed.
2529+
2530+ Parameters
2531+ ----------
2532+
2533+ mol : sire.mol.Molecule
2534+ The perturbable molecule.
2535+
2536+ changing_bonds : set of (int, int)
2537+ Pairs of atom index values for bonds that change between end states.
2538+ Pass ring-making bonds for is_lambda1=False, ring-breaking bonds for
2539+ is_lambda1=True.
2540+
2541+ modifications : dict
2542+ A dictionary to store details of the modifications made.
2543+
2544+ is_lambda1 : bool, optional
2545+ Whether to modify dihedrals at lambda = 1.
2546+
2547+ Returns
2548+ -------
2549+
2550+ mol : sire.mol.Molecule
2551+ The updated molecule.
2552+ """
2553+
2554+ if not changing_bonds :
2555+ return mol
2556+
2557+ info = mol .info ()
2558+
2559+ if is_lambda1 :
2560+ mod_key = "lambda_1"
2561+ suffix = "1"
2562+ else :
2563+ mod_key = "lambda_0"
2564+ suffix = "0"
2565+
2566+ dihedrals = mol .property ("dihedral" + suffix )
2567+ new_dihedrals = _SireMM .FourAtomFunctions (mol .info ())
2568+ modified = False
2569+
2570+ for p in dihedrals .potentials ():
2571+ idx0 = info .atom_idx (p .atom0 ())
2572+ idx1 = info .atom_idx (p .atom1 ())
2573+ idx2 = info .atom_idx (p .atom2 ())
2574+ idx3 = info .atom_idx (p .atom3 ())
2575+
2576+ i , j , k , l = idx0 .value (), idx1 .value (), idx2 .value (), idx3 .value ()
2577+ central = (min (j , k ), max (j , k ))
2578+
2579+ if central in changing_bonds :
2580+ _logger .debug (
2581+ f" Removing cross-bond dihedral: [{ i } -{ j } -{ k } -{ l } ], { p .function ()} "
2582+ )
2583+ modifications [mod_key ]["removed_dihedrals" ].append (f"{ i } ,{ j } ,{ k } ,{ l } " )
2584+ modified = True
2585+ else :
2586+ new_dihedrals .set (idx0 , idx1 , idx2 , idx3 , p .function ())
2587+
2588+ if modified :
2589+ mol = (
2590+ mol .edit ()
2591+ .set_property ("dihedral" + suffix , new_dihedrals )
2592+ .molecule ()
2593+ .commit ()
2594+ )
2595+
2596+ return mol
2597+
2598+
25112599def _soften_mixed_dihedrals (
25122600 mol , ghosts , modifications , soften_anchors = 1.0 , is_lambda1 = False
25132601):
0 commit comments