Open Babel的安装与使用
技术背景
Open Babel是化学领域常用的一个文件格式转换工具,它可以支持xyz的坐标格式、SMILES表达式、InChI表达式和mol以及mol2等格式之间的互相转化。比如说,你只有一个甲烷的SMILES表达式C,那么你就可以使用Open Babel将其转化成一个mol2文件,这样就可以用vmd等工具进行分子的可视化(参考这篇博客)。
OBABEL的安装
OBABEL的安装方式有两种,一种是从官方地址获取最新版本的源码进行手动编译安装,另一种是基于Conda的自动化安装,但是后者的版本会比手动编译安装的版本更低一些。因此,如果需要获取最新的版本,只能采取手动编译安装的方案。
手动编译安装
首先访问官方的源码下载地址去下载一个适合本地硬件设备和软件版本的源码压缩包,下载到本地后可以创建一个目录用于解压和编译,具体的操作流程如下代码所示:
dechin@ubuntu2004:~/projects/gitlab/dechin/src/vmd/openbabel/$ tar zxf openbabel-3.1.1.tar.bz2
dechin@ubuntu2004:~/projects/gitlab/dechin/src/vmd/openbabel/$ cd openbabel-3.1.1
dechin@ubuntu2004:~/projects/gitlab/dechin/src/vmd/openbabel/openbabel-3.1.1$ mkdir build
dechin@ubuntu2004:~/projects/gitlab/dechin/src/vmd/openbabel/openbabel-3.1.1$ cd build/
dechin@ubuntu2004:~/projects/gitlab/dechin/src/vmd/openbabel/openbabel-3.1.1/build$ cmake ..
dechin@ubuntu2004:~/projects/gitlab/dechin/src/vmd/openbabel/openbabel-3.1.1/build$ make
dechin@ubuntu2004:~/projects/gitlab/dechin/src/vmd/openbabel/openbabel-3.1.1/build$ sudo make install
其中注意的是在build目录下执行的是cmake ..,这一点跟官方所提供的指令安装方案略有区别,但是在Ubuntu 20.04系统中这个安装策略才是正确的。经过sudo make install之后我们就可以在全局使用obabel指令,比如可以用如下指令检验Open Babel是否安装成功:
dechin@ubuntu2004:~/projects/gitlab/dechin/src/vmd/openbabel/openbabel-3.1.1/build$ obabel --help
Open Babel converts chemical structures from one file format to another
Usage:
obabel[-i<input-type>] <infilename> [-o<output-type>] -O<outfilename> [Options]
The extension of a file decides the format, unless it is overridden
by -i or -o options, e.g. -icml, or -o smi
See below for available format-types, which are the same as the
file extensions and are case independent.
If no input or output file is given stdin or stdout are used instead.
More than one input file can be specified and their names can contain
wildcard chars (* and ?). The format of each file can be different unless
the -i option has been used, when they are all the same.
By default, the molecules are aggregated in the output file,
but see -m option, Splitting, below.
Options, other than -i -o -O -m, must come after the input files.
Conversion options
-f <#> Start import at molecule # specified
-l <#> End import at molecule # specified
-e Continue with next object after error, if possible
-k Attempt to translate keywords
-H Outputs this help text
-Hxxx (xxx is file format ID e.g. -Hcml) gives format info
-Hall Outputs details of all formats
-V Outputs version number
-L <category> Lists plugin classes of this category, e.g. <formats>
Use just -L for a list of plugin categories.
Use -L <ID> e.g. -L sdf for details of a format or other plugin.
-m Produces multiple output files, to allow:
Splitting: e.g. obabel infile.mol -O new.smi -m
puts each molecule into new1.smi new2.smi etc
Batch conversion: e.g. obabel *.mol -osmi -m
converts each input file to a .smi file
Interface to OBAPI internals
API options, e.g. ---errorlevel 2
errorlevel # min warning level displayed
To see a list of recognized file formats use
babel -L formats [read] [write]
To see details and specific options for a particular format, e.g CML, use
babel -L cml
如果显示结果如上,则表示安装成功。
非编译模式的安装
用conda来安装,conda会自动帮我们解决一些系统环境的依赖,比较人性化一些,具体的安装指令如下:
dechin@ubuntu2004:~/projects/gitlab/dechin/src/vmd/openbabel/openbabel-3.1.1/build$ conda install -c openbabel openbabel
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: \
Found conflicts! Looking for incompatible packages.
This can take several minutes. Press CTRL-C to abort.
failed
UnsatisfiableError: The following specifications were found
to be incompatible with the existing python installation in your environment:
Specifications:
- openbabel -> python[version='2.7.*|3.4.*|3.5.*|3.6.*|>=2.7,<2.8.0a0|>=3.5,<3.6.0a0|>=3.6,<3.7.0a0|>=3.7,<3.8.0a0|>=3.4,<3.5.0a0']
Your python: python=3.8
If python is on the left-most side of the chain, that's the version you've asked for.
When python appears to the right, that indicates that the thing on the left is somehow
not available for the python version you are constrained to. Note that conda will not
change your python version to a different minor version unless you explicitly specify
that.
这里第一次执行安装指令时遇到了一些问题,我们从这个错误日志中可以看到,是因为本地我们的python版本是3.8,而Open Babel依赖于更低一些级别的python环境。这时候我们可以用conda来统一的管理这些python环境,比如创建一个新的python3.7.5的虚拟环境:
dechin@ubuntu2004:~/projects/gitlab/dechin/src/vmd/openbabel/openbabel-3.1.1/build$ conda create -n py37 python=3.7.5
(base) dechin@ubuntu2004:~/projects/gitlab/dechin/src/vmd/openbabel/openbabel-3.1.1/build$ conda activate py37
(py37) dechin@ubuntu2004:~/projects/gitlab/dechin/src/vmd/openbabel/openbabel-3.1.1/build$ python3
Python 3.7.5 (default, Oct 25 2019, 15:51:11)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
创建成功后,我们在这个py37的虚拟环境下再尝试一下安装Open Babel:
(py37) dechin@ubuntu2004:~/projects/gitlab/dechin/src/vmd/openbabel/openbabel-3.1.1/build$ conda install -c openbabel openbabel
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: done
==> WARNING: A newer version of conda exists. <==
current version: 4.9.2
latest version: 4.10.1
Please update conda by running
$ conda update -n base -c defaults conda
## Package Plan ##
environment location: /home/dechin/anaconda3/envs/py37
added / updated specs:
- openbabel
The following packages will be downloaded:
package | build
---------------------------|-----------------
fontconfig-2.13.1 | h6c09931_0 250 KB
glib-2.63.1 | h5a9c865_0 2.9 MB
openbabel-2.4.1 | py37_6 5.1 MB openbabel
------------------------------------------------------------
Total: 8.2 MB
The following NEW packages will be INSTALLED:
bzip2 pkgs/main/linux-64::bzip2-1.0.8-h7b6447c_0
cairo pkgs/main/linux-64::cairo-1.14.12-h8948797_3
fontconfig pkgs/main/linux-64::fontconfig-2.13.1-h6c09931_0
freetype pkgs/main/linux-64::freetype-2.10.4-h5ab3b9f_0
glib pkgs/main/linux-64::glib-2.63.1-h5a9c865_0
icu pkgs/main/linux-64::icu-58.2-he6710b0_3
libpng pkgs/main/linux-64::libpng-1.6.37-hbc83047_0
libuuid pkgs/main/linux-64::libuuid-1.0.3-h1bed415_2
libxcb pkgs/main/linux-64::libxcb-1.14-h7b6447c_0
libxml2 pkgs/main/linux-64::libxml2-2.9.10-hb55368b_3
openbabel openbabel/linux-64::openbabel-2.4.1-py37_6
pcre pkgs/main/linux-64::pcre-8.44-he6710b0_0
pixman pkgs/main/linux-64::pixman-0.40.0-h7b6447c_0
Proceed ([y]/n)? y
Downloading and Extracting Packages
glib-2.63.1 | 2.9 MB | ################################################################################## | 100%
openbabel-2.4.1 | 5.1 MB | ################################################################################## | 100%
fontconfig-2.13.1 | 250 KB | ################################################################################## | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
(py37) dechin@ubuntu2004:~/projects/gitlab/dechin/src/vmd$ obabel -V
Open Babel 2.4.1 -- Sep 2 2019 -- 21:57:37
可以看到,我们成功的安装了Open Babel 2.4.1的版本,虽然比前面手动编译安装的3.1.1版本更低一些,但是也都具备基本的功能。这里补充一个conda的虚拟环境的使用方法,如果我们想要关闭一个虚拟环境,只需要执行deactivate env_name即可。如果是需要激活一个虚拟环境,则需要运行conda activate env_name的指令。
OBABEL的使用
不论是手动编译安装还是conda直接安装的方案,安装成功后都具备基本的功能,比如如下所展示的基本示例。首先我们创建一个名为file.xyz的文件,内容如下所示:
24
mol
C -1.615 -0.739 -3.043
C -0.076 -0.706 -3.045
H -1.963 -1.227 -3.929
H -1.959 -1.275 -2.183
C 0.469 -2.145 -3.087
H 0.268 -0.169 -3.905
H 0.272 -0.218 -2.159
H 1.539 -2.122 -3.089
H 0.126 -2.682 -2.227
H 0.122 -2.633 -3.974
C -2.160 0.701 -3.001
C -3.700 0.667 -2.999
H -1.817 1.237 -3.861
H -1.812 1.188 -2.114
C -4.245 2.107 -2.957
H -4.047 0.179 -3.885
H -4.043 0.131 -2.139
H -3.897 2.594 -2.070
H -3.901 2.643 -3.817
C -5.784 2.073 -2.955
O -6.394 1.131 -3.525
N -6.541 3.141 -2.286
H -7.407 2.773 -1.946
H -6.007 3.500 -1.521
这是一个拥有24个分子的体系,在前面这篇博客中用展示这个分子模型的3D图像。通过Open Babel,我们可以将这个坐标文件导出为一个smi文件,也就是SMILES表达式:
dechin@ubuntu2004:~/projects/gitlab/dechin/src/vmd$ obabel -ixyz file.xyz -osmi -O file.smi
1 molecule converted
(py37) dechin@ubuntu2004:~/projects/gitlab/dechin/src/vmd$ cat file.smi
C(CC)CCCC(=O)N mol
关于更多的使用方法和示例,这里不做过多的展开,参考链接1中的内容非常的全面,感兴趣的童鞋可以参考之。
总结概要
本文主要介绍了在化学领域中常用的文件格式转化工具Open Babel的两种安装方法,与基本的使用案例。其中如果选择手动编译安装可以使用最新的release版本,如果使用conda就只能使用老旧的稳定版本,但是可以很大程度上简化安装的步骤。在基本的案例中我们演示了使用obabel来将一个xyz坐标格式的文件转化成一个SMILES表达式。
版权声明
本文首发链接为:https://www.cnblogs.com/dechinphy/p/obabel.html
作者ID:DechinPhy
更多原著文章请参考:https://www.cnblogs.com/dechinphy/
参考链接
Open Babel的安装与使用的更多相关文章
- 让nodeJS支持ES6的词法----babel的安装和使用
要使用Babel, 我们需要nodeJS的环境和npm, 主要安装了nodeJS, npm就默认安装了 , 现在安装nodeJS很简单了, 直接下载安装就好了: 安装es-checker 在使用Bab ...
- 前端自动化之babel本地化安装
npm添加package.json cd到项目根目录直接调用npm init 会创建package.json文件 本地安装bebel(并非全局安装,这种情况下cmd命令中babel命令不识别): 步骤 ...
- npm+webpack+babel+react安装
npm+webpack+babel+react安装 1.首先要安装 Node.js, Node.js 自带了软件包管理器 npm 2.在项目文件目录下生成package.json # 进入项目目录$ ...
- babel的安装和使用方法
要使用Babel, 我们需要nodeJS的环境和npm, 主要安装了nodeJS, npm就默认安装了 , 现在安装nodeJS很简单了, 直接下载安装就好了: 安装es-checker 在使用Bab ...
- babel环境安装与编译
babel:将浏览器不支持的ES6语法转为javascript 查看node是否安装: npm -v node -v 实例演示:在桌面新建part5目录在cmd命令行中 cd desktop cd p ...
- Babel的安装和使用
安装Node.JS 和 npm,如未安装可参照其他文章 1.创建一个package.json npm init (回车, 一直下一步即可) 安装 Babel npm install --save-de ...
- webpack4.x下babel的安装、配置及使用
前言 目前,ES6(ES2015)这样的语法已经得到很大规模的应用,它具有更加简洁.功能更加强大的特点,实际项目中很可能会使用采用了ES6语法的模块,但浏览器对于ES6语法的支持并不完善.为了实现兼容 ...
- Babel 7 安装与配置
Babel:帮我们把高级的语法(ES6)转为低级的语法 /* Babel 7.x版本 安装如下 (cnpm i @babel/cli -D) //Bab ...
- es6安装babel包
1.前面下载node.js及安装淘宝镜像可以查看我写的vue.js环境搭建 2.安装完node后,安装babel npm install -g babel-cli 3.检验babel是否安装成功: b ...
随机推荐
- JavaBean基本概念
JavaBean 是特殊的 Java 类,使用 Java 语言书写,并且遵守 JavaBean API 规范. JavaBean 与其它 Java 类相比而言独一无二的特征: 提供一个默认的无参构造函 ...
- MySql索引分析及查询优化
B-Tree 核心特点: 多路,非二叉树 每个节点既保存索引,又保存数据 搜索时相当于二分查找 B+Tree 核心特点 多路非二叉 只有叶子节点保存数据 搜索时相当于二分查找 增加了相邻接点的指向指针 ...
- 解决OpenOCD烧录STM32失败, 无法通过SWD连接的问题
OpenOCD烧录STM32失败的问题 Linux下使用 OpenOCD 烧录 STM32, 出现了 Error: init mode failed (unable to connect to the ...
- 帆软报表(finereport)禁用右键
点击模板>模板web属性>(填报,数据分析,分页预览设置),选择为该模板单独设置,在下面的事件设置里面添加一个加载结束事件,完整js代码如下: 这段代码的基本原理是让用户的页面右键点击事件 ...
- 2018 PHP面试题
2018 PHP面试题 题目来自<PHP程序员面试笔试宝典>,里面涵盖了近三年了各大型企业常考的PHP面试题,针对面试题提取出来各种面试知识也涵盖在了本书. 1.PHP常考基础 1.PHP ...
- Solution -「洛谷 P4198」楼房重建
\(\mathcal{Description}\) Link. 给定点集 \(\{P_n\}\),\(P_i=(i,h_i)\),\(m\) 次修改,每次修改某个 \(h_i\),在每次修改后 ...
- Involuting Bunny! (2021.8)
CF1555F & Submission. Tags:「A.生成树」「B.Tricks」 分类处理询问的 trick:连接两个连通块的边显然合法,先用这些边构建生成森林.发现每条边 ...
- scrapy爬取《坏蛋是怎样练成的4》
scrapy具体介绍就不用说了,自己百度一下.或者参考以下文档 https://blog.csdn.net/u011054333/article/details/70165401 直接在cmd里运行 ...
- pytest(5)-断言
前言 断言是完整的测试用例中不可或缺的因素,用例只有加入断言,将实际结果与预期结果进行比对,才能判断它的通过与否. unittest 框架提供了其特有的断言方式,如:assertEqual.asser ...
- OLAP阵营又增一猛将,比肩Power BI不是说说而已!
说到大数据应用最多的技术,不得不提OLAP技术,在国内外,不论传统公司还是互联网公司,都开始利用OLAP技术分析挖掘大数据的价值.也许很多人对OLAP的概念还不是很清楚,简单来说,就把数据处理成数据立 ...