当前位置:网站首页>QSAR model establishment script based on pytoch and rdkit
QSAR model establishment script based on pytoch and rdkit
2022-07-03 03:51:00 【LRJ-jonas】
QSAR
Quantitative structure activity method (quantitative structure-activity relationship, QSAR) It is the most widely used drug design method . The so-called quantitative structure-activity method is to establish a series of combinations through some mathematical statistical methods The quantitative relationship between the physiological activity or some property of a substance and its physical and chemical properties , Through these relationships . It can predict the physiological activity or some properties of compounds , Guide us to design compounds with higher activity .
Installation environment
pip install pprint
pip install argparse
# install rdkit
conda install -c rdkit rdkitinstall pytorch course
be based on pytorch and rdkit Of QSAR model
#!/usr/bin/python3
import pprint
import argparse
import torch
import torch.optim as optim
from torch import nn as nn
import torch.nn.functional as F
from torch.autograd import Variable
from rdkit import Chem
from rdkit.Chem import AllChem
from rdkit.Chem import DataStructs
import numpy as np
#from sklearn import preprocessing
def base_parser():
parser = argparse.ArgumentParser("This is simple test of pytorch")
parser.add_argument("trainset", help="sdf for train")
parser.add_argument("testset", help="sdf for test")
parser.add_argument("--epochs", default=150)
return parser
parser = base_parser()
args = parser.parse_args()
traindata = [mol for mol in Chem.SDMolSupplier(args.trainset) if mol is not None]
testdata = [mol for mol in Chem.SDMolSupplier(args.testset) if mol is not None]
def molsfeaturizer(mols):
fps = []
for mol in mols:
arr = np.zeros((0,))
fp = AllChem.GetMorganFingerprintAsBitVect(mol, 2)
DataStructs.ConvertToNumpyArray(fp, arr)
fps.append(arr)
fps = np.array(fps, dtype = np.float)
return fps
classes = {"(A) low":0, "(B) medium":1, "(C) high":2}
#classes = {"(A) low":0, "(B) medium":1, "(C) high":1}
trainx = molsfeaturizer(traindata)
testx = molsfeaturizer(testdata)
# for pytorch, y must be long type!!
trainy = np.array([classes[mol.GetProp("SOL_classification")] for mol in traindata], dtype=np.int64)
testy = np.array([classes[mol.GetProp("SOL_classification")] for mol in testdata], dtype=np.int64)
# stay pytorch Build models in , Define each layer and the entire structure
X_train = torch.from_numpy(trainx)
X_test = torch.from_numpy(testx)
Y_train = torch.from_numpy(trainy)
Y_test = torch.from_numpy(testy)
print(X_train.size(),Y_train.size())
print(X_test.size(), Y_train.size())
class QSAR_mlp(nn.Module):
def __init__(self):
super(QSAR_mlp, self).__init__()
self.fc1 = nn.Linear(2048, 524)
self.fc2 = nn.Linear(524, 10)
self.fc3 = nn.Linear(10, 10)
self.fc4 = nn.Linear(10,3)
def forward(self, x):
x = x.view(-1, 2048)
h1 = F.relu(self.fc1(x))
h2 = F.relu(self.fc2(h1))
h3 = F.relu(self.fc3(h2))
output = F.sigmoid(self.fc4(h3))
return output
# Build training and prediction models
model = QSAR_mlp()
print(model)
losses = []
optimizer = optim.Adam( model.parameters(), lr=0.005)
for epoch in range(args.epochs):
data, target = Variable(X_train).float(), Variable(Y_train).long()
optimizer.zero_grad()
y_pred = model(data)
loss = F.cross_entropy(y_pred, target)
print("Loss: {}".format(loss.data[0]))
loss.backward()
optimizer.step()
pred_y = model(Variable(X_test).float())
predicted = torch.max(pred_y, 1)[1]
for i in range(len(predicted)):
print("pred:{}, target:{}".format(predicted.data[i], Y_test[i]))
print( "Accuracy: {}".format(sum(p==t for p,t in zip(predicted.data, Y_test))/len(Y_test)))test model
python qsar_pytorch.py solubility.train.sdf solubility.test.sdf边栏推荐
- [mathematical logic] propositional logic (equivalent calculus | idempotent law | exchange law | combination law | distribution law | De Morgan law | absorption rate | zero law | identity | exclusion l
- QQ小程序开发之 一些前期准备:预约开发账号、下载安装开发者工具、创建qq小程序
- [mathematical logic] propositional logic (propositional logic reasoning | formal structure of reasoning | inference law | additional law | simplification law | hypothetical reasoning | refusal | disju
- Ffmpeg recording screen and screenshot
- 没有sXid,suid&sgid将进入险境!-尚文网络xUP楠哥
- What is pytorch? Is pytorch a software?
- 可分离债券与可转债
- Download and install captura and configure ffmpeg in captura
- SAP UI5 应用开发教程之一百零五 - SAP UI5 Master-Detail 布局模式的联动效果实现明细介绍
- IPv6 transition technology-6to4 manual tunnel configuration experiment -- Kuige of Shangwen network
猜你喜欢

Captura下载安装及在Captura配置FFmpeg

105. SAP UI5 Master-Detail 布局模式的联动效果实现明细介绍

Ffmpeg recording screen and screenshot

简易版 微信小程序开发之for指令、上传图片及展示效果优化

Positioning (relative positioning, absolute positioning, fixed positioning, Z-index) 2022-2-11

FileZilla client download and installation

递归:深度优先搜索

Makefile demo
![[embedded module] OLED display module](/img/c4/474f5ee580d132654fbd1a4cd53bab.jpg)
[embedded module] OLED display module

Lvgl usage experience
随机推荐
[learning notes] seckill - seckill project - (11) project summary
sigaction的使用
Mysql Mac版下载安装教程
QQ小程序开发之 一些前期准备:预约开发账号、下载安装开发者工具、创建qq小程序
[set theory] partial order relation (partial order relation definition | partial order set definition | greater than or equal to relation | less than or equal to relation | integer division relation |
TCP, the heavyweight guest in tcp/ip model -- Kuige of Shangwen network
Recursion: quick sort, merge sort and heap sort
Nanning water leakage detection: warmly congratulate Guangxi Zhongshui on winning the first famous brand in Guangxi
Basic operations of mongodb [add, delete, modify, query]
Introduction à mongodb
Separable bonds and convertible bonds
leetcode:动态规划模板
递归:快速排序,归并排序和堆排序
MongoDB簡介
node,npm以及yarn下载安装
没有sXid,suid&sgid将进入险境!-尚文网络xUP楠哥
2022 tea master (intermediate) examination questions and analysis and tea master (intermediate) practical examination video
pytorch项目怎么跑?
Wechat applet + Alibaba IOT platform + Hezhou air724ug build a serverless IOT system (III) -- wechat applet is directly connected to Alibaba IOT platform aliiot
Intercept string fixed length to array