예제 #1
0
def test_binaries_zero_cutoff():
    trajectories = MinimalFsPeptide().get_cached().trajectories
    binarycontactfeaturizer = BinaryContactFeaturizer(cutoff=0)
    binaries = binarycontactfeaturizer.transform(trajectories)

    assert binaries[0].shape[1] == 171
    assert np.sum(binaries[0]) == 0
예제 #2
0
def test_von_mises_featurizer_2():
    trajectories = MinimalFsPeptide().get_cached().trajectories
    # test to make sure results are being put in the right order
    feat = VonMisesFeaturizer(["phi", "psi"], n_bins=10)
    _, all_phi = compute_phi(trajectories[0])
    X_all = feat.transform(trajectories)
    all_res = []
    for frame in all_phi:
        for dihedral_value in frame:
            all_res.extend(
                vm.pdf(dihedral_value, loc=feat.loc, kappa=feat.kappa))

    print(len(all_res))

    # this checks 10 random dihedrals to make sure that they appear in the right columns
    # for the vonmises bins
    n_phi = all_phi.shape[1]
    for k in range(5):
        # pick a random phi dihedral
        rndint = np.random.choice(range(n_phi))
        # figure out where we expect it to be in X_all
        indices_to_expect = []
        for i in range(10):
            indices_to_expect += [n_phi * i + rndint]

        # we know the results in all_res are dihedral1(bin1-bin10) dihedral2(bin1 to bin10)
        # we are checking if X is alldihedrals(bin1) then all dihedrals(bin2)

        expected_res = all_res[rndint * 10:10 + rndint * 10]

        assert (np.array([X_all[0][0, i]
                          for i in indices_to_expect]) == expected_res).all()
예제 #3
0
def test_logistics():
    trajectories = MinimalFsPeptide().get_cached().trajectories
    logisticcontactfeaturizer = LogisticContactFeaturizer()
    logistics = logisticcontactfeaturizer.transform(trajectories)

    assert logistics[0].shape[1] == 171
    assert np.amax(logistics[0]) < 1.0
    assert np.amin(logistics[0]) > 0.0
def test_fs_peptide_nosincos():
    # will produce 18 features

    trajectories = MinimalFsPeptide().get_cached().trajectories
    featurizer = msmbuilder.featurizer.AlphaAngleFeaturizer(sincos=False)
    alphas = featurizer.transform(trajectories)

    assert (alphas[0].shape[1] == 18)
예제 #5
0
def test_binary_to_logistics():
    trajectories = MinimalFsPeptide().get_cached().trajectories
    steepness = np.absolute(10 * np.random.randn())
    center = np.absolute(np.random.randn())
    binarycontactfeaturizer = BinaryContactFeaturizer(cutoff=center)
    binaries = binarycontactfeaturizer.transform(trajectories)
    logisticcontactfeaturizer = LogisticContactFeaturizer(center=center,
                                                          steepness=steepness)
    logistics = logisticcontactfeaturizer.transform(trajectories)

    # This checks that no distances that are larger than the center are logistically
    # transformed such that they are less than 1/2
    np.testing.assert_array_almost_equal(binaries[0], logistics[0] > 0.5)
예제 #6
0
def load_fs():

    from msmbuilder.example_datasets import MinimalFsPeptide
    trajs = MinimalFsPeptide().get().trajectories

    from msmbuilder.featurizer import AtomPairsFeaturizer
    pairs = []
    for i in range(264):
        for j in range(i):
            pairs.append((j, i))
    X = AtomPairsFeaturizer(pairs).fit_transform(trajs)

    from msmbuilder.featurizer import DihedralFeaturizer
    Y = DihedralFeaturizer().fit_transform(trajs)
    return X, Y
예제 #7
0
def test_distance_to_logistic():
    trajectories = MinimalFsPeptide().get_cached().trajectories
    steepness = np.absolute(10 * np.random.randn())
    center = np.absolute(np.random.randn())
    contactfeaturizer = ContactFeaturizer()
    contacts = contactfeaturizer.transform(trajectories)
    logisticcontactfeaturizer = LogisticContactFeaturizer(center=center,
                                                          steepness=steepness)
    logistics = logisticcontactfeaturizer.transform(trajectories)

    for n in range(10):
        i = np.random.randint(0, contacts[0].shape[0] - 1)
        j = np.random.randint(0, contacts[0].shape[1] - 1)

        x = contacts[0][i][j]
        y = logistics[0][i][j]

        if (x > center):
            assert y < 0.5
        if (x < center):
            assert y > 0.5
예제 #8
0
def test_soft_min_contact_featurizer():
    # just get one frame for now
    traj = MinimalFsPeptide().get_cached().trajectories[0][0]
    soft_min_beta = 20

    ri, rj = np.random.choice(np.arange(traj.top.n_residues),
                              size=2,
                              replace=False)
    aind_i = [i.index for i in traj.top.residue(ri).atoms]
    aind_j = [i.index for i in traj.top.residue(rj).atoms]

    atom_pairs = [i for i in itertools.product(aind_i, aind_j)]

    featuizer = ContactFeaturizer(contacts=[[ri, rj]],
                                  scheme='closest',
                                  soft_min=True,
                                  soft_min_beta=soft_min_beta)

    features = featuizer.transform(([traj]))[0]
    distances = md.compute_distances(traj, atom_pairs)
    distances = soft_min_beta / \
        np.log(np.sum(np.exp(soft_min_beta / distances), axis=1))

    np.allclose(features, distances)
예제 #9
0
"""Make sure all the describe features are putting the right features in the
right place
"""
import mdtraj as md
import numpy as np
import pandas as pd
from mdtraj.testing import eq
from scipy.stats import vonmises as vm
import itertools

from msmbuilder.example_datasets import MinimalFsPeptide
from msmbuilder.feature_selection import FeatureSelector
from msmbuilder.featurizer import DihedralFeaturizer, AlphaAngleFeaturizer, \
    KappaAngleFeaturizer, ContactFeaturizer, VonMisesFeaturizer,AtomPairsFeaturizer

trajectories = MinimalFsPeptide().get_cached().trajectories
top = trajectories[0].topology

if np.random.choice([True, False]):
    atom_ind = [
        i.index for i in top.atoms if i.residue.is_protein and (
            i.residue.index in range(15) or i.residue.index in range(20, 23))
    ]
else:
    atom_ind = [i.index for i in top.atoms]


def test_AtomPairsFeaturizer_describe_features():
    current_atom_ind = list(itertools.combinations(atom_ind, 2))
    feat = AtomPairsFeaturizer(current_atom_ind)
    rnd_traj = np.random.randint(len(trajectories))
예제 #10
0
def test_contacts():
    trajectories = MinimalFsPeptide().get_cached().trajectories
    contactfeaturizer = ContactFeaturizer()
    contacts = contactfeaturizer.transform(trajectories)

    assert contacts[0].shape[1] == 171