예제 #1
0
def score_toeholds(toeholds):
    ltoes = []
    for toe in toeholds:
        l = toe[0].lower()
        ltoes.append(l)

    aa = stickydesign.endclasses.endarray(array=ltoes, endtype="S")
    aa = [aa, aa]
    toe = aa[0]
    energyarray = stickydesign.energy_array_uniform(
        toe, stickydesign.EnergeticsBasic(temperature=37))
    maxs = []
    for arr in energyarray:
        maxim = max(arr)
        maxs.append(maxim)
    e_var = statistics.variance(maxs)
    e_rng = max(maxs) - min(maxs)
    return (e_var, e_rng)
예제 #2
0
 def calculate_unrestricted_toehold_characteristics(self):
     import stickydesign as sd
     ends = sd.easyends('TD',
                        self.length,
                        alphabet='h',
                        adjs=['c', 'g'],
                        energetics=self)
     n_ends = len(ends)
     e_array = sd.energy_array_uniform(ends, self)
     e_array = e_array[n_ends:, :n_ends]
     for i in range(n_ends):
         e_array[i, i] = 0
     e_spr = e_array.max() / self.targetdG
     e_vec_ext = self.th_external_dG(ends)
     e_vec_int = self.th_internal_dG(ends)
     e_vec_all = np.concatenate((e_vec_int, e_vec_ext))
     e_avg = e_vec_all.mean()
     e_dev = np.max(np.abs(e_vec_all - self.targetdG))
     return e_avg, e_spr, e_dev, n_ends
예제 #3
0
def from_yaml_endadj(ts, perfect=False, rotate=False):
    import stickydesign as sd
    import stickydesign.energetics as en
    import numpy as np

    # Combine ends and tile-specified adjacents
    newtiles = []
    newends = []
    endslist = set()
    doubleends = []
    doubles = []
    vdoubleends = []
    vdoubles = []

    newtiles.append({
        'name': 'origami',
        'edges': ['origami', 'origami', 'origami', 'origami'],
        'stoic': 0,
        'color': 'white'
    })

    atiles = [None] * 16
    for tilename in ts['seed']['use_adapters']:
        tile = [x for x in ts['seed']['adapters'] if x['name'] == tilename][0]
        newtile = {}
        newtile['edges'] = ['origami'
                            ] + [re.sub('/', '_c', x)
                                 for x in tile['ends']] + ['origami']
        newtile['name'] = tile['name']
        newtile['stoic'] = 0
        newtile['color'] = 'white'
        atiles[tile['loc'] - 1] = newtile
    for tile in atiles:
        if tile:
            newtiles.append(newtile)
        else:
            newtiles.append({
                'name': 'emptyadapt',
                'edges': ['origami', 0, 0, 'origami'],
                'stoic': 0,
                'color': 'white'
            })

    if rotate:
        rotatedtiles = []
        for tile in ts['tiles']:
            if tile['type'] == 'tile_daoe_3up' or tile[
                    'type'] == 'tile_daoe_5up':
                newtile = copy.copy(tile)
                newtile['name'] += '_lrf'
                newtile['ends'] = [tile['ends'][x] for x in (1, 0, 3, 2)]
                rotatedtiles.append(newtile)
                newtile = copy.copy(tile)
                newtile['name'] += '_udf'
                newtile['type'] = 'tile_daoe_' + {
                    '5up': '3up',
                    '3up': '5up'
                }[tile['type'][-3:]]
                newtile['ends'] = [tile['ends'][x] for x in (3, 2, 1, 0)]
                rotatedtiles.append(newtile)
                newtile = copy.copy(tile)
                newtile['name'] += '_bf'
                newtile['type'] = 'tile_daoe_' + {
                    '5up': '3up',
                    '3up': '5up'
                }[tile['type'][-3:]]
                newtile['ends'] = [tile['ends'][x] for x in (2, 3, 0, 1)]
                rotatedtiles.append(newtile)
            elif tile['type'] == 'tile_daoe_doublehoriz_35up':
                newtile = copy.copy(tile)
                newtile['name'] += '_lrf'
                newtile['type'] = 'tile_daoe_doublevert_53up'
                newtile['ends'] = [tile['ends'][x] for x in (2, 1, 0, 5, 4, 3)]
                rotatedtiles.append(newtile)
                newtile = copy.copy(tile)
                newtile['name'] += '_udf'
                newtile['type'] = 'tile_daoe_doublevert_53up'
                newtile['ends'] = [tile['ends'][x] for x in (5, 4, 3, 2, 1, 0)]
                rotatedtiles.append(newtile)
                newtile = copy.copy(tile)
                newtile['name'] += '_bf'
                newtile['ends'] = [tile['ends'][x] for x in (3, 4, 5, 0, 1, 2)]
                rotatedtiles.append(newtile)
            elif tile['type'] == 'tile_daoe_doublevert_35up':
                newtile = copy.copy(tile)
                newtile['name'] += '_lrf'
                newtile['type'] = 'tile_daoe_doublehoriz_53up'
                newtile['ends'] = [tile['ends'][x] for x in (2, 1, 0, 5, 4, 3)]
                rotatedtiles.append(newtile)
                newtile = copy.copy(tile)
                newtile['name'] += '_udf'
                newtile['type'] = 'tile_daoe_doublehoriz_53up'
                newtile['ends'] = [tile['ends'][x] for x in (5, 4, 3, 2, 1, 0)]
                rotatedtiles.append(newtile)
                newtile = copy.copy(tile)
                newtile['name'] += '_bf'
                newtile['ends'] = [tile['ends'][x] for x in (3, 4, 5, 0, 1, 2)]
                rotatedtiles.append(newtile)

        ts['tiles'] += rotatedtiles

    for tile in ts['tiles']:
        if tile['type'] == 'tile_daoe_3up' or tile['type'] == 'tile_daoe_5up':
            newtile = {}
            newtile['edges'] = [re.sub('/', '_c', x) for x in tile['ends']]
            if 'name' in tile: newtile['name'] = tile['name']
            if 'conc' in tile: newtile['stoic'] = tile['conc']
            if 'color' in tile: newtile['color'] = tile['color']
            newtiles.append(newtile)

        if tile['type'] == 'tile_daoe_doublehoriz_35up' or tile[
                'type'] == 'tile_daoe_doublehoriz_53up':
            newtile1 = {}
            newtile2 = {}
            newtile1['edges'] = [ re.sub('/','_c',x) for x in tile['ends'][0:1] ] \
                + [ tile['name']+'_db' ] \
                + [ re.sub('/','_c',x) for x in tile['ends'][4:] ]
            newtile2['edges'] = [ re.sub('/','_c',x) for x in tile['ends'][1:4] ] \
                + [ tile['name']+'_db' ]
            newtile1['name'] = tile['name'] + '_left'
            newtile2['name'] = tile['name'] + '_right'

            doubleends.append(tile['name'] + '_db')
            doubles.append((newtile1['name'], newtile2['name']))

            if 'conc' in tile:
                newtile1['stoic'] = tile['conc']
                newtile2['stoic'] = tile['conc']

            if 'color' in tile:
                newtile1['color'] = tile['color']
                newtile2['color'] = tile['color']

            newtiles.append(newtile1)
            newtiles.append(newtile2)
        if tile['type'] == 'tile_daoe_doublevert_35up' or tile[
                'type'] == 'tile_daoe_doublevert_53up':
            newtile1 = {}
            newtile2 = {}
            newtile1['edges'] = [ re.sub('/','_c',x) for x in tile['ends'][0:2] ] \
                + [ tile['name']+'_db' ] \
                + [ re.sub('/','_c',x) for x in tile['ends'][5:] ]
            newtile2['edges'] = [tile['name'] + '_db'] + [
                re.sub('/', '_c', x) for x in tile['ends'][2:5]
            ]
            newtile1['name'] = tile['name'] + '_top'
            newtile2['name'] = tile['name'] + '_bottom'

            vdoubleends.append(tile['name'] + '_db')
            vdoubles.append((newtile1['name'], newtile2['name']))

            if 'conc' in tile:
                newtile1['stoic'] = tile['conc']
                newtile2['stoic'] = tile['conc']

            if 'color' in tile:
                newtile1['color'] = tile['color']
                newtile2['color'] = tile['color']

            newtiles.append(newtile1)
            newtiles.append(newtile2)

    newends.append({'name': 'origami', 'strength': 100})

    for end in doubleends:
        newends.append({'name': end, 'strength': 10})
    for end in vdoubleends:
        newends.append({'name': end, 'strength': 10})

    gluelist = []
    if not perfect:
        glueends = {'DT': [], 'TD': []}
        for end in ts['ends']:
            newends.append({'name': end['name'], 'strength': 0})
            newends.append({'name': end['name'] + '_c', 'strength': 0})
            if (end['type'] == 'TD') or (end['type'] == 'DT'):
                glueends[end['type']].append((end['name'], end['fseq']))

        ef = en.energetics_santalucia(mismatchtype='max')

        for t in ['DT', 'TD']:
            names, fseqs = zip(*glueends[t])
            allnames = names + tuple(x + '_c' for x in names)
            ea = sd.endarray(fseqs, t)
            ar = sd.energy_array_uniform(ea, ef)
            for i1, n1 in enumerate(names):
                for i2, n2 in enumerate(allnames):
                    gluelist.append([n1, n2, float(ar[i1, i2])])
    else:
        if 'ends' not in ts.keys():
            ts['ends'] = []
        endsinlist = set(e['name'] for e in ts['ends'])
        endsintiles = set()
        for tile in ts['tiles']:
            endsintiles.update(
                re.sub('/', '', e) for e in tile['ends'] if e != 'hp')
        for end in ts['ends'] + list({'name': e} for e in endsintiles):
            newends.append({'name': end['name'], 'strength': 0})
            newends.append({'name': end['name'] + '_c', 'strength': 0})
            gluelist.append([end['name'], end['name'] + '_c', 1.0])

    newends.append({'name': 'hp', 'strength': 0})

    xga = {}
    xga['doubletiles'] = [list(x) for x in doubles]
    xga['vdoubletiles'] = [list(x) for x in vdoubles]
    xga.update(ts['xgrow_options'])
    xga.update(ts['xgrow_options'])

    sts = {
        'tiles': newtiles,
        'bonds': newends,
        'xgrowargs': xga,
        'glues': gluelist
    }

    return sts
