示例#1
0
    def __init__(self, seqname, find_cri, phis, eh, es, eps0=80, fgRPA=False, pH=None, parallel=False, **kwargs):
        self.zc = kwargs.get('zc', 1)
        self.zs = kwargs.get('zs', 1)
        self.find_cri = find_cri
        self.cri_pre_calc = kwargs.get('cri_pre_calc', True)
        self.phi_min_calc = ff.phi_min_calc
        self.invT = 1e2
        self.wtwo_ratio = kwargs.get('wtwo_ratio', None)
        self.parallel = parallel
        self.name = kwargs.get('name', None)
        self.cri_only = kwargs.get('cri_only', False)
        self.mimics = kwargs.get("mimics", None)
        self.eps0=eps0

        protein_data = sl.get_the_charge(seqname, pH=pH)
        self.seqname = seqname
        self.sigma = protein_data[0]
        self.N = protein_data[1]
        self.sequence = protein_data[2]

        self.phis = float(phis)
        self.eh = float(eh)
        self.es = float(es)
        self.fgRPA = fgRPA

        self.HP = self.Heteropolymer()
示例#2
0
    def __init__(self, u, seqname, phiTop, phisTop, phiBot=None, phisBot=None, zc=1, zs=1, **kwargs):
        self.u = u
        self.du = kwargs.get('du', 0.1)
        self.zc = zc
        self.zs = zs

        protein_data = sl.get_the_charge(seqname)
        self.seqname = seqname
        self.sigma = protein_data[0]
        self.N = protein_data[1]
        self.sequence = protein_data[2]

        self.nt = kwargs.get('nt', 100)
        self.ionic_strength = kwargs.get('ionic_strength', 100e-3)

        # Flory parameters !
        self.eh, self.es = 0, 0
        self.phiTop, self.phiBot = phiTop, phiBot
        self.phisTop, self.phisBot = phisTop, phisBot

        self.HP = self.Heteropolymer()

        # Minimization helpers
        self.phi_min_calc = 1e-12
        self.invT = 1e4
示例#3
0
    def __init__(self, phi_m):
        self.T_star = 0.286
        self.eta = 1

        # res_list gives other info also !
        seq_data = seq_list.get_the_charge('Ddx4_N1_m')
        # seq_data = seq_list.get_the_charge('alt_DdX4')
        self.sigmas = seq_data[0]
        self.N = seq_data[1]

        self.phi_m = phi_m
        self.phi_c = phi_m * np.abs(np.sum(self.sigmas)) / self.N
        self.dphi_c = np.abs(np.sum(self.sigmas)) / self.N
        self.phi_s = 0
        # Assuming r_i = 0 for all i
        self.phi_w = 1 - self.phi_m - self.phi_c - self.phi_s
        self.dphi_w = -1 - self.dphi_c
示例#4
0
    def __init__(self,
                 seqname,
                 ehs,
                 phis_mM,
                 find_cri,
                 umax,
                 pH,
                 zc=1,
                 zs=1,
                 epsfun=False,
                 eps_modify_ehs=False,
                 **kwargs):
        self.du = kwargs.get('du', 0.1)
        self.zc = zc
        self.zs = zs
        self.epsfun = epsfun
        self.eps_modify_ehs = eps_modify_ehs
        self.ehs = ehs
        self.umax = umax

        protein_data = sl.get_the_charge(seqname, pH=7)
        self.seqname = seqname
        self.sigma = protein_data[0]
        self.N = protein_data[1]
        self.sequence = protein_data[2]

        self.nt = kwargs.get('nt', 100)
        self.ionic_strength = kwargs.get('ionic_strength', 100e-3)

        # Flory parameters !
        self.phis_mM = phis_mM
        self.phis = phis_mM * 0.001 / (1000. / 18.)

        self.HP = self.Heteropolymer()
        self.find_cri = find_cri

        # Minimization helpers
        self.phi_min_calc = 1e-12
        self.invT = 1e4

        self.r_res = 1
        self.r_con = 1
        self.r_sal = 1
        self.eta = 1

        self.phi_min_sys = 1e-12
