文件转换的脚本,谁帮忙写一个呢?

sh/bash/dash/ksh/zsh等Shell脚本
头像
月下叹逍遥
论坛版主
帖子: 33994
注册时间: 2010-10-07 14:23
系统: Archdows10
来自: 某系某星某洲某国某省某市
联系:

文件转换的脚本,谁帮忙写一个呢?

#1

帖子 月下叹逍遥 » 2013-10-24 16:53

假设如下的py代码

代码: 全选

from ATK.KohnSham import *
from ATK.MPI import processIsMaster

# Generate time stamp
if processIsMaster():
    import platform, time
    print '#',time.ctime()
    print '#',platform.node(),platform.platform()+'\n'

# Opening vnlfile
if processIsMaster(): file = VNLFile('molecular-cpfecp.vnl')

# Define elements
elements = [Carbon,   Carbon,   Carbon,   Carbon,   
            Carbon,   Hydrogen, Hydrogen, Hydrogen, 
            Hydrogen, Hydrogen, Iron,     Carbon,   
            Carbon,   Carbon,   Carbon,   Carbon,   
            Hydrogen, Hydrogen, Hydrogen, Hydrogen, 
            Hydrogen]

# Define coordinates
coordinates = [[ 11.63525   ,  12.69039999,   5.33493008],
               [ 11.63483003,  10.30985998,   5.34161008],
               [ 12.5       ,  11.5       ,   5.33600008],
               [ 10.23643005,  12.23554997,   5.34013008],
               [ 10.23618007,  10.76515   ,   5.34430008],
               [ 11.99185002,  13.78896998,   5.25666007],
               [ 11.99110001,   9.21061991,   5.27288008],
               [  9.30041003,  12.91331004,   5.27040008],
               [  9.29973006,  10.08723997,   5.28153008],
               [ 13.65497005,  11.49973   ,   5.25828008],
               [ 11.24606   ,  11.4965    ,   3.7263701 ],
               [ 11.63525   ,  12.69039999,   1.99892998],
               [ 11.63483003,  10.30985998,   2.00560999],
               [ 12.5       ,  11.5       ,   2.        ],
               [ 10.23643005,  12.23554997,   2.00413013],
               [ 10.23618007,  10.76515   ,   2.00830007],
               [ 11.99185002,  13.78896998,   1.92066002],
               [ 11.99110001,   9.21061991,   1.93688011],
               [  9.30041003,  12.91331004,   1.93440008],
               [  9.29973006,  10.08723997,   1.94553018],
               [ 13.65497005,  11.49973   ,   1.92228007]]*Angstrom

# Set up configuration
molecule_configuration = MoleculeConfiguration(elements,coordinates)
if processIsMaster(): nlPrint(molecule_configuration)
if processIsMaster(): file.addToSample(molecule_configuration, 'molecule_configuration')
只读取elements和coordinates两个数组的东西,elements里是元素单词,coordinates里是元素坐标,将这两组数组保存成下面的格式:
C 11.63525 12.69039999 5.33493008
C 11.63483003 10.30985998 5.34161008
C 12.5 11.5 5.33600008
C 10.23643005 12.23554997 5.34013008
C 10.23618007 10.76515 5.34430008
H 11.99185002 13.78896998 5.25666007
H 11.99110001 9.21061991 5.27288008
H 9.30041003 12.91331004 5.27040008
H 9.29973006 10.08723997 5.28153008
H 13.65497005 11.49973 5.25828008
Fe 11.24606 11.4965 3.7263701
C 11.63525 12.69039999 1.99892998
C 11.63483003 10.30985998 2.00560999
C 12.5 11.5 2.
C 10.23643005 12.23554997 2.00413013
C 10.23618007 10.76515 2.00830007
H 11.99185002 13.78896998 1.92066002
H 11.99110001 9.21061991 1.93688011
H 9.30041003 12.91331004 1.93440008
H 9.29973006 10.08723997 1.94553018
H 13.65497005 11.49973 1.92228007
每个元素单词写成元素符号,按照“元素符号 坐标“的格式输出,保存成gjf格式
浮生七十今三十,从此凄惶未可知
头像
Methuselar
帖子: 122
注册时间: 2009-06-04 12:06
联系:

Re: 文件转换的脚本,谁帮忙写一个呢?

#2

帖子 Methuselar » 2013-10-24 17:10

直接用py不行么??
Mea Culpa!
头像
lilydjwg
论坛版主
帖子: 4258
注册时间: 2009-04-11 23:46
系统: Arch Linux
联系:

Re: 文件转换的脚本,谁帮忙写一个呢?

#3

帖子 lilydjwg » 2013-10-24 17:14

没看懂。那个脚本是干什么的?
nae6taiyie0T
帖子: 482
注册时间: 2013-09-13 0:42
系统: Debian sid

