Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Torsion Distribution plotting/analysis #20

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added src/__init__.py
Empty file.
86 changes: 86 additions & 0 deletions src/openfe_analysis/torsions_distributions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import itertools
import MDAnalysis as mda
from MDAnalysis.analysis import rms
import netCDF4 as nc
import numpy as np
import pathlib

from openfe_analysis.reader import FEReader
from openfe_analysis.transformations import (
NoJump, Minimiser, Aligner
)

from typing import List
from rdkit import Chem
from rdkit.Chem import AllChem

from matplotlib import pyplot as plt
from MDAnalysis.analysis.dihedrals import Dihedral

def calculate_dihedrals(mol, torsion_ids_list)->np.array:
dihedrals = []
for c in mol.GetConformers():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work for our trajectories right?

frame_dihs = []
for tba in torsion_ids_list:
tangle = Chem.rdMolTransforms.GetDihedralDeg(c, *tba)
frame_dihs.append(tangle)
dihedrals.append(frame_dihs)
dihedrals = np.array(dihedrals_B)
return dihedrals


def calculate_dihedrals_all_torsions(mol)->(List[List[int]], np.array):
rbA = get_rotatable_bonds(mol)

tbA = []
for rba in rbA:
tba = get_torsion_atoms_idx(rba)
tbA.append(tba)

dihedrals = calculate_dihedrals(mol, tbA)

return (tbA, dihedrals)


def get_rotatable_bonds(mol: Chem.Mol) -> List[Chem.Bond]:
"""Function to find all rotatable bonds in a molecule taking symmetry into account.

Parameters
----------
mol : Chem.Mol
The rdkit.Chem.Mol object

Returns
-------
List[Chem.Bond]
List of rdkit.Chem.Bond that were found in a molecule taking symmetry into account.
"""
RotatableBondSmarts = Chem.MolFromSmarts("[!$(*#*)&!D1]-&!@[!$(*#*)&!D1]")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this different from the definition in Lipinski?

find_rbs = lambda x, y=RotatableBondSmarts: x.GetSubstructMatches(y, uniquify=1)
rbs = find_rbs(mol)
bonds = [mol.GetBondBetweenAtoms(*inds) for inds in rbs]

return bonds


def get_torsion_atoms_idx(bond: Chem.Bond) -> List[int]:
"""Function that finds the atomic ids that specify a torsion around the bond of interest.

Parameters
----------
bond : Chem.Bond
The bond of interest around which the torsion should be specified.

Returns
-------
List[int]
List of atomic ids that specify a torsion around the bond of interest.
"""
bond_atoms = [bond.GetBeginAtom(), bond.GetEndAtom()]
additional_atom1 = list(filter(lambda x: x.GetIdx() != bond_atoms[1].GetIdx(), bond_atoms[0].GetNeighbors()))[0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're going to ignore hydrogen torsions right? Does slicing the zeroth element here potentially miss a heavy atom torsion?

additional_atom2 = list(filter(lambda x: x.GetIdx() != bond_atoms[0].GetIdx(), bond_atoms[1].GetNeighbors()))[0]
torsion_atoms = [additional_atom1] + list(bond_atoms) + [additional_atom2]
torsion_atom_ids = [a.GetIdx() for a in torsion_atoms]

return torsion_atom_ids

2 changes: 2 additions & 0 deletions src/openfe_analysis/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .lassoo_highlights import draw_multi_matches, draw_substructurematch

Loading
Loading