def CalcTangent(i, pivots, Eprev, Ethis, Enext, L): dispPrev = med.PeriodicDisplacement(pivots[i], pivots[i - 1], L) dispNext = med.PeriodicDisplacement(pivots[i + 1], pivots[i], L) dispPrevNorm = np.linalg.norm(dispPrev) dispNextNorm = np.linalg.norm(dispNext) if Enext > Ethis != (Eprev > Ethis): #is not an extremum tangent = dispNext / dispNextNorm if Enext > Eprev else dispPrev / dispPrevNorm else: #if it is an extremum, apply smoothening delta = np.abs([Enext - Ethis, Eprev - Ethis]) deltamax = np.max(delta) deltamin = np.min(delta) tangent = dispNext * deltamax + dispPrevNorm * deltamin if Enext > Eprev else dispNext * deltamin + dispPrevNorm * deltamax tangent /= np.linalg.norm(tangent) return tangent, dispPrevNorm, dispNextNorm
delta = 1. / args.npoints alphas = np.arange(0, 1 + delta, delta) energies = [] distances = [] for alpha in alphas: interpPos = med.PeriodicInterpPoints(pos2, pos1, L, alpha) snap.particles.position[:] = interpPos system.restore_snapshot(snap) hoomd.run(2) energy = analyzer.query('potential_energy') print(energy) energies.append(energy) distances.append(med.PeriodicDistance(pos1, interpPos, L)) #Vector of all the particle displacements disp = med.PeriodicDisplacement(pos1, pos2, L) # # FIGURES # from matplotlib import pyplot as plt from mpl_toolkits.mplot3d import Axes3D import seaborn as sns #Barrier from the linear interpolation fig, ax1 = plt.subplots() ax1.set_xlabel('distance') ax1.set_ylabel('energy') ax1.plot(distances, energies) ax1.tick_params(axis='x') ax2 = ax1.twiny() # instantiate a second axes that shares the same x-axis
msd=np.zeros(trajDuration, dtype=np.float64) Fk=np.zeros(trajDuration,dtype=np.float64) ################################################################ # # SAVE TRAJECTORY AND CALCULATE MEAN SQUARE DISPLACEMENT # ################################################################ for iframe in range(0, trajDuration, 1): ## we only look 1 frame every "every_forMemory" frame, to save memory: trajectory[iframe] = np.array(hoomdTraj[iframe*every_forMemory].particles.position, dtype=np.float64) time=np.int64(hoomdTraj[iframe*every_forMemory].configuration.step)-time0 times[iframe]=time*every_forMemory*dt msd[iframe]=med.PeriodicSquareDistance(trajectory[iframe], initialPositions, L)/Natoms all_displacements=med.PeriodicDisplacement(trajectory[iframe], initialPositions, L) Fk[iframe]=med.ComputeFkt(n1, n2, n3, L, all_displacements) HoomdFlow.close() ################################################################ # # SAVE MSD and FkT # ################################################################ # # MSD and Fk(t) # #Remove preexisting output files to avoid conflicts namemsd_txt='msd'+label+'.txt'
print('From the energy barrier height I expect it to be: ', (energies[imax] - energies[-1]) / ek) print('------') else: print('temperature = ', args.temperature) # Save the path np.save('./test-output/pivots.npy', pivots) # # Now some measurements on the path # # Histogram of the motion with the transition state, and participation ratios import seaborn as sns disp_inimax = np.linalg.norm(med.PeriodicDisplacement(pivots[0], pivots[imax], L), axis=1) disp_maxfin = np.linalg.norm(med.PeriodicDisplacement(pivots[imax], pivots[-1], L), axis=1) disp_inifin = np.linalg.norm(med.PeriodicDisplacement(pivots[0], pivots[-1], L), axis=1) ipr_inimax = med.InvPRdist(disp_inimax) ipr_maxfin = med.InvPRdist(disp_maxfin) ipr_inifin = med.InvPRdist(disp_inifin) nmovedIPR = int(round(2.0 / (ipr_inimax + ipr_maxfin))) disps_pivots = np.ndarray((len(pivots) - 1, Natoms)) ipr_pivots = np.ndarray((len(pivots) - 1)) for i in range(len(pivots) - 1):