コード例 #1
0
def test_pyCEquality():
    """
    Trying to find where / why conOptDist and conOptDistC don't
    return the same thing
    """
    fname = 'mols8.gsd'
    traj = gsd.hoomd.open(op.join(data_path, fname))

    ats = 17
    molno = 8
    cutoff = 1.1 * 1.1
    t = 97
    clustSnap = cl.ContactClusterSnapshot(t, traj, ats, molno)
    for i in range(molno):
        for j in range(molno):
            mol1 = clustSnap.pos[i, :].astype(np.double)
            mol2 = clustSnap.pos[j, :].astype(np.double)

            r = cl.conOptDistance(mol1, mol2)
            rc = conOptDistanceCython(mol1, mol2)
            ar = cl.alignedDistance(mol1, mol2)
            arc = alignDistancesCython(mol1, mol2)

            npt.assert_almost_equal(r, rc, 5)
            npt.assert_almost_equal(ar, arc, 5)
コード例 #2
0
def test_dummyfull():
    """
    Makes sure that all three cluster types return what is expected,
    employing the hand-crafted 6 snapshot system of dummy molecules that
    are similar to the 17-bead HOOMD rigid bodies
    """
    fname = 'dummyfull4.gsd'
    traj = gsd.hoomd.open(op.join(data_path, fname))
    atsCC = 17
    atsOC = 12
    atsAC = 6
    molno = 4
    contactcut = 1.1 * 1.1
    opticalcut = 0.35 * 0.35
    alignedcut = 0.35 * 0.35
    ts = range(6)
    nclustsActualCC = [4, 2, 1, 1, 1, 1]
    nclustsActualOC = [4, 3, 2, 2, 1, 1]
    nclustsActualAC = [4, 4, 3, 2, 2, 1]
    clustSizesActualCC = [[1, 1, 1, 1], [2, 2, 2, 2], [4, 4, 4, 4],
                          [4, 4, 4, 4], [4, 4, 4, 4], [4, 4, 4, 4]]
    clustSizesActualOC = [[1, 1, 1, 1], [1, 1, 2, 2], [2, 2, 2, 2],
                          [2, 2, 2, 2], [4, 4, 4, 4], [4, 4, 4, 4]]
    clustSizesActualAC = [[1, 1, 1, 1], [1, 1, 1, 1], [2, 2, 1, 1],
                          [2, 2, 2, 2], [2, 2, 2, 2], [4, 4, 4, 4]]
    for t in ts:
        print(t)
        clustSnapCC = cl.ContactClusterSnapshot(t, traj, atsCC, molno)
        clustSnapCC.setClusterID(contactcut)
        clustSizeCC = clustSnapCC.idsToSizes()
        assert (clustSizeCC == clustSizesActualCC[t]).all()
        assert clustSnapCC.nclusts == nclustsActualCC[t]

        atype = 'AB'
        compairs = [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10, 11]]
        clustSnapOC = cl.OpticalClusterSnapshot(t,
                                                traj,
                                                atsOC,
                                                molno,
                                                atype=atype)
        clustSnapOC.setClusterID(opticalcut)
        clustSizeOC = clustSnapOC.idsToSizes()
        assert (clustSizeOC == clustSizesActualOC[t]).all()
        assert clustSnapOC.nclusts == nclustsActualOC[t]

        clustSnapAC = cl.AlignedClusterSnapshot(t,
                                                traj,
                                                atsAC,
                                                molno,
                                                compairs=compairs,
                                                atype=atype)
        clustSnapAC.setClusterID(alignedcut)
        clustSizeAC = clustSnapAC.idsToSizes()
        assert (clustSizeAC == clustSizesActualAC[t]).all()
        assert clustSnapAC.nclusts == nclustsActualAC[t]
コード例 #3
0
def test_clusterPackAndUnpack():
    """
    Test to and from array stuff which is basically my own version of 
    'pickling' in a numpy array for use with mpi4py.
    """
    fname = 'mols8.gsd'
    traj = gsd.hoomd.open(op.join(data_path, fname))

    ats = 17

    cutoff = 1.1 * 1.1
    molno = 8
    t = 97
    clustSnap = cl.ContactClusterSnapshot(t, traj, ats, molno)
    clustSnap.setClusterID(cutoff)
    carray = clustSnap.toArray()
    clustSnap2 = cl.ContactClusterSnapshot(0, carray, ats, molno)
    assert clustSnap.timestep == clustSnap2.timestep
    assert clustSnap.ats == clustSnap2.ats
    assert clustSnap.nclusts == clustSnap2.nclusts
    assert (clustSnap.pos == clustSnap2.pos).all()
    assert (clustSnap.clusterIDs == clustSnap2.clusterIDs).all()
