def __init__(self, pdb_file_lines, include_hetatm=False): self.pdb_const_str = pdb_constants() self.lines = pdb_file_lines self.include_hetatm = include_hetatm self.index = 0 self.model_lines = [] self.wrap_with_header_and_footer = True
def __init__(self, pdb_atom_line): """ parse the pdb_atom_line into the attribu :param pdb_atom_line: """ self.pdb_const_str = pdb_constants() self.pdb_line = pdb_atom_line.rstrip('\n').rstrip('\r').rstrip('\n') pdb_line = self.pdb_line try: # TODO use class methods here self.record_name = pdb_line[0:6].strip() # record name self.atom_serial_number = pdb_line[6:12].strip( ) # atom serial number self.atom_name = pdb_line[12:16].strip() # atom name with type self.orig_atom_name = pdb_line[ 12:16] # atom name with type nostip for str func self.altloc = pdb_line[16].strip() # alternate locatin indicator self.resname = pdb_line[17:20].strip() # residue name self.chain_id = pdb_line[21] # chain identifier self.resseq = pdb_line[22:26].strip() # residue sequence number self.icode = pdb_line[26] # insertion code self.x = float(pdb_atom_line[30:38].strip()) # coordinates X self.y = float(pdb_line[38:46].strip()) # coordinates Y self.z = float(pdb_line[46:54].strip()) # coordinates Z self.occupancy = float( pdb_line[54:60].strip()) # standard deviation of occupancy self.tempfactor = float( pdb_line[60:66].strip()) # standard deviation of temperature self.element_symbol = pdb_line[76:78].strip() # element symbol self.charge = pdb_line[78:80].strip() # charge on the atom except Exception as e: print("line={}".format(pdb_atom_line)) raise e
def __init__(self, pdb_chains, model_number='1'): if not model_number: self.model_number = '1' else: self.model_number = str(model_number) self.pdb_const_str = pdb_constants() self.extend(pdb_chains) self.wrap_with_header_and_footer = True
def __init__(self, pdb_atoms, ter_line=None): self.pdb_const_str = pdb_constants() self.chain_id = pdb_atoms[0].chain_id for i, pdbatom in enumerate(pdb_atoms): if not self.chain_id == pdbatom.chain_id: raise ValueError( "expecting chain_id:'{}', but I got:'{}' in atom:'{}'". format(self.chain_id, pdbatom.chain_id, pdbatom.pdb_line)) self.append(pdbatom) self.ter_line = ter_line
def __str__(self): s = "" chomp = lambda s: s.rstrip('\n') if self.include_extdta_in__str__: s += "\n".join(map(chomp, self.extdta)) s += "\n" if self.include_remarks_in__str__: s += str(self.remarks) if self.include_seqres_in__str__: s += "\n".join(list(map(chomp, self.seqres))) s += "\n" s += "\n".join(map(str, self)) + "\n" + pdb_constants().END + "\n" return s
def __str__(self): s = "" to_line = lambda ln: "{}{:>4} {}".format(pdb_constants().REMARK, self.remark_number, ln) s += "\n".join(map(to_line, self)) s += "\n" return s
def is_remark_line(cls, pdb_line): return pdb_line.startswith(pdb_constants().REMARK)
def from_pdb_model_lines(cls, pdb_model_lines, model_number='1', include_hetatm=False, pdb_file_name=""): if not model_number: model_number = '1' else: model_number = str(model_number) pdb_atoms_lines = [] pdb_chains = [] pdb_const_str = pdb_constants() # flag=False used_chain_ids = ['NO_CHAIN'] for li, line in enumerate(pdb_model_lines): if line.startswith(pdb_const_str.TER): ter_line = line chain = pdb_chain.from_pdb_atoms_lines(pdb_atoms_lines, ter_line) pdb_chains.append(chain) pdb_atoms_lines = [] used_chain_ids.append(chain.chain_id) continue record_name = pdb_atom.parse_record_name(line) current_chain_id = pdb_atom.parse_chain_id(line) if record_name == pdb_const_str.HETATM and current_chain_id in used_chain_ids: # HETATM after to TER line with prev used_chain_ids continue if record_name not in [pdb_const_str.ATOM, pdb_const_str.HETATM]: continue # chain change without ter_line so will create the terr line if len(pdb_atoms_lines) > 0: this_chain_id = pdb_atom(pdb_atoms_lines[0]).chain_id curr_line_chain_id = current_chain_id # if flag: # print ("this_chain_id={},curr_line_chain_id={}".format(this_chain_id,curr_line_chain_id)) # chain end - But no TER line if curr_line_chain_id != this_chain_id: print("WARN: {}: TER line is missing before:'{}'".format( pdb_file_name, line), file=sys.stderr) last_atom_line = pdb_atoms_lines[0] ter_line = pdb_chain.create_ter_line(last_atom_line) chain = pdb_chain.from_pdb_atoms_lines( pdb_atoms_lines, ter_line) pdb_chains.append(chain) # print ("new_chain: this_chain_id={},curr_line_chain_id={}".format(this_chain_id,curr_line_chain_id)) # print ("\n".join(pdb_atoms_lines)) pdb_atoms_lines = [] continue if line.startswith(pdb_const_str.ATOM): pdb_atoms_lines.append(line) elif line.startswith(pdb_const_str.HETATM) and include_hetatm: pdb_atoms_lines.append(line) # we should remove the last HETATM section in the following sequances: # ATOM-HETATM- ATOM -TER-HETATM-CONNECT # ATOM-...-ATOM-... -TER-HETATM-ENDMDL # ATOM-HETATM-..-ATOM-TER-HETATM_A-ATOM-HETATM-..-ATOM-TER-HETATM_B # -CONNECT # cahin A ^ chain B ^ # is_atom = lambda a: a.record_name == pdb_const_str.ATOM has_atoms_records = lambda c: len(list(filter(is_atom, c))) > 0 for i in range(-1, -1 * len(pdb_chains) - 1, -1): if not has_atoms_records(pdb_chains[-1]): del (pdb_chains[-1]) else: break return cls(pdb_chains, model_number)