def test_nnang_spread_10mols45(): #initialize dummy snapshot trj = op.join(data_path, 'DFAG.gro') ats = 29 molno = 1 t = 0 cutoff = 1. ainds = np.arange(0, 3) snap = cl.ContactClusterSnapshotXTC(t, trj, ats, molno) #reset all snapshot properties snap.nclusts = 1 snap.box = np.array([30, 30, 30]) snap.clusterIDs = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] snap.pos = np.array([[0., 0., 0., 1., 0., 0., 2., 0., 0.], [0., 1., 0., 1., 1., 0., 2., 1., 0.], [0., 2., 0., 1., 2., 0., 2., 2., 0.], [0., 3., 0., 1., 3., 0., 2., 3., 0.], [0., 4., 0., 1., 4., 0., 2., 4., 0.], [ 1 - np.sin(np.pi / 4), 5., 0. - np.cos(np.pi / 4), 1., 5., 0., 1. + np.sin(np.pi / 4), 5., np.cos(np.pi / 4) ], [0., 6., 0., 1., 6., 0., 2., 6., 0.], [0., 7., 0., 1., 7., 0., 2., 7., 0.], [0., 8., 0., 1., 8., 0., 2., 8., 0.], [0., 9., 0., 1., 9., 0., 2., 9., 0.]]) snap.setClusterID(cutoff) angMat = snap.nnangSpread(ainds) expangMat = np.array([[10, 0.17453292519943295, 0.34632803675275337]]) npt.assert_array_almost_equal(angMat, expangMat)
def test_contactXTC_clustering_contact(): """ Make sure we cluster correctly for contact cluster from xtc/gro """ trj = op.join(data_path, 'contact_test.gro') ats = 5 molno = 2 t = 0 snap = cl.ContactClusterSnapshotXTC(t, trj, ats, molno) snap.setClusterID(1.0) assert (snap.nclusts == 1)
def test_nnang_spread_1mol(): """ For one molecule, the output should be an empty matrix """ trj = op.join(data_path, 'DFAG.gro') ats = 29 molno = 1 t = 0 cutoff = 0.5 ainds = np.arange(9, 20) snap = cl.ContactClusterSnapshotXTC(t, trj, ats, molno) snap.setClusterID(cutoff) angMat = snap.nnangSpread(ainds) expangMat = np.array([]) #pdb.set_trace() npt.assert_array_almost_equal(angMat, expangMat)
def test_contactXTC_init_optical(): """ Test initializing an optical cluster from xtc/gro """ trj = op.join(data_path, 'optical_test.gro') ats = 5 molno = 2 t = 0 snap = cl.ContactClusterSnapshotXTC(t, trj, ats, molno) pos = np.array( [[0., 0., 0., 0.5, 0., 0., 0.75, 0.443, 0., 1., 0., 0., 1.5, 0., 0.], [ 0., 0., 0.5, 0.5, 0., 0.5, 0.75, 0.443, 0.5, 1., 0., 0.5, 1.5, 0., 0.5 ]]) npt.assert_array_equal(snap.pos, pos)
def test_contactXTC_init_contact(): """ Test initializing a contact cluster from xtc/gro """ trj = op.join(data_path, 'contact_test.gro') ats = 5 molno = 2 t = 0 snap = cl.ContactClusterSnapshotXTC(t, trj, ats, molno) pos = np.array([[ 0., 0., 0., 0.354, 0.354, 0.0, 0.604, 0.8, 0.0, 0.854, 0.354, 0.0, 1.207, 0.0, 0.0 ], [ 0.0, -0.8, 0.0, 0.354, -1.154, 0.0, 0.604, -1.6, 0.0, 0.854, -1.154, 0.0, 1.207, -0.8, 0.0 ]]) npt.assert_array_equal(snap.pos, pos)
def test_ang_spread_2mols_rotate_long90(): #initialize dummy snapshot trj = op.join(data_path, 'DFAG.gro') ats = 29 molno = 1 t = 0 cutoff = 20. * 20. ainds = np.arange(0, 3) snap = cl.ContactClusterSnapshotXTC(t, trj, ats, molno) snap.setClusterID(cutoff) #reset all snapshot properties snap.nclusts = 1 snap.box = np.array([20, 20, 20]) snap.clusterIDs = [0, 0] snap.pos = np.array([[0., 0., 0., 1., 0., 0., 2., 0., 0.], [1., 10., 1., 1., 10., 0., 1., 10., -1.]]) angMat = snap.angSpread(cutoff, ainds) expangMat = np.array([[2, 1.1107, 0.]]) npt.assert_array_almost_equal(angMat, expangMat, decimal=4)
def test_ang_spread_2mols_no_rotate_short(): """ two molecules parallel to one another should have an angle spread of 0 the mean projection should depend on how far apart they are (because it depends on the direction of the principal gyration tensor) """ #initialize dummy snapshot trj = op.join(data_path, 'DFAG.gro') ats = 29 molno = 1 t = 0 cutoff = 2. ainds = np.arange(0, 3) snap = cl.ContactClusterSnapshotXTC(t, trj, ats, molno) snap.setClusterID(cutoff) #reset all snapshot properties snap.nclusts = 1 snap.box = np.array([20, 20, 20]) snap.clusterIDs = [0, 0] snap.pos = np.array([[0., 0., 0., 1., 0., 0., 2., 0., 0.], [0., 1., 0., 1., 1., 0., 2., 1., 0.]]) angMat = snap.angSpread(cutoff, ainds) expangMat = np.array([[2, 0., 1.]]) npt.assert_array_almost_equal(angMat, expangMat)
def test_nnang_spread_2mols_no_rotate_short(): """ two molecules parallel to one another should make an angle of 0 and by definition stddev should be 0 """ #initialize dummy snapshot trj = op.join(data_path, 'DFAG.gro') ats = 29 molno = 1 t = 0 cutoff = 2. ainds = np.arange(0, 3) snap = cl.ContactClusterSnapshotXTC(t, trj, ats, molno) #reset all snapshot properties snap.nclusts = 1 snap.box = np.array([20, 20, 20]) snap.clusterIDs = [0, 0] snap.pos = np.array([[0., 0., 0., 1., 0., 0., 2., 0., 0.], [0., 1., 0., 1., 1., 0., 2., 1., 0.]]) snap.setClusterID(cutoff) angMat = snap.nnangSpread(ainds) expangMat = np.array([[2, 0., 0.]]) npt.assert_array_almost_equal(angMat, expangMat)