I am beginning a code to create an array of coordinates of an FCC lattice. Here is my code so far, with helpful print statements:
def init_FCC(a, x_rep,y_rep,z_rep):
n_atoms = 4*x_rep*y_rep*z_rep
UC = array([[0, 0, 0],[(a/2),(a/2),0],[(a/2), 0, (a/2)],[0,(a/2),(a/2)]])
coords = UC[:]
print(array_equal(coords,UC))
for n in range(x_rep):
if array_equal(coords,UC) == False:
coords = vstack((coords, UC))
UC[:,0] += a
print(UC,id(UC))
print(coords,id(coords),'\n',60*'*')
return(coords)
When using the function, for example a=5, x_rep=3, the print statements indicate that the if statement is never True, i.e. the arrays 'UC' and 'coords' are always the same. But as you can see, directly after the if statement I alter the first column of UC, but not coords, each time the for loop iterates. I checked the ids of each to ensure they are different memory locations. Why is the array coords changing when I alter UC, and how do I prevent this? As an after-note, I know this is probably not the best way to accomplish my end goal of creating an FCC lattice but I wanted to make my own code.
Thanks.
coordsright here:coords = vstack((coords, UC)), hence the new memory location.array,array_equalorv_stackare defined.