Example #1
0
    def test_write_2dsplinelib(self):
        """Test the write_2dsplinelib function"""
        mlib = self.get_mdt_library()

        restype = mdt.features.ResidueType(mlib)
        phi = mdt.features.PhiDihedral(mlib,
                                       bins=mdt.uniform_bins(18, -180.0, 40.0))
        psi = mdt.features.PsiDihedral(mlib,
                                       bins=mdt.uniform_bins(18, -180.0, 40.0))
        m = self.get_test_mdt(mlib, [restype, phi, psi])
        mdt.write_2dsplinelib(open('test.out', 'w'), m)

        # Make sure that valid Python code was produced
        code = compile(open('test.out').read(), 'test.out', 'exec')
        os.unlink('test.out')
Example #2
0
    def test_write_2dsplinelib(self):
        """Test the write_2dsplinelib function"""
        mlib = self.get_mdt_library()

        restype = mdt.features.ResidueType(mlib)
        phi = mdt.features.PhiDihedral(mlib,
                                       bins=mdt.uniform_bins(18, -180.0, 40.0))
        psi = mdt.features.PsiDihedral(mlib,
                                       bins=mdt.uniform_bins(18, -180.0, 40.0))
        m = self.get_test_mdt(mlib, [restype, phi, psi])
        with open('test.out', 'w') as fh:
            mdt.write_2dsplinelib(fh, m)

        # Make sure that valid Python code was produced
        with open('test.out') as fh:
            _ = compile(fh.read(), 'test.out', 'exec')
        os.unlink('test.out')
Example #3
0
m = m.reshape(features=(xray, restyp, psi, phi),
              offset=(0, 0, 0, 0),
              shape=(1, -2, -1, -1))

# Let's get rid of the resolution variable from the output MDT table:
m = m.integrate(features=(restyp, psi, phi))

# Process the raw histograms to get appropriate pdf 1D splines for restraints:

# 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=2, 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=2, dx_dy=(5., 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=2)

mdt.write_2dsplinelib(file("phipsi.py", "w"), m, density_cutoff=0.1)