def test_system_set_CIDs_MPI(): """ Test setting the cluster IDs with MPI """ cldict = {'contact': 1.1 * 1.1} syst = cl.SnapSystem(traj, {'contact': ats}, molno, cldict) syst.get_clusters_mpi('contact') 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]] if rank == 0: ind = 0 nind = 0 print(len(syst.clsnaps['contact'])) tclustSnap = syst.clsnaps['contact'][7] print(tclustSnap.pos[0]) print(tclustSnap.idsToSizes()) while ind < ttotal: clustSnap = syst.clsnaps['contact'][nind] if not np.isnan(clustSnap.pos[0][0]): print("ind is: ", ind) print("nind is: ", nind) csizes = clustSnap.idsToSizes() print("csizes is: ", csizes) print("actual is: ", clustSizesActual[ind]) assert (csizes == clustSizesActual[ind]).all() ind += 1 nind += 1
def test_getSizesFromFile(): """test reading sizes out of a written file""" tname = "dummyfull4" fname = 'molsdf4sizesAC' for i in range(1, 6): traj = gsd.hoomd.open( op.join(data_path, tname + '_run' + str(i) + '.gsd')) box = traj[0].configuration.box ats = {'aligned': 6} cldict = {'aligned': 0.35 * 0.35} molno = 4 atype = 'AB' compairs = np.array([[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10, 11]]) syst = cl.SnapSystem(traj, ats, molno, cldict, compairs=compairs, atype=atype) syst.get_clusters_serial('aligned', box) syst.writeSizes('aligned',op.join(data_path,fname + '_run' \ + str(i) + '.dat')) fnames = [ op.join(data_path, fname + '_run1.dat'), op.join(data_path, fname + '_run2.dat'), op.join(data_path, fname + '_run3.dat'), op.join(data_path, fname + '_run4.dat'), op.join(data_path, fname + '_run5.dat') ] actualSizes1 = np.array([[1, 1, 1, 1], [1, 1, 1, 1], [2, 2, 1, 1], [2, 2, 2, 2], [2, 2, 2, 2], [4, 4, 4, 4]]) actualSizes2 = np.array([[1, 1, 1, 1], [1, 1, 1, 1], [2, 2, 1, 1], [2, 2, 2, 2], [4, 4, 4, 4], [4, 4, 4, 4]]) actualSizes3 = np.array([[1, 1, 1, 1], [1, 1, 1, 1], [2, 2, 2, 2], [2, 2, 2, 2], [2, 2, 2, 2], [2, 2, 2, 2]]) actualSizes4 = np.array([[1, 1, 1, 1], [2, 2, 1, 1], [2, 2, 2, 2], [2, 2, 2, 2], [4, 4, 4, 4], [4, 4, 4, 4]]) actualSizes5 = np.array([[1, 1, 1, 1], [1, 1, 1, 1], [2, 2, 1, 1], [2, 2, 2, 2], [2, 2, 2, 2], [2, 2, 2, 2]]) csizes1 = cl.getSizesFromFile([fnames[0]], 6) assert (csizes1 == actualSizes1).all() csizes2 = cl.getSizesFromFile([fnames[1]], 6) assert (csizes2 == actualSizes2).all() csizes3 = cl.getSizesFromFile([fnames[2]], 6) assert (csizes3 == actualSizes3).all() csizes4 = cl.getSizesFromFile([fnames[3]], 6) assert (csizes4 == actualSizes4).all() csizes5 = cl.getSizesFromFile([fnames[4]], 6) assert (csizes5 == actualSizes5).all() csizes = cl.getSizesFromFile(fnames, 6) print(csizes) assert (csizes == np.concatenate( (csizes1, csizes2, csizes3, csizes4, csizes5), axis=1)).all()
def test_system_init_MPI(): """ Test the initialization of the system using MPI """ cldict = {'contact': 1.1 * 1.1} syst = cl.SnapSystem(traj, {'contact': ats}, molno, cldict) assert syst.mpi assert syst.ats == {'contact': ats} assert syst.molno == molno assert syst.cldict == cldict
def test_readCID(): """ test reading the CID from a file """ fname = 'mols8.gsd' traj = gsd.hoomd.open(op.join(data_path, fname)) box = traj[0].configuration.box ats = {'contact': 17} cutoff = 1.1 * 1.1 molno = 8 cldict = {'contact': cutoff} syst = cl.SnapSystem(traj, ats, molno, cldict) syst.get_clusters_serial('contact', box) syst.writeCIDs('contact', op.join(data_path, 'mols8cIDs.dat')) systwrit = cl.SnapSystem(traj, ats, molno, cldict) for i in range(len(systwrit.clsnaps['contact'])): snapf = systwrit.clsnaps['contact'][i] snapf.setClusterIDFromFile(op.join(data_path, 'mols8cIDs.dat')) snap = syst.clsnaps['contact'][i] assert (snapf.clusterIDs == snap.clusterIDs).all()
def test_writeSizes(): """ test writing out the clusterIDs """ fname = 'mols8.gsd' traj = gsd.hoomd.open(op.join(data_path, fname)) box = traj[0].configuration.box ats = {'contact': 17} cutoff = 1.1 * 1.1 molno = 8 cldict = {'contact': cutoff} syst = cl.SnapSystem(traj, ats, molno, cldict) syst.get_clusters_serial('contact', box) syst.writeSizes('contact', op.join(data_path, 'mols8sizes.dat'))
def test_full_system_set_CIDs_MPI(): """ Test setting the cluster IDs with MPI for all cluster types """ cldict = { 'contact': 1.1 * 1.1, 'optical': 0.35 * 0.35, 'aligned': 0.35 * 0.35 } traj = gsd.hoomd.open( '/home/rachael/Analysis_and_run_code/analysis/cluster_analysis/clustering/data/dummyfull4.gsd' ) ats = {'contact': 17, 'optical': 12, 'aligned': 6} molno = 4 compairs = np.array([[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10, 11]]) atype = 'AB' syst = cl.SnapSystem(traj, ats, molno, cldict, compairs=compairs, atype=atype) syst.get_clusters_mpi('contact') syst.get_clusters_mpi('optical') syst.get_clusters_mpi('aligned') ttotal = 6 cSizesActual = dict() cSizesActual['contact'] = [[1, 1, 1, 1], [2, 2, 2, 2], [4, 4, 4, 4], [4, 4, 4, 4], [4, 4, 4, 4], [4, 4, 4, 4]] cSizesActual['optical'] = [[1, 1, 1, 1], [1, 1, 2, 2], [2, 2, 2, 2], [2, 2, 2, 2], [4, 4, 4, 4], [4, 4, 4, 4]] cSizesActual['aligned'] = [[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 key in cSizesActual.keys(): if rank == 0: ind = 0 nind = 0 while ind < ttotal: clustSnap = syst.clsnaps[key][nind] if not np.isnan(clustSnap.pos[0][0]): csizes = clustSnap.idsToSizes() assert (csizes == cSizesActual[key][ind]).all() ind += 1 nind += 1
def test_linearFit(): """test Smol linear fitting on dummy runs""" tname = "dummyfull4" fname = 'molsdf4sizesAC' for i in range(1, 6): traj = gsd.hoomd.open( op.join(data_path, tname + '_run' + str(i) + '.gsd')) box = traj[0].configuration.box ats = {'aligned': 6} cldict = {'aligned': 0.35 * 0.35} molno = 4 atype = 'AB' compairs = np.array([[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10, 11]]) syst = cl.SnapSystem(traj, ats, molno, cldict, compairs=compairs, atype=atype) syst.get_clusters_serial('aligned', box) syst.writeSizes('aligned',op.join(data_path,fname + '_run' \ + str(i) + '.dat')) fnames = [ op.join(data_path, fname + '_run1.dat'), op.join(data_path, fname + '_run2.dat'), op.join(data_path, fname + '_run3.dat'), op.join(data_path, fname + '_run4.dat'), op.join(data_path, fname + '_run5.dat') ] (tc, sigtc, mu2s) = cl.linearWithErrors(fnames, 6, dt=0.5, fullreturn=True, plotstats=[ op.join(data_path, fname + 'dummyfull4'), 't (0.5)', '$\mu_2$', ['o', 'x', '^', 'v', 's'] ]) (tct, R2t) = cl.linearFit(0.5 * np.arange(6), mu2s[:, 2]) npt.assert_almost_equal(2 / tct, 0.5091, 4) npt.assert_almost_equal(R2t, 0.6727, 4) actualMu2s = np.array([[1, 1, 1, 1, 1, 1], [1, 1, 1, 3 / 2, 1, 11 / 10], [3 / 2, 3 / 2, 2, 2, 3 / 2, 17 / 10], [2, 2, 2, 2, 2, 2], [2, 4, 2, 4, 2, 14 / 5], [4, 4, 2, 4, 2, 16 / 5]]) npt.assert_array_almost_equal(actualMu2s, mu2s)
def test_mu2vtime(): """ test the (serial) version of getting the mass-averaged cluster size v time """ fname = 'mols8.gsd' traj = gsd.hoomd.open(op.join(data_path, fname)) ats = {'contact': 17} cutoff = 1.1 * 1.1 molno = 8 cldict = {'contact': cutoff} box = traj[0].configuration.box syst = cl.SnapSystem(traj, ats, molno, cldict) syst.get_clusters_serial('contact', box) mu2vtime = syst.getMassAvVsTime('contact') assert np.shape(mu2vtime)[1] == len(traj) assert not (np.isnan(mu2vtime)).all()
def test_trajectory(): """ Try running on an xtc trajectory (from a pull simulation) """ trj = op.join(data_path, 'md_whole.xtc') tpr = op.join(data_path, 'md_dummy.tpr') molno = 100 ats = 33 tstart = 0 ttotal = 4000 comIDs = COMS cainds = CAINDS oainds = OAINDS cldict = {'contact': 0.5 * 0.5, 'optical': 0.7 * 0.7} start = time.time() syst = cl.SnapSystem(trj, ats, molno, cldict, compairs=comIDs, ttotal=ttotal, tstart=tstart, tpr=tpr) end = time.time() print("Time to setup: " + str(end - start) + "\n") start = time.time() syst.get_clusters_serial('contact', np.array([[24.25935], [24.25935], [24.25935]])) end = time.time() print("Time to get contact: " + str(end - start) + "\n") start = time.time() syst.get_clusters_serial('optical', np.array([[24.25935], [24.25935], [24.25935]])) end = time.time() print("Time to get optical: " + str(end - start) + "\n") syst.writeCIDs('contact', 'contact-CIDs.dat') syst.writeCIDs('optical', 'optical-CIDs.dat') syst.writeSizes('contact', 'contact-sizes.dat') syst.writeSizes('optical', 'optical-sizes.dat') start = time.time() syst.writeNNAngSpread('contact', 'nn-angspread-contact.dat', cainds) syst.writeNNAngSpread('optical', 'nn-angspread-optical.dat', oainds) end = time.time() print("Time to get/write NN angle data: " + str(end - start) + "\n")
def run_ang_spread(): """ Try running on an xtc trajectory (from a pull simulation) """ trj = op.join(data_path, 'md_whole.xtc') tpr = op.join(data_path, 'md_dummy.tpr') molno = 100 ats = 33 tstart = 0 ttotal = 4000 cainds = range(12, 23) oainds = range(0, 3) cfname = op.join(data_path, 'angle-spread-contact.dat') ofname = op.join(data_path, 'angle-spread-optical.dat') comIDs = np.array([[12, 13, 14], [16, 17, 18], [20, 21, 22]]) cldict = {'contact': 0.5 * 0.5, 'optical': 0.7 * 0.7} cfname = op.join(data_path, 'contact-CIDs.dat') ofname = op.join(data_path, 'optical-CIDs.dat') start = time.time() syst = cl.SnapSystem(trj, ats, molno, cldict, compairs=comIDs, ttotal=ttotal, tstart=tstart, tpr=tpr) end = time.time() print("Time to setup: " + str(end - start) + "\n") start = time.time() syst.get_clusters_from_file('contact', cfname) end = time.time() print("Time to get contact: " + str(end - start) + "\n") start = time.time() syst.get_clusters_from_file('optical', ofname) end = time.time() print("Time to get optical: " + str(end - start) + "\n") start = time.time() syst.writeAngSpread('contact', cfname, cainds) syst.writeAngSpread('optical', ofname, oainds) end = time.time() print("Time to get angle spread: " + str(end - start))
def test_intermixsetup(): fname = 'dummyfull2type_run1.gsd' traj = gsd.hoomd.open(op.join(data_path, fname)) compairs = np.array([[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10, 11]]) molno = 4 contactcut = 1.1 * 1.1 opticalcut = 0.35 * 0.35 ats = {'contact': 17, 'optical': 12} cutoff = {'contact': contactcut, 'optical': opticalcut} Syst = cl.SnapSystem(traj, ats, molno, cutoff, compairs=compairs, atype='AB', ttotal=6, tstart=0, het=True, typelist=[u'EA', u'EB']) boxL = traj[0].configuration.box[0] Syst.get_clusters_serial('contact', boxL) Syst.get_clusters_serial('optical', boxL) intermixlistC = Syst.writeIntermix('contact', 'dummyfull2type_run1_cImix.dat', returnmat=True) intermixlistO = Syst.writeIntermix('optical', 'dummyfull2type_run1_oImix.dat', returnmat=True) iC0 = np.array([[1, 0, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0]]) iC1 = np.array([[2, 0, 1, 1], [2, 0, 1, 1]]) iC2 = np.array([[4, 1, 2, 3]]) iC3 = np.array([[4, 0, 4, 4]]) iC4 = np.array([[4, 1, 4, 5]]) iC5 = np.array([[4, 2, 4, 6]]) iCs = [iC0, iC1, iC2, iC3, iC4, iC5] iO0 = iC0 iO1 = np.array([[1, 0, 0, 0], [1, 0, 0, 0], [2, 0, 1, 1]]) iO2 = np.array([[2, 0, 1, 1], [2, 0, 1, 1]]) iO3 = np.array([[2, 0, 1, 1], [2, 0, 1, 1]]) iO4 = np.array([[4, 1, 2, 3]]) iO5 = np.array([[4, 2, 2, 4]]) iOs = [iO0, iO1, iO2, iO3, iO4, iO5] return (intermixlistC, intermixlistO, iCs, iOs)
def analyze_clusters(): data_path = '/home/rachael/coarsegraining/CG/active_learning/martini-assembly/dfmi/4_production' #where to look for data trj = op.join(data_path, 'md_whole.xtc') tpr = op.join(data_path, 'md_dummy.tpr') molno = 100 #number of molecules ats = 33 #number of atoms per molecule tstart = 0 ttotal = 4000 comIDs = np.array([[9, 10, 11], [13, 14, 15], [18, 19, 20]]) #index of beads comprising aromatics cldict = { 'contact': 0.5 * 0.5, 'optical': 0.7 * 0.7 } #cutoffs for different cluster types start = time.time() outGro = op.join(data_path, 'conf') syst = cl.SnapSystem(trj, ats, molno, cldict, compairs=comIDs, ttotal=ttotal, tstart=tstart, tpr=tpr, outGro=outGro) end = time.time() print("Time to setup: " + str(end - start) + "\n") start = time.time() syst.get_clusters_serial('contact', np.array([[24.25935], [24.25935], [24.25935]])) end = time.time() print("Time to get contact: " + str(end - start) + "\n") start = time.time() syst.get_clusters_serial('optical', np.array([[19.97738], [19.97738], [19.97738]])) end = time.time() print("Time to get optical: " + str(end - start) + "\n") syst.writeCIDs('contact', 'pull-test-contact-CIDs-dfmi.dat') syst.writeCIDs('optical', 'pull-test-optical-CIDs-dfmi.dat') syst.writeSizes('contact', 'pull-test-contact-sizes-dfmi.dat') syst.writeSizes('optical', 'pull-test-optical-sizes-dfmi.dat')
def test_get_clusters_serial_full(): """ test the serial implementation of setting all the cluster correctly for all cluster types """ fname = 'dummyfull4.gsd' traj = gsd.hoomd.open(op.join(data_path, fname)) box = traj[0].configuration.box ats = {'contact': 17, 'optical': 12, 'aligned': 6} molno = 4 cldict = { 'contact': 1.1 * 1.1, 'optical': 0.35 * 0.35, 'aligned': 0.35 * 0.35 } compairs = np.array([[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10, 11]]) atype = 'AB' syst = cl.SnapSystem(traj, ats, molno, cldict, compairs=compairs, atype=atype) syst.get_clusters_serial('contact', box) syst.get_clusters_serial('optical', box) syst.get_clusters_serial('aligned', box) cSizesActual = dict() cSizesActual['contact'] = [[1, 1, 1, 1], [2, 2, 2, 2], [4, 4, 4, 4], [4, 4, 4, 4], [4, 4, 4, 4], [4, 4, 4, 4]] cSizesActual['optical'] = [[1, 1, 1, 1], [1, 1, 2, 2], [2, 2, 2, 2], [2, 2, 2, 2], [4, 4, 4, 4], [4, 4, 4, 4]] cSizesActual['aligned'] = [[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 key in ats.keys(): cid = 0 clsnaps = syst.clsnaps[key] for clsnap in clsnaps: csizes = clsnap.idsToSizes() assert (cSizesActual[key][cid] == csizes).all() cid += 1
def test_writeout(): """ Test the MPI writing out of cluster stuff """ cldict = {'contact': 1.1 * 1.1} syst = cl.SnapSystem(traj, {'contact': ats}, molno, cldict) syst.get_clusters_mpi('contact') 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]] if rank == 0: syst.writeCIDs('contact', 'dummyCIDs.dat') syst.writeSizes('contact', 'dummysizes.dat') try: fCIDs = open('dummyCIDs.dat') except IOError: print("ERROR! cluster index file was not written.") return False try: fsizes = open('dummysizes.dat') except IOError: print("ERROR! cluster sizes file was not written.") return False lind = 0 for line in fsizes: try: assert (clustSizesActual[lind] == [ int(n) for n in line.split() ]) lind += 1 except AssertionError: print("{0} is not equal to {1}.".format( clustSizesActual[lind], [int(n) for n in line.split()])) return False fCIDs.close() fsizes.close() return True
def test_write_out_frame(): fname = 'mols8.gsd' traj = gsd.hoomd.open(op.join(data_path, fname)) box = traj[0].configuration.box ats = {'contact': 17} cutoff = 1.1 * 1.1 molno = 8 cldict = {'contact': cutoff} syst = cl.SnapSystem(traj, ats, molno, cldict) syst.get_clusters_serial('contact', box) syst.writeCIDs('contact', op.join(data_path, 'mols8cIDs.dat')) cIDfile = op.join(data_path, 'mols8cIDs.dat') cIDfile = open(cIDfile) lines = cIDfile.readlines() cIDfile.close() line = lines[35] cIDsf = [float(c) for c in line.split()] cIDs = [int(c) for c in cIDsf] cl.writeFrameForVMD(cIDs, molno, ats['contact'], op.join(data_path, 'testframe35.dat'))
def test_get_clusters_serial(): """ test the serial implementation of setting all the clusters correctly """ fname = 'dummy8.gsd' traj = gsd.hoomd.open(op.join(data_path, fname)) ats = {'contact': 2} cutoff = 1.1 * 1.1 molno = 8 cldict = {'contact': cutoff} syst = cl.SnapSystem(traj, ats, molno, cldict) box = traj[0].configuration.box syst.get_clusters_serial('contact', box) 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]] cid = 0 clsnaps = syst.clsnaps['contact'] for clsnap in clsnaps: csizes = clsnap.idsToSizes() assert (clustSizesActual[cid] == csizes).all() cid += 1
def test_trajectory(): """ Try running on an xtc trajectory (from a pull simulation) """ trj = op.join(data_path, 'pull_whole.xtc') tpr = op.join(data_path, 'pull.tpr') molno = 2 ats = 29 tstart = 0 ttotal = 498 comIDs = np.array([[9, 10, 11], [13, 14, 15], [18, 19, 20]]) cldict = {'contact': 0.5 * 0.5, 'optical': 0.7 * 0.7} start = time.time() syst = cl.SnapSystem(trj, ats, molno, cldict, compairs=comIDs, ttotal=ttotal, tstart=tstart, tpr=tpr) end = time.time() print("Time to setup: " + str(end - start) + "\n") start = time.time() syst.get_clusters_serial('contact', np.array([[24.25935], [24.25935], [24.25935]])) end = time.time() print("Time to get contact: " + str(end - start) + "\n") start = time.time() syst.get_clusters_serial('optical', np.array([[24.25935], [24.25935], [24.25935]])) end = time.time() print("Time to get optical: " + str(end - start) + "\n") syst.writeCIDs('contact', 'pull-test-contact-CIDs.dat') syst.writeCIDs('optical', 'pull-test-optical-CIDs.dat') syst.writeSizes('contact', 'pull-test-contact-sizes.dat') syst.writeSizes('optical', 'pull-test-optical-sizes.dat')
def test_getLengthDistribution(): """ test getting the length distribution from a trajectory """ fname = 'dummyfull4.gsd' traj = gsd.hoomd.open(op.join(data_path, fname)) box = traj[0].configuration.box ats = {'contact': 17, 'optical': 12, 'aligned': 6} molno = 4 cldict = { 'contact': 1.1 * 1.1, 'optical': 0.35 * 0.35, 'aligned': 0.35 * 0.35 } compairs = np.array([[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10, 11]]) atype = 'AB' syst = cl.SnapSystem(traj, ats, molno, cldict, compairs=compairs, atype=atype) syst.get_clusters_serial('contact', box) syst.get_clusters_serial('optical', box) syst.get_clusters_serial('aligned', box) box = traj[0].configuration.box[0:3] ldistribt = syst.getLengthDistribution('contact', cldict['contact'], box, conOptDistanceCython) npt.assert_array_almost_equal(ldistribt, np.array([[0., 0., 0., 0.], [2.92, 2.92, 1.22, 1.22], [4.92, 4.92, 4.92, 4.92], [4.12, 4.12, 4.12, 4.12], [3.08, 3.08, 3.08, 3.08], [1.93, 1.93, 1.93, 1.93]]), decimal=2)
atype = u'LS' #optical/aligned bead type combeadtype = 'E' #bead type of center of mass bead colors = {'contact': 'red', 'optical': 'blue'} fbase = 'mols'+str(molnolabel)+'_' + str(AAdlabel)+'-'\ +str(SCdlabel)+'-'+str(BBdlabel)+'_short_run' #template of .gsd file name fnames = [fbase + r + '.gsd' for r in runs] start = time() traj = gsd.hoomd.open(fname) box = traj[0].configuration.box[0:3] Systs = [ cl.SnapSystem(traj, ats, molno, cutoff, compairs=compairs, ttotal=ttotal, tstart=tstart, atype=atype) for fname in fnames ] end = time() print("Time to setup clusters: ", end - start) #Find all cluster IDs start = time() lind = 0 for Syst in Systs: Syst.get_clusters_serial('contact', box, lcompute=None) Syst.get_clusters_serial('optical', box, lcompute=None) lind += 1 end = time()
def test_clusters_and_length_serial(): """ test reusing the BallTree from cluster computation for the length distribution computation """ fname = 'mols8.gsd' traj = gsd.hoomd.open(op.join(data_path, fname)) snap = traj[0] box = snap.configuration.box[0:3] ats = {'contact': 17, 'optical': 12, 'aligned': 6} cldict = { 'contact': 1.1 * 1.1, 'optical': 0.35 * 0.35, 'aligned': 0.35 * 0.35 } molno = 8 syst = cl.SnapSystem(traj, ats, molno, cldict) syst.get_clusters_serial('contact', box, lcompute=op.join(data_path, 'mols8CLdistrib.dat')) syst.get_clusters_serial('optical', box, lcompute=op.join(data_path, 'mols8OLdistrib.dat')) syst.get_clusters_serial('aligned', box, lcompute=op.join(data_path, 'mols8ALdistrib.dat')) filecidbase = op.join(data_path, 'mols8CIDs_') fileszbase = op.join(data_path, 'mols8sizes_') syst.writeCIDs('contact', filecidbase + 'C.dat') syst.writeSizes('contact', fileszbase + 'C.dat') syst.writeCIDs('optical', filecidbase + 'O.dat') syst.writeSizes('optical', fileszbase + 'O.dat') syst.writeCIDs('aligned', filecidbase + 'A.dat') syst.writeSizes('aligned', fileszbase + 'A.dat') lC = open(op.join(data_path, 'mols8CLdistrib.dat')) lO = open(op.join(data_path, 'mols8OLdistrib.dat')) lA = open(op.join(data_path, 'mols8ALdistrib.dat')) linesC = lC.readlines() linesO = lO.readlines() linesA = lA.readlines() lC.close() lO.close() lA.close() flinesC = np.array([float(f) for f in linesC[len(linesC) - 1].split()]) flinesO = np.array([float(f) for f in linesO[len(linesO) - 1].split()]) flinesA = np.array([float(f) for f in linesA[len(linesA) - 1].split()]) npt.assert_array_almost_equal( flinesC, np.array([6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25]), decimal=2) npt.assert_array_almost_equal( flinesO, np.array([0., 4.18, 0., 4.18, 4.18, 4.18, 4.18, 4.18]), decimal=2) npt.assert_array_almost_equal( flinesA, np.array([0., 0., 0., 1.03, 0.98, 0., 1.03, 0.98]), decimal=2)
BBdlabel = BBBB #BB bead parameter label dt = 1.0 #assumed timestep atype = u'LS' #optical/aligned bead type colors = {'contact':'red','optical':'blue'} typelist = [u'EA',u'EB'] fbase = 'mols'+str(molnolabel)+'_' + str(AAdlabel)+'-02-'\ +str(SCdlabel)+'-150-'+str(BBdlabel)+'_small_run' #template of .gsd file name fnames = [save_path + '/' + fbase + str(r) + '.gsd' for r in range(1,runs+1)] start = time() traj = gsd.hoomd.open(fnames[0]) box = traj[0].configuration.box[0:3] Systs = [cl.SnapSystem(fname,ats,molno,cutoff, compairs=compairs,ttotal=ttotal,tstart=tstart, atype=atype,het=True,typelist=typelist) for fname in fnames] end = time() print("Time to setup clusters: ",end-start) #Find all cluster IDs start = time() lind = 0 for Syst in Systs: Syst.get_clusters_serial('contact',box,lcompute=None) Syst.get_clusters_serial('optical',box,lcompute=None) lind += 1 end = time() print("Time to get clusters: ",end-start)
fnames = [] ldfnames = [] for i in range(runs): fname = op.join(traj_path, fbase + str(i + 1) + '.gsd') fnames.append(fname) ldfname = op.join(data_path, fbase + 'ldistrib' + str(i + 1)) ldfnames.append(ldfname) start = time() traj = gsd.hoomd.open(fname) box = traj[0].configuration.box[0:3] Systs = [ cl.SnapSystem(gsd.hoomd.open(fname), ats, molno, cutoff, compairs=compairs, ttotal=ttotal, tstart=tstart, atype=atype) for fname in fnames ] end = time() if rank == 0: print("Time to setup clusters: ", end - start) #Find all cluster IDs start = time() lind = 0 for Syst in Systs: ldfnameC = ldfnames[lind] + '_C.dat' ldfnameO = ldfnames[lind] + '_O.dat' cidNameC = op.join(
test long run with mpi (run with mpiexec) """ from __future__ import absolute_import, division, print_function import os.path as op import numpy as np import numpy.testing as npt import clustering as cl import gsd.hoomd import sys from mpi4py import MPI comm = MPI.COMM_WORLD rank = comm.Get_rank() size = comm.Get_size() data_path = op.join(cl.__path__[0], 'data') ats = 17 molno = 10000 trajname = op.join(data_path, 'mols10000_740-0-0_run1.gsd') cutoff = 1.1 * 1.1 traj = gsd.hoomd.open(trajname) cldict = {'contact': 1.1 * 1.1} syst = cl.SnapSystem(traj, ats, molno, cldict, 12) syst.get_clusters_mpi('contact', 12) if rank == 0: print("writing clusterIDs") syst.writeCIDs('contact', op.join(data_path, 'mols10KcIDs.dat')) print("writing cluster sizes") syst.writeSizes('contact', op.join(data_path, 'mols10KcSizes.dat'))