當前位置: 首頁>>代碼示例>>Python>>正文


Python FortranFile.write方法代碼示例

本文整理匯總了Python中scipy.io.FortranFile.write方法的典型用法代碼示例。如果您正苦於以下問題:Python FortranFile.write方法的具體用法?Python FortranFile.write怎麽用?Python FortranFile.write使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在scipy.io.FortranFile的用法示例。


在下文中一共展示了FortranFile.write方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: reorder_uXu

# 需要導入模塊: from scipy.io import FortranFile [as 別名]
# 或者: from scipy.io.FortranFile import write [as 別名]
def reorder_uXu(ext,formatted=False):
  try:
    print "----------\n  {0}  \n----------".format(ext)
    
    if formatted:
	f_uXu_in = open(seedname+"."+ext, 'r')
	f_uXu_out = open(seednameGW+"."+ext, 'w')
	header=f_uXu_in.readline()
	f_uXu_out.write(header)
	nbnd,NK,nnb=np.array(f_uXu_in.readline().split(),dtype=int)
	f_uXu_out.write("  ".join(str(x) for x in [NBND,NK,nnb])+"\n")
    else:
	f_uXu_in = FortranFile(seedname+"."+ext, 'r')
	f_uXu_out = FortranFile(seednameGW+"."+ext, 'w')
	header=f_uXu_in.read_record(dtype='c')
        f_uXu_out.write_record(header)
	nbnd,NK,nnb=np.array(f_uXu_in.read_record(dtype=np.int32))
	f_uXu_out.write_record(np.array([NBND,NK,nnb],dtype=np.int32))
    
    assert nbnd==nbndDFT
    print nbnd,NK,nnb
    
    if formatted:
	uXu=np.loadtxt(f_uXu_in).reshape(-1)
	start=0
	length=nbnd*nbnd

    for ik in xrange(NKPT):
	for ib2 in xrange(nnb):
	    for ib1 in xrange(nnb):
		if formatted:
		    A=uXu[start:start+length]
		    start+=length
		else:
		    A=f_uXu_in.read_record(dtype=np.complex)
		A=(A.reshape(nbnd,nbnd,order='F')[BANDSORT[KPNB[ik][ib2]],:][:,BANDSORT[KPNB[ik][ib1]]]+
			np.einsum('ln,lm,l->nm',MMN[ik][ib2].conj(),MMN[ik][ib1],eigenDE[ik]) ).reshape(-1,order='F')
		if formatted:
		    f_uXu_out.write("".join("{0:26.16e}  {1:26.16f}\n".format(x.real,x.imag) for x in A))
		else:
	    	    f_uXu_out.write_record(A)
    f_uXu_out.close()
    f_uXu_in.close()
    print "----------\n {0} OK  \n----------\n".format(ext)
  except IOError as err:
    print "WARNING: {0}.{1} not written : ".format(seednameGW,ext),err 
開發者ID:wannier-developers,項目名稱:wannier90,代碼行數:48,代碼來源:gw2wannier90.py

示例2: xrange

# 需要導入模塊: from scipy.io import FortranFile [as 別名]
# 或者: from scipy.io.FortranFile import write [as 別名]
	length=(3*nbnd*(nbnd+1))/2

    for ik in xrange(NK):
	if SPNformatted:
	    A=SPN[start:start+length]
	    start+=length
	else:
	    A=np.zeros((3,nbnd,nbnd),dtype=np.complex)
	A[:,indn,indm]=f_spn_in.read_record(dtype=np.complex).reshape(3,nbnd*(nbnd+1)/2,order='F')
	A[:,indm,indn]=A[:,indn,indm].conj()
	check=np.einsum('ijj->',np.abs(A.imag))
	if check> 1e-10:
	    raise RuntimeError ( "REAL DIAG CHECK FAILED for spn: {0}".format(check) )
	A=A[:,:,BANDSORT[ik]][:,BANDSORT[ik],:][:,indnQP,indmQP].reshape((3*NBND*(NBND+1)/2),order='F')
	if formatted:
	    f_spn_out.write("".join("{0:26:16e} {1:26:16e}\n".format(x.real,x.imag) for x in A))
	else:
	    f_spn_out.write_record(A)

    f_spn_in.close()
    f_spn_out.close()
    print "----------\n SPN OK  \n---------\n"
  except IOError as err:
    print "WARNING: {0}.spn not written : ".format(seednameGW) ,err

if calcUNK:
    unkgwdir="UNK_GW"
    unkdftdir="UNK_DFT"
    files_list=[]
    for f_unk_name in  glob.glob("UNK*"):
        files_list.append(f_unk_name)
開發者ID:wannier-developers,項目名稱:wannier90,代碼行數:33,代碼來源:gw2wannier90.py


注:本文中的scipy.io.FortranFile.write方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。