存档

文章标签 ‘Chemistry’

Archlinux 下 ICC+MKL 方案编译 GAMESS

2010年1月16日
Comments Off

点此下载效果更好的 pdf 版本

                    Archlinux 下 ICC+MKL 方案编译安装 GAMESS
                                作者: xiooli
                                邮箱: <xioooli[at]yahoo.com.cn>
                                网站: http://joolix.com

    此文系根据自己实际操作写就,其中查考了 Sobereva 和王涛的文章 (见参考文献)
    在此表示感谢。
    本文依据 CC 协议发布,在保留原作品的署名的情况下你可以自由转载或修改再发布
    (仅限非商业用途)

—————————————正文—————————————
一,机器配置
    型号: lenove ThinkCenter M8000t
    主板: Intel Q45
    CPU:    Intel(R) Core(TM)2 Quad CPU Q9550 @ 2.83GHz (四核)
    内存: DDR3 1066MHz 2G X 2
    硬盘:   SATA 500G 7200RPM

二,系统及编译环境
    系统: Archlinux x86_64
    内核: 2.6.32-ARCH
    SHELL:
        bash:   version 4.0.35(2)-release
            这是用户的默认登录 shell,编译操作基本上都是在 bash 里面完成的
        csh:    tcsh 6.17.00 (Astron) 2009-07-10
            因 gamess 的很多脚本是用 csh 写成,故而需要安装 csh (包名是 tcsh)
    C 编译器:
        GCC:    4.4.2 20091208 (prerelease)
            GCC 是默认的编译器,可以从你发行版的软件源里面安装
        ICC:    Version 11.1
            intel 的 CPU 用 ICC 可以优化执行性能,其他 CPU 的同学可以不必使用 ICC
            需要去 intel 的官网下载安装,个人和非商业使用只需注册一下,免费使用
            ——————————-设置开始——————————–

            ICC 一般是安装到 /opt 里面去的,系统并不能直接找到其可执行文件
            所以需要将其 bin 目录加到 PATH 环境变量里面去
            以我为例:
            在 /opt/intel/Compiler/11.1/056/bin/ 下面有两个文件一个目录(依系统位数
            的不同,目录的名字可能不一样): intel64/, iccvars.csh 和 iccvars.sh,你
            需要在 /etc/profile.d/ 下面建立一个脚本,比如 iccvars.sh 其内容如下:

            ——————————-不含此线——————————–
            #!/bin/bash
            source /opt/intel/Compiler/11.1/056/bin/iccvars.sh intel64
            ——————————-不含此线——————————–

            最后的那个参数 intel64 依你的系统不同而不同,应该和你在
            /opt/intel/Compiler/11.1/056/bin/ 中看的的目录名字相同,然后赋可执行权限:

            sudo chmod a+x /etc/profile.d/iccvars.sh

            注意,这样只会在重启后生效,若要当时生效,须执行一下:

          . /etc/profile.d/iccvars.sh 或 source /etc/profile.d/iccvars.sh

            此外,为了让程序(这里是 icc 等)找到它们所依赖的库,须得将 icc 的 lib
            路径加入到 /etc/ld.so.conf 里面
            以我为例:
            在 /etc/ld.so.conf 里面加上一行:

            ——————————-不含此线——————————–
            /opt/intel/Compiler/11.1/056/lib/
            ——————————-不含此线——————————–

            然后以 root 权限运行 ldconfig
            ICC 的设置到此结束
            ——————————-设置结束——————————–
    FORTRAN 编译器:
        IFORT:  Version 11.0
            这个也是 intel 的编译器,同样需要去其官方注册下载,个人版也是免费的
            当然你也可以使用 g95 等开源的 FORTRAN 编译器
            ——————————-设置开始——————————–

            IFORT 同样也是安装到 /opt 里面去的,所以也需要将其 bin 目录加到 PATH
            环境变量里面去
            以我为例:
            在 /opt/intel/Compiler/11.0/074/bin/ 下面有两个文件一个目录(依系统位数
            的不同,目录的名字可能不一样): intel64/, ifortvars.csh 和 ifortvars.sh
            你亦需要在 /etc/profile.d/ 下面建立一个脚本,比如 ifortvars.sh 其内容如下:

            ——————————-不含此线——————————–
            #!/bin/bash
            source /opt/intel/Compiler/11.0/074/bin/ifortvars.sh intel64
            ——————————-不含此线——————————–

            最后的那个参数 intel64 依你的系统不同而不同,应该和你在
            /opt/intel/Compiler/11.0/074/bin/ 中看的的目录名字相同,然后赋可执行权限:

            sudo chmod a+x /etc/profile.d/ifortvars.sh

            注意,这样只会在重启后生效,若要当时生效,须执行一下:

          . /etc/profile.d/ifortvars.sh 或 source /etc/profile.d/ifortvars.sh

            此外,为了让程序(这里是 icc 等)找到它们所依赖的库,须得将 ifort 的 lib
            路径加入到 /etc/ld.so.conf 里面
            以我为例:
            在 /etc/ld.so.conf 里面加上一行:

            ——————————-不含此线——————————–
            /opt/intel/Compiler/11.0/074/lib/
            ——————————-不含此线——————————–

            然后以 root 权限运行 ldconfig
            IFORT 的设置到此结束
            ——————————-设置结束——————————–
    数学库:
        MKL: Version 10.2.3.029
            这个是 intel 的数学核心函数库,据说使用ifort编译器结合MKL数学库可以使
            代码执行速度大大提升。当然你如果不使用 MKL 的话会默认使用 BLAS 这个库
            AMD CPU 的同学可以考虑使用 ACML 这个数学库。同样,MKL 也可以到 intel 的
            官网上面申请免费版本
            ——————————-设置开始——————————–

            MKL 的设置相对简单,因为其只是一些库,没有可执行文件,所以只需要将 MKL
            库的位置加到 ld.so.conf 里面即可
            在 /etc/ld.so.conf 里面加上一行:

            ——————————-不含此线——————————–
            /opt/intel/mkl/10.2.3.029/lib/em64t/
            ——————————-不含此线——————————–

            然后以 root 权限运行 ldconfig
            IFORT 的设置到此结束
            ——————————-设置结束——————————–

