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()
#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 #AA traj parameters Trj, BoxL, mappedatoms = parseTraj(LammpsTraj) #create the system object Sys = alg.makeSys(LDCut = LDCut, SysData = SysData, fftype = fftype, BoxL = BoxL, Prefix = Prefix, paramstring = None, Delta = 1.2) #initialize and energy minimize sim.system.init.positions.CubicLattice(Sys, Random = 0.1) sim.system.init.velocities.Canonical(Sys, Temp = TempSet) Int = Sys.Int Int.Method = Int.Methods.VVQuench Int.Run(NStep['Min']) #change to MD Int.Method = Int.Methods.VVIntegrate Int.Method.Thermostat = Int.Method.ThermostatLangevin Int.Method.LangevinGamma = 0.01 Sys.TempSet = TempSet #mapping function
#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 ####all-atom print '---> Calculating AA deriviative...\n'
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) block_end_AA = (b+1) * int(len(Trj_AA)/NBlocks) block_start_CG = b * int(len(Trj_CG_1)/NBlocks) block_end_CG = (b+1) * int(len(Trj_CG_1)/NBlocks)
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",