def test_fit_noisy(self): noise = np.sin(self.x) * 0.01 y2 = noise + self.y a = polymer.fit_exponential_decay(self.x, y2) assert_almost_equal(a, self.a_ref, decimal=3)
def test_fit_noisy(self): noise = np.sin(self.x) * 0.01 y2 = noise + self.y a = polymer.fit_exponential_decay(self.x, y2) assert_almost_equal(a, self.a_ref, decimal=3)
def test_fit_simple(self): a = polymer.fit_exponential_decay(self.x, self.y) assert a == self.a_ref
def test_fit_noisy(self): y2 = self.y + (np.random.random(len(self.y)) - 0.5) * 0.05 a = polymer.fit_exponential_decay(self.x, y2) assert_(np.rint(a) == self.a_ref)
def test_fit_simple(self): a = polymer.fit_exponential_decay(self.x, self.y) assert_(a == self.a_ref)
def PersistenceL(trajFile, top, backboneAtoms, NP, coef=1. / 10., stride=1., chain0Id=0, firstpoint=2): """ get persistence length of chains of indices from chain0Id to chain0Id+NP-1 coef: divide results by 10. to convert to nm since MDAnalysis uses Angstrom """ from MDAnalysis.lib.mdamath import make_whole import MDAnalysis as mda from MDAnalysis.analysis import polymer u = mda.Universe(top, trajFile) for frag in u.atoms.fragments: make_whole(frag) molecules = u.atoms.fragments filter = 'name {}'.format(*backboneAtoms) backbones = [mol.select_atoms(filter) for mol in molecules][chain0Id:chain0Id + NP] sorted_backbones = [polymer.sort_backbone(bb) for bb in backbones] persistence_length = polymer.PersistenceLength(sorted_backbones) persistence_length.run() LB = persistence_length.lb * coef if firstpoint == 0: LP = persistence_length.lp * coef else: LP = polymer.fit_exponential_decay( persistence_length.x[firstpoint:], persistence_length.results[firstpoint:]) persistence_length.fit = np.exp(-persistence_length.x[firstpoint:] / LP) LP *= coef fig, ax = plt.subplots(nrows=1, ncols=1, figsize=[3, 2]) ax.plot(persistence_length.x * coef, persistence_length.results, 'ro', label='Result') ax.plot(persistence_length.x[firstpoint:] * coef, persistence_length.fit, label='Fit') ax.vlines(LP, 0., 1, ls=':', lw=0.75) plt.text(2. * LP, 0.5 * max(persistence_length.fit), '$<cos\\theta> = exp(-n*{}/{})$'.format(round(LB, 3), round(LP, 3)), size=7) ax.set_xlim(-0.1, 1.1 * max(persistence_length.x * coef)) ax.set_xlabel(r'$n*l_b$') ax.set_ylabel(r'$C(n*l_b)$') plt.savefig('persistenceL.png', dpi=500, transparent=True, bbox_inches="tight") return LP, LB, len(sorted_backbones[0])
def test_fit_noisy(self): y2 = self.y + (np.random.random(len(self.y)) - 0.5) * 0.05 a = polymer.fit_exponential_decay(self.x, y2) assert_(np.rint(a) == self.a_ref)