def test_typical_omega(self): size = 1000 trials = 100 threshold = .9 count_typical = 0 for i in range(trials): poly = Polymer(size) poly.make_environment() count_typical += spacevar_typical(poly) # print count_typical self.assertTrue(count_typical > threshold*trials)
def test_typical_omega(self): size = 1000 trials = 100 threshold = .9 count_typical = 0 for i in range(trials): poly = Polymer(size) poly.make_environment() count_typical += spacevar_typical(poly) # print count_typical self.assertTrue(count_typical > threshold * trials)
def test_tau(self): size = 1000 poly = Polymer(size) poly.make_environment() poly.compute_actions() path = poly.compute_path() end = poly.compute_endpoint() tau = poly.compute_tau() self.assertTrue(abs(end) > abs(path[tau - 1]))
def test_action(self): size = 1000 poly = Polymer(size) poly.make_environment() poly.compute_actions() poly.compute_path() self.assertEqual( poly.action_range(1, size) + poly.environment[0][size], poly.max_action)
def test_action(self): size = 1000 poly = Polymer(size) poly.make_environment() poly.compute_actions() poly.compute_path() self.assertEqual(poly.action_range(1, size)+poly.environment[0][size], poly.max_action)
def test_unwrap(): l=10 box = Box([0,0,0],[l,l,l]) P1 = Polymer(N=20,type_bead=1,ptolerance=0,type_polymer="linear",start_id=0,lconstrain=[],gconstrain=[box]) for i in range(20): P1.coords[i][0] = i if P1.coords[i][0] > l: P1.coords[i][0] -= l print P1.coords P1.unwrap(ref=[0,0,0],box=box) print P1.coords assert np.sum(P1.coords[::,0] - np.array(range(20))) < 1e-9
def test_end_discrepancy(self): size = 1000 exponent = 0.5 constant = 10 poly = Polymer(size) poly.make_environment() poly.compute_actions() path = poly.compute_path() end = poly.compute_endpoint() self.assertTrue( poly.discrepancy(end) < constant * pow(abs(float(end)), -exponent))
def test_endpoint(self): size = 1000 poly = Polymer(size) poly.make_environment() poly.compute_actions() path = poly.compute_path() end = poly.compute_endpoint() self.assertTrue(abs(path[-1] - end) <= 1)
def test_lammps_angle(): Simu = LSimu() box = Box([0,0,0],[10,10,10]) liaison = {"1-1":[1,1]} angle_def = {"1-1-1":[20,1]} P1 = Polymer(N=20,type_bead=1,liaison=liaison,angle_bond=True,angle_def=angle_def,ptolerance=0,type_polymer="linear",start_id=0,lconstrain=[],gconstrain=[box]) Simu.add(P1) Simu.add_box(box) for idl,value in liaison.iteritems(): R0,idbond = value idpair1,idpair2=map(int,idl.split("-")) Simu.add_bond(typeb="harmonic",idbond=idbond,K=80,R0=R0) Simu.add_pair(typep="lj/cut",idpair1=idpair1,idpair2=idpair2,epsilon=1,sigma=R0,cutoff1=1.15) for idl,value in angle_def.iteritems(): K,idangle = value idpair1,idpair2,idpair3=map(int,idl.split("-")) Simu.add_angle(typea="harmonic",idangle=idangle,K=K,theta=180) Simu.generate_xyz("test/lp.xyz",Mass="one") Simu.generate_interactions("test/ainteractions") Simu.generate_pdb("test/lp.pdb") Simu.generate_script("test/lp.txt",run_length=10000,samplingrate=10,initconf="test/lp.xyz", outtraj="test/lp.dcd",outfile="test/lp.xyz",interactions="test/ainteractions",particle="1 2") Simu.run(script="test/lp.txt")
def test_tau(self): size = 1000 poly = Polymer(size) poly.make_environment() poly.compute_actions() path = poly.compute_path() end = poly.compute_endpoint() tau = poly.compute_tau() self.assertTrue(abs(end) > abs(path[tau-1]))
def test_end_discrepancy(self): size = 1000 exponent = 0.5 constant = 10 poly = Polymer(size) poly.make_environment() poly.compute_actions() path = poly.compute_path() end = poly.compute_endpoint() self.assertTrue(poly.discrepancy(end) < constant*pow(abs(float(end)), -exponent) )
def test_pinned_path(n): poly = Polymer(n) poly.make_environment() poly.compute_actions() for i in range(n + 1): j = random.randint(-i, i) try: poly.pinned_path(j, i) except IndexError: print "failure at ", j, i
def test_unwrap(): l = 10 box = Box([0, 0, 0], [l, l, l]) P1 = Polymer(N=20, type_bead=1, ptolerance=0, type_polymer="linear", start_id=0, lconstrain=[], gconstrain=[box]) for i in range(20): P1.coords[i][0] = i if P1.coords[i][0] > l: P1.coords[i][0] -= l print P1.coords P1.unwrap(ref=[0, 0, 0], box=box) print P1.coords assert np.sum(P1.coords[::, 0] - np.array(range(20))) < 1e-9
def test_pinned_path(n): poly = Polymer(n) poly.make_environment() poly.compute_actions() for i in range(n+1): j = random.randint(-i,i) try: poly.pinned_path(j, i) except IndexError: print "failure at ", j, i
def test_lammps_from_hand_mix(): Simu = LSimu() box = Box([0,0,0],[10,10,10]) liaison={"1-1":[1,1],"1-2":[1,2],"2-2":[1,3]} P1 = Polymer(N=20,type_bead=1,liaison=liaison,ptolerance=0,type_polymer="linear",start_id=0,lconstrain=[],gconstrain=[box]) P2 = Polymer(N=20,type_bead=2,liaison=liaison,ptolerance=0,type_polymer="linear",start_id=0,lconstrain=[],gconstrain=[box]) Simu.add(P1) Simu.add(P2) for idl,value in liaison.iteritems(): R0,idbond = value idpair1,idpair2=map(int,idl.split("-")) Simu.add_bond(typeb="harmonic",idbond=idbond,K=80,R0=R0) Simu.add_pair(typep="lj/cut",idpair1=idpair1,idpair2=idpair2,epsilon=1,sigma=R0,cutoff1=1.15) Simu.add_box(box) Simu.generate_xyz("test/mix.xyz",Mass="one") Simu.generate_interactions("test/interactionsm") Simu.generate_pdb("test/mix.pdb") Simu.generate_script("test/basic.txt",run_length=1000,samplingrate=10,initconf="test/mix.xyz", outtraj="test/out.dcd",outfile="test/out.xyz",interactions="test/interactionsm",particle="1 2") Simu.run(script="test/basic.txt")
def Test(f, name, num): rules = reg.Rules.get(name) handlers = reg.Handlers.get(name, []) ts0 = time.strftime('%H:%M:%S') numpass = 0 numfail = { '1': 0, } ki = None try: for case in Polymer.ModelsChooser(rules, num).Gen(): sentence = ''.join([v[1] for v in case]) ts = time.time() intent = api.Do(AGENT, USERID, sentence) if intent.NAME == name: # TODO: match handlers #resp = intent.Go() msg = '{}, {}ms, +pass, {} {}'.format( time.strftime('%H:%M:%S'), int((time.time() - ts) * 1000), name, sentence, ) numpass += 1 else: msg = '{}, {}ms, -fail, 1(intent dismatch), {} => {} {}'.format( time.strftime('%H:%M:%S'), int((time.time() - ts) * 1000), name, intent.NAME, sentence, ) numfail['1'] += 1 f.write(msg+'\n') print(msg) except KeyboardInterrupt as e: ki = e tfail = 0 for k in numfail: tfail += numfail[k] total = numpass+tfail msg = 'Passed {}, Total {}, {}, {}-{}'.format( str(round(numpass/total*100, 1))+'%' if total else 'N/A', total, name, ts0, time.strftime('%H:%M:%S'), ) msg = '{}\n{}\n{}'.format( '---', msg, '---', ) f.write(msg+'\n') print(msg) if ki: raise ki return numpass, tfail, numfail
def test_lammps_from_hand(): Simu = LSimu() box = Box([0,0,0],[10,10,10]) P1 = Polymer(N=20,type_bead=1,ptolerance=0,type_polymer="linear",start_id=0,lconstrain=[],gconstrain=[box]) Simu.add(P1) Simu.add_box(box) Simu.add_bond(typeb="harmonic",idbond=1,K=80,R0=1) Simu.add_pair(typep="lj/cut",idpair1=1,idpair2=1,epsilon=1,sigma=1,cutoff1=1.12) Simu.generate_xyz("test/mixh.xyz",Mass="one") Simu.generate_interactions("test/interactionsh") Simu.generate_pdb("test/mixh.pdb") Simu.generate_script("test/basich.txt",run_length=1000,samplingrate=10,initconf="test/mixh.xyz", outtraj="test/out.dcd",outfile="test/out.xyz",interactions="test/interactionsh",particle="1") Simu.run(script="test/basich.txt")
def read_pdb(self, pdb): self.clear() chain_id = '-' res_num = None res_insert = ' ' is_last_chain_protein = False for line in open(pdb, 'r').readlines(): if line.startswith("ATOM"): atom = AtomFromPdbLine(line) if not is_last_chain_protein or chain_id != atom.chain_id: protein = Protein() protein.id = atom.chain_id chain_id = protein.id self.append_chain(protein) is_last_chain_protein = True res_num = None if (res_num != atom.res_num) or (res_insert != atom.res_insert): residue = Residue(atom.res_type, atom.chain_id, atom.res_num, atom.res_insert) residue.chain_id = chain_id protein.append_residue_no_renum(residue) res_num = atom.res_num res_insert = atom.res_insert protein.insert_atom(-1, atom) if line.startswith("HETATM"): atom = AtomFromPdbLine(line) if res_num != atom.res_num or chain_id != atom.chain_id: mol = Polymer() residue = Residue(atom.res_type, atom.chain_id, atom.res_num) residue.chain_id = atom.chain_id mol.append_residue_no_renum(residue) mol.id = atom.chain_id self.append_chain(mol) res_num = atom.res_num chain_id = atom.chain_id last_chain_is_polymer = False mol.insert_atom(0, atom) if line.startswith("TER"): chain_id = '-' if line.startswith("ENDMDL"): break
def create_polymers(self, NP, **kwargs): """ create NP polymers All the option to cleate a polymer are defined in the function one_polymer in the create module if a box is specified it will be added in the global constrained of the polymer """ if kwargs.has_key("box"): self.box = kwargs["box"] kwargs.pop("box") if kwargs.has_key("gconstrain"): kwargs["gconstrain"].append(self.box) else: kwargs["gconstrain"] = [self.box] else: print("must specify a box") raise self.molecules = [] for p in range(NP): self.add(Polymer(**kwargs))
def read_pdb(self, pdb): self.clear() chain_id = '-' res_num = None res_insert = ' ' is_last_chain_protein = False for line in open(pdb, 'r').readlines(): if line.startswith("ATOM"): atom = AtomFromPdbLine(line) if not is_last_chain_protein or chain_id != atom.chain_id: protein = Protein() protein.id = atom.chain_id chain_id = protein.id self.append_chain(protein) is_last_chain_protein = True res_num = None if (res_num != atom.res_num) or (res_insert != atom.res_insert): residue = Residue(atom.res_type, atom.chain_id, atom.res_num, atom.res_insert) residue.chain_id = chain_id protein.append_residue_no_renum(residue) res_num = atom.res_num res_insert = atom.res_insert protein.insert_atom(-1, atom) if line.startswith("HETATM"): atom = AtomFromPdbLine(line) if res_num != atom.res_num or chain_id != atom.chain_id: mol = Polymer() residue = Residue(atom.res_type, atom.chain_id, atom.res_num) residue.chain_id = atom.chain_id mol.append_residue_no_renum(residue) mol.id = atom.chain_id self.append_chain(mol) res_num = atom.res_num chain_id = atom.chain_id last_chain_is_polymer = False mol.insert_atom(0, atom); if line.startswith("TER"): chain_id = '-' if line.startswith("ENDMDL"): break
from polymer import Polymer user_sglq_a = Polymer([ '增加', '新增', '新建', '创建', '执行', '处理', '关注', '完成', '标记完成', '被完成', ]) user_sglq_s = Polymer([ '已经完成', '已完成', '未完成', '待完成', '没有完成', '尚未完成', '还没有完成', '过期', '已过期', '已经过期', ]) user_sglq_w = Polymer([ '刘德华', '张学友', ])
def setUpClass(cls): buildingBlockTests.itp = Polymer()
from polymer import Polymer kw_gei = Polymer([ '给', '发给', '送给', '捎给', '给到', '送到', ]) 给 = kw_gei
from polymer import Polymer kw_bei = Polymer([ '被', '需要', ]) 被 = kw_bei
# -*- coding: utf-8 -*- from case.polymer import Polymer TimeWords = Polymer( ['今天', '明天', '后天'], Polymer.Range(8, 13), '点', ) DriveWords = Polymer( ['开车', '步行', '坐地铁'], '去', ) EventWords = Polymer(['吃饭', '上班', '开会'], ) Cases = Polymer(TimeWords, DriveWords.OR(), EventWords)
from polymer import Polymer from dict.sys_time import sys_time from dict.sys_period import sys_period 前后 = Polymer([ '前', '后', ]) 几 = Polymer('几', ) 日期 = Polymer([ '日', '天', '周', '星期', '礼拜', '月', '年', ]) common = Polymer([ '最近', '近期', '最近一段时间', '近段时间', '这段时间', '最近几天', '这几', '近几天', '凌晨', '早晨',
import reg from polymer import Polymer IntentName = 'UPLOAD_FILE2' # <base> 我想 = Polymer(['我想', '我想要', '我要', '我准备', '我希望']) 上传 = Polymer(['上传', '保存', '添加', '创建', '提交', '上载', '新建', '建', '加', '存']) 文档 = Polymer(['文档', '文件', '文本', '档案']) 一份 = Polymer(['一份', '一个', '一些', '几个', '几份', '几份儿', '一份儿', '个', '份']) 怎么 = Polymer([ '怎么', '怎样', '如何', '该如何', '我应该怎么', '应该怎么', '应该如何', '我该怎么', '我该如何', '我应该如何', '我如何', '我怎么', '我要怎么', '我要如何' ]) 啊 = Polymer(['啊', '呀']) # </base> reg.AddRules( IntentName, Polymer(我想.OR(), 上传, 一份.OR(), 文档, 啊.OR()), Polymer(怎么, 上传, 一份.OR(), 文档, 啊.OR()), )
from polymer import Polymer kw_inc = Polymer([ '有关于', '包含有', '包含', '包括', '包涵', '含有', '关于', '有关', ]) 包含 = kw_inc
from polymer import Polymer kw_is = Polymer([ '是', '就是', '为', ]) 是 = kw_is
def cell(chrlen,chrcen,Ribopos,lp,Radius,mt,liaison,angle_def,angle_bond,special=[]): """ chrlen and chrcen are in monomere unit Ribopos also lp also """ chl = [] chn = [] for l,cen in zip(chrlen,chrcen): if cen == None: chl.append(None) chn.append([None,None,l]) else: fact = 16 chl.append([np.sqrt(2*fact*lp**2*cen),np.sqrt(2*fact*lp**2*(l-cen))]) chn.append([cen,(l-cen),l]) chl = np.array(chl) Refs = get_ref_points(snucleus=Radius,smicrotubule=mt,l_len_p=chl) #print liaison nucleus = Sphere(position=[0,0,0],radius=Radius) list_polymer = [] for chromosome,(rep,length,spe) in enumerate(zip(Refs,chn,special)): #print chromosome,length,chl[chromosome] #,rep #print Radius,mt #print start,middle,end type_bead = [1 for n in range(length[2])] for special_beads in spe: [P,T] = special_beads type_bead[P] = T for ch,insert,rlength in Ribopos: if chromosome == ch-1: type_bead[insert:insert+rlength] = [3 for _i in range(rlength)] cm_nuc = insert + int(rlength)/2 if rep != None: start = Point(index=0,position=rep[0]._v) middle = Point(index=length[0],position=rep[1]._v) end = Point(index=length[2],position=rep[2]._v) lconstrain=[start,middle,end] else: lconstrain = [] for ch,insert,rlength in Ribopos: if chromosome == ch-1: nucleole = Point(index=cm_nuc,position=(0.66*Radius,0,0)) lconstrain=[start,middle,nucleole,end] #print liaison list_polymer.append(Polymer(N=length[2],type_bead=type_bead,liaison=liaison, angle_bond=angle_bond, angle_def=angle_def, ptolerance=0,type_polymer="linear", lconstrain=lconstrain,gconstrain=[nucleus], max_trial=300000,rc=1.,virtual_lp=None, rigid_constrain=False)) return list_polymer
from polymer import Polymer kw_done = Polymer([ '完成', '做完', '执行完', '做掉', '完成掉', '进行', '执行', '搞定', '做', '开始', '开始做', '开始进行', '必须完成', '必须做完', '必须搞定', '必须做掉', '必须要完成', '必须要做完', '必须要搞定', '必须要做掉', '一定要完成', '一定得完成', '一定得做完', ]) 完成 = kw_done
import reg from polymer import Polymer IntentName = 'HELP2' # <base> 我 = Polymer(['我']) 需要 = Polymer(['需要', '想要', '要']) 我需要 = Polymer(我.OR(), 需要) 一份 = Polymer(['一份', '一个', '份']) 使用 = Polymer(['使用', '操作', '用']) 帮助 = Polymer(['帮助', '说明', '手册', '例句', '操作手册', '操作说明', '帮助文档', '帮助手册', '指导']) 了解 = Polymer(['了解', '知道', '明白', '搞清楚', '弄清楚', '弄明白']) 吧 = Polymer(['吧']) 啊 = Polymer(['啊', '呀']) 给我 = Polymer(['给我', '能给我', '能发我', '发我', '给', '发']) 怎么 = Polymer(['怎么', '怎样', '如何', '该如何', '我应该怎么', '应该怎么', '应该如何', '我该怎么', '我该如何', '我应该如何', '我如何', '我怎么', '我要怎么', '我要如何']) 小助手 = Polymer(['小助手', '机器人', '这', '这东西', '这玩意儿', '这玩意', '这家伙']) # </base> reg.AddRules( IntentName, Polymer(我需要.OR(), 一份.OR(), 使用.OR(), 帮助, 吧.OR()), Polymer(我需要.OR(), 了解.OR(), 怎么, 使用, 啊.OR()), Polymer(小助手, 需要.OR(), 怎么, 使用, 啊.OR()), Polymer(Polymer(我需要, 了解).OR(), 小助手, 怎么, 使用, 啊.OR()),
def test__path(n): poly = Polymer(n) poly.make_environment() poly.compute_actions() poly.compute_path() poly.compute_record_discrepancies() poly.records for i in range(n+1): try: poly.compute_path(i) except IndexError: print "failure at ", i
from polymer import Polymer kw_gen = Polymer([ '跟', '对', '给', ]) 跟 = kw_gen
from polymer import Polymer user_sglq_w = Polymer([ '刘德华', '张学友', ]) 人物 = user_sglq_w
reg.AddRules( IntentName, Polymer([ '绑定', '绑定账号', '请帮我绑定账号', '我想要绑定账号', '绑定一下', '帮我绑定一下', '绑定链接', '有绑定链接吗', '把绑定链接发我一下', '怎样绑定', '怎么绑定', '怎样绑定账号', '怎么绑定账号', '绑定小助手', '我想绑定小助手', '我要绑定小助手', '怎么绑定小助手', '帮我绑定小助手', '绑定一下小助手', '我想要绑定链接', '绑定账号的链接发我一下', '绑定链接发我一下', '怎样绑定呢', '怎样绑定账号呢', '怎样才能拿到绑定链接', ]), )
from polymer import Polymer from dict.user_sglq_asw import * user_db_cr = Polymer(['创建人', '创建者', '创建的人']) 创建er = user_db_cr 二重行为 = 行为 二重状态 = 状态
from polymer import Polymer ti_event = Polymer([ '去杭州参加云栖大会', '开会', '旅游', '一起去郊游', '去看电影', '参加单身排队', '和刘总讨论节目内容精简的事情', ]) 事件 = ti_event