def update_potential(p):    
    # Update potential
    a = 0
    for fn in range(len(g.pot_functions['functions'])): 
      if(g.pot_functions['functions'][fn]['fit_type'] == 1):     # NODE SPLINE    
        ###NEED TO REDO MAYBE??###
      
        # Calc b
        b = a + g.pot_functions['functions'][fn]['fit_size']          
        # LOAD ORIGINAL
        g.pot_functions['functions'][fn]['points'] = numpy.copy(g.pot_functions['functions'][fn]['points_original'])        
        # VARY SPLINE
        potential.vary_tabulated_points(fn, p[a:b])
        # Update a
        a = b        
      elif(g.pot_functions['functions'][fn]['fit_type'] == 2):   # ANALYTIC  
        b = a + g.pot_functions['functions'][fn]['fit_size'] 
        # Make Analytic Points
        g.pot_functions['functions'][fn]['a_params'][:] = p[a:b]
        potential.make_analytic_points_inner(fn)
        a = b    
      
    # Rescale density functions 0.0 to 1.0  
    if(pf.rescale_on):
      rescale_density.run()

    
    # Update efs and bp modules
    potential.efs_add_potentials()     # Load potentials
    potential.bp_add_potentials()      # Load potentials
    def spline_cycles_prep():

        # Number of Nodes
        pf.pw_per_f = 20

        # Load Best
        pf.update_potential(pf.ps[-5, :])

        # Prep each with a spline
        yvar = numpy.zeros((pf.pw_per_f, ), )
        for fn in range(len(g.pot_functions['functions'])):
            potential.vary_tabulated_points(fn, yvar)

        # Update potential fit settings
        for fn in range(len(g.pot_functions['functions'])):
            pw = 0
            # Replace original points with new points
            g.pot_functions['functions'][fn]['points_original'] = numpy.copy(
                g.pot_functions['functions'][fn]['points'])
            # fit type to spline
            g.pot_functions['functions'][fn]['fit_type'] = 1
            g.pot_functions['functions'][fn]['fit_size'] = pf.pw_per_f
            g.pot_functions['functions'][fn]['fit_parameters'] = numpy.zeros((
                2,
                pf.pw_per_f,
            ), )
            g.pot_functions['functions'][fn]['fit_mult'] = 1.0
            pw = pw + pf.pw_per_f
 def set_up():  
   # If a spline fit, convert into a spline 
   for fn in range(len(g.pot_functions['functions'])):       
     if(g.pot_functions['functions'][fn]['fit_type'] == 1): 
       potential.vary_tabulated_points(fn)
 
   # Setup EFS
   efs.init()                         # Initialise (allocate arrays)
   potential.efs_add_potentials()     # Load potentials
   configs.efs_add_config()           # Add configs
   
   # Setup BP    
   bp_calc.init()
   potential.bp_add_potentials()
   b_props.bp_add()
   
   # Rescale density function
   rescale_density.run()