Re: 文件转换的脚本,谁帮忙写一个呢?

#4

帖子 nae6taiyie0T » 2013-10-24 17:34

月下叹逍遥 写了:假设如下的py代码

代码: 全选

from ATK.KohnSham import *
from ATK.MPI import processIsMaster

# Generate time stamp
if processIsMaster():
    import platform, time
    print '#',time.ctime()
    print '#',platform.node(),platform.platform()+'\n'

# Opening vnlfile
if processIsMaster(): file = VNLFile('molecular-cpfecp.vnl')

# Define elements
elements = [Carbon,   Carbon,   Carbon,   Carbon,   
            Carbon,   Hydrogen, Hydrogen, Hydrogen, 
            Hydrogen, Hydrogen, Iron,     Carbon,   
            Carbon,   Carbon,   Carbon,   Carbon,   
            Hydrogen, Hydrogen, Hydrogen, Hydrogen, 
            Hydrogen]

# Define coordinates
coordinates = [[ 11.63525   ,  12.69039999,   5.33493008],
               [ 11.63483003,  10.30985998,   5.34161008],
               [ 12.5       ,  11.5       ,   5.33600008],
               [ 10.23643005,  12.23554997,   5.34013008],
               [ 10.23618007,  10.76515   ,   5.34430008],
               [ 11.99185002,  13.78896998,   5.25666007],
               [ 11.99110001,   9.21061991,   5.27288008],
               [  9.30041003,  12.91331004,   5.27040008],
               [  9.29973006,  10.08723997,   5.28153008],
               [ 13.65497005,  11.49973   ,   5.25828008],
               [ 11.24606   ,  11.4965    ,   3.7263701 ],
               [ 11.63525   ,  12.69039999,   1.99892998],
               [ 11.63483003,  10.30985998,   2.00560999],
               [ 12.5       ,  11.5       ,   2.        ],
               [ 10.23643005,  12.23554997,   2.00413013],
               [ 10.23618007,  10.76515   ,   2.00830007],
               [ 11.99185002,  13.78896998,   1.92066002],
               [ 11.99110001,   9.21061991,   1.93688011],
               [  9.30041003,  12.91331004,   1.93440008],
               [  9.29973006,  10.08723997,   1.94553018],
               [ 13.65497005,  11.49973   ,   1.92228007]]*Angstrom

# Set up configuration
molecule_configuration = MoleculeConfiguration(elements,coordinates)
if processIsMaster(): nlPrint(molecule_configuration)
if processIsMaster(): file.addToSample(molecule_configuration, 'molecule_configuration')
只读取elements和coordinates两个数组的东西,elements里是元素单词,coordinates里是元素坐标,将这两组数组保存成下面的格式:
C 11.63525 12.69039999 5.33493008
C 11.63483003 10.30985998 5.34161008
C 12.5 11.5 5.33600008
C 10.23643005 12.23554997 5.34013008
C 10.23618007 10.76515 5.34430008
H 11.99185002 13.78896998 5.25666007
H 11.99110001 9.21061991 5.27288008
H 9.30041003 12.91331004 5.27040008
H 9.29973006 10.08723997 5.28153008
H 13.65497005 11.49973 5.25828008
Fe 11.24606 11.4965 3.7263701
C 11.63525 12.69039999 1.99892998
C 11.63483003 10.30985998 2.00560999
C 12.5 11.5 2.
C 10.23643005 12.23554997 2.00413013
C 10.23618007 10.76515 2.00830007
H 11.99185002 13.78896998 1.92066002
H 11.99110001 9.21061991 1.93688011
H 9.30041003 12.91331004 1.93440008
H 9.29973006 10.08723997 1.94553018
H 13.65497005 11.49973 1.92228007
每个元素单词写成元素符号,按照“元素符号 坐标“的格式输出,保存成gjf格式
gjf?
gif?
这是要画分子结构?
头像
月下叹逍遥
论坛版主
帖子: 33994
注册时间: 2010-10-07 14:23
系统: Archdows10
来自: 某系某星某洲某国某省某市
联系:

Re: 文件转换的脚本,谁帮忙写一个呢?

#5

帖子 月下叹逍遥 » 2013-10-24 18:37

nae6taiyie0T 写了:
月下叹逍遥 写了:假设如下的py代码

代码: 全选

from ATK.KohnSham import *
from ATK.MPI import processIsMaster

# Generate time stamp
if processIsMaster():
    import platform, time
    print '#',time.ctime()
    print '#',platform.node(),platform.platform()+'\n'

# Opening vnlfile
if processIsMaster(): file = VNLFile('molecular-cpfecp.vnl')