三,具体操作过程
    在配置好了上面的编译环境以后便可以进行后续的编译过程了。
    首先,当然是准备 gamess 的源码咯,去 gamess 的网站上面填写申请,一般一到两天后会
    批下来,然后会邮件通知你下载地址,用户名和密码,然后就去拖下来咯,压缩包的大小约
    10M 左右,我下载的版本是: GAMESS version January 12, 2009 R3 for 64 bit
    (x86_64 compatible) under Linux with gnu compilers
    然后准备一个安装目录(我将其安放在 /home/gamess 里面),将压缩包解压到安装目录下面
    好了,可以看到几个可执行文件:
    compall, comp, lked, runall 和 rungms

    ———————————–修改脚本—————————————–
    我们接下来将编辑这几个文件以使其符合我们自己的实际情况
    以我为例:
    compall:
        line 16:  set TARGET=linux-ia64
        line 17:  set /home/gamess
        line 70:  if  ($TARGET == linux-ia64) set CCOMP=‘icc’ # 没有 icc 的可以继续 gcc
    comp:
        line 15:  set TARGET=linux-ia64
        line 16:  set /home/gamess
        line 109: if  ($TARGET == linux-ia64)   set BLAS3=/opt/intel/mkl/10.2.3.029/lib/em64t/
        # 如果你没有安装 MKL 的话就不要动上面这行
        # 由于我选择的 TARGET=linux-ia64,在 line 1507 可以看到已经是默认用了 ifort 作为 FORTRAN
        # 的编译器,如果你的 TARGET 是其他的而又想用 ifort 的话,可以去对应的地方 (即
        # if ($TARGET == xxx) then 下面将 FORTRAN 编译器改成 ifort)
    lked:
        line 18:  set TARGET=linux-ia64
        line 19: chdir /home/gamess
        line 498: if ($TARGET == linux-ia64) then # 若使用 MKL 则在下面添加一行
        line 499:     setenv MKLPATH /opt/intel/mkl/10.2.3.029/lib/em64t
        # 看它的脚本理论上来说不添加这行也是可以找到 MKL 的,不过在我这里报错说
        # 找不到 MKL 里面的某个 so,所以还是加上比较保险
    rungms:
        line 60:  set SCR=/home/gamess/scr/$USER
        # 存放运算临时文件的地方,自己喜欢放哪里放哪里,如果你内存够大的话也可以放在
        # /dev/shm (实际是个在内存里面的目录)
        将所有的 ~mike/gamess 换成你的 gamess 安装目录(我的是 /home/gamess)
        $USER/scr 替换成 $SCR
        你可以通过运行下面命令来一次性完成此工作:

        sed -i s|~mike/gamess|/home/gamess|g;s|~$USER/scr|$SCR|g ./rungms

        如果你想使用 SMP 方式并行多核运算的话如果是双核机器则修改这里:

        line 497: case br.msg.chem.iastate.edu: # 下面添加一行
        line 498: case YOUR-SERVER-NAME: # YOUR-SERVER-NAME 是运行 hostname 出来的结果
        line 499:   if ($NCPUS > 2) set NCPUS=2

        如果是四核机器则修改这里:

        line 490: case sc.msg.chem.iastate.edu: # 下面添加一行
        line 491:   case YOUR-SERVER-NAME: # YOUR-SERVER-NAME 是运行 hostname 出来的结果
        line 492:       if ($NCPUS > 4) set NCPUS=4
    runall:
        line 13:  chdir /home/gamess

    ———————————–编译 actvte—————————————
    下面我们要编译链接激活 gamess 代码的程序 actvte (下面命令均在终端下输入):

    cd /home/gamess/tools/
    # 视你 gamess 源文件存放地点的不同而 cd 到不同的目录
    cp actvte.code actvte.f
    sed -i s|^\*UNX|    |g actvte.f
    # 把以 *UNX 的开头用四个空格替换掉,即取消注释,亮出 UNIX-LIKE 系统的激活代码
    ifort -o actvte.x -Vaxlib actvte.f
    # 或 g95 -o actvte.x actvte.f 如果你没有 ifort 的话
    # 成功生成了 actvte.x 以后可以将 actvte.f 删除

    ———————————–开始编译—————————————–
    然后便可以开始编译了,在终端运行:

    cd /home/gamess
    ./compall
    # 如果你想看着它编译的话,或者让其在后台运行
    ./compall &> compall.log &
    # 上面两条命令选一即可,无须都执行
    # 经过一段取决于你机器性能的时间后(我这里大约用了 20 分钟)主要编译便完成了

    其后编译 gamess 的分布式数据接口 (DDI) 消息传递库,无论是否打算并行计算都必须
    编译,否则下面 lked 步骤通不过。假设现在主机名是 YOUR-SERVER-NAME(用 hostname
    命令可以看到当前主机名),就在 /etc/hosts 里面填上一行当前主机的IP地址和主机名
    例如: 192.168.153.3 YOUR-SERVER-NAME # [参考文献 1]
    命令:

    sudo su
    echo "192.168.153.3 YOUR-SERVER-NAME" >> /etc/hosts

    进入 /home/gamess/ddi 目录,修改 compddi
    
    compddi:
        line 18:  set TARGET = linux-ia64
        line 62:  set MAXCPUS  = 4
        line 63:  set MAXNODES = 2
        # set MAXCPUS 和 set MAXNODES 后面设成你的实际情况,前者代表每个节点中最多
        # 包含几个核心(每个节点内可以以SMP方式并行的核心数目),后者代表最多有几个
        # 节点,它们设的都可以比实际情况多 [参考文献 1]

    修改 /home/gamess/ddi/src/std_system.c

    std_system.c
        line 26:      struct hostent *hp; # 在其后插入一行
        line 27:      name = "YOUR-SERVER-NAME";
        # 之所以要加入这么一行是因为GAMESS的bug,会将主机名强行认作为localhost而不是
        # 实际主机名,导致运行时提示TCP error之类错误 [参考文献 1]

    最后运行命令:

    ./compddi
    mv ddikick.x ..

    最后编译图形应用程序

    cd /home/gamess/graphics
    编辑 complink 文件
    complink:
        line 15:  chdir /home/gamess/graphics
        line 18:  set TARGET=linux-pc
        line 31:  if ($TARGET == linux-pc)   set FORT=‘ifort -O2′

    之后运行./complink来编译

    ———————————–链接程序—————————————–
    链接可执行文件
    命令:

    cd /home/gamess
    ./lked gamess &> lked.log

    如果不出问题的话最终会在当前目录下生成一个 gamess.00.x 这样的可执行文件,至此我们的
    编辑工作就全部完成了,下面就是测试环节,在 /home/gamess 目录下运行 ./runall 将会对
    编译好的GAMESS程序进行测试,自动运行44个测试文件,将在当前目录下得到一批 exam??.log
    文件。修改 /home/gamess/tools/checktst 目录下的 checktst 文件:

    checktst:
        line 9:       set GMSPATH=/home/gamess
    
    然后运行此文件,出现提示时输入 /home/gamess,会将所得log文件的结果与标准结果相对比
    检查任务是否已正常结束,以及计算误差是否超过阈值。对于failed的任务,检查相应的log文件
    除掉毛病后,把 scr 目录下对应文件删掉,若要单独运行一个测试比如 exam42 可以使用命令:

    cd /home/gamess
    ./rungms exam42 00 4 &>exam42.log
    # rungms 的参数意义为: JOB=$1 (输入文件 xxx.inp,可以不输入扩展名); VERNO=$2 (lked
    # 一步的 revision 数字,默认 00); NCPUS=$3 (运行时调用的 CPU 核心数)

    待完成后再 checktst 看是否都已通过。

    一般情况下 exam42 和 exam43 会由于 linux 默认的单个共享内存段的最大值太小而不能通过
    使用 /sbin/sysctl -a | grep shmmax 命令察看默认值,这两个任务需要约 48MB,修改
    /etc/sysctl.conf,在里面加入一行 kernel.shmmax = 5000000000 将其增加到约 500MB
    可以使用命令 /sbin/sysctl -w kernel.shmmax=5000000000 来使其立即生效

