Creating a 3D lattice with periodic boundaries - create every combination of (x,y,z)
<p>I am trying to create a program that puts identical non-overlapping particles of diameter d in a cubic (3d) lattice with periodic boundary conditions.</p>

<p>Really what this means is I need a program that creates an XYZ file that will look something like the below but will go through every comibination:</p>

<pre><code>H 0.0000000.0000005.000000
H 0.0000000.0000006.000000
H 0.0000000.0000007.000000
H 0.0000000.0000008.000000
H 0.0000000.0000009.000000
</code></pre>

<p>Now for some reason, my code below is keeping my z value 0 and not going through the values to create the the other combinations ...instead its only going through x and y. </p>

<pre><code>#create a file and enter first two lines
text_file=open("question1.xyz","w")
text_file.write("\n")
text_file.write("comment goes here\n")

L=10
d=1

#first particle or line will be at 0,0,0, counter used to count how many lines
x,y,z = 0,0,0
counter=0

#placing the particles
while x&lt;=L-d:
    while y&lt;=L-d:
        while z&lt;=L-d:
            text_file.write('H ')
            text_file.write('%f'%x)
            text_file.write('%f'%y)
            text_file.write('%f\n'%z)
            counter=counter+1
            z=z+d
        z=0
        y=y+d
    z,y=0,0
    x=x+d

text_file.close()

with open("question1.xyz") as infile:
    with open("outputfile.xyz","w") as outfile:
        for i,line in enumerate(infile):
            if i==0:
                outfile.write('%f\n'%counter)
            else:
                outfile.write(line)
</code></pre>

<p>Any ideas on why its happening? My while statement is a little messy but i am not sure how else to do it</p>
