1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
def set_spin(x, y, z, spin):
if not valid(x, y, z):
error("not valid atom")
for K in {-1, 1}:
for L in {-1, 1}:
for M in {-1, 1}:
[xn, yn, zn] = x+K, y+L, z+M
if not valid(xn, yn, zn):
continue
neighbour = atoms.at(xn, yn, zn)
[alpha, beta] = parameters(xn, yn, zn)
deltaU = alpha * f(neighbour, s, spin) + beta * g(neighbour, s, spin)
result[write_result(xn, yn, zn)] += delt
def parameters(x, y, z):
if x < mol_left:
return [JL, bL]
if between(mol_left, x, mol_right):
return [Jml, bml]
//...
def write_result(x, y, z):
//say that result is a vector, then you may return the index to update
if x < mol_left:
return {1, 3}
return [0, 1, 0, 1, 0, 0]
|