def data237_fp_gen(refresh = True): path = os.path.join(data237_root ,"splitted_complex","*") print path for fp in glob(path): complex_id = os.path.basename(fp) #prepare neccessary directory if not os.path.exists(data237_fp_root): os.makedirs(data237_fp_root) fp_path = os.path.join(data237_fp_root,"%s.fp" %complex_id) if not refresh and os.path.exists(fp_path): print "%s processed" %complex_id else: print "processing %s" %complex_id atb_path = os.path.join(fp,"antibody.pdb") atg_path = os.path.join(fp,"antigen.pdb") antibody = load_pdb_struct(atb_path) antigen = load_pdb_struct(atg_path) fingerprint = FP121(antigen,antibody) fingerprint.gen_all_fp() fpstr2file(fingerprint.get_fp_str(),fp_path) print "fingerprint saved"
def data237_epitope_paratope(refresh = False): source_path = os.path.join(data237_complex_root,"*") print source_path for fp in glob(source_path): complex_id = os.path.basename(fp) if not refresh and os.path.exists(os.path.join(data237_epitope_root,complex_id,"paratope.pdb")): print "%s processed" %complex_id else: print "processing %s" %complex_id try: atb_path = os.path.join(fp,"antibody.pdb") atg_path = os.path.join(fp,"antigen.pdb") antibody = load_pdb_struct(atb_path,residue_cls = ElectricResidue) antigen = load_pdb_struct(atg_path,residue_cls = ElectricResidue) complex = Complex(antigen,antibody) output_path = os.path.join(data237_epitope_root, complex_id) if not os.path.exists(output_path): os.makedirs(output_path) complex.write_epitope(fp,output_path) complex.write_paratope(fp,output_path) print "epitope and paratope saved" except: sys.stderr.write("%s encountered error\n" %complex_id) continue
def data237_fp_gen(refresh=False): for complex_id in complex_ids(path = data237_complex_root): output_path = os.path.join(data237_fp6_root,complex_id) if not refresh and os.path.exists(output_path): print("%s already processed" %complex_id) continue print "start processing %s" %complex_id data_dir = os.path.join(data237_complex_root,complex_id) antigen = load_pdb_struct(os.path.join(data_dir,"antigen.pdb"),residue_cls = Residue) antibody = load_pdb_struct(os.path.join(data_dir,"antibody.pdb"),residue_cls = Residue) try: c = Complex(complex_id, antigen,antibody) fps = c.gen_fps() except: sys.stderr.write("complex %s encountered error.\n" %complex_id) if not os.path.exists(output_path): os.makedirs(output_path) for i,fp in enumerate(fps): path = os.path.join(output_path,"fp%d.txt" %(i+1)) print "to path", path fp.tofile(path)
def single_test(complex_id): data_dir = os.path.join(data237_complex_root,complex_id) antigen = load_pdb_struct(os.path.join(data_dir,"antigen.pdb"),residue_cls = Residue) antibody = load_pdb_struct(os.path.join(data_dir,"antibody.pdb"),residue_cls = Residue) c = Complex(complex_id, antigen,antibody) c.nth_fp(1) fps = c.gen_fps() print fps[2].fp_str() return fps
def __init__(self,c_id = None, **kwargs): if not c_id:#c_id not set c_id = "1SLG_D" atg = load_pdb_struct(os.path.join(data237_complex_root, c_id, "antigen.pdb"), residue_class) atb = load_pdb_struct(os.path.join(data237_complex_root, c_id, "antibody.pdb"), residue_class) super(ComplexClass,self).__init__(complex_id = c_id, antigen = atg, antibody = atb, **kwargs)
def setUp(self): c_id = "2NLJ_C" #c_id = "1SLG_D" from ve.fp.fp_80 import Residue atg = load_pdb_struct(os.path.join(data237_complex_root, c_id, "antigen.pdb"), Residue) atb = load_pdb_struct(os.path.join(data237_complex_root, c_id, "antibody.pdb"), Residue) self.c = ComplexPlaneBasedComplex(complex_id = c_id, antigen = atg, antibody = atb)
def load_base_complex(): """ () -> BaseComplex load testcase of basic complex type with residue type of the basic type """ atg = load_pdb_struct(os.path.join(test_data_dir, "antigen.pdb")) atb = load_pdb_struct(os.path.join(test_data_dir, "antibody.pdb")) c_id = "1SLG_D" return BaseComplex(complex_id = c_id, antigen = atg, antibody = atb)
def gen_fp(complex_id): data_dir = os.path.join(data237_complex_root,complex_id) antigen = load_pdb_struct(os.path.join(data_dir,"antigen.pdb"),residue_cls = Residue80) antibody = load_pdb_struct(os.path.join(data_dir,"antibody.pdb"),residue_cls = Residue80) c = ComplexSingle(complex_id, antigen, antibody) c.gen_fp_to_file(complex_id, fp_type="single") c = ComplexDual(complex_id, antigen, antibody) c.gen_fp_to_file(complex_id, fp_type="double")
def main(): import os from ve.util.load_pdb import complex_ids, load_pdb_struct from ve.config import data237_root paraepi_dir = os.path.join(data237_root, "paraepi") #cids = complex_ids(paraepi_dir) cids = ["1SLG_D"] for cid in cids: paratope_st = load_pdb_struct(os.path.join(paraepi_dir, cid, "paratope.pdb")) convert(cid, paratope_st, PCache) epitope_st = load_pdb_struct(os.path.join(paraepi_dir, cid, "epitope.pdb")) convert(cid, epitope_st, ECache)
def fp_gen_test(complex_id): print "procssing %s" %complex_id path = os.path.join(data237_complex_root,complex_id) print path atb_path = os.path.join(path,"antibody.pdb") atg_path = os.path.join(path,"antigen.pdb") antibody = load_pdb_struct(atb_path,residue_cls = ElectricResidue) antigen = load_pdb_struct(atg_path,residue_cls = ElectricResidue) complex = Complex(antigen,antibody) fp_path = os.path.join(data237_fp105_root,"%s.csv" %complex_id) fp = complex.gen_fp() fp.tofile(fp_path)
def single_test(complex_id): data_dir = os.path.join(data237_complex_root, complex_id) print data237_complex_root antigen = load_pdb_struct(os.path.join(data_dir, "antigen.pdb"), residue_cls=Residue) antibody = load_pdb_struct(os.path.join(data_dir, "antibody.pdb"), residue_cls=Residue) c = ComplexDual(complex_id, antigen, antibody) atg_fp = c.gen_antigen_fp() atb_fp = c.gen_antibody_fp() type = "double" atb_fp.tofile("%s_atb_%s.fp" % (complex_id, type)) atg_fp.tofile("%s_atg_%s.fp" % (complex_id, type)) return atg_fp, atb_fp
def epi_gen_test(complex_id): print "procssing %s" %complex_id path = os.path.join(data237_complex_root,complex_id) print path output_path = os.path.join(data237_epitope_root, complex_id) atb_path = os.path.join(path,"antibody.pdb") atg_path = os.path.join(path,"antigen.pdb") antibody = load_pdb_struct(atb_path,residue_cls = ElectricResidue) antigen = load_pdb_struct(atg_path,residue_cls = ElectricResidue) complex = Complex(antigen,antibody) if not os.path.exists(output_path): os.makedirs(output_path) complex.write_epitope(path,output_path) complex.write_paratope(path,output_path)
def data237_fp_gen(refresh = True): path = os.path.join(data237_complex_root,"*") print path for fp in glob(path): complex_id = os.path.basename(fp) #lst = ["1SLG_D","1T6V_L","1N4X_L","1JV5_A"] #lst = ["1SLG_D"] #if complex_id not in lst: #continue #prepare neccessary directory if not os.path.exists(data237_fp105_root): os.makedirs(data237_fp105_root) fp_path = os.path.join(data237_fp105_root,complex_id) if not refresh and os.path.exists(fp_path): print "%s processed" %complex_id else: print "processing %s" %complex_id atb_path = os.path.join(fp,"antibody.pdb") atg_path = os.path.join(fp,"antigen.pdb") try: antibody = load_pdb_struct(atb_path,residue_cls = ElectricResidue) antigen = load_pdb_struct(atg_path,residue_cls = ElectricResidue) complex = Complex(antigen,antibody) out_path =os.path.join(data237_fp105_root,complex_id) if not os.path.exists(out_path):os.makedirs(out_path) atg_fp,atb_fp = complex.gen_fps() atg_fp.tofile(os.path.join(out_path,"antigen.csv")) atb_fp.tofile(os.path.join(out_path,"antibody.csv")) except: sys.stderr.write("%s encountered error\n" %complex_id) continue
def load_atg_atb(c_id): """ (str) => (antigen, antibody) shortcut for loading the antigen and antibody >>> atg, atb = load_atg_atb("1SLG_D") >>> type(atg) <class 've.util.structure.mystructure'> """ import os from ve.config import data237_complex_root as complex_dir from ve.util.load_pdb import load_pdb_struct return load_pdb_struct(os.path.join(complex_dir, c_id, "antigen.pdb"), MyResidue), load_pdb_struct(os.path.join(complex_dir, c_id, "antibody.pdb"), MyResidue)
from schrodinger.structure import Structure class mystructure(object): def __init__(self,structure): self.st = structure def to_json(self): from simplejson import dumps return dumps({ "atoms": [{"element": a.element,"location": a.xyz} for a in self.atom], "bonds":[{"atoms": (b.atom1.index,b.atom2.index), "order": b.order} for b in self.bond] }) def __getattr__(self,name): if hasattr(self.st, name): return getattr(self.st,name) else: raise AttributeError("\"%s\" method not found." %name) if __name__ == '__main__': from ve.util.load_pdb import load_pdb_struct c = load_pdb_struct("data/data480/ab_pdb/1SLG_B.pdb") print c.to_json()
rec_tree.parse_receptor() rec_tree.find_close_residues(binder , 10.0) with open(fp_path, 'w') as out_fp: lig_name = rec_tree.fingerprints.sifts.keys()[0] for res_num , sift_bitset in rec_tree.fingerprints.sifts[lig_name].sift.items(): print res_num , sift_bitset out_fp.write('%d %s\n' %(res_num , ' '.join([bit for bit in sift_bitset.bit_set]))) print 'saved to',fp_path return fp_path if __name__ == "__main__": #antigen = load_pdb_struct( os.path.join(os.path.dirname( data_src) ,"1DEE_G.pdb") ) #antibody = load_pdb_struct( os.path.join(os.path.dirname( data_src) ,"1DEE_H.pdb") ) antigen = load_pdb_struct(os.path.join(data_root,"complex/1A14","antigen.pdb")) antibody = load_pdb_struct(os.path.join(data_root,"complex/1A14","antibody.pdb")) print "loaded" fp = FingerPrint_60(antigen , antibody) fp.get_fingerprint() #print ' '.join("%d" %res.resnum for res in antigen.residue)#check it now fp.display_fingerprint(start = 30) fp.display_group_info() #gen_fp_to_file(antigen , antibody , "tmp.txt")
def __eq__(self,other): return self.fingerprint == other.fingerprint if isinstance(other, self.__class__) else False def __hash__(self): return hash(self.fingerprint) def __repr__(self): return "triangle-%s" %(self.fingerprint) def __iter__(self): return iter(self.pts) if __name__ == "__main__": from ve.util.load_pdb import load_pdb_struct from ve.config import * data_dir = os.path.join(data237_complex_root,"1SLG_D") antigen = load_pdb_struct(os.path.join(data_dir,"antigen.pdb")) antibody = load_pdb_struct(os.path.join(data_dir,"antibody.pdb")) r1,r2,r3,r4 = list(antigen.residue)[:4] rt1 = ResTriangle([r1,r2,r3]) rt2 = ResTriangle([r3,r1,r2]) rt3 = ResTriangle([r1,r2,r4]) rt4 = ResTriangle([r3,r2,r4]) s = set([rt1,rt2,rt3,rt4]) print s