Best Python code snippet using freezegun
datetime_helpers.py
Source:datetime_helpers.py
...99 # if neither ms or ns were provided, passthru previous nanos.100 inst._nanosecond = prev_nanos101 return inst102 @property103 def nanosecond(self):104 """Read-only: nanosecond precision."""105 return self._nanosecond or self.microsecond * 1000106 def rfc3339(self):107 """Return an RFC3339-compliant timestamp.108 Returns:109 (str): Timestamp string according to RFC3339 spec.110 """111 if self._nanosecond == 0:112 return _to_rfc3339(self)113 nanos = str(self._nanosecond).rjust(9, "0").rstrip("0")114 return "{}.{}Z".format(self.strftime(_RFC3339_NO_FRACTION), nanos)115 @classmethod116 def from_rfc3339(cls, stamp):117 """Parse RFC3339-compliant timestamp, preserving nanoseconds....
plot_msd.py
Source:plot_msd.py
1import numpy as np2import h5py3from yaff import System, Cell4import matplotlib.pyplot as pt5from molmod.units import picosecond, angstrom, nanosecond6frac_coords_pores = np.array([[0.0,0.0,0.0],[0.5,0.5,0.5]])7n_framework_atoms = 2768with h5py.File('msd_long.h5', 'r') as f:9 loc_molecule = np.array(f['loc_molecules'])10 pos_molecule = np.array(f['pos_molecules'])11 time = np.array(f['time'])12for i in range(pos_molecule.shape[1]):13 pos_molecule[:,i,:] -= pos_molecule[0,i,:]14n_molecules = pos_molecule.shape[1]15msd_all = np.zeros((pos_molecule.shape[0], pos_molecule.shape[1]))16print(pos_molecule.shape)17for t in range(pos_molecule.shape[0]):18 dt = t+119 # Run over every molecule20 for j in range(pos_molecule.shape[1]):21 msd_tot = 022 counter = 023 # Run over every time interval24 for i in range(len(time)//dt):25 msd_tot += ((pos_molecule[(i+1)*dt-1,j,:] - pos_molecule[i*dt,j,:])**2).sum()26 counter += 127 msd_all[t,j] = msd_tot/counter28pt.clf()29pt.xlabel('Simulation time [ns]')30pt.ylabel('Mean squared displacement [\AA$^2$]')31pt.plot(time/nanosecond,(pos_molecule**2).sum(axis=1).sum(axis=1)/n_molecules/(angstrom**2), '0.5',label='total')32pt.plot(time/nanosecond,(pos_molecule[:,:,0]**2).sum(axis=1)/n_molecules/(angstrom**2), '#ef6548', label='x component')33pt.plot(time/nanosecond,(pos_molecule[:,:,1]**2).sum(axis=1)/n_molecules/(angstrom**2), '#41ab5d', label='y component')34pt.plot(time/nanosecond,(pos_molecule[:,:,2]**2).sum(axis=1)/n_molecules/(angstrom**2), '#3690c0', label='z component')35pt.plot(time[:len(time)/2]/nanosecond,msd_all[:len(time)/2,:].sum(axis=1)/n_molecules/(angstrom**2), 'k', label='multiple origin')36legend = pt.legend(loc='upper left',fancybox=True)37pt.xlim([0,5])38pt.tight_layout()39pt.savefig('ZIF8_diff_H2O_long.svg', format='svg', bbox_inches = 'tight')40pt.savefig('ZIF8_diff_H2O_long.png', bbox_inches = 'tight')41pt.clf()42pt.xlabel('Simulation time [ns]')43pt.ylabel('Diffusion coefficient [\AA$^2$/nanosecond]')44pt.plot(time[1000:]/nanosecond,(pos_molecule[1000:,:,:]**2).sum(axis=1).sum(axis=1)/(6*time[1000:])/n_molecules/(angstrom**2/nanosecond), '0.5',label='total')45pt.plot(time[1000:]/nanosecond,(pos_molecule[1000:,:,0]**2).sum(axis=1)/(6*time[1000:])/n_molecules/(angstrom**2/nanosecond), '#ef6548', label='x component')46pt.plot(time[1000:]/nanosecond,(pos_molecule[1000:,:,1]**2).sum(axis=1)/(6*time[1000:])/n_molecules/(angstrom**2/nanosecond), '#41ab5d', label='y component')47pt.plot(time[1000:]/nanosecond,(pos_molecule[1000:,:,2]**2).sum(axis=1)/(6*time[1000:])/n_molecules/(angstrom**2/nanosecond), '#3690c0', label='z component')48pt.plot(time[1000:len(time)/2]/nanosecond,(msd_all[1000:len(time)/2,:]).sum(axis=1)/n_molecules/(6*time[1000:len(time)/2])/(angstrom**2/nanosecond), 'k', label='multiple origin')49legend = pt.legend(loc='upper right',fancybox=True)50pt.xlim([0,5])51pt.tight_layout()52pt.savefig('ZIF8_D_H2O_long.svg', format='svg', bbox_inches = 'tight')...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!