Skip to content

Instantly share code, notes, and snippets.

@janoliver
Last active January 7, 2019 14:06
Show Gist options
  • Save janoliver/10492c26e58cbec30b743361c1d49c84 to your computer and use it in GitHub Desktop.
Save janoliver/10492c26e58cbec30b743361c1d49c84 to your computer and use it in GitHub Desktop.
#!/bin/env python
import gc
from ase.build import bulk, cut
from gpaw import GPAW, mpi
my_comm = mpi.world.new_communicator([mpi.world.rank])
my_output = "log_%d" % mpi.world.rank
def chunker(seq, size):
return (seq[pos:pos + size] for pos in range(0, len(seq), size))
calculations = []
for i in range(100):
b = bulk("GaP", crystalstructure="zincblende", cubic=True, a=5.4504)
cell = cut(b, a=(2,0,0), b=(0,2,0), c=(0,0,1))
cell.set_pbc((True, True, False))
pos = cell.positions.copy()
cell.rattle(seed=i)
cell.positions[:,2] = pos[:,2]
calculations.append(cell)
for ichunk, group in enumerate(chunker(calculations, mpi.world.size)):
if mpi.world.rank < len(group):
calc = GPAW(mode='pw', xc='LDA', h=0.3, communicator=my_comm, txt=my_output)
atoms = group[mpi.world.rank].copy()
atoms.set_calculator(calc)
print("Success!", ichunk, mpi.world.rank, atoms.get_potential_energy())
del atoms
del calc
gc.collect()
mpi.world.barrier()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment