def get_force_vector(cls, ballfn, memsec, forcefn=None): #"""TODO""" bdata = bbtmio.read_ball_file(ballfn) bn = len(bdata['COORDX']) f = np.zeros((3*bn,1)) sections, profile = memsec secnum = len(sections) free = [] # loop over balls for i in range(bn): zcoord = bdata['COORDZ'][i] forcefactor = 0 # loop over sections for j in range(secnum): if sections[j][0] >= zcoord and zcoord >= sections[j][1]: forcefactor = profile[j] break if bdata['FACING'][i]!='SP': f[3*i] = bdata['COORDX'][i] * forcefactor f[3*i+1] = bdata['COORDY'][i] * forcefactor free += ( [3*i], [3*i+1], [3*i+2] ) f = f[free,[0]] if forcefn != None: np.savetxt(forcefn, f.reshape((f.shape[0]/3, 3)), delimiter='\t') return f
def __init__(self, extballfn, extstickfn, forcevec, kassigner): self.ballfn = extballfn self.stickfn = extstickfn self.f = forcevec self.kassigner = kassigner self.bdata = bbtmio.read_ball_file(extballfn) self.ballnum = len(self.bdata['COORDX']) self.sdata = bbtmio.read_stick_file(extstickfn) self.sticknum = len(self.sdata['BALL1']) self.k_mat = self.__get_k_matrix()
def __init__(self, ballfn='', stickfn='', dispdifffn='', forcevec = None, ktypeassinger=None): self.ballfn = ballfn self.stickfn = stickfn self.dispdifffn = dispdifffn self.f = forcevec self.ktypeassinger = ktypeassinger self.ba_mat = None if ballfn != '': self.bdata = bbtmio.read_ball_file(self.ballfn) self.ballnum = len(self.bdata['COORDX']) self.ba_mat = self.__get_ba_matrix()
def section_divide(ballfn, memsec): bdata = bbtmio.read_ball_file(ballfn) # get section ranges and profile. profile is dummy sections, profile = memsec sectionnum = len(sections) seciddict = {} for i in range(sectionnum): seciddict[i] = [] # seciddict is like { 0:[bid1x, bid1y, bid1z, ..., bidsx, bidsy, bidsz], # 1:[bid1x, bid1y, bid1z, ..., bidsx, bidsy, bidsz], ... } for i,z in enumerate( bdata['COORDZ'] ): for j in range(sectionnum): if sections[j][0] > z and z > sections[j][1]: seciddict[j].append(3*i) seciddict[j].append(3*i+1) seciddict[j].append(3*i+2) break return seciddict
def __init__(self,ballfn,stickfn): ball_data = bbtmio.read_ball_file(ballfn) ballnum = len(ball_data['COORDX']) stick_data = bbtmio.read_stick_file(stickfn) sticknum = len(stick_data['BALL1']) # stick orientation dict self.sodict = {} # stick type dict self.stdict = {} # loop over stick for i in range(sticknum): id1 = stick_data['BALL1'][i] id2 = stick_data['BALL2'][i] # make sure 1st endball id always less than or eq to 2nd endball id if id1 > id2: id1, id2 = id2, id1 self.stdict[(id1,id2)] = stick_data['TYPE'][i] # ball1 coord coord1 = np.array( (ball_data['COORDX'][id1], ball_data['COORDY'][id1], ball_data['COORDZ'][id1]) ).reshape((1,3)) # ball2 coord coord2 = np.array( (ball_data['COORDX'][id2], ball_data['COORDY'][id2], ball_data['COORDZ'][id2]) ).reshape((1,3)) # stick vector stick = coord1 - coord2 # stick orientation so = stick / np.linalg.norm(stick) # calculate block # block(ijpair)=| ll lm ln | # | lm mm mn | # | ln mn nn | block = np.empty((3,3)) for j in range(3): for k in range(3): block[j][k] = so[0][j]*so[0][k] self[id1, id2] = block
def opm_mempos(pdbfn, ballfn): """ get membrane position from opmdb pdb file """ geo_data = bbtmio.read_geo_file(pdbfn[:-3]+'geo') # an anchor used to find out the offset. ithas no meaning base_res_id = geo_data['startingSNs'][0] opmstruct = bbtmio.read_pdb_file(pdbfn[:-8]+'opmdb/'+pdbfn[-8:]) opmchain = opmstruct[0][ bbtmio.guess_chain_id(opmstruct, geo_data) ] for res in opmchain: if res.get_id()[1] == base_res_id: opm_base_z = res['CA'].get_coord()[2] break ball_data = bbtmio.read_ball_file(ballfn) my_base_z = ball_data['COORDZ'][0] # offset from my ball coords to opm pdb coords my_z_offset = opm_base_z - my_base_z # get the last chain, then the first res, then the first atom, and then the coord # just get the absolute value since membrane thickness is symetric in opm pdb file opm_half_thickness = abs( opmstruct[0].get_list()[-1].get_list()[0].get_list()[0].get_coord()[2] ) # my extracellular membrane position my_extra_z = opm_half_thickness - my_z_offset # my periplasm membrane position my_peri_z = -opm_half_thickness - my_z_offset return my_z_offset, my_extra_z, my_peri_z
import numpy as np import sys import os sys.path.append(os.path.abspath(os.path.dirname(__file__))+'/../../../pyscripts/') import bbtmio import bbtmequs import typeutils from typeutils import * import equtils import bbtmml codes = [ '1BXW', '1FEP', '1I78', '1K24', '1KMO', '1NQE', '1P4T' ] for code in codes: deformedcoords = bbtmio.get_ball_coords( bbtmio.read_ball_file(code+'.balls.deformed') ) reconstructedcoords = bbtmio.get_ball_coords( bbtmio.read_ball_file(code+'.balls.reconstruct') ) disp = deformedcoords - reconstructedcoords rmsd = np.mean(np.square(np.linalg.norm(disp, axis=1))) ** 0.5 print code, rmsd
else: bbtmio.write_bbin_file(pdbfn, geofn) print( '\tFile '+pdbcode+'.bbin written.\n' ) bbin_data = bbtmio.read_bbin_file(bbinfn) ################################################ # write balls and sticks file print( '\tPreparing .balls and .sticks files' ) ball_ori_fn = pdbfn[:-4]+'_origin.balls' stick_fn = pdbfn[:-4]+'.sticks' if os.path.isfile(ball_ori_fn) and os.path.isfile(stick_fn) and not args['overwrite']: print( '\tFile '+pdbcode+'_origin.balls and .sticks exist. Nothing changed.\n' ) else: os.system('exec/barrel.out '+pdbfn[:-4]+'.bbin') print( '\tFile '+pdbcode+'_origin.balls and .sticks written.\n' ) ball_data = bbtmio.read_ball_file(ball_ori_fn) # temporary file, register for cleaning files_to_clean.append(ball_ori_fn) ################################################ # recenter balls print( '\tRecentering the coordinate matrix in balls file' ) ball_fn = pdbfn[:-4]+'.balls' if os.path.isfile(ball_fn) and not args['overwrite']: print( '\tFile '+pdbcode+'.balls exists. Nothing changed.\n' ) else: ball_coord_mat = bbtmio.recenter_coord_mat( bbtmio.get_ball_coords(ball_data), bbin_data) ball_data = bbtmio.set_ball_coords(ball_data, ball_coord_mat) bbtmio.write_ball_file(ball_data, ball_fn) print( '\tFile '+pdbcode+'.balls written.\n' ) ball_data = bbtmio.read_ball_file(ball_fn)
codes = [ '1K24' ] # generated deformed balls file for code in codes: extballfn = datapath+'testdata/'+code+'.balls.ideallarge.ext' extstickfn = datapath+code+'.sticks.ext' pdbfn = datapath+code+'.pdb' #memsec = equtils.wimley_section_divide(equtils.opm_mempos(pdbfn, extballfn)) memsec = equtils.uni_section_divide(equtils.opm_mempos(pdbfn, extballfn)) f = equtils.ForceGen.get_force_vector( extballfn,memsec ) equsys = bbtmequs.StiffnessEquSys(extballfn, extstickfn, f, TestKAssigner ) equsys.solve() disp = equsys.result['u'].reshape(equsys.result['u'].shape[0]/3, 3) ballfn = datapath+'testdata/'+code+'.balls.ideallarge' balldat = bbtmio.read_ball_file(ballfn) ballcoords = bbtmio.get_ball_coords(balldat) # rec means after reconstruction recballcoords = ballcoords + disp recballdat = bbtmio.set_ball_coords(balldat, recballcoords) recballfn = code+'.balls.reconstruct' bbtmio.write_ball_file(recballdat, recballfn) dispfn = code+'.displacement.reconstruct' bbtmio.write_displacement_file(ballcoords, recballcoords, dispfn)
ks2 = np.array( [ 2.49441195, 0.65856546, 0.86605534, 0.79412971, 2.91011336, 1.71480196, 0.68283227] ) ks3 = np.array( [ 1.31824322, 0.88899824, 0.9253788 , 0.72740754, 2.81697644, 0.66983903, 0.36771102] ) ks = np.mean(np.vstack((ks1,ks2,ks3)), axis=0) @classmethod def get_k(cls, btype, a1type, a2type): return 100 if btype=='SP' else 100000000 * np.dot( cls.kta.get_assign_vec(a1type, a2type, btype), cls.ks ) for coden in testset: ses = bbtmdsm.StiffnessEquSys('../../../data/testdata/'+coden+'.balls.ideallarge.ext', '../../../data/testdata/'+coden+'.sticks.ideallarge.ext', testkassigner ) ses.solve() u = ses.u.reshape(ses.u.shape[0]/3, 3) ideallargecoords = bbtmio.get_ball_coords( bbtmio.read_ball_file('../../../data/testdata/'+coden+'.balls.ideallarge') ) pdbcoords = bbtmio.get_ball_coords( bbtmio.read_ball_file('../../../data/'+coden+'_pdb.balls') ) afteru = ideallargecoords + u newafteru = bbtmio.recenter_coord_mat(afteru, bbtmio.read_bbin_file('../../../data/'+coden+'.bbin')) bbtmio.write_ball_file( bbtmio.set_ball_coords( bbtmio.read_ball_file('../../../data/testdata/'+coden+'.balls.ideallarge'), newafteru ), coden+'.balls.au') dummy,newpdbcoords = bbtmio.align_coordmat(pdbcoords, newafteru) disp = newafteru - newpdbcoords rmsd = np.mean(np.square(np.linalg.norm(disp, axis=1))) ** 0.5 print coden, disp.shape[0], rmsd #sys.exit(0)
import numpy as np import glob import sys import os sys.path.append(os.path.abspath(os.path.dirname(__file__)) + "/../../../pyscripts/") import bbtmio for fn in glob.glob("../../../data/????.balls"): bdata = bbtmio.read_ball_file(fn) bdata["COORDX"] = bdata["COORDX"] * 1.45 bdata["COORDY"] = bdata["COORDY"] * 1.45 bbtmio.write_ball_file(bdata, fn + ".ideallarge")
import numpy as np import sys import os sys.path.append(os.path.abspath(os.path.dirname(__file__))+'/../../../pyscripts/') import bbtmio import bbtmequs import typeutils from typeutils import * import equtils import bbtmml datapath = '../../../data/' codes = [ '1BXW', '1FEP', '1I78', '1K24'] #codes = [ '1BXW', '1FEP', '1I78', '1K24', '1KMO', '1NQE', '1P4T' ] for code in codes: deformedcoords = bbtmio.get_ball_coords( bbtmio.read_ball_file(datapath+code+'_pdb.balls') ) reconstructedcoords = bbtmio.get_ball_coords( bbtmio.read_ball_file(code+'.balls.reconstruct') ) disp = deformedcoords - reconstructedcoords rmsd = np.mean(np.square(np.linalg.norm(disp, axis=1))) ** 0.5 print code, rmsd