<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def from_prev_calc(cls, prev_calc_dir, copy_wavecar=True, mode="DIAG", nbands_factor=5, ncores=16, **kwargs):
 """ Generate a set of Vasp input files for GW or BSE calculations from a directory of previous Exact Diag Vasp run. Args: prev_calc_dir (str):
 The directory contains the outputs( vasprun.xml of previous vasp run. copy_wavecar: Whether to copy the old WAVECAR, WAVEDER and associated files. Defaults to True. mode (str):
 Supported modes are "STATIC", "DIAG" (default), "GW", and "BSE". nbands_factor (int):
 Multiplicative factor for NBANDS. Only applies if mode=="DIAG". Need to be tested for convergence. ncores (int):
 numbers of cores you do calculations. VASP will alter NBANDS if it was not dividable by ncores. Only applies if mode=="DIAG". \\*\\*kwargs: All kwargs supported by MVLGWSet, other than structure, prev_incar and mode, which are determined from the prev_calc_dir. """

        vasprun, outcar = get_vasprun_outcar(prev_calc_dir)
        prev_incar = vasprun.incar
        structure = vasprun.final_structure

        nbands = int(vasprun.parameters["NBANDS"])
        if mode.upper() == "DIAG":
            nbands = int(np.ceil(nbands * nbands_factor / ncores) * ncores)

        # copy WAVECAR, WAVEDER (derivatives)
        files_to_transfer = {}
        if copy_wavecar:
            for fname in ("WAVECAR", "WAVEDER", "WFULL"):
                w = sorted(glob.glob(str(Path(prev_calc_dir) / (fname + "*"))))
                if w:
                    if fname == "WFULL":
                        for f in w:
                            fname = Path(f).name
                            fname = fname.split(".")[0]
                            files_to_transfer[fname] = f
                    else:
                        files_to_transfer[fname] = str(w[-1])

        return cls(structure=structure, prev_incar=prev_incar,
                   nbands=nbands, mode=mode,
                   files_to_transfer=files_to_transfer, **kwargs)