# ta tb tr tc tq td tg

aa = stickydesign.endclasses.endarray(array=b, endtype="S")
aa = [aa, aa]

#aa=stickydesign.easyends('S',6,number=7, maxspurious=0.4,interaction=0, tries=2,energetics=stickydesign.EnergeticsBasic(temperature=37), adjs=['c','g'],alphabet='h')

print(aa)

i = 1
toe = aa[0]

print('ta tb tr tc tq td tg')

energyarray = stickydesign.energy_array_uniform(
    toe, stickydesign.EnergeticsBasic(temperature=37))
maxs = []
for arr in energyarray:
    maxim = max(arr)
    maxs.append(maxim)
print('Maxs:', maxs)
print("Variance of %s set is % s" % (i, statistics.variance(maxs)))
print("Mean of %s set is % s" % (i, statistics.mean(maxs)))
print("Max Energy toehold %s - Min Energy Toehold %s is %s" %
      (max(maxs), min(maxs), max(maxs) - min(maxs)))

fig = stickydesign.plots.heatmap(toe,
                                 stickydesign.EnergeticsBasic(temperature=37))
pyplot.show(fig)
i = i + 1
예제 #5
0
파일: gen_th.py 프로젝트: harel55/piperine
    if args.number:
        n_ths = args.number
    else:
        n_ths = 3

    ############## end Interpret arguments

    # Give the energetics instance the target energy
    ef = energetics.energyfuncs()
    ef.targetdG = thold_e

    # new_toeholds returns 1 when second toehold assignment fails. Use a while
    # loop to run the toehold generation until successful.
    ends_all = None
    while type(ends_all) is not sd.endarray:
        ends_all = new_toeholds(ef, n_ths, thold_l, thold_e, e_dev, m_spurious)
        if type(ends_all) == int:
            if ends_all == 1:
                print(
                    'Not enough appropriate first toeholds found. Trying again.'
                )
            if ends_all == 2:
                print('First-second toehold pairing failed. Trying again.')
            if ends_all == 3:
                print("dunno")

    # Plot energy array
    e_array = sd.energy_array_uniform(ends_all, ef)

    print('Done!')