Пример #1
0
def testSplineCoeff():
    import parse_potential as pp
    
    prefix = '/home/cask0/home/tsanyal/c25ld/data/cg_ff/methane/methane_wca_SPLD'
    logfile, histfile, sumfile = pp.parseFileNames(prefix)
    paramstring = pp.parseParamString(sumfile)
    h = pp.parseHist(histfile)['LD']
    
    rho_t = h[0]; rho_m = h[1] 
       
    d = alg.makeSysData(isPolymer = False, hasLJ = True)
    Sys = alg.makeSys(LDCut = 6.5, SysData = d, Prefix = 'testsys', paramstring = paramstring, fftype = 'wca')
    (nknot, spdist, spc0, spc1, spc2, spc3) = alg.getLDSpline(Sys = Sys)
    
    rho = rho_t
    dfdrho = np.zeros(len(rho))
    frho = np.zeros(len(rho))
    
    for n in range(len(rho)):
        x = (rho[n] - min(rho)) * spdist[1]
        i = max(min(int(x), nknot-2), 0)
        t = max(min(x - float(i), 1.0), 0.0)
        frho[n] = spc0[i] + t * (spc1[i] + t*(spc2[i]+t*spc3[i]))
        dfdrho[n] = spdist[1] * (spc1[i] + t * (2.*spc2[i]+t*3.*spc3[i]))
    
    fig = plt.figure
    ax1 = plt.subplot(211) ; ax2 = plt.subplot(212)
    ax1.plot(rho, frho, linewidth = 3, label = r'$f(\rho)$'); ax1.legend()
    ax2.plot(rho, dfdrho, linewidth = 3, label = r'$\frac{df}{d\rho}$'); ax2.legend()
Пример #2
0
def Restart(checkpt = 'SP'):
    if checkpt == 'start':
        return
    else:
        print 'Restarting from after ', checkpt
        checkptFile = Prefix + '_%s_sum.txt' % checkpt
        paramstring = pp.parseParamString(checkptFile)
        Sys.ForceField.SetParamString(paramstring)
        Sys.ForceField.Update()
        for p in Sys.ForceField: p.FreezeParam()
        
        if checkpt == 'SP': 
            Pspline.UnfreezeParam()
        
        if checkpt == 'SPLD':
            Pspline.SetParam(Knots = 0.)
            Plocaldensity.UnfreezeParam()
            if not Plj is None: Plj.SetParam(Epsilon = SysData['poly_dict']['LJEpsilon'])
        
        if checkpt == 'LD':
            Plocaldensity.UnfreezeParam()
Пример #3
0
def Restart(checkpt = 'SP'):
    #possible options for checkpt are 'start', 'SP' or 'SPLD'
    #for 'start', it will run from the start with 0 knot values
    #for 'SP' it will run SPLD with previously obtained SP knots
    #for 'SPLD' it will run SPLD with previously obtained SPLD knots
    if checkpt == 'start':
        return
    else:
        checkptFile = Prefix + '_%s_sum.txt' % checkpt
        if os.path.isfile(checkptFile):
            paramstring = pp.parseParamString(checkptFile)
            Sys.ForceField.SetParamString(paramstring)
            Sys.ForceField.Update()
            for p in Sys.ForceField: p.FreezeParam()
            if checkpt == 'SP': 
                Pspline.UnfreezeParam()
            if checkpt == 'SPLD': 
                Pspline.UnfreezeParam()
                Plocaldensity.UnfreezeParam()
        else:
            raise IOError('%s not found' % checkptFile)    
Пример #4
0
LDCut = float(sys.argv[9])

#MD iteration settings
if isPolymer:
    NStep = NStep_polymer
else:
    NStep = NStep_methane

#system parameters
SysData = alg.makeSysData(isPolymer = isPolymer, hasLJ = hasLJ, N_mon = N_mon, N_water = N_water)
TempSet = 298.0
Delta = 1.2

#CG forcefield parameters
cg_ff_file = cgffPrefix + '_sum.txt'
paramstring = pp.parseParamString(cg_ff_file)

#boxlength extracted from AA traj
BoxL = pickleTraj(LammpsTraj).FrameData['BoxL']

#create the system object
Sys = alg.makeSys(LDCut = LDCut, SysData = SysData, fftype = fftype, BoxL = BoxL, Prefix = Prefix, paramstring = paramstring, Delta = 1.2)

#initialize system
sim.system.init.positions.CubicLattice(Sys, Random = 0.1)
sim.system.init.velocities.Canonical(Sys, Temp = TempSet)

##different MD steps
Int = Sys.Int

#energy minimization
Пример #5
0
BoxL = Trj_AA.FrameData['BoxL'][0]