参考文献:
    参考文献 1: http://hi.baidu.com/sobereva/blog/item/fff7b5fd1e8dd04fd6887db6.html
    参考文献 2: 王涛, 量子化学计算程序包GAMESS, 科学计算应用软件系列介绍

Chemistry ,

获取所有符合条件分子式的脚本

2009年12月24日
Comments Off

在某些时候我们只知道某一个分子的分子量和大概的碳氢氧的个数范围,在这种情况下要算出符合这些条件的分子式,用手工的方法算是很麻烦的,于是就有了下面的这个脚本,其特点是:
1) 全面,无漏网之鱼
2) 用了不饱和度检测,不饱和度不正常的(如为小数)分子式均被排除
3) python 写的,可跨平台使用。

例子:

xiooli@XIOOLI> python  .bin/fmcom.py
Please input: 173 c,8,18 h,0,20 o,0,10 n,0,6
The results are as follows:
MF: C8H3O2N3   Ω: 9
MF: C8H7N5     Ω: 8
MF: C8H15O3N   Ω: 2
MF: C8H19ON3   Ω: 1
MF: C9H3O3N    Ω: 9
MF: C9H7ON3    Ω: 8
MF: C9H19O2N   Ω: 1
MF: C10H7O2N   Ω: 8
MF: C10H11N3   Ω: 7
MF: C11H11ON   Ω: 7
MF: C12H15N    Ω: 6
MF: C13H3N     Ω: 13

说明一下: 173 c,8,18 h,0,20 o,0,10
这里 173 是分子量, 后边的表达式都是一样的如:c,8,18 表示 碳原子 个数范围为 8 到 18。
注意分隔符是英文逗号。

源码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Name:     fmcom.py
# Author:   xiooli <xioooli[at]yahoo.com.cn>
# Site:     http://joolix.com
# Licence:  GPLv3
# Version:  091224
 
'''compute out the formula of a given molecular weight'''
 
import sys
 
# dictionary for the elements: { 'element': (atomic weight, omiga factor)
edic = { 'C': (12, 1),
        'H': (1, -0.5),
        'O': (16, 0),
        'N': (14, 0.5)
        }
 
args = sys.argv
 
def gen_formula(args):
    '''Main function for generating the formula'''
 
    mw = args[0]
    e_info = []
    formula = ''
    omiga = ''
    fors = ''
    ifs =''
 
    E = lambda x, y: (y==0 and ' ') or (y==1 and x.upper()) or x.upper() + str(y)
    L = lambda x, y: (x, len(x), y)
 
    for tmp in args[1:]:
        e_info.append(tmp.split(','))
        element, num1, num2 = tmp.split(',')
        element = element.upper()
        formula += 'E("' + str(element) + '",' + element + ') + '
        fors += ' for ' + element + ' in range(' + num1 + ',' + num2 + ') '
        ifs += str(edic[element][0]) + '*' + element + ' + '
        omiga += str(edic[element][1]) + '*' + element + ' + '
 
    formula = formula.strip('+ ')
    omiga += '1'
    ifs = ifs.strip('+ ')
 
    cmd = '[ L((' + formula + ').replace(\' \',\'\'), ' + omiga + ')' + fors + \
            'if ' + ifs + ' == ' + mw + ' and int(' + omiga + ') == ' + omiga + ']'
    l = eval(cmd)
 
    if l:
        print 'The results are as follows:'
        for f in l:
            str_omiga = str(int(f[2]))
            print 'MF: ' + f[0] + ('Ω: ' + str_omiga).rjust(15 - f[1] + len(str_omiga))
    else:
        print 'No suitable molecular formula found.'
 
if __name__ == '__main__':
    if len(args) <= 1:
        input = raw_input('Please input: ')
        args = input.split(' ')
        gen_formula(args)
    elif args[1] == '-h' or args[1] == '--help':
        print args[0] + ' [molecular weight] [element1, least, most] [element2, least, most] ...'
    else:
        gen_formula(args[1:])

Chemistry, Script , ,

snail 溶剂比例计算器升级版

2009年12月12日
Comments Off

添加了利用现有两种溶液来计算欲配溶液的功能
修复了一些易引发错误的代码。
片片:
snail2 抓图

代码:
snail.py :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/python
# -*- coding: utf-8 -*-
 
# Author:   xiooli <xioooli[at]yahoo.com.cn>
# Site:     http://joolix.com
# Licence:  GPLv3
 
