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()
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()
def test_convert_chunked_project_1(): fetch_alanine_dipeptide() with tempdir(): root = os.path.join(get_data_home(), 'alanine_dipeptide') if sys.platform == 'win32': pattern = "*.dcd" else: pattern = "'*.dcd'" cmd = 'msmb ConvertChunkedProject out {root} --pattern {pattern} -t {root}/ala2.pdb'.format( root=root, pattern=pattern) shell(cmd) assert set(os.listdir('out')) == set( ('traj-00000000.dcd', 'trajectories.jsonl')) # check that out/traj-00000.dcd really has concatenated all of # the input trajs length = len(md.open('out/traj-00000000.dcd')) assert length == sum( len(md.open(f)) for f in glob.glob('%s/*.dcd' % root)) with open('out/trajectories.jsonl') as f: record = json.load(f) assert set(record.keys()) == set(('filename', 'chunks')) assert record['filename'] == 'traj-00000000.dcd' assert sorted(glob.glob('%s/*.dcd' % root)) == record['chunks']
def test_convert_chunked_project_1(): fetch_alanine_dipeptide() with tempdir(): root = os.path.join(get_data_home(), 'alanine_dipeptide') if sys.platform == 'win32': pattern = "*.dcd" else: pattern = "'*.dcd'" cmd = ('msmb ConvertChunkedProject out {root} --pattern {pattern} ' '-t {root}/ala2.pdb' .format(root=root, pattern=pattern)) shell(cmd) assert set(os.listdir('out')) == {'traj-00000000.dcd', 'trajectories.jsonl'} # check that out/traj-00000.dcd really has concatenated all of # the input trajs length = len(md.open('out/traj-00000000.dcd')) assert length == sum(len(md.open(f)) for f in glob.glob('%s/*.dcd' % root)) with open('out/trajectories.jsonl') as f: record = json.load(f) assert set(record.keys()) == {'filename', 'chunks'} assert record['filename'] == 'traj-00000000.dcd' assert sorted(glob.glob('%s/*.dcd' % root)) == record['chunks']