# Define elements
elements = [Carbon,   Carbon,   Carbon,   Carbon,   
            Carbon,   Hydrogen, Hydrogen, Hydrogen, 
            Hydrogen, Hydrogen, Iron,     Carbon,   
            Carbon,   Carbon,   Carbon,   Carbon,   
            Hydrogen, Hydrogen, Hydrogen, Hydrogen, 
            Hydrogen]

# Define coordinates
coordinates = [[ 11.63525   ,  12.69039999,   5.33493008],
               [ 11.63483003,  10.30985998,   5.34161008],
               [ 12.5       ,  11.5       ,   5.33600008],
               [ 10.23643005,  12.23554997,   5.34013008],
               [ 10.23618007,  10.76515   ,   5.34430008],
               [ 11.99185002,  13.78896998,   5.25666007],
               [ 11.99110001,   9.21061991,   5.27288008],
               [  9.30041003,  12.91331004,   5.27040008],
               [  9.29973006,  10.08723997,   5.28153008],
               [ 13.65497005,  11.49973   ,   5.25828008],
               [ 11.24606   ,  11.4965    ,   3.7263701 ],
               [ 11.63525   ,  12.69039999,   1.99892998],
               [ 11.63483003,  10.30985998,   2.00560999],
               [ 12.5       ,  11.5       ,   2.        ],
               [ 10.23643005,  12.23554997,   2.00413013],
               [ 10.23618007,  10.76515   ,   2.00830007],
               [ 11.99185002,  13.78896998,   1.92066002],
               [ 11.99110001,   9.21061991,   1.93688011],
               [  9.30041003,  12.91331004,   1.93440008],
               [  9.29973006,  10.08723997,   1.94553018],
               [ 13.65497005,  11.49973   ,   1.92228007]]*Angstrom

# Set up configuration
molecule_configuration = MoleculeConfiguration(elements,coordinates)
if processIsMaster(): nlPrint(molecule_configuration)
if processIsMaster(): file.addToSample(molecule_configuration, 'molecule_configuration')
只读取elements和coordinates两个数组的东西,elements里是元素单词,coordinates里是元素坐标,将这两组数组保存成下面的格式:
C 11.63525 12.69039999 5.33493008
C 11.63483003 10.30985998 5.34161008
C 12.5 11.5 5.33600008
C 10.23643005 12.23554997 5.34013008
C 10.23618007 10.76515 5.34430008
H 11.99185002 13.78896998 5.25666007
H 11.99110001 9.21061991 5.27288008
H 9.30041003 12.91331004 5.27040008
H 9.29973006 10.08723997 5.28153008
H 13.65497005 11.49973 5.25828008
Fe 11.24606 11.4965 3.7263701
C 11.63525 12.69039999 1.99892998
C 11.63483003 10.30985998 2.00560999
C 12.5 11.5 2.
C 10.23643005 12.23554997 2.00413013
C 10.23618007 10.76515 2.00830007
H 11.99185002 13.78896998 1.92066002
H 11.99110001 9.21061991 1.93688011
H 9.30041003 12.91331004 1.93440008
H 9.29973006 10.08723997 1.94553018
H 13.65497005 11.49973 1.92228007
每个元素单词写成元素符号,按照“元素符号 坐标“的格式输出,保存成gjf格式
gjf?
gif?
这是要画分子结构?
嗯,是的。
浮生七十今三十,从此凄惶未可知
头像
月下叹逍遥
论坛版主
帖子: 33994
注册时间: 2010-10-07 14:23
系统: Archdows10
来自: 某系某星某洲某国某省某市
联系:

Re: 文件转换的脚本,谁帮忙写一个呢?

#6

帖子 月下叹逍遥 » 2013-10-24 18:40

Methuselar 写了:直接用py不行么??
软件不认PY的
lilydjwg 写了:没看懂。那个脚本是干什么的?
第一个是一个软件的计算脚本,内容啥的,暂且不管,就是要其中的分子结构部分。
浮生七十今三十,从此凄惶未可知
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: 文件转换的脚本,谁帮忙写一个呢?

#7

帖子 eexpress » 2013-10-25 8:57

可怜的不会perl的,居然求助其他语言。
● 鸣学
头像
huangbster
帖子: 187
注册时间: 2012-10-29 11:35
系统: UBUNTU

Re: 文件转换的脚本,谁帮忙写一个呢?

#8

帖子 huangbster » 2013-10-25 9:17

VNL文件格式,以前没听说过。
头像
月下叹逍遥
论坛版主
帖子: 33994
注册时间: 2010-10-07 14:23
系统: Archdows10
来自: 某系某星某洲某国某省某市
联系:

Re: 文件转换的脚本,谁帮忙写一个呢?

#9

帖子 月下叹逍遥 » 2013-10-25 10:09

huangbster 写了:VNL文件格式,以前没听说过。
用不着vnl的,只把py改成gjf

