def write_cp2k(in_name, file_name, vectors, atoms, temp_name):
    """
    Make a cp2k input file from a template.

    To use this, first make a template file with the name as XXX__NAME__XXX,
    the vectors as XXX__AVEC__XXX, XXX__BVEC__XXX and XXX__CVEC__XXX and the
    positions as XXX__POS__XXX.

    Parameters
    ----------
    in_name : string
        Project name
    file_name : string
        Name of the cp2k input file
    vectors : 3x3 matrix
        Lattice vectors
    atoms : list of Atom objects
        Atoms in the system
    temp_name : string
        Name of the template file


    """
    with open(temp_name) as temp_file:
        temp_content = temp_file.readlines()
    aVec = '{:10.6f} {:10.6f} {:10.6f}'.format(*vectors[0])
    bVec = '{:10.6f} {:10.6f} {:10.6f}'.format(*vectors[1])
    cVec = '{:10.6f} {:10.6f} {:10.6f}'.format(*vectors[2])
    cp2k_in = open(file_name, 'w')
    for line in temp_content:
        if 'XXX__NAME__XXX' in line:
            cp2k_in.write(line.replace('XXX__NAME__XXX', in_name))
        elif 'XXX__AVEC__XXX' in line:
            cp2k_in.write(line.replace('XXX__AVEC__XXX', aVec))
        elif 'XXX__BVEC__XXX' in line:
            cp2k_in.write(line.replace('XXX__BVEC__XXX', bVec))
        elif 'XXX__CVEC__XXX' in line:
            cp2k_in.write(line.replace('XXX__CVEC__XXX', cVec))
        elif 'XXX__POS__XXX' in line:
            for atom in atoms:
                line_str = '{:>6} {:10.6f} {:10.6f} {:10.6f}'.format(atom.
                    elem, atom.x, atom.y, atom.z)
                cp2k_in.write(line_str + '\n')
        else:
            cp2k_in.write(line)
    cp2k_in.close()
    return
