def test_write_splinelib(self): """Test the write_splinelib function""" mlib = self.get_mdt_library() restype = mdt.features.ResidueType(mlib) ang = mdt.features.Chi1Dihedral(mlib, bins=mdt.uniform_bins(180, -180.0, 4.0)) m = self.get_test_mdt(mlib, [restype, ang]) mdt.write_splinelib(open('test.out', 'w'), m, 'chi1') # Make sure that valid Python code was produced code = compile(open('test.out').read(), 'test.out', 'exec') os.unlink('test.out')
def test_write_splinelib(self): """Test the write_splinelib function""" mlib = self.get_mdt_library() restype = mdt.features.ResidueType(mlib) ang = mdt.features.Chi1Dihedral( mlib, bins=mdt.uniform_bins(180, -180.0, 4.0)) m = self.get_test_mdt(mlib, [restype, ang]) with open('test.out', 'w') as fh: mdt.write_splinelib(fh, m, 'chi1') # Make sure that valid Python code was produced with open('test.out') as fh: _ = compile(fh.read(), 'test.out', 'exec') os.unlink('test.out')
# (the scaling actually does not matter, because I am eventually taking the # log and subtracting the smallest element of the final pdf, so this command # could be omitted without impact): m = m.normalize(to_pdf=True, dimensions=1, dx_dy=2.5, to_zero=True) # Take the logarithm of the smoothed frequencies # (this is safe: none of bins is 0 because of mdt.smooth()): m = m.log_transform(offset=0., multiplier=1.) # Reverse the sign: m = m.linear_transform(offset=0., multiplier=-1.) # Offset the final distribution so that the lowest value is at 0: m = m.offset_min(dimensions=1) mdt.write_splinelib(file("phi.py", "w"), m, "phi", density_cutoff=0.1) text = """ SET TICK_FONT = 5, CAPTION_FONT = 5 SET Y_TICK = -999 -999 -999 SET WORLD_WINDOW = -999 -999 -999 -999 """ m.write_asgl(asglroot='modlib-a', plot_type='PLOT2D', every_x_numbered=20, text=text, dimensions=1, plot_position=1, plots_per_page=8) os.system('asgl modlib-a')
# Start by smoothing with a uniform prior (equal weight when 10 points per bin), # producing a normalized distribution that sums to 1 (not a pdf when dx != 1): m = m.smooth(dimensions=1, weight=10) # Normalize it to get the true pdf (Integral p(x) dx = 1): # (the scaling actually does not matter, because I am eventually taking the # log and subtracting the smallest element of the final pdf, so this command # could be omitted without impact): m = m.normalize(to_pdf=True, dimensions=1, dx_dy=2.5, to_zero=True) # Take the logarithm of the smoothed frequencies # (this is safe: none of bins is 0 because of mdt.smooth()): m = m.log_transform(offset=0., multiplier=1.) # Reverse the sign: m = m.linear_transform(offset=0., multiplier=-1.) # Offset the final distribution so that the lowest value is at 0: m = m.offset_min(dimensions=1) mdt.write_splinelib(file("chi2.py", "w"), m, "chi2", density_cutoff=0.1) text = """ SET TICK_FONT = 5, CAPTION_FONT = 5 SET Y_TICK = -999 -999 -999 SET WORLD_WINDOW = -999 -999 -999 -999 """ m.write_asgl(asglroot='modlib-a', plot_type='PLOT2D', every_x_numbered=20, text=text, dimensions=1, plot_position=1, plots_per_page=8) os.system('asgl modlib-a')
# (the scaling actually does not matter, because I am eventually taking the # log and subtracting the smallest element of the final pdf, so this command # could be omitted without impact): m = m.normalize(to_pdf=True, dimensions=1, dx_dy=2.5, to_zero=True) # Take the logarithm of the smoothed frequencies # (this is safe: none of bins is 0 because of mdt.smooth()): m = m.log_transform(offset=0., multiplier=1.) # Reverse the sign: m = m.linear_transform(offset=0., multiplier=-1.) # Offset the final distribution so that the lowest value is at 0: m = m.offset_min(dimensions=1) mdt.write_splinelib(file("chi4.py", "w"), m, "chi4", density_cutoff=0.1) text = """ SET TICK_FONT = 5, CAPTION_FONT = 5 SET Y_TICK = -999 -999 -999 SET WORLD_WINDOW = -999 -999 -999 -999 """ m.write_asgl(asglroot='modlib-a', plot_type='PLOT2D', every_x_numbered=20, text=text, dimensions=1, plot_position=1, plots_per_page=8) os.system('asgl modlib-a')
# Start by smoothing with a uniform prior (equal weight when 10 points per bin), # producing a normalized distribution that sums to 1 (not a pdf when dx != 1): m = m.smooth(dimensions=1, weight=10) # Normalize it to get the true pdf (Integral p(x) dx = 1): # (the scaling actually does not matter, because I am eventually taking the # log and subtracting the smallest element of the final pdf, so this command # could be omitted without impact): m = m.normalize(to_pdf=True, dimensions=1, dx_dy=2.5, to_zero=True) # Take the logarithm of the smoothed frequencies # (this is safe: none of bins is 0 because of mdt.smooth()): m = m.log_transform(offset=0., multiplier=1.) # Reverse the sign: m = m.linear_transform(offset=0., multiplier=-1.) # Offset the final distribution so that the lowest value is at 0: m = m.offset_min(dimensions=1) mdt.write_splinelib(file("psi.py", "w"), m, "psi", density_cutoff=0.1) text = """ SET TICK_FONT = 5, CAPTION_FONT = 5 SET Y_TICK = -999 -999 -999 SET WORLD_WINDOW = -999 -999 -999 -999 """ m.write_asgl(asglroot='modlib-a', plot_type='PLOT2D', every_x_numbered=20, text=text, dimensions=1, plot_position=1, plots_per_page=8) os.system('asgl modlib-a')