def __init__(self, file_name): ''' Protein class constructor Receives the file from which it is to be read. It needs to be in pdb or gro formats. Proteins must be ungapped (all resiude numbers must be consecutive). Only standard residues are considered. ''' super(Protein, self).__init__() ext = file_name.split('.')[-1].lower() if ext == 'pdb': with open(fileName, 'r') as f: fileContent = f.read().split('\n') for line in fileContent: if line[0:6] in ['TER ', 'END ']: return None elif line[0:6] == 'ATOM ': index = int(line[6:11]) name = line[12:16].strip() resName = line[17:20].strip() if res_name in ['HIP', 'HIE', 'HID']: res_name = 'HIS' assert res_name in AMINO_ACID_NAMES, \ "Only standard residues are considered." resId = int(line[22:26]) x = float(line[30:38]) y = float(line[38:46]) z = float(line[46:54]) if resId > 0: try: self.addResidue(Residue(resId, resName)) except AssertionError: pass self.addAtom(Atom(index, name, x, y, z), resId) q = [x for x in self if x != None] assert None not in self[self.index(q[0]):self.index(q[-1])+1], \ "Protein contains gaps." elif ext == 'gro': with open(file_name, 'r') as read_file: file_content = read_file.read().split('\n') number_of_atoms = int(file_content[1]) for index in range(number_of_atoms): line = file_content[2 + index].split() index = int(line[2]) name = line[1] res_name = line[0][-3:] res_id = int(line[0][:-3]) pos_x = float(line[3]) * 10 pos_y = float(line[4]) * 10 pos_z = float(line[5]) * 10 try: self.add_residue(Residue(res_id, res_name)) except AssertionError: pass self.add_atom(Atom(index, name, (pos_x, pos_y, pos_z)), res_id) else: raise NameError('Unknown file extension') return None
def find_common_residues(structures, save_file): if 1 == 2: with open(safe_file, "rb") as f: common_residues = pickle.load(f) return common_residues else: all_residues = [] for structure in structures: structure_residues = set() top = md.load(structure).topology for residue in top.residues: if residue.is_protein: res = Residue(resSeq=residue.resSeq, chain_id=residue.chain.id, res_name="%s%d" % (residue.name, residue.resSeq)) #res = Residue(resSeq = residue.resSeq) structure_residues.add(res) all_residues.append(structure_residues) common_residues = list(set.intersection(*all_residues)) print((sorted([r.resSeq for r in common_residues]))) print(("There are %d common residues between input structures" % len(common_residues))) import pickle with open(save_file, "wb") as f: pickle.dump(common_residues, f) return common_residues
def __init__(self, atoms, resInfo=None, options=None): """ Constructer of chain object """ self.chainID = atoms[atoms["keys"][0]][0].chainID self.alignment = None self.residues = [] self.configurations = [] self.last_residue = None if options.verbose == True: pka_print("constructing chain %c (atoms: configurations)" % (self.chainID)) # creating the 'residues' for key in atoms["keys"]: myResidue = Residue(atoms[key], resInfo=resInfo) if myResidue.checked(): self.last_residue = myResidue self.residues.append(myResidue) # setting up list of configuration keys in this chain for residue in self.residues: for key in residue.configurations: if key not in self.configurations: self.configurations.append(key) # checking and correcting C-terminus and N-terminus self.addNTerminus(resInfo=resInfo) self.addCTerminus(resInfo=resInfo)
def __init__(self): """ Takes a filename and initializes the self.residue_table list with the contents of a residue table file """ self.residue_table = {} residue_list = data.aminoacids.buildTable() for r in residue_list: res = Residue(r[0], r[1], r[2], r[3], r[4], r[5], r[6], r[7]) self.residue_table[res.letterCode3] = res
def addCTerminus(self, resInfo=None): """ Creating a C-terminus residue for this chain and adding it to 'residues' list """ last_residue = None for residue in self.residues: if residue.type == "amino-acid": last_residue = residue if last_residue != None: atoms = last_residue.checkOXT() Cterminus = Residue(atoms, resName="C- ", resInfo=resInfo) self.residues.append(Cterminus)
def addNTerminus(self, resInfo=None): """ Creating a N-terminus residue for this chain and adding it to 'residues' list """ atom = None for residue in self.residues: if residue.type == "amino-acid": atom = residue.getAtom(name="N") break if atom != None: Nterminus = Residue([atom], resName="N+ ", resInfo=resInfo) self.residues.append(Nterminus)
def load_fragments(): from residue import Residue import os ref = Residue('REF') ref.append_atom(Atom( 'N', [0.000, 0.300, 0.000])) ref.append_atom(Atom('CA', [1.181, -0.540, 0.000])) ref.append_atom(Atom( 'C', [2.440, 0.300, 0.000])) # load all residues this_dir, this_filename = os.path.split(__file__) DATA_PATH = os.path.join(this_dir, "static", "residues.pdb") residue_container = Molecule.LoadFromFile(DATA_PATH) for fragment in residue_container.iter_residues(): fit(ref, ('N','CA','C'), fragment, ('N','CA','C')) FragmentProvider.FRAGMENTS[fragment.name] = fragment
def LoadFromFile(fname): from residue import Residue from atom import Atom def parse_pdb_line(s): # atname, resname, resid, xyz return s[12:16].strip(), \ s[17:21].strip(), \ int(s[22:26]), \ np.array([s[i:i+8] for i in (30,38,46)], dtype=float) rindex = 0 pivot = None atoms = [None] is_head = True molecule = Molecule('mol') with open(fname, 'r') as fin: for line in fin: if line.startswith('TITLE'): molecule.name = line[5:].strip() elif line.startswith('ATOM'): atname,resname,resid,xyz = parse_pdb_line(line) if is_head or (resid != rindex): residue = Residue(resname) molecule.append_residue(residue, is_head) is_head = False rindex = resid atom = Atom(atname, xyz) atoms.append(atom) residue.append_atom(atom) elif line.startswith('TER'): is_head = True elif line.startswith('CONECT'): idxs = map(int, line[6:].split()) pivot = atoms[idxs[0]] for i in idxs[1:]: pivot.connect_to(atoms[i]) auto_setup = pivot is None molecule.compile(auto_setup=auto_setup) return molecule
def convert_list_to_resobject_list(contact_residues): resobject_list = [] for residue in contact_residues: new_residue = Residue(resSeq=residue[1], chain_id=residue[0]) resobject_list.append(new_residue) return (resobject_list)
resobject_list = [] for residue in contact_residues: new_residue = Residue(resSeq = residue[1], chain_id = residue[0]) resobject_list.append(new_residue) return(resobject_list) #CHOOSE RESIDUES: bp_4dkl = md.load("/home/enf/md_simulations/MOR/4dkl_bp_6pt6.pdb") bp_5c1m = md.load("/home/enf/md_simulations/MOR/5c1m_bp_6pt6.pdb") bp_4dkl_residues = set([r.resSeq for r in bp_4dkl.topology.residues if r.is_protein]) bp_5c1m_residues = set([r.resSeq for r in bp_4dkl.topology.residues if r.is_protein]) bp_residues = sorted(list(bp_4dkl_residues | bp_5c1m_residues)) bp_residue_objects = convert_list_to_resobject_list([("R", i) for i in bp_residues]) cutoff = 1. feature_name = "bp_residues_4dkl_5c1m_under_cutoff%dA" %(int(10*cutoff)) common_residues_pkl = get_common_residues_pkl(base) contact_residues = find_common_residues([inactive_dir, active_dir, simulation_structure], common_residues_pkl) contact_resSeq = [r.resSeq for r in contact_residues] bfna_resobj = Residue(resSeq = 601, res_name = "BF0") _, bp_4dkl_residues = find_binding_pocket_residues(bfna_resobj, contact_residues, inactive_dir, cutoff=cutoff) bu72_resobj = Residue(resSeq = 401, res_name = "4VO") _, bp_5c1m_residues = find_binding_pocket_residues(bu72_resobj, contact_residues, active_dir, cutoff=cutoff) bp_residue_objects = sorted(list(set(bp_4dkl_residues) | set(bp_5c1m_residues))) #bp_residue_objects = [res for res in bp_residue_objects if res.resSeq in contact_resSeq]