python生成dat文件_Ra-使用Python脚本生成shape.dat文件

#!/usr/bin/env python

# -*- coding: UTF-8 -*-

"""

该代码主要用来生成球形的shape.dat,用于ddscat的计算

"""

header_template = """ >core_shell.py: NBX, NBY, NBZ= {} {} {}

{:>7} = NAT

1.0000 0.0000 0.0000 = A_1 vector

0.0000 1.0000 0.0000 = A_2 vector

1.000000 1.000000 1.000000 = lattice spacings (d_x,d_y,d_z)/d

0.0 0.0 0.0

JA IX IY IZ ICOMP(x,y,z)

"""

data = list()

index = 1

radius = 20

for x in range(-1*radius, radius+1):

for y in range(-1*radius, radius+1):

for z in range(-1*radius, radius+1):

if x**2 + y**2 + z**2 <= radius**2:

data.append('{:>7}{:>4}{:>4}{:>4} 1 1 1\n'.format(index, x, y, z))

index = index + 1

with open('shape.dat', 'w', encoding="utf-8") as f:

f.write(header_template.format(radius*2, radius*2, radius*2, index-1))

f.write(''.join(data))

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值