Ejemplo n.º 1
0
def create_initial_configuration(traj):

    len_chrom = traj["len_chrom"]
    Cent = traj["Cent"]
    p_ribo = traj["p_ribo"]
    R = traj["R"]
    micron = traj["micron"]

    # Diffusing elements
    N_diffu = traj["N_diffu"]
    r_diffu = traj.get("diameter_diffu", 1) / 2

    # exit()
    p_origins = traj["p_origins"]

    if type(len_chrom) != list:
        len_chrom, _ = load_lengths_and_centro(len_chrom, traj["coarse"])

    if type(Cent) != list:
        _, Cent = load_lengths_and_centro(Cent, traj["coarse"])

    if type(p_origins) != list:
        p_origins = load_ori_position(traj["p_origins"], traj["ori_type"],
                                      len_chrom, traj["coarse"])
    p_ribo = [[int(position) // int(traj["coarse"] // 1000), length]
              for position, length in p_ribo]

    two_types = traj.get("two_types", False)
    p_second = traj.get("p_second", [])
    dstrength = traj.get("dstrength", 0)
    strengths = None
    if p_second != []:

        # Assign delta_strength
        if dstrength != 0:
            strengths = []
            for bands, pos in zip(p_second, p_origins):
                strengths.append([])
                for p in pos:
                    found = False
                    for Intervals in bands:
                        if Intervals[0] < p < Intervals[1]:
                            strengths[-1].append(dstrength)
                            found = True
                            break
                    if not found:
                        strengths[-1].append(1)

        ps = []
        for ch in p_second:
            ps.append([])
            for p1, p2 in ch:
                ps[-1] += range(p1, p2)
        p_second = ps

    boundaries = traj.get("boundaries", False)
    if boundaries:
        extra_boundaries = load_boundaries(coarse=traj["coarse"])
    print("strengths", strengths)
    # Yeast case
    spb = traj["spb"]
    nucleole = traj["nucleole"]
    telomere = traj["telomere"]
    microtubule_length = traj["microtubule_length"] * micron
    special_start = traj["special_start"]
    visu = traj["visu"]
    dump_hic = traj["dump_hic"]

    # Scenari
    diff_bind_when_free = traj["diff_bind_when_free"]

    # Simulation parameters

    Np = len(len_chrom)
    assert (len(len_chrom) == len(Cent) == len(p_ribo))
    if special_start:
        Sim = create_init_conf_yeast(len_chrom=len_chrom,
                                     dist_centro=Cent,
                                     p_ribo=p_ribo,
                                     Radius=R - 1,
                                     Mt=microtubule_length)
    else:
        Sim = []

    spbp = 0 if not spb else 1

    Total_particle = sum(len_chrom) + N_diffu * 2 + spbp
    list_nuc = [
        list(range(start, start + size)) if size != 0 else []
        for start, size in p_ribo
    ]
    # print(list_nuc)
    # exit()

    snapshot = data.make_snapshot(N=Total_particle,
                                  box=data.boxdim(L=2 * R),
                                  bond_types=['polymer'])

    spbb = Np if spb else 0

    if visu:
        spbb = 0

    bond_diffu = 0
    if diff_bind_when_free:
        bond_diffu = N_diffu

    snapshot.bonds.resize(sum(len_chrom) - len(len_chrom) + bond_diffu + spbb)

    bond_list = ['Mono_Mono', 'Diff_Diff', 'Mono_Diff']

    if spb:
        bond_list += ["Spb_Cen"]
    if nucleole:
        bond_list += ["Mono_Nuc", "Nuc_Nuc"]

    snapshot.bonds.types = bond_list

    plist = ['Mono', 'Ori', 'Diff', 'S_Diff', 'F_Diff', "I_Diff"]
    if two_types:
        plist.append("Mono1")

    if spb:
        plist.append("Spb")
        if visu:
            plist.append("Cen")
    if nucleole:
        plist += ['Nuc', 'A_Nuc', 'P_Nuc']

    if telomere:
        plist += ["Telo"]

    snapshot.particles.types = plist

    offset_bond = 0
    offset_particle = 0
    lPolymers = []

    ################################################
    # Polymer chains
    Cen_pos = []
    list_ori = []
    for i in range(Np):

        found_cen = False
        npp = len_chrom[i]  # Number of particles
        # Position of origin of replication
        pos_origins = p_origins[i]

        istrength = None
        if strengths is not None:
            istrength = strengths[i]

        if Sim == []:
            initp = 2 * np.random.rand(3) - 1
        else:
            # print(i)
            initp = Sim.molecules[i].coords[0]

        for p in range(npp - 1):
            inuc = 0
            if nucleole:
                if p in list_nuc[i]:
                    inuc += 1
                if p + 1 in list_nuc[i]:
                    inuc += 1

            snapshot.bonds.group[offset_bond + p] = [
                offset_particle + p, offset_particle + p + 1
            ]
            if inuc == 0:
                snapshot.bonds.typeid[offset_bond + p] = bond_list.index(
                    'Mono_Mono')  # polymer_A
            if inuc == 1:
                snapshot.bonds.typeid[offset_bond + p] = bond_list.index(
                    'Mono_Nuc')  # polymer_A
            if inuc == 2:
                snapshot.bonds.typeid[offset_bond + p] = bond_list.index(
                    'Nuc_Nuc')  # polymer_A

        offset_bond += npp - 1

        for p in range(npp):
            # print(offset_bond, offset_bond + p)
            if Sim == []:
                new = 2 * (2 * np.random.rand(3) - 1)
                while linalg.norm(initp + new) > R - 1:
                    new = 2 * (2 * np.random.rand(3) - 1)

                initp += new
            else:
                initp = Sim.molecules[i].coords[p]

            snapshot.particles.position[offset_particle + p] = initp
            # snapshot.particles.diameter[offset_particle + p] = 1

            if p in pos_origins:
                list_ori.append(offset_particle + p)

            if visu and (p in pos_origins):
                snapshot.particles.typeid[offset_particle + p] = plist.index(
                    'Ori')  # Ori
            else:
                snapshot.particles.typeid[offset_particle + p] = plist.index(
                    'Mono')  # A
                if two_types and p in p_second[i]:
                    snapshot.particles.typeid[offset_particle +
                                              p] = plist.index('Mono1')  # A

            if spb and p == Cent[i]:
                Cen_pos.append(offset_particle + p)
                if visu:
                    snapshot.particles.typeid[offset_particle +
                                              p] = plist.index('Cen')  # A
                found_cen = True

            if nucleole and p in list_nuc[i]:
                snapshot.particles.typeid[offset_particle +
                                          p] = plist.index('Nuc')

            if telomere and (p == 0 or p == npp - 1):
                snapshot.particles.typeid[offset_particle +
                                          p] = plist.index('Telo')

            if boundaries and p in extra_boundaries[i]:
                snapshot.particles.typeid[offset_particle +
                                          p] = plist.index('Telo')

        lPolymers.append(
            Polymer(i,
                    offset_particle,
                    offset_particle + npp - 1,
                    [po + offset_particle for po in pos_origins],
                    strengths=istrength))
        offset_particle += npp

        assert (found_cen == spb)

    phic = 0
    if dump_hic:
        phic = 0 + offset_particle - 1
    ###################################################
    # SPD
    tag_spb = None
    if spb:
        tag_spb = 0 + offset_particle
        # print(tag_spb)
        # print(snapshot.particles[offset_particle])
        snapshot.particles.position[offset_particle] = [-R + 0.1, 0, 0]
        snapshot.particles.typeid[offset_particle] = plist.index('Spb')
        offset_particle += 1

        if not visu:
            for i in range(Np):
                # print(offset_particle - 1, Cen_pos[i])
                snapshot.bonds.group[offset_bond] = [
                    offset_particle - 1, Cen_pos[i]
                ]
                snapshot.bonds.typeid[offset_bond] = bond_list.index(
                    'Spb_Cen')  # polymer_A

                offset_bond += 1
    ############################################################
    # Diffusing elements
    # Defining useful classes

    # Defining particles and bonds for the simulation
    p_tag_list = []
    for i in range(N_diffu):
        npp = 2  # Number of particles

        initp = (R - 2) * (2 * np.random.rand(3) - 1)
        while linalg.norm(initp) > R - 1:
            initp = (R - 2) * (2 * np.random.rand(3) - 1)
        if diff_bind_when_free:
            for p in range(npp - 1):
                snapshot.bonds.group[offset_bond + p] = [
                    offset_particle + p, offset_particle + p + 1
                ]
                snapshot.bonds.typeid[offset_bond + p] = bond_list.index(
                    'Diff_Diff')  # Diff_Diff
            offset_bond += npp - 1

        p_tag_list.append([])
        for p in range(npp):

            # print(offset_bond, offset_bond + p)
            if diff_bind_when_free:
                new = 2 * (2 * np.random.rand(3) - 1)
                while linalg.norm(initp + new) > R - 1:
                    new = 2 * (2 * np.random.rand(3) - 1)
                    # print(initp,new,R,linalg.norm(initp + new))
                    # exit()
                initp += new
            else:
                initp = (R - 2) * (2 * np.random.rand(3) - 1)
                while linalg.norm(initp) > R - 1:
                    initp = (R - 2) * (2 * np.random.rand(3) - 1)

            snapshot.particles.position[offset_particle + p] = initp
            # snapshot.particles.mass[offset_particle + p] = r_diffu**3 * 2**3
            snapshot.particles.typeid[offset_particle + p] = plist.index(
                "Diff")  # Diffu
            p_tag_list[-1].append(offset_particle + p)
        offset_particle += npp

    # Load the configuration

    for i, p in enumerate(snapshot.bonds.group):
        if p[0] == p[1]:
            print(i, p)

    return snapshot, phic, tag_spb, bond_list, plist, Cen_pos, lPolymers, list_ori, p_tag_list
Ejemplo n.º 2
0
        parameters.pop("sumatra_label")
    else:
        print("no extra label")

    parameters["data_folder"] = os.path.join(parameters["data_folder"], "")
    parameters["filename"] = param_file

    print(parameters["data_folder"])
    with open(os.path.join(parameters["data_folder"], "params.json"), "w") as f:
        s = json.dumps(parameters)
        f.write(s)

    # ensembleSim(Nsim, Nori, Ndiff, lengths, p_on, p_off, only_one,
    # all_same_ori=False, l_ori=[], cut=10)
    if type(parameters["lengths"]) == str:
        lengths, _ = load_lengths_and_centro(parameters["lengths"], parameters["coarse"])
        parameters["lengths"] = lengths

    if type(parameters["Nori"]) == str and parameters["Nori"] != "xenope":
        l_ori = load_ori_position(parameters["Nori"],
                                  parameters["ori_type"],
                                  parameters["lengths"],
                                  parameters["coarse"])

    if parameters["Nori"] == "xenope":
        l_ori = [list(range(parameters["lengths"][0]))]

    parameters.pop("filename")
    data_folder = parameters.pop("data_folder")
    parameters.pop("ori_type")
    c = parameters.pop("coarse")