def init_positions(num_monos, polymer="isotropic", length=50):
    """
    Create list of monomer positions to be fed into sim.load()
    """
    step_size = 1.0

    if polymer == "boxed":
        step_size = length / np.sqrt(num_monos)
        init_polymer = tools.create_boxed_random_walk(step_size,
                                                      num_monos,
                                                      max_length=length)
        print("polymer is boxed")
    elif polymer == "extended":
        step_size = length / np.sqrt(num_monos)
        init_polymer = polymerutils.create_random_walk(1, num_monos)
        print("polymer is extended")
    elif polymer == "compact":
        init_polymer = polymerutils.grow_rw(num_monos, int(length) - 2)
        print("polymer is compact")
    else:  # isotropic
        init_polymer = tools.create_isotropic_random_walk(step_size, num_monos)
        print("polymer is isotropic, input was", polymer)

    return init_polymer
    400, 100, 200, 400, 100, 200, 400, 100, 200, 400, 100, 200, 400, 100, 200,
    400, 100, 200, 400, 100, 200, 400, 100, 200
]
'lleft and lright are defined in SMCTranslocator!'
lleft = (np.cumsum(TADSizes, dtype=np.int64) - 1
         )  #Load in with left arm active
lright = (np.cumsum(TADSizes, dtype=np.int64)[0:-1] + 1
          )  #Load with right arm active
N = sum(TADSizes)  # number of monomers
smcStepsPerBlock = 1  # I take something like 1/steppingprobability, because stepping is not determistic. I usually choose the probability of stepping to be max 0.1. Usually I take 20 for genes speeding up and 10 for genes slowing down
stiff = 0  # Polymer siffness in unit of bead size
dens = 0.2  #float(sys.argv[4]) # 0.2 # density in beads / volume. The density can roughly be estimated by looking at the amount of chromatin in a nuclear volume.
box = (
    N / dens
)**0.33  # Define size of the bounding box for Periodic Boundary Conditions
data = polymerutils.grow_rw(N, int(box) - 2)  # creates a compact conformation
block = 0  # starting block
kon = 0  #float(sys.argv[5]) # CTCF binding rate
koff = 1  #float(sys.argv[6]) #CTCF unbinding rate
CTCFsites = np.array(
    [0]
)  #CTCF binding sites (take np.cumsum(TADsizes) if you want to compare to CTCF sites that are stall sites).
CTCFCohesinEn = 0  # float(sys.argv[7]) # Cohesin-CTCF interaction energy in kT, without a neighbouring cohesin, the unbinding rate of CTCF is koff, if a cohesin is right next to a CTCF site, the CTCF unbinding rate is koff*exp(-CTCFCohesinEn)

kswitch = 0  #float(sys.argv[4])
CTCFPause = 1
zloops = 1
'this variable is controlled in smcTranslocator'

steps = int(
    200 * (smcStepsPerBlock)
コード例 #3
0
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)
コード例 #4
0
def exampleOpenmm(supercoilCompaction=4, plectonemeLength=10, plectonemeGap=0, stifness=2, ind=0, domainNum=30, domainLen=5):
    """
    A method that performs one simulation.
    """

    a = Simulation(timestep=100, thermostat=0.01)

    a.setup(platform="cuda",  GPU=sys.argv[1])

    foldername = "newSweep_lambda{0}_L{1}_gap{2}_stiff{3}_ind{4}".format(supercoilCompaction, plectonemeLength,
                                                         plectonemeGap, stifness, ind)
    a.saveFolder(foldername)  # folder where to save trajectory


    """
    Defining all parameters of the simulation
    """
    genomeLengthBp = 4000000
    lengthNm = 1500
    diamNm = 450
    supercoilBpPerNm = 4.5 * supercoilCompaction

    supercoilDiameterNm = 3.45 * np.sqrt(supercoilBpPerNm)
    supercoilBpPerBall = supercoilBpPerNm * supercoilDiameterNm * 2  # 2 strands
    print(supercoilBpPerBall)
    print(supercoilDiameterNm)

    ballNumber = 2 * int(0.5 * (genomeLengthBp / supercoilBpPerBall))
    radiusMon = 0.5 * (diamNm / float(supercoilDiameterNm))
    halfLengthMon = 0.5 * (lengthNm / float(supercoilDiameterNm))

    N = ballNumber
    print(N)
    avLength = plectonemeLength

    # Growing a circular polymer
    bacteria = grow_rw(N, int(halfLengthMon * 2), "line")
    bacteria = bacteria - np.mean(bacteria, axis=0)
    a.load(bacteria)  # filename to load
    print(bacteria[0])

    a.tetherParticles([0, N - 1])

    a.addCylindricalConfinement(r=radiusMon, bottom=-halfLengthMon, top=halfLengthMon, k=1.5)


    BD = makeBondsForBrush(chainLength=a.N)

    # Coordinates of top highly expressed genes
    geneCoord = [1162773, 3509071, 1180887, 543099, 1953250, 2522439, 3328524, 1503879, 900483, 242693, 3677144, 3931680, 3677704, 3762707, 3480870, 3829656, 1424678, 901855, 1439056, 3678537]
    particleCoord = [(i / 4042929.) * a.N for i in geneCoord]
    particleCoord = [int(i) for i in particleCoord]
    particleCoord = sorted(particleCoord)

    # Below making sure that if two PFRs overlap, we just create a PFR which is twice longer
    gapShift = 7
    gaps = []
    gapStart = particleCoord[0]
    gapEnd = particleCoord[0]
    for i in particleCoord:
        if i > gapEnd:
            gaps.append((gapStart, gapEnd))
            gapStart = i
            gapEnd = i + gapShift
        else:
            gapEnd += gapShift
    gaps.append((gapStart, gapEnd))

    # Adding PFRs at highly expressed genes
    M = domainNum
    particles = []
    for st, end in gaps:
        BD.addGap(st, end)

    # Making bonds
    BD.addBristles(3, plectonemeLength, 0, plectonemeGap)
    BD.sortSegments()
    print(BD.segments)
    BD.createBonds()
    BD.checkConnectivity()

    BD.save(os.path.join(a.folder, "chains"))
    a.setChains(chains=BD.getChains())


    a._initHarmonicBondForce()
    for i in BD.bonds:
        a.addBond(i[0], i[1], bondWiggleDistance=0.15, bondType="Harmonic")


    a.addGrosbergStiffness(k=stifness)
    a.addGrosbergRepulsiveForce(trunc=1.)
    # a.addSoftLennardJonesForce(epsilon=0.46, trunc=2.5, cutoff=2.3)
    a.save(os.path.join(a.folder, "start"))
    a.localEnergyMinimization()
    a.save()

    for step in range(500):
        a.doBlock(50000)
        a.save()
    a.printStats()