コード例 #4
0
def test_fixPBC():
    """
    test fixing clusters across PBCs
    """
    fname = 'dummy2PBC.gsd'
    cutoff = 0.6
    traj = gsd.hoomd.open(op.join(data_path, fname))
    clustSnap = cl.ContactClusterSnapshot(0, traj, 3, 2)
    clustSnap.setClusterID(cutoff)
    fixedXYZ = clustSnap.fixPBC(0,
                                cutoff,
                                writegsd=op.join(data_path,
                                                 'dummy2PBCunwrapped.gsd'))
    npt.assert_array_almost_equal(
        fixedXYZ,
        np.array([[0., 0., 4.75, 0., 0., 5.25, 0., 0., 5.75],
                  [-0.5, 0., 5.25, -0.5, 0., 5.75, -0.5, 0., 6.25]]))
コード例 #5
0
def test_ContactClusterSnapshot_init():
    """
    Testing the instantiation of a Cluster Snapshot
    """
    fname = 'mols8.gsd'
    traj = gsd.hoomd.open(op.join(data_path, fname))

    ats = 17
    molno = 8
    cutoff = 1.1 * 1.1
    t = 97
    clustSnap = cl.ContactClusterSnapshot(t, traj, ats, molno)
    clustSnap.setClusterID(cutoff)
    assert clustSnap.timestep == t
    sz = np.shape(traj[t].particles.position)
    assert len(clustSnap.clusterIDs) == sz[0] / ats
    assert clustSnap.nclusts == 2
コード例 #6
0
def test_mu2():
    """
    test mass-averaged cluster size instantiation
    """
    fname = 'dummy8.gsd'
    traj = gsd.hoomd.open(op.join(data_path, fname))
    ats = 2
    molno = 8
    cutoff = 1.1 * 1.1
    ts = range(8)
    mu2s = np.array([1, 2, 5 / 2, 11 / 4, 17 / 4, 17 / 4, 8, 8])
    for t in ts:
        clustSnap = cl.ContactClusterSnapshot(t, traj, ats, molno)
        clustSnap.setClusterID(cutoff)
        clustSize = clustSnap.idsToSizes()
        mu2 = cl.massAvSize(clustSize)

        npt.assert_almost_equal(mu2, mu2s[t], 10)
コード例 #7
0
def test_dummy8():
    """
    Makes sure that contact clusters return what is expected, employing
    the hand-crafted 8 snapshot system of 2 atoms in each molecule
    """
    fname = 'dummy8.gsd'
    traj = gsd.hoomd.open(op.join(data_path, fname))
    ats = 2
    molno = 8
    cutoff = 1.1 * 1.1
    ts = range(8)
    clustSizesActual = [[1, 1, 1, 1, 1, 1, 1, 1], [1, 2, 2, 1, 3, 3, 1, 3],
                        [1, 3, 3, 3, 3, 3, 1, 3], [2, 3, 3, 3, 3, 3, 2, 3],
                        [5, 5, 5, 5, 3, 3, 5, 3], [5, 5, 5, 5, 3, 3, 5, 3],
                        [8, 8, 8, 8, 8, 8, 8, 8], [8, 8, 8, 8, 8, 8, 8, 8]]
    nclustsActual = [8, 5, 4, 3, 2, 2, 1, 1]
    for t in ts:
        clustSnap = cl.ContactClusterSnapshot(t, traj, ats, molno)
        clustSnap.setClusterID(cutoff)
        clustSize = clustSnap.idsToSizes()
        assert (clustSize == clustSizesActual[t]).all()
        assert clustSnap.nclusts == nclustsActual[t]
コード例 #8
0
    for r in range(size):
        if rem != 0:
            if r < rem:
                ts = r * (num + 1) + np.arange(num + 1)
                tslist[currid:(len(ts) + currid)] = ts

            else:
                ts = r * (num + 1) - (r - rem) + np.arange(num)
                tslist[currid:(len(ts) + currid)] = ts
                tslist[(len(ts) + currid):(len(ts) + currid + (r - rem) +
                                           1)] = -1
            currid += num + 1
        else:
            tslist = np.arange(num * size)
    print(tslist)
    clusters = [cl.ContactClusterSnapshot(t, traj, ats, molno) for t in tslist]
    carraylen = clusters[0].getCArrayLen()
    clusterarray = np.zeros(carraylen * len(clusters))
    cind = 0
    for cls in clusters:
        carray = cls.toArray()
        clusterarray[(cind * carraylen):(cind * carraylen +
                                         carraylen)] = carray
        cind += 1
else:
    tCSnap = cl.ContactClusterSnapshot(0, traj, ats, molno)
    carraylen = tCSnap.getCArrayLen()
    clusterarray = None
if rem == 0:
    ncsnaps = num
else: