Example #1
0
def setup_module():
    global DATADIR, HMM
    DATADIR = tempfile.mkdtemp()
    # 4 components and 3 features. Each feature is going to be the x, y, z
    # coordinate of 1 atom
    HMM = sklearn.hmm.GaussianHMM(n_components=4)
    HMM.transmat_ = np.array([[0.9, 0.1, 0.0, 0.0],
                              [0.1, 0.7, 0.2, 0.0],
                              [0.0, 0.1, 0.8, 0.1],
                              [0.0, 0.1, 0.1, 0.8]])
    HMM.means_ = np.array([[-10, -10, -10],
                           [-5,  -5,   -5],
                           [5,    5,    5],
                           [10,  10,   10]])
    HMM.covars_ = np.array([[0.1, 0.1, 0.1],
                            [0.5, 0.5, 0.5],
                            [1, 1, 1],
                            [4, 4, 4]])
    HMM.startprob_ = np.array([1, 1, 1, 1]) / 4.0

    # get a 1 atom topology
    topology = md.load(get_mdtraj_fn('native.pdb')).restrict_atoms([1]).topology

    # generate the trajectories and save them to disk
    for i in range(10):
        d, s = HMM.sample(100)
        t = md.Trajectory(xyz=d.reshape(len(d), 1, 3), topology=topology)
        t.save(os.path.join(DATADIR, 'Trajectory%d.h5' % i))

    fetch_alanine_dipeptide()
Example #2
0
def setup_module():
    global DATADIR, HMM
    DATADIR = tempfile.mkdtemp()
    # 4 components and 3 features. Each feature is going to be the x, y, z
    # coordinate of 1 atom
    HMM = sklearn.hmm.GaussianHMM(n_components=4)
    HMM.transmat_ = np.array([[0.9, 0.1, 0.0, 0.0], [0.1, 0.7, 0.2, 0.0],
                              [0.0, 0.1, 0.8, 0.1], [0.0, 0.1, 0.1, 0.8]])
    HMM.means_ = np.array([[-10, -10, -10], [-5, -5, -5], [5, 5, 5],
                           [10, 10, 10]])
    HMM.covars_ = np.array([[0.1, 0.1, 0.1], [0.5, 0.5, 0.5], [1, 1, 1],
                            [4, 4, 4]])
    HMM.startprob_ = np.array([1, 1, 1, 1]) / 4.0

    # get a 1 atom topology
    topology = md.load(get_mdtraj_fn('native.pdb')).restrict_atoms([1
                                                                    ]).topology

    # generate the trajectories and save them to disk
    for i in range(10):
        d, s = HMM.sample(100)
        t = md.Trajectory(xyz=d.reshape(len(d), 1, 3), topology=topology)
        t.save(os.path.join(DATADIR, 'Trajectory%d.h5' % i))

    fetch_alanine_dipeptide()
Example #3
0
def test_atomindices_1():
    fn = get_mdtraj_fn('2EQQ.pdb')
    t = md.load(fn)
    with tempdir():
        shell('msmb AtomIndices -o all.txt --all -a -p %s' % fn)
        shell('msmb AtomIndices -o all-pairs.txt --all -d -p %s' % fn)
        atoms = np.loadtxt('all.txt', int)
        pairs = np.loadtxt('all-pairs.txt', int)
        eq(t.n_atoms, len(atoms))
        eq(int(t.n_atoms * (t.n_atoms - 1) / 2), len(pairs))
Example #4
0
def test_atomindices_3():
    fn = get_mdtraj_fn('2EQQ.pdb')
    t = md.load(fn)
    with tempdir():
        shell('msmb AtomIndices -o alpha.txt --alpha -a -p %s' % fn)
        shell('msmb AtomIndices -o alpha-pairs.txt --alpha -d -p %s' % fn)
        atoms = np.loadtxt('alpha.txt', int)
        pairs = np.loadtxt('alpha-pairs.txt', int)
        assert all(t.topology.atom(i).name == 'CA' for i in atoms)
        assert sum(1 for a in t.topology.atoms if a.name == 'CA') == len(atoms)
        eq(np.array(list(itertools.combinations(atoms, 2))), pairs)
Example #5
0
def test_atomindices_2():
    fn = get_mdtraj_fn('2EQQ.pdb')
    t = md.load(fn)
    with tempdir():
        shell('msmb AtomIndices -o heavy.txt --heavy -a -p %s' % fn)
        shell('msmb AtomIndices -o heavy-pairs.txt --heavy -d -p %s' % fn)
        atoms = np.loadtxt('heavy.txt', int)
        pairs = np.loadtxt('heavy-pairs.txt', int)
        assert all(t.topology.atom(i).element.symbol != 'H' for i in atoms)
        assert (sum(1 for a in t.topology.atoms
                    if a.element.symbol != 'H') == len(atoms))
        eq(np.array(list(itertools.combinations(atoms, 2))), pairs)
