def next(self): if len(self.filenames) == 0: raise StopIteration data = polymerutils.load(self.filenames.pop()) contacts = self.method(data, cutoff=self.cutoff) // self.coarsegrain return contacts
def getCmap(prefix = "", radius = 6): """ This is a function to calculate a simulated Hi-C contact map from one or several folders with conformations, defined by "prefix". """ n = 20 # number of processes to use = number of cores coarsegrainBy = 5 # how many monomers per pixel in a heatmap print(os.getcwd()) folders = [i for i in os.listdir(".") if i.startswith(prefix)] foldes = [i for i in folders if os.path.exists(i)] print(folders) files = sum([polymerutils.scanBlocks(i)["files"] for i in folders], []) filegroups = [files[i::n] for i in range(n)] data = polymerutils.load(files[0]) N = len(data) method = contactmaps.findMethod(data,radius) cmapN = int(np.ceil(N / coarsegrainBy)) cmap = averageContacts(contactCalculator, filegroups, cmapN, classInitArgs=[radius, coarsegrainBy, method ], nproc=n, bucketNum = 60, useFmap=True) pickle.dump(cmap, open("cmaps/cmap{0}_r={1}.pkl".format(prefix, radius), 'wb'))
#!/usr/bin/env python import sys from openmmlib import pymol_show from openmmlib.polymerutils import load inFile = sys.argv[1] data = load(inFile) pymol_show.show_chain(data)
def doPolymerSimulation(steps, dens, stiff, folder): from openmmlib.openmmlib import Simulation from openmmlib.polymerutils import grow_rw import time SMCTran = initModel() box = (N / dens)**0.33 # density = 0.1 if os.path.exists(os.path.join(folder, "block10.dat")): block = scanBlocks(folder)["keys"].max() - 1 data = polymerutils.load( os.path.join(folder, "block{0}.dat".format(block))) else: data = grow_rw(N, int(box) - 2) block = 0 assert len(data) == N skip = 0 time.sleep(1) while True: SMCTran.steps(3) if (block % 2000 == 0) and (skip == 0): print("doing dummy steps") SMCTran.steps(500000) skip = 100 print(skip, "blocks to skip") a = Simulation(timestep=80, thermostat=0.01) a.setup(platform="CUDA", PBC=True, PBCbox=[box, box, box], GPU=sys.argv[4], precision="mixed") a.saveFolder(folder) a.load(data) a.addHarmonicPolymerBonds(wiggleDist=0.1) if stiff > 0: a.addGrosbergStiffness(stiff) a.addPolynomialRepulsiveForce(trunc=1.5, radiusMult=1.05) left, right = SMCTran.getSMCs() for l, r in zip(left, right): a.addBond(l, r, bondWiggleDistance=0.5, distance=0.3, bondType="harmonic") a.step = block if skip > 0: print("skipping block") a.doBlock(steps, increment=False) skip -= 1 if skip == 0: a.doBlock(steps) block += 1 a.save() if block == 50000: break data = a.getData() del a time.sleep(0.1)
def load(filename): from openmmlib import polymerutils return polymerutils.load(filename)