Generate_mc_rattled_structures error

I wanted to read the optimized POSCAR file and use generate_mc_rattled_structures() to generate structures, but I ran into some problems. I don’t know if it’s the POSCAR file or the input parameters to generate_mc_rattled_structures()

from import read   # ASE reading and writing POSCAR with selective dynamics
from import write
from import bulk
from ase.calculators.emt import EMT
from hiphive.structure_generation import generate_mc_rattled_structures

# parameters
n_structures = 5
cell_size = 4
rattle_std = 0.03
minimum_distance = 2.3

prim = read('POSCAR')
atoms_ideal = prim.repeat(cell_size)

# generate structures
structures = generate_mc_rattled_structures(atoms_ideal, n_structures, rattle_std, minimum_distance)

Results from run of the code

Atoms(symbols='C2', pbc=True, cell=[[1.2340150698661443, -2.1373767983138197, 0.0], [1.2340150698661443, 2.1373767983138197, 0.0], [0.0, 0.0, 19.998293]])
Traceback (most recent call last):
  File "C:/Users/Tung/Desktop/tutorial_graphene/", line 28, in <module>
    structures = generate_mc_rattled_structures(atoms_ideal, n_structures, rattle_std, minimum_distance)
  File "D:\Python38\lib\site-packages\hiphive\structure_generation\", line 108, in generate_mc_rattled_structures
    displacements = mc_rattle(atoms_tmp, rattle_std, d_min, seed=seed,
  File "D:\Python38\lib\site-packages\hiphive\structure_generation\", line 214, in mc_rattle
    raise Exception('Maxmium attempts for atom {}'.format(i))
Exception: Maxmium attempts for atom 0

1.2340150698661443 -2.1373767983138197 0.0000000000000000
1.2340150698661443 2.1373767983138197 0.0000000000000000
0.0000000000000000 0.0000000000000000 19.9982930000000003
0.6666666666666666 0.3333333333333333 0.5000000000000000
0.3333333333333334 0.6666666666666667 0.5000000000000000

I think the problem is that you set the minimum distance to 2.3, but your ideal structure already contains much smaller distances than this so no trial displacements work and thus you reach the maximum number of attempts.

You can check out the examples and documentation for the mc-rattle function on the hiphive website to understand the input parameter, e.g. here.

Also note that prim.repeat(cell_size) will repeat the system in all directions (x, y, z), looking at the structure maybe you only want to repeat in the xy plane?

Thanks for your reply!
As a beginner, I want to use Fourth-order Force Constants to calculate lattice thermal conductivity through ShengBTE. Can you provide an example of using Hiphive to compute Fourth-order Force Constants in the ShengBTE format of a particular POSCAR?

For extracting 4th order you can see the tutorial here, also see the FAQ.
There are also many more examples on the hiphive website that you can take a look at, e.g. how to write force constants in different formats here.

hiphive supports writing 3rd order force constants to shengBTE format, but not 4th order.