def write_hoomdxml(structure, filename, ref_distance=1.0, ref_mass=1.0,
                   ref_energy=1.0, rigid_bodies=None, shift_coords=True,
                   auto_scale=False):
    """Output a HOOMD XML file.

    Parameters
    ----------
    structure : parmed.Structure
        ParmEd structure object
    filename : str
        Path of the output file.
    ref_distance : float, optional, default=1.0, units=nanometers
        Reference distance for conversion to reduced units
    ref_mass : float, optional, default=1.0, units=amu
        Reference mass for conversion to reduced units
    ref_energy : float, optional, default=1.0, units=kJ/mol
        Reference energy for conversion to reduced units
    rigid_bodies : list
        List of rigid body information. An integer value is required
        for each particle corresponding to the number of the rigid body with
        which the particle should be included. A value of None indicates the
        particle is not part of any rigid body.
    shift_coords : bool, optional, default=True
        Shift coordinates from (0, L) to (-L/2, L/2) if necessary.
    auto_scale : bool, optional, default=False
        Automatically use largest sigma value as ref_distance, largest mass value
        as ref_mass and largest epsilon value as ref_energy.

    Returns
    -------
    ReferenceValues : namedtuple
        Values used in scaling

    Example
    -------
    ref_values = ethane.save(filename='ethane-opls.hoomdxml', forcefield_name='oplsaa', auto_scale=True)
    print(ref_values.mass, ref_values.distance, ref_values.energy)


    Notes
    -----
    The following elements are always written:

    * **position** : particle positions
    * **type** : particle types
    * **mass** : particle masses (default 1.0)
    * **charge** : particle charges

    The following elements may be written if applicable:

    * **pair_coeffs** : Pair coefficients for each particle type (assumes a 12-6 LJ pair style). The following information is written for each particle type:

                        * type : particle type
                        * epsilon : LJ epsilon
                        * sigma : LJ sigma

    * **bond_coeffs** : Coefficients for each bond type (assumes a harmonic bond style). The following information is written for each bond type:

                        * type : bond type
                        * k : force constant (units of energy/distance^2)
                        * r0 : bond rest length (units of distance)

    * **bond** : system bonds
    * **angle_coeffs** : Coefficients for each angle type (assumes a harmonic angle style). The following information is written for each angle type:

                         * type : angle type
                         * k : force constant (units of energy/radians^2)
                         * theta : rest angle (units of radians)

    * **angle** : system angles
    * **dihedral_coeffs** : Coefficients for each dihedral type (assumes an OPLS dihedral style). The following information is written for each dihedral type:

                            * type : dihedral type
                            * k1, k2, k3, k4 : force coefficients (units of energy)

    * **dihedral** : system dihedrals

    * **body** : ID of the rigid body to which each particle belongs

    """
    ref_distance *= 10  # Parmed unit hack
    ref_energy /= 4.184  # Parmed unit hack
    forcefield = True
    if structure[0].type == '':
        forcefield = False
    if auto_scale and forcefield:
        ref_mass = max([atom.mass for atom in structure.atoms])
        pair_coeffs = list(set((atom.type,
                                atom.epsilon,
                                atom.sigma) for atom in structure.atoms))
        ref_energy = max(pair_coeffs, key=operator.itemgetter(1))[1]
        ref_distance = max(pair_coeffs, key=operator.itemgetter(2))[2]

    xyz = np.array([[atom.xx, atom.xy, atom.xz] for atom in structure.atoms])
    if shift_coords:
        xyz = coord_shift(xyz, structure.box[:3])

    with open(filename, 'w') as xml_file:
        xml_file.write('<?xml version="1.2" encoding="UTF-8"?>\n')
        xml_file.write('<hoomd_xml version="1.2">\n')
        xml_file.write('<!-- ref_distance (nm) ref_mass (amu) ref_energy (kJ/mol) -->\n')
        xml_file.write('<!-- {} {} {} -->\n'.format(ref_distance, ref_mass, ref_energy))
        xml_file.write('<configuration time_step="0">\n')
        _write_box_information(xml_file, structure, ref_distance)
        _write_particle_information(xml_file, structure, xyz, forcefield,
                ref_distance, ref_mass, ref_energy)
        _write_bond_information(xml_file, structure, ref_distance, ref_energy)
        _write_angle_information(xml_file, structure, ref_energy)
        _write_dihedral_information(xml_file, structure, ref_energy)
        _write_rigid_information(xml_file, rigid_bodies)
        xml_file.write('</configuration>\n')
        xml_file.write('</hoomd_xml>')

    ReferenceValues = namedtuple("ref_values", ["distance", "mass", "energy"])

    return ReferenceValues(ref_distance, ref_mass, ref_energy)
Output a HOOMD XML file.

    Parameters
    ----------
    structure : parmed.Structure
        ParmEd structure object
    filename : str
        Path of the output file.
    ref_distance : float, optional, default=1.0, units=nanometers
        Reference distance for conversion to reduced units
    ref_mass : float, optional, default=1.0, units=amu
        Reference mass for conversion to reduced units
    ref_energy : float, optional, default=1.0, units=kJ/mol
        Reference energy for conversion to reduced units
    rigid_bodies : list
        List of rigid body information. An integer value is required
        for each particle corresponding to the number of the rigid body with
        which the particle should be included. A value of None indicates the
        particle is not part of any rigid body.
    shift_coords : bool, optional, default=True
        Shift coordinates from (0, L) to (-L/2, L/2) if necessary.
    auto_scale : bool, optional, default=False
        Automatically use largest sigma value as ref_distance, largest mass value
        as ref_mass and largest epsilon value as ref_energy.

    Returns
    -------
    ReferenceValues : namedtuple
        Values used in scaling

    Example
    -------
    ref_values = ethane.save(filename='ethane-opls.hoomdxml', forcefield_name='oplsaa', auto_scale=True)
    print(ref_values.mass, ref_values.distance, ref_values.energy)


    Notes
    -----
    The following elements are always written:

    * **position** : particle positions
    * **type** : particle types
    * **mass** : particle masses (default 1.0)
    * **charge** : particle charges

    The following elements may be written if applicable:

    * **pair_coeffs** : Pair coefficients for each particle type (assumes a 12-6 LJ pair style). The following information is written for each particle type:

                        * type : particle type
                        * epsilon : LJ epsilon
                        * sigma : LJ sigma

    * **bond_coeffs** : Coefficients for each bond type (assumes a harmonic bond style). The following information is written for each bond type:

                        * type : bond type
                        * k : force constant (units of energy/distance^2)
                        * r0 : bond rest length (units of distance)

    * **bond** : system bonds
    * **angle_coeffs** : Coefficients for each angle type (assumes a harmonic angle style). The following information is written for each angle type:

                         * type : angle type
                         * k : force constant (units of energy/radians^2)
                         * theta : rest angle (units of radians)

    * **angle** : system angles
    * **dihedral_coeffs** : Coefficients for each dihedral type (assumes an OPLS dihedral style). The following information is written for each dihedral type:

                            * type : dihedral type
                            * k1, k2, k3, k4 : force coefficients (units of energy)

    * **dihedral** : system dihedrals

    * **body** : ID of the rigid body to which each particle belongs