diff --git a/CAT/attachment/ligand_attach.py b/CAT/attachment/ligand_attach.py index a9d562ca..69a1c5dc 100644 --- a/CAT/attachment/ligand_attach.py +++ b/CAT/attachment/ligand_attach.py @@ -242,9 +242,7 @@ def get_name() -> str: ligand.properties.dummies.properties.anchor = True # Attach the rotated ligands to the core, returning the resulting strucutre (PLAMS Molecule). - lig_array = rot_mol(ligand, vec1, vec2, atoms_other=core.properties.dummies, idx=idx) - _evaluate_distance(lig_array, len(core)) - + lig_array = rot_mol(ligand, vec1, vec2, atoms_other=core.properties.dummies, core=core, idx=idx) qd = core.copy() array_to_qd(ligand, lig_array, mol_out=qd) qd.round_coords() @@ -260,6 +258,7 @@ def get_name() -> str: }) # Print and return + _evaluate_distance(qd) return qd @@ -350,6 +349,7 @@ def rot_mol(xyz_array: np.ndarray, vec2: np.ndarray, idx: int = 0, atoms_other: Optional[np.ndarray] = None, + core: Optional[np.ndarray] = None, bond_length: Optional[int] = None, step: float = 1/16, dist_to_self: bool = True) -> np.ndarray: @@ -430,10 +430,11 @@ def rot_mol(xyz_array: np.ndarray, # Returns the conformation of each molecule that maximizes the inter-moleculair distance # Or return all conformations if dist_to_self = False and atoms_other = None - return rotation_check_kdtree(xyz, at_other) + return rotation_check_kdtree(xyz, at_other, core) -def rotation_check_kdtree(xyz: np.ndarray, at_other: np.ndarray, k: int = 10): +def rotation_check_kdtree(xyz: np.ndarray, core_anchor: np.ndarray, + core: np.ndarray, k: int = 10): """Perform the rotation check using SciPy's :class:`cKDTree Union[None, NoReturn]: """Eavluate all the distance matrix of **xyz3D** and perform **action** when distances are below **threshold**.""" # noqa @@ -485,7 +491,7 @@ def _evaluate_distance(xyz3D: np.ndarray, if action == 'ignore': return None - xyz = xyz3D.reshape(-1, 3) + xyz = np.asarray(mol) tree = cKDTree(xyz) dist, idx = tree.query(xyz, k=[2]) @@ -495,14 +501,14 @@ def _evaluate_distance(xyz3D: np.ndarray, bool_ar = dist < threshold if bool_ar.any(): _idx2 = np.stack([np.arange(len(idx)), idx]).T - _idx2 += 1 + offset + _idx2 += 1 _idx2.sort(axis=1) idx2 = np.unique(_idx2[bool_ar], axis=0) n = len(idx2) exc = MoleculeError( - f"\nEncountered >= {n} unique ligand atom-pairs at a distance shorter than " + f"\nEncountered >= {n} unique atom-pairs at a distance shorter than " f"{threshold} Angstrom:\n{aNDRepr.repr(idx2.T)}" ) action_func(exc)