#begin looping over different LD cutoffs
for i, LDCut in enumerate(LDCuts):
	
	print '\n\nLDCut = %g\n' % LDCut
	
	#calculate coefficients
	(coeff, dcoeff) = alg.calcCoeff(LDCut = LDCut, Delta = 1.2)

	#get AA and CG trj
	Trj_CG = pickleTraj(base_fmt['cg_trj'] % (fftype, i))
	
	#get Spline Coeffs for CG forcefield
	ffield_CG = base_fmt['cg_ff'] % (fftype, i)
	paramstring = parse_potential.parseParamString(ffield_CG)
	Sys = alg.makeSys(LDCut = LDCuts[i], Delta = Delta, BoxL = BoxL, fftype = fftype, Prefix = 'ldsplinecoeff',
                      paramstring = paramstring, sample_trajtype = 'CG', eval_trajtype = 'CG', SysData = SysData)

	(nknot, spdist, spc0, spc1, spc2, spc3) = alg.getLDSpline(Sys = Sys)

	for key in TrjIter.keys():
	   if TrjIter[key][1] == -1:
	       if key == 'AA': TrjIter[key][1] = len(Trj_AA)
	       if key == 'CG': TrjIter[key][1] = len(Trj_CG)
	  
	FrameRange_AA = range(TrjIter['AA'][0], TrjIter['AA'][1], TrjIter['AA'][2])
	FrameRange_CG = range(TrjIter['CG'][0], TrjIter['CG'][1], TrjIter['CG'][2])
	NFrames_AA = len(FrameRange_AA); NFrames_CG = len(FrameRange_CG)
	
	#frame stepping
Пример #6
0
#set up Srel optimizer
Sys.TempSet = TempSet
Opt = sim.srel.OptimizeTrajClass(Sys, Map, Traj = Trj, SaveLoadArgData = True, FilePrefix = Prefix)
sim.srel.optimizetraj.PlotFmt = 'svg'
Opt.MinReweightFrac = 0.2

#lock all potentials in place
def ResetPotentials():
	print "Resetting all potentials to base case and freezing."
	if not Pspline is None: Pspline.SetParam(Knots = 0.)
	if not Plocaldensity is None:  Plocaldensity.SetParam(Knots = 0.)
	if not Plj is None: Plj.SetParam(Epsilon = 0.)
	for ptype in Sys.ForceField:
		ptype.FreezeParam()

#srel_minimzation
ResetPotentials()
Opt.Reset()
Opt.FilePrefix = Prefix + '_SPLD'
print "\n\nOptimizing for the case: SPLD"
s = pp.parseParamString('%s_SP_sum.txt' % Prefix)
Sys.ForceField.SetParamString(s)
Pspline.UnfreezeParam()
Plocaldensity.UnfreezeParam()
Sys.ForceField.Update()

print Sys.ForceField.ParamString()

Opt.RunConjugateGradient(StepsEquil = NStep['Equil'], StepsProd = NStep['Prod'], StepsStride = NStep['Freq']) 
Пример #7
0
serial_index = {'AA': (0, poly_dict['N_mon']*poly_dict['N_poly']), 
                'CG': (0, poly_dict['N_mon']*poly_dict['N_poly'])} #always using a mapped traj

#extract all necessary AA data
Trj_AA = pickleTraj(LammpsTraj)
BoxL = Trj_AA.FrameData['BoxL']

#begin looping over different LD cutoffs
for i, LDCut in enumerate(LDCuts[0:-1]):
    
    print '\n\nLDCUTs = (%g, %g)\n' % (LDCuts[i], LDCuts[i+1])
  
    #extract all necessary CG data
    sumfile1 = base_fmt['cg_ff'] % (fftype, i); sumfile2 = base_fmt['cg_ff'] % (fftype, (i+1))
    trajfile1 = base_fmt['cg_trj'] % (fftype, i) ; trajfile2 = base_fmt['cg_trj'] % (fftype, (i+1))
    ParamString1 = parse_potential.parseParamString(sumfile1); ParamString2 = parse_potential.parseParamString(sumfile2)
    Trj_CG_1 = pickleTraj(trajfile1); Trj_CG_2 = pickleTraj(trajfile2)
    
    #create systems with forcefields of LDCuts i and i+1
    Sys1 = alg.makeSys(LDCut = LDCuts[i], Delta = Delta, BoxL = BoxL, fftype = fftype, Prefix = 'bennettsys1',
                       paramstring = ParamString1, sample_trajtype = 'CG', eval_trajtype = 'CG', SysData = SysData)
                       
    Sys2 = alg.makeSys(LDCut = LDCuts[i+1], Delta = Delta, BoxL = BoxL, fftype = fftype, Prefix = 'bennettsys2',
                       paramstring = ParamString2, sample_trajtype = 'CG', eval_trajtype = 'CG', SysData = SysData)
                      
    # block average
    if not doBlockAvg: NBlocks = 1
    for j, b in enumerate(range(NBlocks)):
    	print '\n======== BLOCK %d ==============\n' % b
    	
    	block_start_AA = b * int(len(Trj_AA)/NBlocks)