import sys, os
from PyQt4 import QtCore, QtGui
from ui_zh import Ui_mainWindow
from PyQt4.QtGui import QMainWindow
from PyQt4.QtCore import pyqtSignature
 
 
class Win(QMainWindow, Ui_mainWindow):
    def __init__(self, parent = None):
        QMainWindow.__init__(self, parent)
        self.setupUi(self)
    @pyqtSignature("")
    def on_pushButton_clicked(self):
        self.label_6_txt = ""
        now_B_A = now_B_B = ""
        continue_com = ""
        vol = ""
        rst = ""
 
        try:
            now_B_A = float(self.lineEdit_4.text())
            now_B_B = float(self.lineEdit_5.text())
        except:
            pass
        try:
            now_A_A = float(self.lineEdit_1.text())
            now_A_B = float(self.lineEdit_2.text())
            now_vol = float(self.lineEdit_3.text())
            want_A = float(self.lineEdit_6.text())
            want_B = float(self.lineEdit_7.text())
        except ValueError:
           self.label_6_txt = "错误:有输入框未输入数字,或输入了非数字字符!"
 
        if ( not self.label_6_txt ) and ( now_B_A and now_B_B ):
            try:
                vol,rst = self.lineEdit_3.text(),\
                        round(now_vol*( now_A_A/(now_A_A+now_A_B)-want_A/(want_A+want_B) ) / \
                        ( want_A/(want_A+want_B)-now_B_A/(now_B_A+now_B_B) ), 4)
            except ZeroDivisionError:
                self.label_6_txt = "错误:试图除零!"
            if rst != "" and rst > 0:
                rst = str(rst)
                self.label_6_txt = "须向 " + vol + " ML 现有溶液 A 中加入现有溶液 B " + rst + " ML"
            else:
                self.label_6_txt = "注意:现有溶液 A 和 B 不能配制出欲配溶液<p>"
                continue_com = 1
 
        if ( not self.label_6_txt ) or continue_com:
            if want_A*(now_A_A+now_A_B) == 0:
                self.label_6_txt = "错误:试图除零!"
            elif want_B != 0 and (now_A_B == 0 or now_A_A / now_A_B > want_A / want_B):
                vol,rst = self.lineEdit_3.text(),\
                        str(round(now_vol*now_A_A*(want_A+want_B)/(want_A*(now_A_A+now_A_B))-now_vol,4))
                self.label_6_txt += "须向 " + vol + " ML 现有溶液 A 中加入溶剂 B " + rst + " ML"
            elif want_B != 0 and now_A_B != 0 and now_A_A / now_A_B == want_A / want_B:
                self.label_6_txt = "现有溶液 A 和欲配溶液是同一种溶液,无须额外动作。"
            else:
                try:
                    vol,rst=self.lineEdit_3.text(),\
                            str(round(now_vol*now_A_B*(want_A+want_B)/(want_B*(now_A_A+now_A_B))-now_vol,4))
                    self.label_6_txt += "须向 " + vol + " ML 现有溶液 A 中加入溶剂 A " + rst + " ML"
                except ZeroDivisionError:
                    self.label_6_txt = "错误:试图除零!"
 
        self.label_6.setText(QtGui.QApplication.translate("mainWindow", self.label_6_txt, None, QtGui.QApplication.UnicodeUTF8))
 
 
if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    win=Win()
    win.show()
    sys.exit(app.exec_())

ui_zh.py :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# -*- coding: utf-8 -*-
 
# Form implementation generated from reading ui file 'snail.ui'
#
# Created: Wed Nov 11 21:15:36 2009
#      by: PyQt4 UI code generator 4.6.1
#
# WARNING! All changes made in this file will be lost!
 
from PyQt4 import QtCore, QtGui
 
