def input2xyz(abivar, basename, datasets):
    """
    Take an input object 'av' and write the
    corresponding XYZ file in the given
    'basename'
    """
    for idts in datasets:
        struct = abivar.get_structure(idts)
        natom = struct.natom
        if idts == '':
            filep = basename + '.xyz'
        else:
            filep = basename + '_DS' + str(idts) + '.xyz'
        wf = open(filep, 'w')
        wf.write(str(natom) + '\n\n')
        for iatom in range(natom):
            wf.write('%s %16.8f %16.8f %16.8f\n' % (struct.symbols[iatom],
                struct.positions[iatom, 0], struct.positions[iatom, 1],
                struct.positions[iatom, 2]))
        wf.close()