Example #6
0
def test_atomindices_4():
    fn = get_mdtraj_fn('2EQQ.pdb')
    t = md.load(fn)
    with tempdir():
        shell('msmb AtomIndices -o minimal.txt --minimal -a -p %s' % fn)
        shell('msmb AtomIndices -o minimal-pairs.txt --minimal -d -p %s' % fn)
        atoms = np.loadtxt('minimal.txt', int)
        pairs = np.loadtxt('minimal-pairs.txt', int)
        assert all(
            t.topology.atom(i).name in ['CA', 'CB', 'C', 'N', 'O']
            for i in atoms)
        eq(np.array(list(itertools.combinations(atoms, 2))), pairs)
Example #7
0
def test_featurizer():
    fn = get_mdtraj_fn('1bpi.pdb')
    with tempdir():
        shell('hmsm atomindices -o alpha.dat --alpha -a -p %s' % fn)
        shell('hmsm featurizer --top %s -o alpha.pickl -a alpha.dat' % fn)
        f = np.load('alpha.pickl')
        eq(f.atom_indices, np.loadtxt('alpha.dat', int))

    with tempdir():
        shell('hmsm atomindices -o alphapairs.dat --alpha -d -p %s' % fn)
        shell('hmsm featurizer --top %s -o alpha.pickl -d alphapairs.dat' % fn)
        f = np.load('alpha.pickl')
        eq(f.pair_indices, np.loadtxt('alphapairs.dat', int))
Example #8
0
def test_featurizer():
    fn = get_mdtraj_fn('1bpi.pdb')
    with tempdir():
        shell('hmsm atomindices -o alpha.dat --alpha -a -p %s' % fn)
        shell('hmsm featurizer --top %s -o alpha.pickl -a alpha.dat' % fn)
        f = np.load('alpha.pickl')
        eq(f.atom_indices, np.loadtxt('alpha.dat', int))

    with tempdir():
        shell('hmsm atomindices -o alphapairs.dat --alpha -d -p %s' % fn)
        shell('hmsm featurizer --top %s -o alpha.pickl -d alphapairs.dat' % fn)
        f = np.load('alpha.pickl')
        eq(f.pair_indices, np.loadtxt('alphapairs.dat', int))
Example #9
0
def test_dihedralindices():
    fn = get_mdtraj_fn('1bpi.pdb')
    t = md.load(fn)
    with tempdir():
        shell('hmsm dihedralindices -o phi.dat --phi -p %s' % fn)
        shell('hmsm dihedralindices -o psi.dat --psi -p %s' % fn)
        eq(len(np.loadtxt('phi.dat', int)), len(np.loadtxt('psi.dat', int)))
        shell('hmsm dihedralindices -o chi1.dat --chi1 -p %s' % fn)
        shell('hmsm dihedralindices -o chi2.dat --chi2 -p %s' % fn)
        assert len(np.loadtxt('chi2.dat')) < len(np.loadtxt('chi1.dat'))
        shell('hmsm dihedralindices -o chi3.dat --chi3 -p %s' % fn)
        shell('hmsm dihedralindices -o chi4.dat --chi4 -p %s' % fn)
        shell('hmsm dihedralindices -o omega.dat --omega -p %s' % fn)
        shell('hmsm dihedralindices -o all.dat --phi --psi --chi1 --chi2 --chi3 --chi4 --omega -p %s' % fn)
Example #10
0
def test_dihedralindices():
    fn = get_mdtraj_fn('1bpi.pdb')
    t = md.load(fn)
    with tempdir():
        shell('hmsm dihedralindices -o phi.dat --phi -p %s' % fn)
        shell('hmsm dihedralindices -o psi.dat --psi -p %s' % fn)
        eq(len(np.loadtxt('phi.dat', int)), len(np.loadtxt('psi.dat', int)))
        shell('hmsm dihedralindices -o chi1.dat --chi1 -p %s' % fn)
        shell('hmsm dihedralindices -o chi2.dat --chi2 -p %s' % fn)
        assert len(np.loadtxt('chi2.dat')) < len(np.loadtxt('chi1.dat'))
        shell('hmsm dihedralindices -o chi3.dat --chi3 -p %s' % fn)
        shell('hmsm dihedralindices -o chi4.dat --chi4 -p %s' % fn)
        shell('hmsm dihedralindices -o omega.dat --omega -p %s' % fn)
        shell('hmsm dihedralindices -o all.dat --phi --psi --chi1 --chi2 --chi3 --chi4 --omega -p %s' % fn)
