本文整理汇总了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
示例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)