示例#5
0
    def __init__(self, seqname, ehs, phis_mM, find_cri, pH=7, zc=1, zs=1, eps0=80, epsfun=False, eps_modify_ehs=False,
                 parallel=False, **kwargs):
        self.du = kwargs.get('du', 0.05)
        self.zc = zc
        self.zs = zs
        self.eps0 = eps0
        self.epsfun = epsfun
        self.eps_modify_ehs = eps_modify_ehs
        self.ehs = ehs
        self.parallel = parallel
        self.name = kwargs.get('name',None)
        self.cri_only = kwargs.get('cri_only', False)
        self.mimics = kwargs.get("mimics", None)

        protein_data = sl.get_the_charge(seqname, pH=pH, mimics=self.mimics)
        self.seqname = seqname
        self.sigma = protein_data[0]
        self.N = protein_data[1]
        self.sequence = protein_data[2]

        self.nt = kwargs.get('nt', 100)
        self.ionic_strength = kwargs.get('ionic_strength', 100e-3)

        # Flory parameters !
        self.phis_mM = phis_mM
        self.phis = phis_mM * 0.001 / (1000. / 18.)

        self.HP = self.Heteropolymer()
        self.find_cri = find_cri

        # Minimization helpers
        self.phi_min_calc = 0
        self.invT = 1e4

        self.r_res = 1
        self.r_con = 1
        self.r_sal = 1
        self.eta = 1

        self.phi_min_sys = 1e-12
ehs = [float(x) for x in sys.argv[3:5]]

# use  phi-dependent permittivity or not
ef = False

if sys.argv[2] == "cri_calc":
    cri_calc_end = 1
else:
    cri_calc_end = 0
    umin = float(sys.argv[2])

du = 0.1

#=========================== Set up parameters ===========================
seq_name = sys.argv[1]  # Select a sequence in seq_list.py
sig, N, the_seq = sl.get_the_charge(seq_name)

HP = tt.RPAFH(sig, ehs=ehs, epsfun=ef)

#======================= Calculate critical point ========================

print('Seq:' , seq_name, '=' , the_seq ,'\nphi_s=', phis , \
      'r_res ='   , gv.r_res , ', r_con =' , gv.r_con , \
      ', r_sal =' , gv.r_sal , ', eta ='   , gv.eta, \
      '\nehs :' , ehs[0], ehs[1] )

t0 = time.time()

#critical_point
phi_cri, u_cri = fs.cri_calc(HP, phis)
示例#7
0
write_configs_to_file = False # write generated chain configurations to files or not

T    = 1.    # T = l/l_B = reduced temperature
rD   = 3.    # Debye screening length
cut  = 0.    # short-range cutoff for monomer-monomer interaction

Rmax    = 100  # Maximum distance between two chains
n_R     = 100  # number of different R

n_ch1s, n_ch2s = int(1e4), int(1e4) # number of chain configurations
n_pairs = n_ch1s*n_ch2s

# Import sequences
seqname1, seqname2 = sys.argv[1], sys.argv[2]  
sig1, N1, seq1 = sl.get_the_charge(seqname1)
sig2, N2, seq2 = sl.get_the_charge(seqname2)
 
# Generate chain configurations    
def PolyGen1(_):    
    return cg.ChargedPolymer(sig1)

def PolyGen2(_):
    return cg.ChargedPolymer(sig2)

t = time.perf_counter()

pool = mp.Pool(processes=40) 
chain1s = pool.map(PolyGen1,range(n_ch1s))
chain2s = pool.map(PolyGen2,range(n_ch2s))
pool.close() 
示例#8
0
    phis = 0

# eh, es: now it is a must before setup pH and w2r
try: 
    tt.eh = float(sys.argv[4])
    tt.es = float(sys.argv[5])    
except:
    tt.eh = 0
    tt.es = 0

# pH value
pHchange = False
pHvalue = 0
try:
    pHvalue = float(sys.argv[6])
    sig, N, the_seq = sl.get_the_charge(seqname, pH=pHvalue )
    pHchange = True
except:
    sig, N, the_seq = sl.get_the_charge(seqname)   

# short-range repulsion
try:
    wtwo_ratio = float(sys.argv[7])
    HP = tt.Heteropolymer(sig, zc=zc,zs=zs, w2=4*np.pi/3*wtwo_ratio)
except:
    wtwo_ratio = 1
    HP = tt.Heteropolymer(sig, zc=zc,zs=zs)


# doing fg-RPA
if fgRPA:
示例#9
0
def run(seqname, u, phiTop, phisTop, phiBot=-1, phisBot=-1, zc=1, zs=1):
    # Select a sequence in seq_list.py
    sig, N, the_seq = sl.get_the_charge(seqname)

    HP = tt.Heteropolymer(sig, zc=zc, zs=zs)

    print('Seq:', seqname, '=', the_seq)

    #------------------- Prepare phi origin ------------------------

    nt = 100

    if len(sys.argv) > 7:
        phiall = np.linspace(phiBot + (phiTop - phiBot) * 0.001,
                             phiTop - (phiTop - phiBot) * 0.001, nt)
        phisall = np.linspace(phisBot + (phisTop - phisBot) * 0.001,
                              phisTop - (phisTop - phisBot) * 0.001, nt)
    else:
        phiall = np.linspace(0.1, phiTop, nt)
        phisall = np.linspace(phisTop * 0.01, phisTop * 0.999, nt)

    phisall
    pp = np.array([[phiall[i], phisall[i]] for i in range(nt)])

    #-------------------- Parallel calculate (phi, phis) --------------------

    def salt_parallel(p):
        try:
            x = fss.bisolve(HP, u, p)
            print(p, x)
            return p[0], p[1], x[0], x[1], x[2], x[3], x[4]
        except:
            for test in range(5):
                p[0] = p[0] * (0.95 + 0.1 * np.random.rand())
                try:
                    x = fss.bisolve(HP, u, p)
                    print(p, x)
                    return p[0], p[1], x[0], x[1], x[2], x[3], x[4]
                except:
                    pass
            return p[0], p[1], -1, -1, -1, -1, -1

    phi0, phis0, phia, phisa, phib, phisb, v = zip(*map(salt_parallel, pp))

    #-------------------------- Prepare for output --------------------------

    output = np.zeros((pp.shape[0], 7))

    output[:, 0] = np.array(phi0)
    output[:, 1] = np.array(phis0)
    output[:, 2] = np.array(phia)
    output[:, 3] = np.array(phisa)
    output[:, 4] = np.array(phib)
    output[:, 5] = np.array(phisb)
    output[:, 6] = np.array(v)

    head = ' u=' + str(u) + ' , phiTop=' + str(phiTop) + ' , phisTop=' + str(phisTop) + \
                           ' , phiBot=' + str(phiBot) + ' , phisBot=' + str(phisBot) +  '\n' + \
           '  [phiori, phisori]  [phia, phisa]  [phib, phisb], v \n' + \
           '--------------------------------------------------------------------------------------------'
    np.savetxt('saltdept_zc' + str(HP['zc']) + '_zs' +  str(HP['zs']) + '_' \
               + seqname + '_u' + str(u) + '_w2_4.189.txt',output,header=head)
示例#10
0
    def run(self):
        HP = self.HP
        seqname = self.seqname  # 'Ddx4_N1'
        phis = self.phis
        ff.eh = self.eh
        ff.es = self.es

        duD = int(2)
        du = 10 ** (-duD)

        try:
            pHvalue = float(sys.argv[6])
            sig, N, the_seq = sl.get_the_charge(seqname, pH=pHvalue)
        except:
            sig, N, the_seq = sl.get_the_charge(seqname)

        if self.fgRPA:
            ff.useleff = False

        # ----------------------- Calculate critical point -----------------------

        print('Seq:', seqname, '=', the_seq)

        print('w2=', HP['w2'])
        print('phis=', phis)
        print('eh=' + str(ff.eh) + ' , es=' + str(ff.es))

        t0 = time.time()
        phi_cri, u_cri = self.cri_calc()
        phi_cri, u_cri = 1e-4, 2
        print('Critical point found in', time.time() - t0, 's')
        umax = u_cri * 1.5
        print('u_cri =', '{:.8e}'.format(u_cri), ', phi_cri =', '{:.8e}'.format(phi_cri))
        if umax is None:
            sys.exit()

        # ---------------------------- Set up u range ----------------------------
        ddu = du / 10
        umin = (np.floor(u_cri / ddu) + 1) * ddu
        uclose = (np.floor(u_cri / du) + 2) * du
        if umax < u_cri:
            umax = np.floor(u_cri * 1.5)
        if uclose > umax:
            uclose = umax
        uall = np.append(np.arange(umin, uclose, ddu), np.arange(uclose, umax + du, du))

        # -------------------- Parallel calculate multiple u's -------------------

        def bisp_parallel(u):
            sp1, sp2 = self.ps_sp_solve(u, phi_cri)
            print(u, sp1, sp2, 'sp done!', flush=True)
            bi1, bi2 = self.ps_bi_solve(u, (sp1, sp2), phi_cri)
            print(u, bi1, bi2, 'bi done!', flush=True)

            return sp1, sp2, bi1, bi2
        if self.parallel:
            pool = mp.Pool(processes=4)
            sp1, sp2, bi1, bi2 = zip(*pool.map(bisp_parallel, uall))
        else:
            sp1, sp2, bi1, bi2 = zip(*map(bisp_parallel, uall))

        # ---------------------- Prepare for output ----------------------

        ind = np.where(np.array(bi1) > self.phi_min_calc)[0]
        nout = ind.shape[0]

        sp1t = np.array([sp1[i] for i in ind])
        sp2t = np.array([sp2[i] for i in ind])
        bi1t = np.array([bi1[i] for i in ind])
        bi2t = np.array([bi2[i] for i in ind])
        ut = np.array([round(uu, duD + 1) for uu in uall[ind]])
        new_umax = np.max(ut)

        sp_out = np.zeros((2 * nout + 1, 2))
        bi_out = np.zeros((2 * nout + 1, 2))

        sp_out[:, 1] = np.concatenate((ut[::-1], [u_cri], ut))
        sp_out[:, 0] = np.concatenate((sp1t[::-1], [phi_cri], sp2t))
        bi_out[:, 1] = sp_out[:, 1]
        bi_out[:, 0] = np.concatenate((bi1t[::-1], [phi_cri], bi2t))

        print(sp_out)
        print(bi_out)

        calc_info = seqname + '_N' + str(N) + '_TwoFields' + \
                    '_phis' + str(phis) + \
                    '_w2r' + str(self.wtwo_ratio) + \
                    '_eh' + str(ff.eh) + '_es' + str(ff.es) + \
                    '_umax' + str(round(new_umax, duD)) + \
                    '_du' + str(du) + '_ddu' + str(ddu) + \
                    '.txt'

        if self.name is None:
            sp_file = '/home/adria/perdiux/prod/lammps/final/RPA/rg_ucst/sp' + calc_info
            bi_file = '/home/adria/perdiux/prod/lammps/final/RPA/rg_ucst/bi' + calc_info
        else:
            sp_file = '/home/adria/perdiux/prod/lammps/final/RPA/rg_ucst/sp_' + self.name + '.txt'
            bi_file = '/home/adria/perdiux/prod/lammps/final/RPA/rg_ucst/bi_' + self.name + '.txt'

        print(sp_file)
        print(bi_file)

        cri_info = "u_cri= " + str(u_cri) + " , phi_cri= " + str(phi_cri) + \
                   "\n------------------------------------------------------------"

        np.savetxt(sp_file, sp_out, fmt='%.10e', header=cri_info)
        np.savetxt(bi_file, bi_out, fmt='%.10e', header=cri_info)
