当前位置: 首页>>代码示例>>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;未经允许,请勿转载。