material 版 (精华区)
发信人: chumsdock (微笑服务), 信区: material
标 题: 非晶作业:FCC结构原子配位数的python代码
发信站: BBS 听涛站 (Fri Oct 15 13:31:25 2004), 转信
def fullset(setitem):
if setitem==[]: return []
res=[]
set=setitem
seq=[0,1,2]
for i in seq:
for j in seq:
if i!=j:
for k in seq:
if not (k==j or k==i):
if [set[i],set[j],set[k]] not in res :
res.append([set[i],set[j],set[k]])
if [-set[i],set[j],set[k]] not in res :
res.append([-set[i],set[j],set[k]])
if [set[i],-set[j],set[k]] not in res :
res.append([set[i],-set[j],set[k]])
if [set[i],set[j],-set[k]] not in res :
res.append([set[i],set[j],-set[k]])
if [-set[i],-set[j],set[k]] not in res :
res.append([-set[i],-set[j],set[k]])
if [-set[i],set[j],-set[k]] not in res :
res.append([-set[i],set[j],-set[k]])
if [set[i],-set[j],-set[k]] not in res :
res.append([set[i],-set[j],-set[k]])
if [-set[i],-set[j],-set[k]] not in res :
res.append([-set[i],-set[j],-set[k]])
return res
#上面的子程序是把一个坐标的所有等效坐标生成一个列表,如由(0,0,1)形成
#(1,0,0),(-1,0,0)…………,所以len( fullset([0,0,1]) )即坐标个数。
class info:
def __init__(self,value):
self.pos=value[0]
self.num=value[1]
self.dist=value[2]
def __cmp__(self,other):
if self.dist>other.dist: return 1
elif self.dist==other.dist: return 0
elif self.dist<other.dist: return -1
#生成一个类,为的是排序方便。
uvw=[]
fullinfo=[]
item=[]
for a1 in [0,1,2,3,4,5]:
for a2 in[0,1,2,3,4,5]:
for a3 in[0,1,2,3,4,5]:
for item in uvw:
if [a1,a2,a3] in fullset(item): break
else:
distance=a1**2+a2**2+a3**2
number=len(fullset([a1,a2,a3]))
temp=info([[a1,a2,a3],number,distance])
fullinfo.append(temp)
uvw.append([a1,a2,a3])
for a2 in[0.5,1.5,2.5,3.5,4.5]:
for a3 in[0.5,1.5,2.5,3.5,4.5]:
for item in uvw:
if item in fullset([a1,a2,a3]): break
else:
distance=a1**2+a2**2+a3**2
number=len(fullset([a1,a2,a3]))
temp=info([[a1,a2,a3],number,distance])
fullinfo.append(temp)
uvw.append([a1,a2,a3])
#注意distance实际是距离的平方,但是在这里没有必要多计算一步,也面得算出小数来
fullinfo.sort(info.__cmp__)
#这里排序,简单地调用类里面关于大小的定义,大大减小了编程工作量
for i in range(20):
temp2=fullinfo[i]
print "%f \t %d \t %r"%(temp2.dist,temp2.num,temp2.pos)
#输出结果
--
You were never satisfied
No matter how I tried
※ 修改:·chumsdock 于 Oct 15 13:33:15 修改本文·[FROM: 219.224.174.181]
※ 来源:·BBS 听涛站 tingtao.net·[FROM: 219.224.174.181]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:1.090毫秒