示例#11
0
def run(seq_name, umin, ehs0, ehs1, I):
    gv.r_res = 1
    gv.r_con = 1
    gv.r_sal = 1
    gv.eta = 1

    # convert [Salt] in mM to [Salt]/[H2O]
    # phis_mM = float(sys.argv[5])
    phis_mM = I
    phis = phis_mM * 0.001 / (1000. / 18.)

    # ehs must be a 2-element list: the first for entropy and the latter enthalpy
    # ehs = [float(x) for x in sys.argv[3:5]]
    ehs = [ehs0, ehs1]

    # use  phi-dependent permittivity or not
    ef = False

    if sys.argv[2] == "cri_calc":
        cri_calc_end = 1
    else:
        cri_calc_end = 0
        # umin = float(sys.argv[2])

    du = 0.1

    # =========================== Set up parameters ===========================
    # seq_name = sys.argv[1]  # Select a sequence in seq_list.py
    sig, N, the_seq = sl.get_the_charge(seq_name)

    HP = tt.RPAFH(sig, ehs=ehs, epsfun=ef)

    # ======================= Calculate critical point ========================

    print('Seq:', seq_name, '=', the_seq, '\nphi_s=', phis, \
          'r_res =', gv.r_res, ', r_con =', gv.r_con, \
          ', r_sal =', gv.r_sal, ', eta =', gv.eta, \
          '\nehs :', ehs[0], ehs[1])

    t0 = time.time()

    # critical_point
    phi_cri, u_cri = fs.cri_calc(HP, phis)

    print('Critical point found in', time.time() - t0, 's')
    print('u_cri =', '{:.4e}'.format(u_cri),
          'T*_cri = {:.4f}'.format(1 / u_cri), ', phi_cri =',
          '{:.8e}'.format(phi_cri))

    if (cri_calc_end):
        sys.exit()

    # ============================ Set up u range =============================
    ddu = du / 10
    umax = (np.ceil(u_cri / ddu) - 1) * ddu
    uclose = (np.ceil(u_cri / du) - 2) * du
    if umin > u_cri:
        umin = u_cri / 1.5
    if uclose < umin:
        uclose = umin

    uall = np.append(np.arange(umax, uclose, -ddu), \
                     np.arange(uclose, umin - du, -du))

    print(uall, flush=True)

    # ==================== Parallel calculate multiple u's ====================

    def bisp_parallel(u):
        sp1, sp2 = fs.ps_sp_solve(HP, phis, u, phi_cri)
        print(u, sp1, sp2, 'sp done!', flush=True)
        bi1, bi2 = fs.ps_bi_solve(HP, phis, u, [sp1, sp2], phi_cri)
        print(u, bi1, bi2, 'bi done!', flush=True)

        return sp1, sp2, bi1, bi2

    # Sequential, for testing:
    # sp1ss = []
    # sp2ss = []
    # bi1ss = []
    # bi2ss = []
    # for  u_i in uall:
    #    print("u_i=", u_i)
    #    result = bisp_parallel(u_i)
    #    sp1ss.append(result[0])
    #    sp2ss.append(result[1])
    #    bi1ss.append(result[2])
    #    bi2ss.append(result[3])

    # pool = mp.Pool(processes=4)
    print("ZIPPED", zip(*map(bisp_parallel, uall)))
    sp1ss, sp2ss, bi1ss, bi2ss = zip(*map(bisp_parallel, uall))

    ind_slc = np.where(np.array(bi1ss) > gv.phi_min_sys)[0]
    unew = uall[ind_slc]
    sp1s, sp2s = np.array(sp1ss)[ind_slc], np.array(sp2ss)[ind_slc]
    bi1s, bi2s = np.array(bi1ss)[ind_slc], np.array(bi2ss)[ind_slc]
    new_umax = np.max(unew)
    nnew = ind_slc.shape[0]

    sp_out, bi_out = np.zeros((2 * nnew + 1, 2)), np.zeros((2 * nnew + 1, 2))
    sp_out[:, 0] = np.append(np.append(sp1s[::-1], phi_cri), sp2s)
    sp_out[:, 1] = np.append(np.append(unew[::-1], u_cri), unew)
    bi_out[:, 0] = np.append(np.append(bi1s[::-1], phi_cri), bi2s)
    bi_out[:, 1] = sp_out[:, 1]

    print(sp_out)
    print(bi_out)

    monosize = str(gv.r_res) + '_' + str(gv.r_con) + '_' + str(gv.r_sal)
    ehs_str = '_'.join(str(x) for x in ehs)

    calc_info = '_RPAFH_N{}_phis_{:.5f}_{}_eh{:.2f}_es{:.2f}_umax{:.2f}_du{:.2f}_ddu{:.2f}.txt'.format(
        N, phis, seq_name, ehs[0], ehs[1], new_umax, du, ddu)

    sp_file = './results/sp' + calc_info
    bi_file = './results/bi' + calc_info

    print(sp_file)
    print(bi_file)

    cri_info = "u_cri= " + str(u_cri) + " , phi_cri= " + str(phi_cri)

    np.savetxt(sp_file, sp_out, fmt='%.8e', header=cri_info)
    np.savetxt(bi_file, bi_out, fmt='%.8e', header=cri_info)