def write_poscar(ofile, c, fract):
    """ Write POSCAR file for VASP
    NOTE: the order of atoms changes because of the sorting!
    """
    print('Written with manage_crystal', file=ofile)
    print('1', file=ofile)
    for k in range(3):
        print('%11.8f %11.8f %11.8f' % (c.matrix[k][0], c.matrix[k][1], c.
            matrix[k][2]), file=ofile)
    for e in c.element:
        print('{} '.format(e), end='', file=ofile)
    print('', file=ofile)
    for e in c.element:
        print('{} '.format(c.element_count[e]), end='', file=ofile)
    print('', file=ofile)
    if fract:
        print('direct', file=ofile)
    else:
        print('cartesian', file=ofile)
    for e in c.element:
        for i, a in enumerate(c.atom_element):
            if e == a:
                if fract:
                    print('%9.5f %9.5f %9.5f' % (c.atom_fract[i][0], c.
                        atom_fract[i][1], c.atom_fract[i][2]), file=ofile)
                else:
                    print('%9.5f %9.5f %9.5f' % (c.atom_fract[i][0], c.
                        atom_fract[i][1], c.atom_fract[i][2]), file=ofile)
    return
