实际上,问题在于我试图获取单元格中原子位置的列表并构建相应的超级单元格,给定输入次数以重复细胞在每个方向。更新3D数组时出现意外的行为
这导致循环结构:
#Create Every Unit Cell in SuperCell
aNum=2
bNum=2
cNum=2
atomPos = copy.deepcopy(atomPositions)
for l in range(len(atomPos)):
index=0
for i in range(cNum):
for j in range(bNum):
for k in range(aNum):
for _ in range(numEachAtom[l]):
atomPositions[l][index][0] = atomPos[l][index][0] + 1*k
atomPositions[l][index][1] = atomPos[l][index][1] + 1*j
atomPositions[l][index][2] = atomPos[l][index][2] + 1*i
print atomPositions[0][0]
index += 1
凡atomPositions
是3D阵列,使得: atomPositions[atomtype=l][atom=index][atomposition=0] = [x,y,z]
和打印语句是用于诊断目的。
问题是,从print语句看来,atomPositions[0][0]
的变化比原子类型更频繁,而且索引似乎正确更新,我简直不明白这一点。
为什么atomPositions[0][0]
的更改频率比l
?
最初我遇到了修改正在迭代的列表的问题,因此在开始时深度复制。任何意见将不胜感激!
P.S.这是我第一次问一个问题,我在Python一个完整的初学者,所以请随时对我缺乏格式化/清晰度/风格等发表意见
编辑: 年初的一个例子输出为numEachAtom=[4,6]
:
[0.17611251675504244, 0.17611251675504244, 0.17611251675504244]
[0.17611251675504244, 0.17611251675504244, 0.17611251675504244]
[0.17611251675504244, 0.17611251675504244, 0.17611251675504244]
[0.17611251675504244, 0.17611251675504244, 0.17611251675504244]
[1.1761125167550424, 0.17611251675504244, 0.17611251675504244]
[1.1761125167550424, 0.17611251675504244, 0.17611251675504244]
[1.1761125167550424, 0.17611251675504244, 0.17611251675504244]
[1.1761125167550424, 0.17611251675504244, 0.17611251675504244]
[0.17611251675504244, 1.1761125167550424, 0.17611251675504244]
[0.17611251675504244, 1.1761125167550424, 0.17611251675504244]
[0.17611251675504244, 1.1761125167550424, 0.17611251675504244]
等
编辑:如何atomPositions被初始化:
#Separate out positions of different atom types
atomPositions = []
counter=0
for i,atomN in enumerate(numEachAtom):
atomPositions.append(origAtomPositions[counter:counter+atomN])
counter += atomN
编辑:依赖等
import sys
import scipy as sp
from scipy import *
import copy
编辑: atomPositions [0]初始化为
[[ 0.17611252 0.17611252 0.17611252]
[ 0.32388748 0.32388748 0.32388748]
[ 0.42611252 0.42611252 0.42611252]
[ 0.07388748 0.07388748 0.07388748]
[ 0.17611252 0.17611252 0.17611252]
[ 0.32388748 0.32388748 0.32388748]
[ 0.42611252 0.42611252 0.42611252]
[ 0.07388748 0.07388748 0.07388748]
[ 0.17611252 0.17611252 0.17611252]
[ 0.32388748 0.32388748 0.32388748]
[ 0.42611252 0.42611252 0.42611252]
[ 0.07388748 0.07388748 0.07388748]
[ 0.17611252 0.17611252 0.17611252]
[ 0.32388748 0.32388748 0.32388748]
[ 0.42611252 0.42611252 0.42611252]
[ 0.07388748 0.07388748 0.07388748]
[ 0.17611252 0.17611252 0.17611252]
[ 0.32388748 0.32388748 0.32388748]
[ 0.42611252 0.42611252 0.42611252]
[ 0.07388748 0.07388748 0.07388748]
[ 0.17611252 0.17611252 0.17611252]
[ 0.32388748 0.32388748 0.32388748]
[ 0.42611252 0.42611252 0.42611252]
[ 0.07388748 0.07388748 0.07388748]
[ 0.17611252 0.17611252 0.17611252]
[ 0.32388748 0.32388748 0.32388748]
[ 0.42611252 0.42611252 0.42611252]
[ 0.07388748 0.07388748 0.07388748]
[ 0.17611252 0.17611252 0.17611252]
[ 0.32388748 0.32388748 0.32388748]
[ 0.42611252 0.42611252 0.42611252]
[ 0.07388748 0.07388748 0.07388748]]
嘿,这是一个很好的问题!提供一个简短的输出示例可能会有所帮助,以便人们可以以具体的方式查看您的问题。 – Marcin 2012-03-13 10:59:07
如何初始化'atomPositions'? – sth 2012-03-13 10:59:42
你能否为列表的内容提供一个工作示例? – 2012-03-13 11:01:36