def pack(R, L, pf=None, n=None, rng=None, periodic=False,<EOL>beta_max=<NUM_LIT>, dL_max=<NUM_LIT>, dr_max=<NUM_LIT>):
if pf is not None:<EOL><INDENT>if pf == <NUM_LIT:0.0>:<EOL><INDENT>return np.array([]), R<EOL><DEDENT>n, pf_actual = pf_to_n(L, pf, R)<EOL><DEDENT>elif n is not None:<EOL><INDENT>if n == <NUM_LIT:0>:<EOL><INDENT>return np.array([]), R<EOL><DEDENT>pf_actual = n_to_pf(L, n, R)<EOL><DEDENT>pf_initial = min(<NUM_LIT>, pf_actual / <NUM_LIT>)<EOL>dim = L.shape[<NUM_LIT:0>]<EOL>increase_initial_ratio = (pf_actual / pf_initial) ** (<NUM_LIT:1.0> / dim)<EOL>L_0 = L * increase_initial_ratio<EOL>r_0, R = pack_simple(R, L_0, n=n, rng=rng, periodic=periodic)<EOL>mg = metro_rcp_factory(periodic, r_0, L_0, R, dr_max, dL_max, rng=rng)<EOL>print('<STR_LIT>'.format(mg.pf))<EOL>t = <NUM_LIT:0><EOL>while mg.pf < pf_actual:<EOL><INDENT>t += <NUM_LIT:1><EOL>beta = beta_max * mg.pf<EOL>mg.iterate(beta)<EOL>if not t % every:<EOL><INDENT>print('<STR_LIT>'.format(<NUM_LIT> * mg.pf))<EOL><DEDENT><DEDENT>print('<STR_LIT>'.format(<NUM_LIT> * mg.pf))<EOL>return mg.r, mg.R<EOL>
Pack a number of non-intersecting spheres into a periodic system.

    Can specify packing by number of spheres or packing fraction.

    This implementation uses the Metropolis-Hastings algorithm for an
    NPT system.

    Parameters
    ----------
    R: float
        Sphere radius.
    L: float array, shape (d,)
        System lengths.
    pf: float or None
        Packing fraction
    n: integer or None
        Number of spheres.
    rng: RandomState or None
        Random number generator. If None, use inbuilt numpy state.
    periodic: bool
        Whether or not the system is periodic.


    Metropolis-Hastings parameters
    ------------------------------
    Playing with these parameters may improve packing speed.

    beta_max: float, greater than zero.
        Inverse temperature which controls how little noiseis in the system.
    dL_max: float, 0 < dL_max < 1
        Maximum fraction by which to perturb the system size.
    dr_max: float, 0 < dr_max < 1
        Maximum system fraction by which to perturb sphere positions.

    Returns
    -------
    r: float array, shape (n, d)
        Coordinates of the centres of the spheres for a valid configuration.
    R_actual: float
        Actual sphere radius used in the packing.