예제 #1
0
def quench_single_CVODE_inverse_power_julia(coord_file_name, foldpath,
                                            sub_fold_name, optimizer,
                                            opt_param_dict):
    """
    quenches a single system through mxopt
    Parameters
    ----------
    coord_file_name: string
        name of the path to the coordinates
    foldername: str
        folder definining the run
    sub_fold_name:
        name of subfolder where the run data is stored
    optimizer: optimizer
        quench
    opt_param_dict: dict
        dictionary of parameters for the optimizer
    """

    sysparams = load_params(foldpath)

    # path to quench coords
    quench_coords_path = (foldpath + "/" + sub_fold_name + "/" + "ensemble/" +
                          coord_file_name)
    quench_coords = np.loadtxt(quench_coords_path)
    radii = get_hs_radii(foldpath, sub_fold_name)

    box_length = get_box_length(radii, sysparams.ndim.value,
                                sysparams.phi.value)
    box_length

    boxv = np.array([box_length] * sysparams.ndim.value)

    ncellx_scale = get_ncellsx_scale(radii, boxv)

    # potential = InversePower(sysparams.power.value,
    #                          sysparams.eps.value,
    #                          use_cell_lists=False,
    #                          ndim=sysparams.ndim.value,
    #                          radii=radii * 1.0,
    #                          boxvec=boxv)

    print(radii)
    pot = Main.pot.InversePower(
        sysparams.power.value,
        sysparams.eps.value,
        radii,
        ndim=sysparams.ndim.value,
        boxvec=boxv,
        use_cell_lists=True,
        ncellx_scale=ncellx_scale,
    )

    ppot = Main.PythonPotential(pot)

    func = Main.gradient_problem_function_pele_b(ppot)
    ba = Main.BasinAssigner(opt_param_dict["rtol"], opt_param_dict["atol"],
                            opt_param_dict["tol"])
    res = Main.find_corresponding_minimum(ba, func, quench_coords, int(10**8),
                                          ppot)

    try:
        None
    except:
        print("exception occured")
        # if exception occurs, treat as failure. this is for rattlers
        # not enough failures occur that it would make a difference to not just assume this never happens
        # but we shoudl switch this out
        # but jic
        return (quench_coords, False, 0, 0, 0, 0, 0)

    results = (res.coords, res.success, res.ngeval, res.nsolve, res.nheval, 0,
               0)

    print(quench_coords_path)
    return results
예제 #2
0
def quench_single_mxopt_inverse_power_julia(coord_file_name, foldpath,
                                            sub_fold_name, optimizer,
                                            opt_param_dict):
    """
    quenches a single system through mxopt
    Parameters
    ----------
    coord_file_name: string
        name of the path to the coordinates
    foldername: str
        folder definining the run
    sub_fold_name:
        name of subfolder where the run data is stored
    optimizer: optimizer
        quench
    opt_param_dict: dict
        dictionary of parameters for the optimizer
    """

    sysparams = load_params(foldpath)

    # path to quench coords
    quench_coords_path = (foldpath + "/" + sub_fold_name + "/" + "ensemble/" +
                          coord_file_name)
    quench_coords = np.loadtxt(quench_coords_path)
    radii = get_hs_radii(foldpath, sub_fold_name)

    box_length = get_box_length(radii, sysparams.ndim.value,
                                sysparams.phi.value)

    boxv = np.array([box_length] * sysparams.ndim.value)

    ncellx_scale = get_ncellsx_scale(radii, boxv)

    # potential = InversePower(sysparams.power.value,
    #                          sysparams.eps.value,
    #                          use_cell_lists=False,
    #                          ndim=sysparams.ndim.value,
    #                          radii=radii * 1.0,
    #                          boxvec=boxv)
    pot = Main.pot.InversePower(
        sysparams.power.value,
        sysparams.eps.value,
        radii,
        ndim=sysparams.ndim.value,
        boxvec=boxv,
        use_cell_lists=False,
        ncellx_scale=ncellx_scale,
    )

    ppot = Main.PythonPotential(pot)
    nls = Main.NewtonLinesearch(ppot, quench_coords, opt_param_dict["tol"])
    mxd = Main.Mixed_Descent(
        ppot,
        Main.CVODE_BDF(),
        nls,
        quench_coords,
        opt_param_dict["T"],
        opt_param_dict["rtol"],
        opt_param_dict["conv_tol"],
        opt_param_dict["tol"],
    )
    # Main.run_b(mxd, 10000)
    try:
        Main.run_b(mxd, 10000)
    except:
        print("exception occured")
        # if exception occurs, treat as failure. this is for rattlers
        # not enough failures occur that it would make a difference to not just assume this never happens
        # but we shoudl switch this out
        # but jic
        return (quench_coords, False, 0, 0, 0, 0, 0)
    results = (
        mxd.optimizer.x0,
        mxd.converged,
        mxd.n_g_evals,
        mxd.iter_number,
        mxd.n_h_evals,
        0,
        0,
    )
    print(quench_coords_path)
    return results
예제 #3
0
def quench_single_inverse_power(coord_file_name, foldpath, sub_fold_name,
                                optimizer, opt_param_dict):
    """
    figures out the minimum correspoding to a set of particle coords
    Parameters
    ----------
    coord_file_name: string
        name of the path to the coordinates
    foldername: str
        folder definining the run
    sub_fold_name:
        name of subfolder where the run data is stored
    optimizer: optimizer
        quench
    opt_param_dict: dict
        dictionary of parameters for the optimizer
    """

    sysparams = load_params(foldpath)

    # path to quench coords
    quench_coords_path = (foldpath + "/" + sub_fold_name + "/" + "ensemble/" +
                          coord_file_name)
    quench_coords = np.loadtxt(quench_coords_path)
    radii = get_hs_radii(foldpath, sub_fold_name)
    box_length = get_box_length(radii, sysparams.ndim.value,
                                sysparams.phi.value)

    boxv = [box_length] * sysparams.ndim.value
    ncellx_scale = get_ncellsx_scale(radii, boxv)

    potential = InversePower(
        sysparams.power.value,
        sysparams.eps.value,
        use_cell_lists=False,
        ndim=sysparams.ndim.value,
        radii=radii * 1.0,
        boxvec=boxv,
    )

    boxv = [box_length] * sysparams.ndim.value
    # ncellx_scale = get_ncellsx_scale(radii, boxv)

    print(potential.getEnergy(quench_coords))
    ret = optimizer(quench_coords, potential, **opt_param_dict)
    try:
        ret = optimizer(quench_coords, potential, **opt_param_dict)
    except:
        print("exception occured")
        # if exception occurs, treat as failure. this is for rattlers
        # not enough failures occur that it would make a difference to not just assume this never happens
        # but we shoudl switch this out
        # but jic
        return (quench_coords, False, 0, 0, 0, 0, 0)

    # This exists because some runs don't have hessian evaluations
    try:
        ret["nhev"]
    except:
        ret["nhev"] = 0

    # mixed optimizer statistics
    try:
        ret["n_phase_1"]
    except:
        ret["n_phase_1"] = 0
    # mixed optimizer statistics
    try:
        ret["n_phase_2"]
    except:
        ret["n_phase_2"] = 0

    print(ret.coords - quench_coords)
    print(opt_param_dict)
    results = (
        ret.coords,
        ret.success,
        ret.nfev,
        ret.nsteps,
        ret.nhev,
        ret.n_phase_1,
        ret.n_phase_2,
    )
    print(quench_coords_path)
    return results
예제 #4
0
def compare_runs_2d(fnames, foldpath, subfoldname, run_a, run_b, ctol):
    """ compares runs on points with names fnames between
        runs done with 2 minima find routines run_a and run_b

    Args:
       fnames filenames
       run_a run a 
       run_b run b

    Returns:
        percentage of minima that are the same

    """
    # TODO: replace this
    sysparams = load_params(foldpath)
    radii = get_hs_radii(foldpath, subfoldname)
    box_length = get_box_length(radii, sysparams.ndim.value,
                                sysparams.phi.value)

    subfoldpath = foldpath + "/" + subfoldname
    data_path_a = subfoldpath + "/" + run_a
    data_path_b = subfoldpath + "/" + run_b
    potential = InversePower(
        sysparams.power.value,
        sysparams.eps.value,
        use_cell_lists=False,
        ndim=sysparams.ndim.value,
        radii=radii * 1.0,
        boxvec=[box_length, box_length],
    )
    minima_checker = CheckSameMinimum(ctol,
                                      dim=2,
                                      boxl=box_length,
                                      hs_radii=radii,
                                      potential=potential)

    same_minimum_check_l = []
    for fname in fnames:
        print(fname)
        minimum_a = np.loadtxt(data_path_a + "/" + fname, delimiter=",")
        minimum_b = np.loadtxt(data_path_b + "/" + fname, delimiter=",")
        boxed_minimum_a = minima_checker.box_reshape_coords(minimum_a)
        boxed_minimum_b = minima_checker.box_reshape_coords(minimum_b)
        # get first index that is not a rattler
        rattlers_exist, rattlers = minima_checker._find_rattlers(minimum_a)
        print(rattlers)
        # number of non rattlers to ensure we're not in a fluid state
        n_non_rattlers = np.count_nonzero(rattlers)
        # only do calculations if all particles aren't rattlers
        if n_non_rattlers != 0:
            first_non_rattler = (np.argwhere(rattlers != 0).T)[0, 0]
            # TODO: rewrite the CheckSameMinimum function
            # load and make sure the particle being aligned is not a rattler later
            # we're choosing -1 because that's always going to be of radius 1.4
            #  particle
            aligned_minimum_b = minima_checker.align_structures(
                boxed_minimum_a, boxed_minimum_b, part_ind=first_non_rattler)
            same_minimum_check = minima_checker.check_same_structure(
                aligned_minimum_b, boxed_minimum_a, rattlers)
            same_minimum_check_l.append(same_minimum_check)

    fraction_same_minimum = np.mean(same_minimum_check_l)
    print(fraction_same_minimum)
    return fraction_same_minimum