Sent from my SK17i using Tapatalk 2
浮生七十今三十,从此凄惶未可知
头像
月下叹逍遥
论坛版主
帖子: 33994
注册时间: 2010-10-07 14:23
系统: Archdows10
来自: 某系某星某洲某国某省某市
联系:

Re: 文件转换的脚本,谁帮忙写一个呢?

#10

帖子 月下叹逍遥 » 2013-10-25 10:10

eexpress 写了:可怜的不会perl的,居然求助其他语言。
为了反抗ee,也要将perl抵制到底

Sent from my SK17i using Tapatalk 2
浮生七十今三十,从此凄惶未可知
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: 文件转换的脚本,谁帮忙写一个呢?

#11

帖子 eexpress » 2013-10-25 10:52

代码: 全选

● perl t.pl<tmp
C => 11.63525,12.69039999,5.33493008
C => 11.63483003,10.30985998,5.34161008
C => 12.5,11.5,5.33600008
C => 10.23643005,12.23554997,5.34013008
C => 10.23618007,10.76515,5.34430008
H => 11.99185002,13.78896998,5.25666007
H => 11.99110001,9.21061991,5.27288008
H => 9.30041003,12.91331004,5.27040008
H => 9.29973006,10.08723997,5.28153008
H => 13.65497005,11.49973,5.25828008
I => 11.24606,11.4965,3.7263701
C => 11.63525,12.69039999,1.99892998
C => 11.63483003,10.30985998,2.00560999
C => 12.5,11.5,2.
C => 10.23643005,12.23554997,2.00413013
C => 10.23618007,10.76515,2.00830007
H => 11.99185002,13.78896998,1.92066002
H => 11.99110001,9.21061991,1.93688011
H => 9.30041003,12.91331004,1.93440008
H => 9.29973006,10.08723997,1.94553018
H => 13.65497005,11.49973,1.92228007

代码: 全选

● dog t.pl |wc -l
13
● 鸣学
头像
月下叹逍遥
论坛版主
帖子: 33994
注册时间: 2010-10-07 14:23
系统: Archdows10
来自: 某系某星某洲某国某省某市
联系:

Re: 文件转换的脚本,谁帮忙写一个呢?

#12

帖子 月下叹逍遥 » 2013-10-25 13:14

eexpress 写了:

代码: 全选

● perl t.pl<tmp
C => 11.63525,12.69039999,5.33493008
C => 11.63483003,10.30985998,5.34161008
C => 12.5,11.5,5.33600008
C => 10.23643005,12.23554997,5.34013008
C => 10.23618007,10.76515,5.34430008
H => 11.99185002,13.78896998,5.25666007
H => 11.99110001,9.21061991,5.27288008
H => 9.30041003,12.91331004,5.27040008
H => 9.29973006,10.08723997,5.28153008
H => 13.65497005,11.49973,5.25828008
I => 11.24606,11.4965,3.7263701
C => 11.63525,12.69039999,1.99892998
C => 11.63483003,10.30985998,2.00560999
C => 12.5,11.5,2.
C => 10.23643005,12.23554997,2.00413013
C => 10.23618007,10.76515,2.00830007
H => 11.99185002,13.78896998,1.92066002
H => 11.99110001,9.21061991,1.93688011
H => 9.30041003,12.91331004,1.93440008
H => 9.29973006,10.08723997,1.94553018
H => 13.65497005,11.49973,1.92228007

代码: 全选

● dog t.pl |wc -l
13
可不是缩写首字母的问题。。。Iron的符号是Fe,而不是I。
:em01 python的字典可以处这个,perl能行么?

Sent from my SK17i using Tapatalk 2
浮生七十今三十,从此凄惶未可知
头像
lilydjwg
论坛版主
帖子: 4258
注册时间: 2009-04-11 23:46
系统: Arch Linux
联系:

Re: 文件转换的脚本,谁帮忙写一个呢?

#13

帖子 lilydjwg » 2013-10-25 13:55

好像终于明白你要什么了……

[python]
from __future__ import print_function
try:
from itertools import izip as zip
except ImportError:
pass

name_map = {
'Carbon': 'C',
# do it yourself
}

for name, coords in zip(elements, coordinates):
print(name_map[name], ' '.join(coords))
[/python]

前五行是为了兼容 Python 2 的。
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: 文件转换的脚本,谁帮忙写一个呢?

#14

帖子 eexpress » 2013-10-25 14:16

● g Car t.pl
13:%h=(Carbon=>C, Hydrogen=>H, Iron=>I,);

真是围观py小白。
● 鸣学
头像
lilydjwg
论坛版主
帖子: 4258
注册时间: 2009-04-11 23:46
系统: Arch Linux
联系:

Re: 文件转换的脚本,谁帮忙写一个呢?

#15

帖子 lilydjwg » 2013-10-25 14:19

Iron=>I :em20 :em20 :em20
iodine 泪流满面……
回复