> svn co svn://www.crystallography.net/codCODは常に更新しているので、時々アップデートする必要がある。まずcodディレクトリーに移動してから、
> cd cod > svn updateもしアップデートで怒られたら、指示通りにclean upを実行する
> svn cleanupアップデートしようとしたら、アップグレードするように言われる時がある。その場合は、
> svn upgrade
#!/usr/bin/python import os,sys base = '/Users/masami/cod/cif/' # cif base directory, change here! list_basedir = ['1','2','3','4','5','6','7','8','9'] #list_basedir = ['1'] # for test purpose, use limited list... for i in range(0,len(list_basedir)): dir1 = base + list_basedir[i] + '/' # first-level directory os.chdir(dir1) # move to second-level directory list_1 = os.listdir('.') # if '.DS_Store' in list_1: # .DS_Store exists? list_1.remove('.DS_Store') # remove .DS_Store for j in range(0,len(list_1)): dir2 = dir1 + list_1[j] + '/' os.chdir(dir2) # move to 3rd-level directory list_2 = os.listdir('.') if '.DS_Store' in list_2: # .DS_Store exists? list_2.remove('.DS_Store') # remove .DS_Store for k in range(0,len(list_2)): dir3 = dir2 + list_2[k] + '/' os.chdir(dir3) # move to 4th-level directory list_3 = os.listdir('.') if '.DS_Store' in list_3: # .DS_Store exists? list_3.remove('.DS_Store') # remove .DS_Store # list_3 contains cif file name list in this directory for l in range(0,len(list_3)): # process cif file fin = open(list_3[l],'r') # open cif file contents = fin.readlines() # read all contents in memory fin.close() # close cif file for line in contents: # for each line of cif file (in memory) try: if '_chemical_name_mineral' in line: # Does this tag exist? tmp = line.strip() # strip \n t = len(tmp) # length of tmp string mineral_name = tmp[33:t] # get mineral name if len(mineral_name) == 0: # if empty, break break else: # next line, remove ' and spaces mineral_name = mineral_name.replace("'","").strip() # make first letter to lower case mineral_name = mineral_name[0].lower() + mineral_name[1:] print mineral_name + ',' + list_3[l] #list_3[l] = cif filename break except: # tag not available in this cif break
> grep forsterite minerals_in_cod.txt forsterite,9000166.cif forsterite,9000167.cif forsterite,9000267.cif 以下省略
https://www.crystallography.net/cod/9000166.cif
#!/usr/bin/python import sys,subprocess base = '/Users/masami/cod/cif/' # cif base directory, change here fname = sys.argv[1] dir = base + fname[0] + '/' + fname[1:3] + '/' + fname[3:5] + '/' + fname cmd = "open -a VESTA " + dir subprocess.call(cmd.split(" "))たとえばこれをvesta.pyとして保存し、実行権限をつけて以下のように実行すると、cifファイルの内容が結晶構造としてVesta上に表示される。
> chmod 755 vesta.py > ./vesta.py 9000166.cif
#!/usr/bin/python import sys,subprocess # curl version list = ['' for i in range(500)] min_name = sys.argv[1] mineral_file = '/Users/masami/minerals_in_cod.txt' # mineral-list, change here try: # text file open fin = open(mineral_file,'r') except IOError, (errno, msg): # file not found print 'minerals_in_cod.txt is missing.' exit() contents = fin.readlines() # read all lines in cif file to contents fin.close() # close file find = 0 for line in contents: if min_name in line: # mineral name in a line? find = find + 1 list[find] = line.strip() # strip \n print str(find) + ": " + list[find] if find == 0: print "No such mineral in the list." exit() elif find == 1: # just one, no selection input_no = 1 else: # select by number print "Select by number? (0 to stop)." input_no = input('>>> ') if (input_no <= 0) or (input_no > find): exit() s = list[input_no].index(",") t = len(list[input_no]) fname = list[input_no][s+1:t] # get file name cmd = "curl -s -o" + " " + fname + " " + "https://www.crystallography.net/cod/" + fname subprocess.call(cmd.split(" ")) # Get specified cif file from the COD site by curl cmd = "open -a VESTA" + " " + fname subprocess.call(cmd.split(" ")) # open VESTA using a downloaded cif file #cmd = "open -a Jedit\ X" + " " + fname #subprocess.call(cmd,shell=True) # open cif file by JeditX exit() # end of the code, mkanzaki@me.com
使い方は、terminal上では次のような感じ。moganiteを検索すると、3つ存在したので、2番目を選んでいる。9005115.cifがCODサイトからダウンロードされ、Vestaに表示される。なお、そのcifファイルはカレントディレクトリに保存されているので、後で再利用できる。
> ./vesta_curl.py moganite 1: moganite,9002648.cif 2: moganite,9002649.cif 3: moganite,9005115.cif Select by number? (0 to stop). >>> 2
Dim Sh As New Shell Sh.Execute( "curl -s -o ~/test.cif https://www.crystallography.net/cod/9000166.cif" ) Sh.Execute( "open -a VESTA ~/test.cif" ) Sh.Execute( "open -a Jedit\ X ~/test.cif" )
cmd = "/Applications/Plot2.1.1/Plot2x.app/Contents/MacOS/Plot2x -i " + dir3 + " &" subprocess.call(cmd,shell=True)
cmd = "open -a Jedit\ X" + " " + filename subprocess.call(cmd,shell=True)