Example #11
0
def test_atomindices():
    fn = get_mdtraj_fn('2EQQ.pdb')
    t = md.load(fn)
    with tempdir():
        shell('msmb AtomIndices -o all.txt --all -a -p %s' % fn)
        shell('msmb AtomIndices -o all-pairs.txt --all -d -p %s' % fn)
        atoms = np.loadtxt('all.txt', int)
        pairs = np.loadtxt('all-pairs.txt', int)
        eq(t.n_atoms, len(atoms))
        eq(int(t.n_atoms * (t.n_atoms - 1) / 2), len(pairs))

    with tempdir():
        shell('msmb AtomIndices -o heavy.txt --heavy -a -p %s' % fn)
        shell('msmb AtomIndices -o heavy-pairs.txt --heavy -d -p %s' % fn)
        atoms = np.loadtxt('heavy.txt', int)
        pairs = np.loadtxt('heavy-pairs.txt', int)
        assert all(t.topology.atom(i).element.symbol != 'H' for i in atoms)
        assert sum(1 for a in t.topology.atoms
                   if a.element.symbol != 'H') == len(atoms)
        eq(np.array(list(itertools.combinations(atoms, 2))), pairs)

    with tempdir():
        shell('msmb AtomIndices -o alpha.txt --alpha -a -p %s' % fn)
        shell('msmb AtomIndices -o alpha-pairs.txt --alpha -d -p %s' % fn)
        atoms = np.loadtxt('alpha.txt', int)
        pairs = np.loadtxt('alpha-pairs.txt', int)
        assert all(t.topology.atom(i).name == 'CA' for i in atoms)
        assert sum(1 for a in t.topology.atoms if a.name == 'CA') == len(atoms)
        eq(np.array(list(itertools.combinations(atoms, 2))), pairs)

    with tempdir():
        shell('msmb AtomIndices -o minimal.txt --minimal -a -p %s' % fn)
        shell('msmb AtomIndices -o minimal-pairs.txt --minimal -d -p %s' % fn)
        atoms = np.loadtxt('minimal.txt', int)
        pairs = np.loadtxt('minimal-pairs.txt', int)
        assert all(
            t.topology.atom(i).name in ['CA', 'CB', 'C', 'N', 'O']
            for i in atoms)
        eq(np.array(list(itertools.combinations(atoms, 2))), pairs)
Example #12
0
def test_atomindices():
    fn = get_mdtraj_fn('2EQQ.pdb')
    t = md.load(fn)
    with tempdir():
        shell('msmb AtomIndices -o all.txt --all -a -p %s' % fn)
        shell('msmb AtomIndices -o all-pairs.txt --all -d -p %s' % fn)
        atoms = np.loadtxt('all.txt', int)
        pairs = np.loadtxt('all-pairs.txt', int)
        eq(t.n_atoms, len(atoms))
        eq(int(t.n_atoms * (t.n_atoms - 1) / 2), len(pairs))

    with tempdir():
        shell('msmb AtomIndices -o heavy.txt --heavy -a -p %s' % fn)
        shell('msmb AtomIndices -o heavy-pairs.txt --heavy -d -p %s' % fn)
        atoms = np.loadtxt('heavy.txt', int)
        pairs = np.loadtxt('heavy-pairs.txt', int)
        assert all(t.topology.atom(i).element.symbol != 'H' for i in atoms)
        assert (sum(1 for a in t.topology.atoms if a.element.symbol != 'H') ==
                len(atoms))
        eq(np.array(list(itertools.combinations(atoms, 2))), pairs)

    with tempdir():
        shell('msmb AtomIndices -o alpha.txt --alpha -a -p %s' % fn)
        shell('msmb AtomIndices -o alpha-pairs.txt --alpha -d -p %s' % fn)
        atoms = np.loadtxt('alpha.txt', int)
        pairs = np.loadtxt('alpha-pairs.txt', int)
        assert all(t.topology.atom(i).name == 'CA' for i in atoms)
        assert sum(1 for a in t.topology.atoms if a.name == 'CA') == len(atoms)
        eq(np.array(list(itertools.combinations(atoms, 2))), pairs)

    with tempdir():
        shell('msmb AtomIndices -o minimal.txt --minimal -a -p %s' % fn)
        shell('msmb AtomIndices -o minimal-pairs.txt --minimal -d -p %s' % fn)
        atoms = np.loadtxt('minimal.txt', int)
        pairs = np.loadtxt('minimal-pairs.txt', int)
        assert all(t.topology.atom(i).name in ['CA', 'CB', 'C', 'N', 'O']
                   for i in atoms)
        eq(np.array(list(itertools.combinations(atoms, 2))), pairs)