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
+
@author: BM109X32G-10GPU-02
|
| 13 |
+
"""
|
| 14 |
+
|
| 15 |
+
from langchain.tools import BaseTool
|
| 16 |
+
from rdkit import Chem
|
| 17 |
+
import requests
|
| 18 |
+
from rdkit import Chem
|
| 19 |
+
from rdkit.Chem import Descriptors, Lipinski, QED
|
| 20 |
+
|
| 21 |
+
def predict_ro5_and_qed(smiles):
|
| 22 |
+
mol = Chem.MolFromSmiles(smiles)
|
| 23 |
+
if mol is None:
|
| 24 |
+
return None
|
| 25 |
+
|
| 26 |
+
molecular_weight = Descriptors.MolWt(mol)
|
| 27 |
+
logp = Descriptors.MolLogP(mol)
|
| 28 |
+
hbd = Lipinski.NumHDonors(mol)
|
| 29 |
+
hba = Lipinski.NumHAcceptors(mol)
|
| 30 |
+
|
| 31 |
+
violations = 0
|
| 32 |
+
if molecular_weight > 500:
|
| 33 |
+
violations += 1
|
| 34 |
+
if logp > 5:
|
| 35 |
+
violations += 1
|
| 36 |
+
if hbd > 5:
|
| 37 |
+
violations += 1
|
| 38 |
+
if hba > 10:
|
| 39 |
+
violations += 1
|
| 40 |
+
ro5_approved = violations <= 1
|
| 41 |
+
|
| 42 |
+
qed_value = QED.qed(mol)
|
| 43 |
+
if violations == 0 & qed_value> 0.5:
|
| 44 |
+
|
| 45 |
+
return "The candidate obey the Lipinski's rule and QED, is considered to be drug-like"
|
| 46 |
+
else:
|
| 47 |
+
return "The candidate obey is considered to be non drug-like"
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
class ADMETLab(BaseTool):
|
| 52 |
+
name:str = "ADMETLab"
|
| 53 |
+
description :str = "Input smiles of drug , returns ADMET properties."
|
| 54 |
+
|
| 55 |
+
def __init__(self ):
|
| 56 |
+
super().__init__()
|
| 57 |
+
|
| 58 |
+
def _run(self, smiles: str) -> str:
|
| 59 |
+
mol = Chem.MolFromSmiles(smiles)
|
| 60 |
+
if mol is None:
|
| 61 |
+
return "Invalid SMILES string"
|
| 62 |
+
try:
|
| 63 |
+
baseUrl = 'https://admetlab3.scbdd.com'
|
| 64 |
+
api = '/api/admet'
|
| 65 |
+
url = baseUrl + api
|
| 66 |
+
param = {
|
| 67 |
+
'SMILES': ["molecule", smiles],
|
| 68 |
+
}
|
| 69 |
+
response = requests.post(url, json=param)
|
| 70 |
+
if response.status_code == 200:
|
| 71 |
+
data = response.json()['data']
|
| 72 |
+
return data
|
| 73 |
+
except Exception as e:
|
| 74 |
+
|
| 75 |
+
return str(e)
|
| 76 |
+
|
| 77 |
+
async def _arun(self, query: str) -> str:
|
| 78 |
+
"""Use the tool asynchronously."""
|
| 79 |
+
raise NotImplementedError()
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
class druglike(BaseTool):
|
| 83 |
+
name:str = "druglike"
|
| 84 |
+
description :str = "Input smiles of drug , returns drug-likeness."
|
| 85 |
+
|
| 86 |
+
def __init__(self ):
|
| 87 |
+
super().__init__()
|
| 88 |
+
|
| 89 |
+
def _run(self, smiles: str) -> str:
|
| 90 |
+
mol = Chem.MolFromSmiles(smiles)
|
| 91 |
+
if mol is None:
|
| 92 |
+
return "Invalid SMILES string"
|
| 93 |
+
try:
|
| 94 |
+
mol = Chem.MolFromSmiles(smiles)
|
| 95 |
+
if mol is None:
|
| 96 |
+
return None
|
| 97 |
+
|
| 98 |
+
molecular_weight = Descriptors.MolWt(mol)
|
| 99 |
+
logp = Descriptors.MolLogP(mol)
|
| 100 |
+
hbd = Lipinski.NumHDonors(mol)
|
| 101 |
+
hba = Lipinski.NumHAcceptors(mol)
|
| 102 |
+
|
| 103 |
+
violations = 0
|
| 104 |
+
if molecular_weight > 500:
|
| 105 |
+
violations += 1
|
| 106 |
+
if logp > 5:
|
| 107 |
+
violations += 1
|
| 108 |
+
if hbd > 5:
|
| 109 |
+
violations += 1
|
| 110 |
+
if hba > 10:
|
| 111 |
+
violations += 1
|
| 112 |
+
ro5_approved = violations <= 1
|
| 113 |
+
|
| 114 |
+
qed_value = QED.qed(mol)
|
| 115 |
+
if violations == 0 & qed_value> 0.5:
|
| 116 |
+
return "The candidate obey the Lipinski's rule and QED, is considered to be drug-like"
|
| 117 |
+
else:
|
| 118 |
+
return "The candidate is considered to be non drug-like"
|
| 119 |
+
except Exception as e:
|
| 120 |
+
return str(e)
|
| 121 |
+
async def _arun(self, query: str) -> str:
|
| 122 |
+
"""Use the tool asynchronously."""
|
| 123 |
+
raise NotImplementedError()
|
| 124 |
+
|