与其爬行PubChem的网站,我更愿意友好地从PubChem ftp站点本地生成图像:
ftp://ftp.ncbi.nih.gov/pubchem/specifications/
唯一的问题是,我被限制在OSX和Linux上,我似乎找不到一种方法来以编程的方式生成他们网站上的2d图像。请参阅此示例:
https://pubchem.ncbi.nlm.nih.gov/compound/6#section=Top
在标题"2D Structure“下,我们有这个图像:
https://pubchem.ncbi.nlm.nih.gov/image/imgsrv.fcgi?cid=6&t=l
这就是我想要生成的。
发布于 2016-08-05 04:13:57
如果你想要一些开箱即用的东西,我建议使用ChemAxon的Marvin (https://www.chemaxon.com/products/marvin/)中的molconvert,它对学者是免费的。它可以很容易地从命令行使用,并支持大量的输入和输出格式。因此,对于您的示例,它将是:
molconvert "png" -s "C1=CC(=C(C=C1[N+](=O)[O-])[N+](=O)[O-])Cl" -o cdnb.png结果如下所示:

它还允许您设置参数,如宽度,高度,质量,背景颜色等。
但是,如果你是一个程序员,我绝对推荐你使用RDKit。遵循一个代码,该代码为一对以微笑形式给出的化合物生成图像。
from rdkit import Chem
from rdkit.Chem import Draw
ms_smis = [["C1=CC(=C(C=C1[N+](=O)[O-])[N+](=O)[O-])Cl", "cdnb"],
["C1=CC(=CC(=C1)N)C(=O)N", "3aminobenzamide"]]
ms = [[Chem.MolFromSmiles(x[0]), x[1]] for x in ms_smis]
for m in ms: Draw.MolToFile(m[0], m[1] + ".svg", size=(800, 800))这将为您提供以下图像:


发布于 2015-09-17 23:11:00
所以我也给PubChem的人发了邮件,他们很快就回复了我,回复如下:
我们对图片的唯一批量访问是通过下载服务:https://pubchem.ncbi.nlm.nih.gov/pc_fetch/pc_fetch.cgi
单次最多可请求50000张图片。
这比我预期的要好,但仍然不令人惊讶,因为它需要下载我理论上可以在本地生成的东西。所以我把这个问题放在一边,直到某个仁慈的人写了一个开源库来做同样的事情。
编辑:
我想,如果人们和我做同样的事情,我也可以帮他们节省一些时间。我在Mechanize上创建了一个Ruby Gem,用于自动下载图片。请善待他们的服务器,只下载你需要的内容。
https://github.com/zachaysan/pubchem
gem install pubchem
发布于 2020-05-03 10:05:43
我选择了1.4.0测试版。
我在将微笑转换为2D结构方面与您有类似的兴趣,并调整了我的Python以解决您的问题并捕获计时信息。它使用CID-SMILES.gz.的PubChem文件传输协议(复合/附加)下载。以下脚本是本地微笑到2D结构转换器的实现,该转换器从异构微笑(包含超过1.02亿条复合记录)的PNG SMILES文件中读取一系列行,并将微笑转换为2D结构的PubChem图像。在三个有1000个微笑到结构转换的测试中,在我的Windows 10笔记本电脑(英特尔i7-7500U CPU,2.70 CPU)上,在运行Python 3.7.4的固态驱动器上,在文件行偏移量为0,100,000和10,000,000的情况下,转换1000个微笑分别花费了35,50和60秒。这3000个文件的总大小为100MB。
from indigo import *
from indigo.renderer import *
import subprocess
import datetime
def timerstart():
# start timer and print time, return start time
start = datetime.datetime.now()
print("Start time =", start)
return start
def timerstop(start):
# end timer and print time and elapsed time, return elapsed time
endtime = datetime.datetime.now()
elapsed = endtime - start
print("End time =", endtime)
print("Elapsed time =", elapsed)
return elapsed
numrecs = 1000
recoffset = 0 # 10000000 # record offset
starttime = timerstart()
indigo = Indigo()
renderer = IndigoRenderer(indigo)
# set render options
indigo.setOption("render-atom-color-property", "color")
indigo.setOption("render-coloring", True)
indigo.setOption("render-comment-position", "bottom")
indigo.setOption("render-comment-offset", "20")
indigo.setOption("render-background-color", 1.0, 1.0, 1.0)
indigo.setOption("render-output-format", "png")
# set data path (including data file) and output file path
datapath = r'../Download/CID-SMILES'
pngpath = r'./2D/'
# read subset of rows from data file
mycmd = "head -" + str(recoffset+numrecs) + " " + datapath + " | tail -" + str(numrecs)
print(mycmd)
(out, err) = subprocess.Popen(mycmd, stdout=subprocess.PIPE, shell=True).communicate()
lines = str(out.decode("utf-8")).split("\n")
count = 0
for line in lines:
try:
cols = line.split("\t") # split on tab
key = cols[0] # cid in cols[0]
smiles = cols[1] # smiles in cols[1]
mol = indigo.loadMolecule(smiles)
s = "CID=" + key
indigo.setOption("render-comment", s)
#indigo.setOption("render-image-size", 200, 250)
#indigo.setOption("render-image-size", 400, 500)
renderer.renderToFile(mol, pngpath + key + ".png")
count += 1
except:
print("Error processing line after", str(count), ":", line)
pass
elapsedtime = timerstop(starttime)
print("Converted", str(count), "SMILES to PNG")https://stackoverflow.com/questions/32633286
复制相似问题