Exemplo n.º 1
0
    def get_all_torsions(
            bond: Tuple[int, int],
            molecule: Molecule) -> List[Tuple[int, int, int, int]]:
        """
        Get all torsions that pass through the central bond to generate smirks patterns.

        Parameters:
            bond: The bond which we want all torsions for.
            molecule: The molecule which the bond corresponds to.

        Returns:
            A list of all of the torsion tuples passing through this central bond.
        """

        torsions = []
        central_bond = molecule.get_bond_between(*bond)
        atom1, atom2 = central_bond.atom1, central_bond.atom2

        for atom in atom1.bonded_atoms:
            for end_atom in atom2.bonded_atoms:
                if atom != atom2 and end_atom != atom1:
                    dihedral = (
                        atom.molecule_atom_index,
                        atom1.molecule_atom_index,
                        atom2.molecule_atom_index,
                        end_atom.molecule_atom_index,
                    )
                    torsions.append(dihedral)
                else:
                    continue

        return torsions
Exemplo n.º 2
0
def check_general_connection(
    connected_atoms: List[int], molecule: off.Molecule
) -> List[int]:
    """
    Check that the list of atoms are all connected in order by explicit bonds in the given molecule.

    Parameters:
        connected_atoms: A list of the atom indices that should be connected in order.
        molecule: The molecule that should be checked for connected atoms.

    Raises:
        AtomConnectionError: If any two of the given list of atoms are not connected.

    Returns:
        The list of validated connected atom indices.
    """
    for i in range(len(connected_atoms) - 1):
        # get the atoms to be checked
        atoms = [connected_atoms[i], connected_atoms[i + 1]]
        try:
            _ = molecule.get_bond_between(*atoms)
        except (off.topology.NotBondedError, IndexError):
            # catch both notbonded errors and tags on atoms not in the molecule
            raise AtomConnectionError(
                f"The set of atoms {connected_atoms} was not valid for the molecule {molecule}, as there is no bond between atoms {atoms}.",
                atoms=atoms,
            )

    return connected_atoms