Skip to content
This repository was archived by the owner on May 5, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
88bdecd
Add fragment merging prep (#23)
abradle Sep 17, 2018
1e7f97c
Update graph querying to proivde fragment information
Sep 22, 2018
8a365ae
Added ability to get bond index from molecule fragmentation
Sep 22, 2018
f707ec0
Update to a more recent version of rdkit
Sep 22, 2018
b348659
Fix rdkit get atoms error:
Sep 24, 2018
8979ce1
Merge pull request #24 from abradle/master
abradle Sep 24, 2018
025c0b9
Update version and fix typo
Sep 25, 2018
38f6b71
Merge branch 'master' of github.com:xchem/fragalysis
Sep 25, 2018
d2a7167
Nonisomeric smiles and fragment viewing code (#25)
abradle Oct 5, 2018
975dac5
Added isomeric / non-isomeric flag to build db
Oct 5, 2018
d2fde5d
Update to v0.0.33 release
Oct 5, 2018
07f5eb5
- Deploy to pypi on tagged releases
Oct 10, 2018
dcd2a80
- Deploy to pypi on tagged releases
Oct 10, 2018
a16924f
Do dockerhub release
Oct 10, 2018
22602d1
Update to travis name
Oct 10, 2018
b58bf85
- Terminate string
Oct 10, 2018
fbbf9fb
Push to image name
Oct 10, 2018
6b1068c
Get atom indices from smiles
Oct 10, 2018
f18383e
- Add option to query non-isomeric smiles
Oct 11, 2018
a4afc35
Fix the default for get vectors:
Oct 11, 2018
53e18ce
fix typo
reskyner Oct 12, 2018
66895da
Merge pull request #26 from xchem/rachael
reskyner Oct 12, 2018
130dc6e
fix isolabels option on get_3d_vects_for_mol
reskyner Oct 17, 2018
5347f1d
Merge pull request #27 from xchem/rachael
reskyner Oct 17, 2018
f4f2209
make sure iso_labels passed to correct variable
reskyner Oct 17, 2018
8ebd339
Merge pull request #28 from xchem/rachael
reskyner Oct 17, 2018
f979f09
version for pip
reskyner Oct 22, 2018
9a748d1
Merge pull request #29 from xchem/rachael
reskyner Oct 22, 2018
5bd36e8
version for pip
reskyner Oct 22, 2018
7a47740
Merge pull request #30 from xchem/rachael
reskyner Oct 22, 2018
9f85ec2
version
reskyner Oct 25, 2018
6c53354
Merge pull request #31 from xchem/rachael
reskyner Oct 25, 2018
e5e15c3
- Merge from xchem/fragalysis (6c53354)
Oct 29, 2018
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
21 changes: 17 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
sudo: required
services:
- docker
env:
global:
- IMAGE_NAME=xchem/fragalysis
install:
- docker build -t xchem/fragalysis .
- docker build -t "$IMAGE_NAME" .
script:
- docker run xchem/fragalysis /bin/sh -c "cd /usr/local/fragalysis && nosetests"
- docker run "$IMAGE_NAME" /bin/sh -c "cd /usr/local/fragalysis && nosetests"
after_success:
- if [ "$TRAVIS_BRANCH" == "master" ]; then
docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD";
docker push xchem/fragalysis;
fi
docker push "${IMAGE_NAME}";
fi
before_deploy:
- docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD";
- docker tag "$IMAGE_NAME" "${IMAGE_NAME}:${TRAVIS_TAG}"
deploy:
provider: script
script: docker tag "$IMAGE_NAME" "${IMAGE_NAME}:${TRAVIS_TAG}" && docker push "${IMAGE_NAME}:${TRAVIS_TAG}"
on:
branch: master
tags: true
repo: xchem/fragalysis
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![Build Status](https://travis-ci.org/xchem/fragalysis.svg?branch=master)](https://travis-ci.org/xchem/fragalysis)
[![stable](http://badges.github.io/stability-badges/dist/stable.svg)](https://github.com/badges/stability-badges)
[![Version](http://img.shields.io/badge/version-0.0.21-blue.svg?style=flat)](https://github.com/xchem/fragalysis)
[![Version](http://img.shields.io/badge/version-0.0.38-blue.svg?style=flat)](https://github.com/xchem/fragalysis)
[![License](http://img.shields.io/badge/license-Apache%202.0-blue.svg?style=flat)](https://github.com/xchem/fragalysis/blob/master/LICENSE.txt)
[![Language grade: Python](https://img.shields.io/lgtm/grade/python/g/xchem/fragalysis.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/xchem/fragalysis/context:python)

Expand Down
68 changes: 68 additions & 0 deletions frag/alysis/improve.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Tools for merging, growing and linking fragments into hybrid queries
from frag.utils.rdkit_utils import RDKitPh4, RDKitAtom


def combine_ph4(
mols, max_num_ph4s=4, min_cluster_size=2, smooth_param=0.5, smooth_grad=0.1
):
"""
Combine a series of pharmacophores into a single query
:param mols: a list of RDKit molecules
:param max_num_ph4s: the maximum number of ph4s in a query
:param min_cluster_size: the minimum size of a cluster for a point to be allowed
:param smooth_param: the max allowed pertubation for an atom
:param smooth_grad: the smoothing gradient for an atom
:return: a series of possible RDKit Pharmacophore queries
"""
rdkit_ph4 = RDKitPh4()
molecule_ph4s = []
for i, mol in enumerate(mols):
ph4s = rdkit_ph4.generate_ph4_for_mol(mol)
molecule_ph4s.append([i, mol, ph4s])
# Cluster and remove points that don't fit into a given cluster

# Combine these combinatorially and generate duplicates with the smoothing


def combine_atoms(
mols, clash_param=1.5, min_cluster_size=2, smooth_param=0.5, smooth_grad=0.1
):
"""
Combine a series of molecules into a single list of atoms - removing clashes
:param mols: a list of RDKit molecules
:param clash_param: the min distance between atoms
:param min_cluster_size: the minimum size of a cluster for a point to be allowed
:param smooth_param: the max allowed pertubation for an atom
:param smooth_grad: the smoothing gradient for an atom
:return: a series of possible combinations of atoms - e.g. as input into USRCAT
"""
rdkit_atom = RDKitAtom()
molecule_atoms = []
for i, mol in enumerate(mols):
atoms = rdkit_atom.generate_atoms_for_mol(mol)
molecule_atoms.append([i, mol, atoms])


def bond_atoms(atom_list):
"""
Attempt to merge allowed atoms given allowed rules and combinations.
This will be based off an R group of a given fragment.
Loss function to define a good molecule - More bonds, more interactions, less atoms.
Simply as ratios:
bonds-fulfilled / atom
interactions / atom
Need to keep the ratio as low
Just train on single molecules, then try merging two, then more and more.
:param atom_list: the list of allowed atoms, x,y,z and atom desc (atomic number and hybridization state)
:return:
"""
pass


def generate_exclusions(proteins):
"""
Generate a series of exclusion spheres for some cavities
:param proteins: a list of protein cavities
:return: the combined exclusion spheres
"""
pass
33 changes: 21 additions & 12 deletions frag/alysis/run_clustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,23 @@
C_OF_M_LAMBDA = 6.0


def build_type_dict(mol_ph4_list,identifiers):
def build_type_dict(mol_ph4_list, identifiers):
type_dict = {}
for i,mol in enumerate(mol_ph4_list):
for i, mol in enumerate(mol_ph4_list):
for ph4 in mol:
x = ph4[0]
y = ph4[1]
z = ph4[2]
ph4_type = ph4[3]
if ph4_type in type_dict:
type_dict[ph4_type]["coords"].append((x,y,z))
type_dict[ph4_type]["coords"].append((x, y, z))
type_dict[ph4_type]["mols"].append(identifiers[i])
else:
type_dict[ph4_type]={"coords":[(x,y,z)],"mols":[identifiers[i]]}
type_dict[ph4_type] = {"coords": [(x, y, z)], "mols": [identifiers[i]]}
return type_dict

def map_cluster(dp_means_cluster,mol_id_list):

def map_cluster(dp_means_cluster, mol_id_list):
"""

:param dp_means_cluster:
Expand All @@ -29,9 +30,11 @@ def map_cluster(dp_means_cluster,mol_id_list):
"""
out_dict = {}
for cluster in dp_means_cluster.clusters:
out_dict[cluster] = {"centre_of_mass": dp_means_cluster.clusters[cluster],
"mol_ids": []}
for i,cluster_id in enumerate(dp_means_cluster.dataClusterId):
out_dict[cluster] = {
"centre_of_mass": dp_means_cluster.clusters[cluster],
"mol_ids": [],
}
for i, cluster_id in enumerate(dp_means_cluster.dataClusterId):
out_dict[cluster_id]["mol_ids"].append(mol_id_list[i])
return out_dict

Expand All @@ -57,12 +60,18 @@ def run_lig_cluster(mols, identifiers):
# First we get the list of mols with their Ph4s
mol_ph4_list = parse_ligand_ph4s(mols)
# Then we build a dict of type: coords: [coords list], mols: [mol_index]
type_dict = build_type_dict(mol_ph4_list,identifiers)
type_dict = build_type_dict(mol_ph4_list, identifiers)
# Then we cluster coords
clusters = {}
for ph4_type in type_dict:
if ph4_type == "c_of_m":
clusters[ph4_type]= cluster_dp(type_dict[ph4_type]["coords"],C_OF_M_LAMBDA,type_dict[ph4_type]["mols"])
clusters[ph4_type] = cluster_dp(
type_dict[ph4_type]["coords"],
C_OF_M_LAMBDA,
type_dict[ph4_type]["mols"],
)
else:
clusters[ph4_type]= cluster_dp(type_dict[ph4_type]["coords"],PH4_LAMBDA,type_dict[ph4_type]["mols"])
return clusters
clusters[ph4_type] = cluster_dp(
type_dict[ph4_type]["coords"], PH4_LAMBDA, type_dict[ph4_type]["mols"]
)
return clusters
22 changes: 0 additions & 22 deletions frag/alysis/scripts/run_cluster.py

This file was deleted.

91 changes: 66 additions & 25 deletions frag/network/decorate.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def decorate_smi(input_smi):
return decorate_mol(get_mol, Chem.MolFromSmiles, input_smi)


def decorate_3d_mol(input_mol_file):
def decorate_3d_mol(input_mol_file, get_indices=False):
res_dict = decorate_mol(
get_mol, Chem.MolFromMolBlock, input_mol_file, three_d_mol=True
)
Expand All @@ -39,12 +39,16 @@ def decorate_3d_mol(input_mol_file):
mol = AllChem.AddHs(Chem.MolFromMolBlock(input_mol_file), addCoords=True)
conf = mol.GetConformer()
for i, atom_pair in enumerate(atom_pairs):
atom_one = conf.GetAtomPosition(atom_pair[0])
atom_two = conf.GetAtomPosition(atom_pair[1])
out_dict[conv_at_xe(res) + "__" + str(i)] = [
(atom_one.x, atom_one.y, atom_one.z),
(atom_two.x, atom_two.y, atom_two.z),
]
if get_indices:
new_atom_pair = (atom_pair[0], atom_pair[1], "NA", True)
out_dict[conv_at_xe(res) + "__" + str(i)] = [new_atom_pair]
else:
atom_one = conf.GetAtomPosition(atom_pair[0])
atom_two = conf.GetAtomPosition(atom_pair[1])
out_dict[conv_at_xe(res) + "__" + str(i)] = [
(atom_one.x, atom_one.y, atom_one.z),
(atom_two.x, atom_two.y, atom_two.z),
]
return out_dict


Expand Down Expand Up @@ -84,12 +88,21 @@ def deletion_linker_sd(input_mol, iso_labels=True):
return deletion_linker_mol(mol, iso_labels)


def get_3d_vects_for_mol(input_mol):
tot_dict = del_link_coord(input_mol)
def get_3d_vects_for_mol(input_mol, iso_labels=True):
tot_dict = del_link_coord(input_mol, iso_labels=iso_labels)
tot_dict["additions"] = decorate_3d_mol(input_mol)
return tot_dict


def get_vect_indices_for_mol(input_mol):
mol = Chem.MolFromSmiles(Chem.MolToSmiles(Chem.MolFromMolBlock(input_mol)))
AllChem.EmbedMolecule(mol)
input_mol = Chem.MolToMolBlock(mol)
tot_dict = del_link_coord(input_mol, get_indices=True, iso_labels=False)
tot_dict["additions"] = decorate_3d_mol(input_mol, get_indices=True)
return tot_dict


def convert_dict_to_mols(tot_dict):
"""
:param tot_dict:
Expand Down Expand Up @@ -118,20 +131,35 @@ def convert_dict_to_mols(tot_dict):
return mol_list


def del_link_coord(input_mol):
tot_vals = deletion_linker_sd(input_mol, iso_labels=False)
def del_link_coord(input_mol, get_indices=False, iso_labels=False):
tot_vals = deletion_linker_sd(input_mol, iso_labels=iso_labels)
deletions = [Chem.MolToSmiles(x, isomericSmiles=True) for x in tot_vals[0]]
linkers = [Chem.MolToSmiles(x, isomericSmiles=True) for x in tot_vals[1]]
ring = [Chem.MolToSmiles(x, isomericSmiles=True) for x in tot_vals[2]]

if not iso_labels:
iso_vals = deletion_linker_sd(input_mol, iso_labels=True)
else:
iso_vals = tot_vals
deletions_iso = [Chem.MolToSmiles(x, isomericSmiles=True) for x in iso_vals[0]]
linkers_iso = [Chem.MolToSmiles(x, isomericSmiles=True) for x in iso_vals[1]]
ring_iso = [Chem.MolToSmiles(x, isomericSmiles=True) for x in iso_vals[2]]

out_d = {"linkers": {}, "deletions": {}, "ring": {}}
for x in linkers:
ret_ans = get_atom_coords(x, Chem.MolFromMolBlock(input_mol))
for i, x in enumerate(linkers):
ret_ans = get_atom_coords(
x, Chem.MolFromMolBlock(input_mol), get_indices, linkers_iso[i]
)
out_d["linkers"][ret_ans[0]] = ret_ans[1:]
for x in deletions:
ret_ans = get_atom_coords(x, Chem.MolFromMolBlock(input_mol))
for i, x in enumerate(deletions):
ret_ans = get_atom_coords(
x, Chem.MolFromMolBlock(input_mol), get_indices, deletions_iso[i]
)
out_d["deletions"][ret_ans[0]] = ret_ans[1:]
for x in ring:
ret_ans = get_atom_coords(x, Chem.MolFromMolBlock(input_mol))
for i, x in enumerate(ring):
ret_ans = get_atom_coords(
x, Chem.MolFromMolBlock(input_mol), get_indices, ring_iso[i]
)
out_d["ring"][ret_ans[0]] = ret_ans[1:]
return out_d

Expand Down Expand Up @@ -178,38 +206,51 @@ def deletion_linker_mol(mol, iso_labels=True):
return out_mols, linker_mol_list, ring_repl_list


def find_atom_pairs(smiles_input):
def find_atom_pairs(smiles_input, get_indices, iso_smiles):
"""
Find the indices of the atom pairs from a SMILES input
:param smiles_input:
:return:
"""
matches = re.findall(XE_PATT, smiles_input)
if iso_smiles:
iso_matches = re.findall(XE_PATT, iso_smiles)
else:
iso_matches = None
isotope = None
ind_list = []
for match in matches:
for i, match in enumerate(matches):
index = int(match[:-2])
indices = ret_comb_index(index)
if iso_matches:
isotope = int(iso_matches[i][:-2])
indices = ret_comb_index(index, get_indices, isotope)
ind_list.append(indices)
return ind_list


def get_atom_coords(smiles_input, mol):
def get_atom_coords(smiles_input, mol, get_indices=False, iso_smiles=None):
"""
Get a
:param smiles_input:
:param mol:
:return:
"""
ind_list = find_atom_pairs(smiles_input)
ind_list = find_atom_pairs(smiles_input, get_indices, iso_smiles)
clean_smi = re.sub(XE_PATT, "Xe", smiles_input)
out_list = [clean_smi]
conf = mol.GetConformer()
for atom_pair in ind_list:
atom_one = conf.GetAtomPosition(atom_pair[0])
atom_two = conf.GetAtomPosition(atom_pair[1])
out_list.extend(
[(atom_one.x, atom_one.y, atom_one.z), (atom_two.x, atom_two.y, atom_two.z)]
)
if get_indices:
out_list.append((atom_pair[0], atom_pair[1], atom_pair[2], False))
else:
out_list.extend(
[
(atom_one.x, atom_one.y, atom_one.z),
(atom_two.x, atom_two.y, atom_two.z),
]
)
return out_list


Expand Down
Loading