class Ui_mainWindow(object):
    def setupUi(self, mainWindow):
        mainWindow.setObjectName("mainWindow")
        mainWindow.resize(872, 452)
        self.centralwidget = QtGui.QWidget(mainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.lineEdit_1 = QtGui.QLineEdit(self.centralwidget)
        self.lineEdit_1.setGeometry(QtCore.QRect(250, 90, 171, 51))
        self.lineEdit_1.setStyleSheet("font: 22pt \"Bitstream Vera Sans Mono\";")
        self.lineEdit_1.setObjectName("lineEdit_1")
        self.lineEdit_2 = QtGui.QLineEdit(self.centralwidget)
        self.lineEdit_2.setGeometry(QtCore.QRect(460, 90, 171, 51))
        self.lineEdit_2.setStyleSheet("font: 22pt \"Bitstream Vera Sans Mono\";")
        self.lineEdit_2.setObjectName("lineEdit_2")
        self.lineEdit_3 = QtGui.QLineEdit(self.centralwidget)
        self.lineEdit_3.setGeometry(QtCore.QRect(670, 90, 161, 51))
        self.lineEdit_3.setStyleSheet("font: 22pt \"Bitstream Vera Sans Mono\";")
        self.lineEdit_3.setObjectName("lineEdit_3")
        self.lineEdit_4 = QtGui.QLineEdit(self.centralwidget)
        self.lineEdit_4.setGeometry(QtCore.QRect(250, 170, 171, 51))
        self.lineEdit_4.setStyleSheet("font: 22pt \"Bitstream Vera Sans Mono\";")
        self.lineEdit_4.setObjectName("lineEdit_4")
        self.lineEdit_5 = QtGui.QLineEdit(self.centralwidget)
        self.lineEdit_5.setGeometry(QtCore.QRect(460, 170, 171, 51))
        self.lineEdit_5.setStyleSheet("font: 22pt \"Bitstream Vera Sans Mono\";")
        self.lineEdit_5.setObjectName("lineEdit_5")
        self.label = QtGui.QLabel(self.centralwidget)
        self.label.setGeometry(QtCore.QRect(280, 20, 131, 41))
        self.label.setStyleSheet("font: 22pt \"Bitstream Vera Sans Mono\"; A")
        self.label.setObjectName("label")
        self.label_2 = QtGui.QLabel(self.centralwidget)
        self.label_2.setGeometry(QtCore.QRect(490, 20, 131, 41))
        self.label_2.setStyleSheet("font: 22pt \"Bitstream Vera Sans Mono\"; A")
        self.label_2.setObjectName("label_2")
        self.label_3 = QtGui.QLabel(self.centralwidget)
        self.label_3.setGeometry(QtCore.QRect(710, 20, 131, 41))
        self.label_3.setStyleSheet("font: 22pt \"Bitstream Vera Sans Mono\"; A")
        self.label_3.setObjectName("label_3")
        self.label_4 = QtGui.QLabel(self.centralwidget)
        self.label_4.setGeometry(QtCore.QRect(40, 100, 171, 41))
        self.label_4.setStyleSheet("font: 22pt \"Bitstream Vera Sans Mono\"; A")
        self.label_4.setObjectName("label_4")
        self.label_5 = QtGui.QLabel(self.centralwidget)
        self.label_5.setGeometry(QtCore.QRect(40, 250, 171, 41))
        self.label_5.setStyleSheet("font: 22pt \"Bitstream Vera Sans Mono\"; A")
        self.label_5.setObjectName("label_5")
        self.pushButton = QtGui.QPushButton(self.centralwidget)
        self.pushButton.setGeometry(QtCore.QRect(670, 170, 161, 51))
        self.pushButton.setStyleSheet("font: 22pt \"Bitstream Vera Sans Mono\";")
        self.pushButton.setObjectName("pushButton")
        self.frame = QtGui.QFrame(self.centralwidget)
        self.frame.setEnabled(True)
        self.frame.setGeometry(QtCore.QRect(40, 330, 791, 91))
        self.frame.setMouseTracking(False)
        self.frame.setAutoFillBackground(False)
        self.frame.setFrameShape(QtGui.QFrame.StyledPanel)
        self.frame.setFrameShadow(QtGui.QFrame.Raised)
        self.frame.setObjectName("frame")
        self.label_6 = QtGui.QLabel(self.frame)
        self.label_6.setGeometry(QtCore.QRect(10, 10, 781, 71))
        self.label_6.setStyleSheet("""font: 22pt \"Bitstream Vera Sans Mono\"; color: rgb(0, 0, 255);""")
        self.label_6.setObjectName("label_6")
        self.label_7 = QtGui.QLabel(self.centralwidget)
        self.label_7.setGeometry(QtCore.QRect(40, 180, 171, 41))
        self.label_7.setStyleSheet("font: 22pt \"Bitstream Vera Sans Mono\"; A")
        self.label_7.setObjectName("label_7")
        self.lineEdit_6 = QtGui.QLineEdit(self.centralwidget)
        self.lineEdit_6.setGeometry(QtCore.QRect(250, 250, 171, 51))
        self.lineEdit_6.setStyleSheet("font: 22pt \"Bitstream Vera Sans Mono\";")
        self.lineEdit_6.setObjectName("lineEdit_6")
        self.lineEdit_7 = QtGui.QLineEdit(self.centralwidget)
        self.lineEdit_7.setGeometry(QtCore.QRect(460, 250, 171, 51))
        self.lineEdit_7.setStyleSheet("font: 22pt \"Bitstream Vera Sans Mono\";")
        self.lineEdit_7.setObjectName("lineEdit_7")
        self.pushButton_2 = QtGui.QPushButton(self.centralwidget)
        self.pushButton_2.setGeometry(QtCore.QRect(670, 250, 161, 51))
        self.pushButton_2.setStyleSheet("font: 22pt \"Bitstream Vera Sans Mono\";")
        self.pushButton_2.setObjectName("pushButton_2")
        mainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtGui.QMenuBar(mainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 872, 25))
        self.menubar.setObjectName("menubar")
        mainWindow.setMenuBar(self.menubar)
        self.statusbar = QtGui.QStatusBar(mainWindow)
        self.statusbar.setObjectName("statusbar")
        mainWindow.setStatusBar(self.statusbar)
 
        self.retranslateUi(mainWindow)
        QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL("clicked()"), self.label_6.clear)
        QtCore.QObject.connect(self.pushButton_2, QtCore.SIGNAL("clicked()"), mainWindow.close)
        QtCore.QMetaObject.connectSlotsByName(mainWindow)
 
    def retranslateUi(self, mainWindow):
        mainWindow.setWindowTitle(QtGui.QApplication.translate("mainWindow", " 溶剂比例计算器 - Snail", None, QtGui.QApplication.UnicodeUTF8))
        self.lineEdit_3.setText(QtGui.QApplication.translate("mainWindow", "1000", None, QtGui.QApplication.UnicodeUTF8))
        self.label.setText(QtGui.QApplication.translate("mainWindow", " 溶剂 A", None, QtGui.QApplication.UnicodeUTF8))
        self.label_2.setText(QtGui.QApplication.translate("mainWindow", " 溶剂 B", None, QtGui.QApplication.UnicodeUTF8))
        self.label_3.setText(QtGui.QApplication.translate("mainWindow", "体积", None, QtGui.QApplication.UnicodeUTF8))
        self.label_4.setText(QtGui.QApplication.translate("mainWindow", "现有溶液 A", None, QtGui.QApplication.UnicodeUTF8))
        self.label_5.setText(QtGui.QApplication.translate("mainWindow", "欲配溶液", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton.setText(QtGui.QApplication.translate("mainWindow", "计算", None, QtGui.QApplication.UnicodeUTF8))
        self.label_6.setText(QtGui.QApplication.translate("mainWindow", "欢迎使用溶剂比例计算器 Snail\nxiooli <xioooli@yahoo.com.cn>", None, QtGui.QApplication.UnicodeUTF8))
        self.label_7.setText(QtGui.QApplication.translate("mainWindow", "现有溶液 B", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton_2.setText(QtGui.QApplication.translate("mainWindow", "关闭", None, QtGui.QApplication.UnicodeUTF8))

Chemistry, Script , ,

化学信息学及相关文章和资源收藏

2009年12月12日
Comments Off

如下:


1: Chemene Cheminformatics Technologies – Blog
2: Chemene JSDraw – A Javascript Chemical Structure Editor/Viewer
3: Creating a web-based, searchable molecular structure database using free software
4: eMolecules.com | Chemical Structure Drawing Search
5: Index of /pch/download/chemistry
6: JME Usage
7: mol2ps Homepage
8: MolDB5 documentation
9: NMRShiftDB – open nmr database on the web
10: Online SMILES Translator
11: Thirty-Two Free Chemistry Databases
12: 化学中的常用计算机软件与资源 化学化工 博研联盟 – Powered by VeryCMS
13: ChemAxon chemistry software toolkit free academic java .net Marvin JChem
14: http://www.cbs.cnrs.fr/GIFA/
15: Mestrelab Research S.L. – Home
16: Base Peak – Mass Spectrometry Software
17: 量子化学网
18: OpenMS / TOPP website
19: LC-MSsim : a simulator for Liquid Chromatography – Mass Spectrometry data
20: 中药化合物数据库
21: Spectral Database for Organic Compounds,SDBS
22: ScreeningAssistant : select compounds for screening tests
23: Journal of Natural Products (ACS Publications and Am. Soc. of Pharmacognosy)
24: The Dundee PRODRG Server
25: Chemoinformatics and Metabolism Team | Publications | EBI
26: NMRShiftDB – open nmr database on the web
27: Bioclipse Documentation
28: DTP / 2D and 3D Structural Information
29: services:dbfetch | EBI Web Services | EBI
30: Hacking NMRShiftDB
31: The PubChem Project
32: scripps.edu
33: eMolecules.com | Chemical Structure Drawing Search
34: Molecular Information Theory and the Theory of Molecular Machines
35: SMILES – 维基百科,自由的百科全书
36: Open Babel
37: Jmol.js JavaScript Library
38: Writings by Andrew Dalke
39: GIF/PNG-Creator for 2D Plots of Chemical Structures
40: CORINA – Generation of 3D coordinates | Inspiring Chemical Discovery
41: NSC: Chemistry: Dalton
42: ZINC – A free database for virtual screening – version 8
43: Daylight Theory: SMILES
44: TORVS Research Team >> Services
45: ChIN目录页:化学软件
46: RasMol and OpenRasMol
47: FIZ Karlsruhe: Home
48: SENECA | Get SENECA at SourceForge.net
49: SourceForge.net Repository – [seneca] Index of /
50: Noel O'Blog: Cheminformatics toolkit face-off: Speed (Python vs Java vs C++)
51: cinfony – Project Hosting on Google Code
52: Using OpenBabel from Python – Open Babel
53: SteinBlog — A molecular informatics weblog
54: InstallationOnLinux – cinfony – This page describes how to install cinfony 0.9.x on Linux – Project Hosting on Google Code
55: Chemistry + python – SWiK
56: Dalke Scientific: Python Training for Cheminformatics
57: The Molecular Modelling Toolkit — Molecular Modelling Toolkit
58: frowns.sourceforge.net
59: PyMOL Molecular Viewer – Home Page
60: PyMol Tutorial
61: Molsoft L.L.C.: MolCart
62: http://www.hellers.com/steve/resume/p122.html
63: Fast Substructure Search Using Open Source Tools Part 1: Fingerprints and Databases
64: Creating a web-based, searchable molecular structure database using free software
65: Molecular fingerprints, background
66: Daylight Theory: Fingerprints
67: Checkmol/Matchmol Homepage
68: ChemHack » Hacking the chemistry world.
69: cdkjython
70: Cheminformatics 101 | What is Cheminformatics?
71: Faster fingerprint substructure tests


Chemistry

pyqt 的溶剂比例计算器 snail

2009年11月10日

RT
开始做植化了,要用,鑫哥的那个是 for win 的,以前写了个 ruby-gtk 的不知道扔哪里去了,于是重新写了个 pyqt 的。

ps: 图形界面的程序真是浪费表情阿,真正干活的就两三行,一旦要图形界面了就几百行,这个看来是死要面子(图形界面)活受罪的真实写照阿,呵呵。

片片:
snail 抓图

源码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/usr/bin/python
# -*- coding: utf-8 -*-
 
# Form implementation generated from reading ui file 'snail.ui'
#
# Created: Tue Nov 10 17:44:47 2009
#      by: PyQt4 UI code generator 4.6.1
#
# WARNING! All changes made in this file will be lost!
 
import sys, os
from PyQt4 import QtCore, QtGui
from PyQt4.QtGui import QMainWindow
from PyQt4.QtCore import pyqtSignature
 
class Ui_mainWindow(object):
    def setupUi(self, mainWindow):
        mainWindow.setObjectName("mainWindow")
        mainWindow.resize(767, 375)
        self.centralwidget = QtGui.QWidget(mainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.textEdit = QtGui.QTextEdit(self.centralwidget)
        self.textEdit.setGeometry(QtCore.QRect(170, 90, 171, 51))
        self.textEdit.setStyleSheet("font: 22pt \"Bitstream Vera Sans Mono\";")
        self.textEdit.setObjectName("textEdit")
        self.textEdit_2 = QtGui.QTextEdit(self.centralwidget)
        self.textEdit_2.setGeometry(QtCore.QRect(380, 90, 171, 51))
        self.textEdit_2.setStyleSheet("font: 22pt \"Bitstream Vera Sans Mono\";")
        self.textEdit_2.setObjectName("textEdit_2")
        self.textEdit_3 = QtGui.QTextEdit(self.centralwidget)
        self.textEdit_3.setGeometry(QtCore.QRect(590, 90, 161, 51))
        self.textEdit_3.setStyleSheet("font: 22pt \"Bitstream Vera Sans Mono\";")
        self.textEdit_3.setObjectName("textEdit_3")
        self.textEdit_4 = QtGui.QTextEdit(self.centralwidget)
        self.textEdit_4.setGeometry(QtCore.QRect(170, 180, 171, 51))
        self.textEdit_4.setStyleSheet("font: 22pt \"Bitstream Vera Sans Mono\";")
        self.textEdit_4.setObjectName("textEdit_4")
        self.textEdit_5 = QtGui.QTextEdit(self.centralwidget)
        self.textEdit_5.setGeometry(QtCore.QRect(380, 180, 171, 51))
        self.textEdit_5.setStyleSheet("font: 22pt \"Bitstream Vera Sans Mono\";")
        self.textEdit_5.setObjectName("textEdit_5")
        self.label = QtGui.QLabel(self.centralwidget)
        self.label.setGeometry(QtCore.QRect(200, 20, 131, 41))
        self.label.setStyleSheet("font: 26pt \"Bitstream Vera Sans Mono\"; 溶剂 A")
        self.label.setObjectName("label")
        self.label_2 = QtGui.QLabel(self.centralwidget)
        self.label_2.setGeometry(QtCore.QRect(410, 20, 131, 41))
        self.label_2.setStyleSheet("font: 26pt \"Bitstream Vera Sans Mono\"; 溶剂 A")
        self.label_2.setObjectName("label_2")
        self.label_3 = QtGui.QLabel(self.centralwidget)
        self.label_3.setGeometry(QtCore.QRect(630, 20, 131, 41))
        self.label_3.setStyleSheet("font: 26pt \"Bitstream Vera Sans Mono\"; 溶剂 A")
        self.label_3.setObjectName("label_3")
        self.label_4 = QtGui.QLabel(self.centralwidget)
        self.label_4.setGeometry(QtCore.QRect(20, 90, 151, 41))
        self.label_4.setStyleSheet("font: 26pt \"Bitstream Vera Sans Mono\"; 溶剂 A")
        self.label_4.setObjectName("label_4")
        self.label_5 = QtGui.QLabel(self.centralwidget)
        self.label_5.setGeometry(QtCore.QRect(20, 190, 151, 41))
        self.label_5.setStyleSheet("font: 26pt \"Bitstream Vera Sans Mono\"; 溶剂 A")
        self.label_5.setObjectName("label_5")
        self.pushButton = QtGui.QPushButton(self.centralwidget)
        self.pushButton.setGeometry(QtCore.QRect(590, 180, 161, 51))
        self.pushButton.setStyleSheet("font: 20pt \"Bitstream Vera Sans Mono\";")
        self.pushButton.setObjectName("pushButton")
        self.label_6 = QtGui.QLabel(self.centralwidget)
        self.label_6.setGeometry(QtCore.QRect(30, 270, 721, 71))
        self.label_6.setStyleSheet("""font: 22pt \"Bitstream Vera Sans Mono\"; color: rgb(0, 0, 255);""")
        self.label_6.setObjectName("label_6")
        self.frame = QtGui.QFrame(self.centralwidget)
        self.frame.setEnabled(True)
        self.frame.setGeometry(QtCore.QRect(20, 260, 731, 91))
        self.frame.setMouseTracking(False)
        self.frame.setAutoFillBackground(False)
        self.frame.setFrameShape(QtGui.QFrame.StyledPanel)
        self.frame.setFrameShadow(QtGui.QFrame.Raised)
        self.frame.setObjectName("frame")
        mainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtGui.QMenuBar(mainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 767, 25))
        self.menubar.setObjectName("menubar")
        mainWindow.setMenuBar(self.menubar)
        self.statusbar = QtGui.QStatusBar(mainWindow)
        self.statusbar.setObjectName("statusbar")
        mainWindow.setStatusBar(self.statusbar)
 
        self.retranslateUi(mainWindow)
        #QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL("clicked()"), self.label_6.)
        QtCore.QMetaObject.connectSlotsByName(mainWindow)
 
    def retranslateUi(self, mainWindow):
        mainWindow.setWindowTitle(QtGui.QApplication.translate("mainWindow", "溶剂比例计算器 -Snail", None, QtGui.QApplication.UnicodeUTF8))
        self.textEdit_3.setHtml(QtGui.QApplication.translate("mainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'Bitstream Vera Sans Mono\'; font-size:22pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">1000</p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
        self.label.setText(QtGui.QApplication.translate("mainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'Bitstream Vera Sans Mono\'; font-size:26pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">溶剂 A</p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
        self.label_2.setText(QtGui.QApplication.translate("mainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'Bitstream Vera Sans Mono\'; font-size:26pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">溶剂 B</p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
        self.label_3.setText(QtGui.QApplication.translate("mainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'Bitstream Vera Sans Mono\'; font-size:26pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">体积</p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
        self.label_4.setText(QtGui.QApplication.translate("mainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'Bitstream Vera Sans Mono\'; font-size:26pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">现有溶液</p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
        self.label_5.setText(QtGui.QApplication.translate("mainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'Bitstream Vera Sans Mono\'; font-size:26pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">欲配溶液</p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton.setText(QtGui.QApplication.translate("mainWindow", "也来算一个!", None, QtGui.QApplication.UnicodeUTF8))
        self.label_6.setText(QtGui.QApplication.translate("mainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'Bitstream Vera Sans Mono\'; font-size:22pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">欢迎使用溶剂比例计算器 Snail</p>\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Xiooli &lt;xioooli@yahoo.com.cn&gt;</p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
 
 
 
class Win(QMainWindow, Ui_mainWindow):
    def __init__(self, parent = None):
        QMainWindow.__init__(self, parent)
        self.setupUi(self)
    @pyqtSignature("")
    def on_pushButton_clicked(self):
        self.label_6_txt = ""
        try:
            now_A = float(self.textEdit.toPlainText())
            now_B = float(self.textEdit_2.toPlainText())
            now_vol = float(self.textEdit_3.toPlainText())
            want_A = float(self.textEdit_4.toPlainText())
            want_B = float(self.textEdit_5.toPlainText())
        except ValueError:
           self.label_6_txt = "错误:有输入框未输入数字,或输入了非数字字符!"
 
        if not self.label_6_txt:
            if want_A*(now_A+now_B) == 0 or want_B*(now_A+now_B) == 0:
                self.label_6_txt = "错误:试图除零!"
            elif now_A / now_B > want_A / want_B:
                vol,rst=self.textEdit_3.toPlainText(),\
                        str(round(now_vol*now_A*(want_A+want_B)/(want_A*(now_A+now_B))-now_vol,4))
                self.label_6_txt = "须向 " + vol + " ML 现有溶液中加入溶液 B " + rst + " ML"
            elif now_A / now_B == want_A / want_B:
                self.label_6_txt = "现有溶液和欲配溶液是同一种溶液,无须额外动作。"
            else:
                vol,rst=self.textEdit_3.toPlainText(),\
                        str(round(now_vol*now_B*(want_A+want_B)/(want_B*(now_A+now_B))-now_vol,4))
                self.label_6_txt = "须向 " + vol + " ML 现有溶液中加入溶液 A " + rst + " ML"
        self.label_6.setText(QtGui.QApplication.translate("mainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'Bitstream Vera Sans Mono\'; font-size:22pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">"+self.label_6_txt+"</p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
 
 
if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    win=Win()
    win.show()
    sys.exit(app.exec_())

Chemistry, Script , , ,

植化流程图生成脚本

2009年9月9日

RT
做植化的同学写报告的时候常常要画分离的流程图,以往大家都是拖啊拖啊的,看起来就恼火,于是就写了这样一个脚本(以后我也要画这种东西嘛),可以将简单的描述语言直接生成流程图,比如,如下的语言就可以生成如下的图:

a#草药样品
b#粗分浸膏
a#$甲醇提取=>b#
c1#正丁醇相
c2#石油醚相
c3#…
c4#水相
b#^$有机溶剂萃取
b#=>c1#
b#=>c2#
b#=>c3#
b#=>c4#
c2#^$继续柱层析分离
c2#=>d1#成分五
c2#=>d2#成分六

生成的流程图

该描述语言语法非常简单:
#前面是 node 的名字,$后面是描述,=> 将两个 node 连接起来,在其中画箭头,可以连续连接 比如 a# => b# => c# 也是可以的,node 后面 => 前面的 $xxx 是线上的注释,如果某一个点要往下分支的话只需用 node#^ 即可,node#^ 后面可以直接加注释,很简单的,看上面那个例子结合图片就可以搞明白了。

运行该脚本需要 python-yapgvb,此脚本受弯弯同学脚本的启发并参考了部分代码(http://python.ubuntu.org.cn/viewtopic.php?f=162&t=180285&sid=e2ae53902848adb1d59c375bf2325043

使用方法:

python liuchengtu.py -o xxx.png deffile

还有很多个性化选项,请参考源码。

源码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env python
# -*- coding: utf-8 -*-
 
# Author: xioooli<at>yahoo.com.cn,joolix.com
# Licence GPLv2
# Version 2009.09.09
 
import sys
import yapgvb
import optparse
 
FORMATS = {"png" : yapgvb.formats.png,
        "jpg" : yapgvb.formats.jpg,
        "gif" : yapgvb.formats.gif}
ENGINES = {"dot" : yapgvb.engines.dot,
        "neato" : yapgvb.engines.neato,
        "circo" : yapgvb.engines.circo,
        "twopi" : yapgvb.engines.twopi}
 
if __name__ == '__main__':
#    args = sys.argv
#    if len(args) < 2:
#        print "Usage: python state_machine.py <def file>"
#        sys.exit(0)
 
    parser = optparse.OptionParser()
    parser.add_option("-f", "--format", dest="format",
            help="store the flow chart in FORMAT (png, svg, jpg, gif)",
            metavar="FORMAT", default="png")
    parser.add_option("-o", "--output", dest="output",
            help="save the flow chart to FILE",
            metavar="FILE")
    parser.add_option("-e", "--engine", dest="engine",
            help="the layout ENGINE to use for the flow chart (dot, neato, circo, twopi)",
            metavar="ENGINE", default="dot")
    parser.add_option("-c", "--color", dest="fillcolor",
            help="the fillcolor of the node",
            default="white")
    parser.add_option("--fs", "--font-size", dest="fontsize",
            help="the font size of the text",
            default="12")
    parser.add_option("--nfc", "--node-font-color", dest="nodefontcolor",
            help="the fillcolor of the font in node",
            default="black")
    parser.add_option("--nc", "--node-color", dest="nodecolor",
            help="the color of the node frame",
            default="black")
    parser.add_option("--ec", "--edge-color", dest="edgecolor",
            help="the color of the edge",
            default="black")
    parser.add_option("--efc", "--edge-font-color", dest="edgefontcolor",
            help="the font color of the edge text",
            default="black")
    parser.add_option("-s", "--style", dest="style",
            help="the style of the node",
            default="filled")
    parser.add_option("--ah", "--arrowhead", dest="arrowhead",
            help="the style of the arrowhead",
            default="normal")
    parser.add_option("--as", "--arrowsize", dest="arrowsize",
            help="the size of the arrow",
            default=1)
    parser.add_option("--ns", "--nodesep", dest="nodesep",
            help="the sepration between two nodes",
            default=.5)
    parser.add_option("--sp", "--shape", dest="shape",
            help="the shape of the node",
            default="box")
 
    options, args = parser.parse_args()
    if len(args) < 1:
        parser.print_usage()
        sys.exit(0)
 
    graph = yapgvb.Graph("States")
    graph.rankdir="TB"
    graph.nodesep=options.nodesep
    node_dict = {}
 
    with open(args[0]) as def_file:
        lines = [l.strip() for l in def_file.readlines()]
        for line in lines:
            nodes = line.split("=>")
            prev_node = None
            for node in nodes[::-1]:
                label = node.strip().split("#")
                if not node_dict.has_key(label[0]) and label[0] != "":
                    try:
                        lb=label[1].split("$")[0]
                    except:
                        lb=""
                    node_in_graph = graph.add_node(label=lb,
                            shape=options.shape, fillcolor=options.fillcolor,
                            fontcolor=options.nodefontcolor, fontsize=options.fontsize,
                            style=options.style, color=options.nodecolor, width=0.5)
                    node_dict[label[0]] = node_in_graph
                elif label[0] != "":
                    node_in_graph = node_dict[label[0]]
 
                try:
                       blanknode = node.strip().split("#^")
                       if len(blanknode) >= 2:
                           blanknode = blanknode[0]
                       else:
                           blanknode = ""
                except:
                       blanknode = ""
                if node_dict.has_key(blanknode) and blanknode != "":
                    node_dict[blanknode + "_0"] = node_dict[blanknode]
                    node_in_graph = graph.add_node(label="",     
                            shape="circle", fillcolor=options.edgecolor,
                            color=options.edgecolor, style="filled", height=.05, width=.05)
                    node_dict[blanknode] = node_in_graph
                    edge = node_dict[blanknode + "_0"] - node_dict[blanknode]
                    edge.color=options.edgecolor
                    try:
                        edge.label=" "+node.strip().split("$")[1]
                        edge.fontcolor=options.edgefontcolor
                        edge.fontsize=options.fontsize
                    except:
                        pass
 
                if prev_node:
                    edge = node_in_graph - prev_node
                    edge.color=options.edgecolor
                    edge.arrowhead = options.arrowhead
                    edge.arrowsize = options.arrowsize
                    try:
                        edge.label=" "+node.strip().split("$")[1]
                        edge.fontcolor=options.edgefontcolor
                        edge.fontsize=options.fontsize
                    except:
                        pass
 
                prev_node = node_in_graph
 
    graph.layout(ENGINES[options.engine])
    format = FORMATS[options.format]
    if options.output:
        out_file = options.output
    else:
        out_file = args[0] + "." + format
 
    graph.render(out_file, format)

Chemistry, Script , , ,