| 查看: 2055 | 回复: 9 | |||||
| 当前只显示满足指定条件的回帖,点击这里查看本话题的所有回帖 | |||||
yjcmwgk禁虫 (文坛精英)
密度泛函·小卒
|
[求助]
用Python读Gaussian的cube文件,速度很慢,怎么破?谢谢!!! 已有4人参与
|
||||
|
向各位python大侠求教一个问题,谢谢各位! 我正在用python读一个由Gaussian生成的cube文件。但是读文件读得非常慢,读一个6M多的cube文件,居然用了3分钟! 具体问题如下: 用cubefile来打开某个cube文件。然后继续 我怀疑tmpline = tmplines[i-1]这句话拖累的速度?应该如何修改?非常感谢高手帮助!! 感谢!! |
» 收录本帖的淘帖专辑推荐
SOB 集锦 | 经验 | 杂书 |
» 猜你喜欢
中国科大电池方向任晓迪课题组招收2026级博士生-电解液/电池安全性/人工智能方向
已经有21人回复
26年秋季博士申请
已经有0人回复
物理化学论文润色/翻译怎么收费?
已经有163人回复
推荐给英语教学者的一本单词书《金鱼单词讲义:从26个拉丁字母到106万个英语单词》
已经有59人回复
推荐给教师的一本单词书《金鱼单词讲义:从26个拉丁字母到106万个英语单词》
已经有32人回复
核磁分析软件MestReNova打开文件时报错
已经有0人回复
在职博后不能申请博后基金了,那么在职博后意义何在?
已经有2人回复
青岛大学化学化工学院分子测量学研究院2026年招收博士研究生
已经有0人回复
香港科技大学(广州)诚招电催化方向博士生(2026秋入学)
已经有0人回复
» 本主题相关价值贴推荐,对您同样有帮助:
AIM如何使用(急!!!)
已经有18人回复
没有Gaussian版权用什么看cube文件里的轨道
已经有6人回复
使用AdNDP方法以及ELF/LOL、多中心键级研究多中心键
已经有14人回复
用Multiwfn、Gaussview、Molekel、VMD观看龙虾、盆景、骨盆、大脑
已经有16人回复
【求助】用gaussian计算得到out文件和chk文件,怎么得到fch文件?
已经有4人回复
【neweroica个人文集】转换VASP的CHGCAR为cube文件的程序chgcar2cube(v0.0)
已经有45人回复
【答案】应助回帖
★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★
感谢参与,应助指数 +1
yjcmwgk: 金币+10, ★有帮助, 非常感谢,我后来用tmpp = ((' '.join(cubefile.readlines())).replace("/n"," ")).split()解决了 2014-10-05 16:10:53
gmy1990: 金币+3 2014-10-05 18:50:03
感谢参与,应助指数 +1
yjcmwgk: 金币+10, ★有帮助, 非常感谢,我后来用tmpp = ((' '.join(cubefile.readlines())).replace("/n"," ")).split()解决了 2014-10-05 16:10:53
gmy1990: 金币+3 2014-10-05 18:50:03
|
你的代码不pythonic,不易读也很低效, 这里给个例子,不知道是不是你要的功能 def readcube(cubefile): cubedata = [] with open(cubefile) as f: lines = f.readlines() # if cubefile is large, read it in streaming or blocks # handle headers here for line in lines[2:]: for item in line.split(): cubedata.append(eval(item)) return cubedata if __name__ == '__main__': testfile = 'test.cube' data = readcube(testfile) print(len(data)) print(data[:10]) print(data[-10:]) |
9楼2014-10-05 15:29:16
yjcmwgk
禁虫 (文坛精英)
密度泛函·小卒
- QC强帖: 38
- 应助: 165 (高中生)
- 贵宾: 16.999
- 金币: 553.8
- 散金: 39880
- 红花: 395
- 沙发: 2
- 帖子: 10406
- 在线: 1528.1小时
- 虫号: 448368
- 注册: 2007-11-01
- 专业: 理论和计算化学
- 管辖: 科研工具资源
2楼2014-10-04 11:08:58
【答案】应助回帖
★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★
感谢参与,应助指数 +1
yjcmwgk: 金币+20, ★有帮助, 非常感谢,我后来用tmpp = ((' '.join(cubefile.readlines())).replace("/n"," ")).split()解决了 2014-10-05 16:10:10
gmy1990: 金币+3 2014-10-05 18:49:03
感谢参与,应助指数 +1
yjcmwgk: 金币+20, ★有帮助, 非常感谢,我后来用tmpp = ((' '.join(cubefile.readlines())).replace("/n"," ")).split()解决了 2014-10-05 16:10:10
gmy1990: 金币+3 2014-10-05 18:49:03
|
试试这个,看看效果如何: [ code] tmplines = cubefile.readlines() tempstr = "".join(tmplines) #把list转化为str,形式应该是'num num ...num\nnum ...' tempstr = tempstr.replace('\n',' ') #把str中的'\n'替换为' ' tmpcubedata = tempstr.split(' ') #把str转为list n=0 numcount=len(tmpcubedata) #list的数据总数 for i in tmpcubedata: n+=1 if i%60000==0: print "Converting", cubefilename, "...... ", int(100.0*float(i)/float(numcount)), "%" #if i=="": #tmpcubedata.remove(i) #如果cubefile 文件中中间有空行,则需要这个功能 if tmpcubedata[-1]=="": del tmpcubedata[-1] #如果cubefile 文件以‘num\n‘结尾 print "Converting", cubefilename, "...... ", "100 %" [ /code] |
3楼2014-10-04 15:23:36
rh1127
捐助贵宾 (著名写手)
一名工程师@上海
- 应助: 2 (幼儿园)
- 金币: 21406.7
- 红花: 5
- 帖子: 1616
- 在线: 139.5小时
- 虫号: 116848
- 注册: 2005-11-25
- 性别: GG
- 专业: 胶体与界面化学
【答案】应助回帖
★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★
感谢参与,应助指数 +1
yjcmwgk: 金币+20, ★有帮助, 非常感谢,我后来用tmpp = ((' '.join(cubefile.readlines())).replace("/n"," ")).split()解决了 2014-10-05 16:10:21
gmy1990: 金币+2 2014-10-05 18:49:14
感谢参与,应助指数 +1
yjcmwgk: 金币+20, ★有帮助, 非常感谢,我后来用tmpp = ((' '.join(cubefile.readlines())).replace("/n"," ")).split()解决了 2014-10-05 16:10:21
gmy1990: 金币+2 2014-10-05 18:49:14
|
用numpy和pandas模块儿来处理大型数组,比只用for循环速度快几十倍不止。python自带的循环未经优化,很忌讳来处理大型数组! 希望对你有帮助。 |

4楼2014-10-05 09:21:10









回复此楼