本文整理汇总了Python中Bio.PDB.StructureBuilder.StructureBuilder.init_structure方法的典型用法代码示例。如果您正苦于以下问题:Python StructureBuilder.init_structure方法的具体用法?Python StructureBuilder.init_structure怎么用?Python StructureBuilder.init_structure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bio.PDB.StructureBuilder.StructureBuilder
的用法示例。
在下文中一共展示了StructureBuilder.init_structure方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: residues_to_struct
# 需要导入模块: from Bio.PDB.StructureBuilder import StructureBuilder [as 别名]
# 或者: from Bio.PDB.StructureBuilder.StructureBuilder import init_structure [as 别名]
def residues_to_struct(name_residues_list, structID):
"""
Build a structure from a list of (chain name, residues) - each as
a chain.
"""
builder = StructureBuilder()
builder.init_structure(structID)
builder.init_model(0)
for (name, residues) in name_residues_list:
builder.init_chain(name)
for res in residues:
builder.chain.add(res)
return builder.get_structure()
示例2: __init__
# 需要导入模块: from Bio.PDB.StructureBuilder import StructureBuilder [as 别名]
# 或者: from Bio.PDB.StructureBuilder.StructureBuilder import init_structure [as 别名]
class XBGFParser:
def __init__(self, PERMISSIVE=1, structure_builder=None):
if structure_builder != None:
self.structure_builder = structure_builder
else:
self.structure_builder = StructureBuilder()
self.PERMISSIVE = PERMISSIVE
# public interface
def parse(self, id, file):
self.structure_builder.init_structure(id)
if isinstance(file, basestring):
file=open(file)
self.charges = dict()
self.chain_suffix = 0
self._parse(file.readlines())
self.structure = self.structure_builder.get_structure()
return self._process_structure()
# private methods
def _parse(self, lines):
self.structure_builder.init_model(0)
self.structure_builder.init_seg("")
self.current_chain_id = None
self.current_residue_id = None
self.current_resname = None
for i in range(0, len(lines)):
self.line_counter = i + 1
self.structure_builder.set_line_counter(self.line_counter)
line = lines[i]
if line[0:6] == 'ATOM ':
self._update_atom(line)
def _update_chain(self, line):
chain_id = self._extract_chain(line)
if self.current_chain_id != chain_id:
try:
self.structure_builder.init_chain(chain_id)
self.current_chain_id = chain_id
self.current_residue_id = None
self.current_resname = None
except PDBConstructionException, message:
self._handle_PDB_exception(message)
示例3: set_structure
# 需要导入模块: from Bio.PDB.StructureBuilder import StructureBuilder [as 别名]
# 或者: from Bio.PDB.StructureBuilder.StructureBuilder import init_structure [as 别名]
def set_structure(self, pdb_object):
"""Check what object the user is providing and build a structure."""
# This is duplicated from the PDBIO class
if pdb_object.level == "S":
structure = pdb_object
else:
sb = StructureBuilder()
sb.init_structure('pdb')
sb.init_seg(' ')
# Build parts as necessary
if pdb_object.level == "M":
sb.structure.add(pdb_object)
self.structure = sb.structure
else:
sb.init_model(0)
if pdb_object.level == "C":
sb.structure[0].add(pdb_object)
else:
sb.init_chain('A')
if pdb_object.level == "R":
try:
parent_id = pdb_object.parent.id
sb.structure[0]['A'].id = parent_id
except ValueError:
pass
sb.structure[0]['A'].add(pdb_object)
else:
# Atom
sb.init_residue('DUM', ' ', 1, ' ')
try:
parent_id = pdb_object.parent.parent.id
sb.structure[0]['A'].id = parent_id
except ValueError:
pass
sb.structure[0]['A'].child_list[0].add(pdb_object)
# Return structure
structure = sb.structure
self.structure = structure
示例4: set_structure
# 需要导入模块: from Bio.PDB.StructureBuilder import StructureBuilder [as 别名]
# 或者: from Bio.PDB.StructureBuilder.StructureBuilder import init_structure [as 别名]
def set_structure(self, pdb_object):
"""Check what the user is providing and build a structure."""
if pdb_object.level == "S":
structure = pdb_object
else:
sb = StructureBuilder()
sb.init_structure('pdb')
sb.init_seg(' ')
# Build parts as necessary
if pdb_object.level == "M":
sb.structure.add(pdb_object.copy())
self.structure = sb.structure
else:
sb.init_model(0)
if pdb_object.level == "C":
sb.structure[0].add(pdb_object.copy())
else:
sb.init_chain('A')
if pdb_object.level == "R":
try:
parent_id = pdb_object.parent.id
sb.structure[0]['A'].id = parent_id
except Exception:
pass
sb.structure[0]['A'].add(pdb_object.copy())
else:
# Atom
sb.init_residue('DUM', ' ', 1, ' ')
try:
parent_id = pdb_object.parent.parent.id
sb.structure[0]['A'].id = parent_id
except Exception:
pass
sb.structure[0]['A'].child_list[0].add(pdb_object.copy())
# Return structure
structure = sb.structure
self.structure = structure
示例5: set_structure
# 需要导入模块: from Bio.PDB.StructureBuilder import StructureBuilder [as 别名]
# 或者: from Bio.PDB.StructureBuilder.StructureBuilder import init_structure [as 别名]
def set_structure(self, pdb_object):
# Check what the user is providing and build a structure appropriately
if pdb_object.level == "S":
structure = pdb_object
else:
sb = StructureBuilder()
sb.init_structure("pdb")
sb.init_seg(" ")
# Build parts as necessary
if pdb_object.level == "M":
sb.structure.add(pdb_object)
self.structure = sb.structure
else:
sb.init_model(0)
if pdb_object.level == "C":
sb.structure[0].add(pdb_object)
else:
sb.init_chain("A")
if pdb_object.level == "R":
try:
parent_id = pdb_object.parent.id
sb.structure[0]["A"].id = parent_id
except Exception:
pass
sb.structure[0]["A"].add(pdb_object)
else:
# Atom
sb.init_residue("DUM", " ", 1, " ")
try:
parent_id = pdb_object.parent.parent.id
sb.structure[0]["A"].id = parent_id
except Exception:
pass
sb.structure[0]["A"].child_list[0].add(pdb_object)
# Return structure
structure = sb.structure
self.structure = structure
示例6: PDBParser
# 需要导入模块: from Bio.PDB.StructureBuilder import StructureBuilder [as 别名]
# 或者: from Bio.PDB.StructureBuilder.StructureBuilder import init_structure [as 别名]
class PDBParser(object):
"""Parse a PDB file and return a Structure object."""
def __init__(self, PERMISSIVE=True, get_header=False,
structure_builder=None, QUIET=False):
"""Create a PDBParser object.
The PDB parser call a number of standard methods in an aggregated
StructureBuilder object. Normally this object is instanciated by the
PDBParser object itself, but if the user provides his/her own
StructureBuilder object, the latter is used instead.
Arguments:
- PERMISSIVE - Evaluated as a Boolean. If false, exceptions in
constructing the SMCRA data structure are fatal. If true (DEFAULT),
the exceptions are caught, but some residues or atoms will be missing.
THESE EXCEPTIONS ARE DUE TO PROBLEMS IN THE PDB FILE!.
- structure_builder - an optional user implemented StructureBuilder class.
- QUIET - Evaluated as a Boolean. If true, warnings issued in constructing
the SMCRA data will be suppressed. If false (DEFAULT), they will be shown.
These warnings might be indicative of problems in the PDB file!
"""
if structure_builder is not None:
self.structure_builder = structure_builder
else:
self.structure_builder = StructureBuilder()
self.header = None
self.trailer = None
self.line_counter = 0
self.PERMISSIVE = bool(PERMISSIVE)
self.QUIET = bool(QUIET)
# Public methods
def get_structure(self, id, file):
"""Return the structure.
Arguments:
- id - string, the id that will be used for the structure
- file - name of the PDB file OR an open filehandle
"""
with warnings.catch_warnings():
if self.QUIET:
warnings.filterwarnings("ignore", category=PDBConstructionWarning)
self.header = None
self.trailer = None
# Make a StructureBuilder instance (pass id of structure as parameter)
self.structure_builder.init_structure(id)
with as_handle(file, mode='rU') as handle:
self._parse(handle.readlines())
self.structure_builder.set_header(self.header)
# Return the Structure instance
structure = self.structure_builder.get_structure()
return structure
def get_header(self):
"""Return the header."""
return self.header
def get_trailer(self):
"""Return the trailer."""
return self.trailer
# Private methods
def _parse(self, header_coords_trailer):
"""Parse the PDB file (PRIVATE)."""
# Extract the header; return the rest of the file
self.header, coords_trailer = self._get_header(header_coords_trailer)
# Parse the atomic data; return the PDB file trailer
self.trailer = self._parse_coordinates(coords_trailer)
def _get_header(self, header_coords_trailer):
"""Get the header of the PDB file, return the rest (PRIVATE)."""
structure_builder = self.structure_builder
i = 0
for i in range(0, len(header_coords_trailer)):
structure_builder.set_line_counter(i + 1)
line = header_coords_trailer[i]
record_type = line[0:6]
if record_type == "ATOM " or record_type == "HETATM" or record_type == "MODEL ":
break
header = header_coords_trailer[0:i]
# Return the rest of the coords+trailer for further processing
self.line_counter = i
coords_trailer = header_coords_trailer[i:]
header_dict = _parse_pdb_header_list(header)
return header_dict, coords_trailer
def _parse_coordinates(self, coords_trailer):
"""Parse the atomic data in the PDB file (PRIVATE)."""
local_line_counter = 0
structure_builder = self.structure_builder
current_model_id = 0
# Flag we have an open model
model_open = 0
#.........这里部分代码省略.........
示例7: StructureDecoder
# 需要导入模块: from Bio.PDB.StructureBuilder import StructureBuilder [as 别名]
# 或者: from Bio.PDB.StructureBuilder.StructureBuilder import init_structure [as 别名]
class StructureDecoder(object):
"""Class to pass the data from mmtf-python into a Biopython data structure."""
def __init__(self):
"""Initialize the class."""
self.this_type = ""
def init_structure(self, total_num_bonds, total_num_atoms,
total_num_groups, total_num_chains, total_num_models,
structure_id):
"""Initialize the structure object.
:param total_num_bonds: the number of bonds in the structure
:param total_num_atoms: the number of atoms in the structure
:param total_num_groups: the number of groups in the structure
:param total_num_chains: the number of chains in the structure
:param total_num_models: the number of models in the structure
:param structure_id: the id of the structure (e.g. PDB id)
"""
self.structure_bulder = StructureBuilder()
self.structure_bulder.init_structure(structure_id=structure_id)
self.chain_index_to_type_map = {}
self.chain_index_to_seq_map = {}
self.chain_index_to_description_map = {}
self.chain_counter = 0
def set_atom_info(self, atom_name, serial_number, alternative_location_id,
x, y, z, occupancy, temperature_factor, element, charge):
"""Create an atom object an set the information.
:param atom_name: the atom name, e.g. CA for this atom
:param serial_number: the serial id of the atom (e.g. 1)
:param alternative_location_id: the alternative location id for the atom, if present
:param x: the x coordiante of the atom
:param y: the y coordinate of the atom
:param z: the z coordinate of the atom
:param occupancy: the occupancy of the atom
:param temperature_factor: the temperature factor of the atom
:param element: the element of the atom, e.g. C for carbon. According to IUPAC. Calcium is Ca
:param charge: the formal atomic charge of the atom
"""
# MMTF uses "\x00" (the NUL character) to indicate to altloc, so convert
# that to the space required by StructureBuilder
if alternative_location_id == "\x00":
alternative_location_id = " "
# Atom_name is in twice - the full_name is with spaces
self.structure_bulder.init_atom(str(atom_name), [x, y, z],
temperature_factor, occupancy,
alternative_location_id, str(atom_name),
serial_number=serial_number,
element=str(element).upper())
def set_chain_info(self, chain_id, chain_name, num_groups):
"""Set the chain information.
:param chain_id: the asym chain id from mmCIF
:param chain_name: the auth chain id from mmCIF
:param num_groups: the number of groups this chain has
"""
# A Bradley - chose to use chain_name (auth_id) as it complies
# with current Biopython. Chain_id might be better.
self.structure_bulder.init_chain(chain_id=chain_name)
if self.chain_index_to_type_map[self.chain_counter] == "polymer":
self.this_type = " "
elif self.chain_index_to_type_map[self.chain_counter] == "non-polymer":
self.this_type = "H"
elif self.chain_index_to_type_map[self.chain_counter] == "water":
self.this_type = "W"
self.chain_counter += 1
def set_entity_info(self, chain_indices, sequence, description, entity_type):
"""Set the entity level information for the structure.
:param chain_indices: the indices of the chains for this entity
:param sequence: the one letter code sequence for this entity
:param description: the description for this entity
:param entity_type: the entity type (polymer,non-polymer,water)
"""
for chain_ind in chain_indices:
self.chain_index_to_type_map[chain_ind] = entity_type
self.chain_index_to_seq_map[chain_ind] = sequence
self.chain_index_to_description_map[chain_ind] = description
def set_group_info(self, group_name, group_number, insertion_code,
group_type, atom_count, bond_count, single_letter_code,
sequence_index, secondary_structure_type):
"""Set the information for a group
:param group_name: the name of this group, e.g. LYS
:param group_number: the residue number of this group
:param insertion_code: the insertion code for this group
:param group_type: a string indicating the type of group (as found in the chemcomp dictionary.
Empty string if none available.
:param atom_count: the number of atoms in the group
:param bond_count: the number of unique bonds in the group
#.........这里部分代码省略.........
示例8: PDBParser
# 需要导入模块: from Bio.PDB.StructureBuilder import StructureBuilder [as 别名]
# 或者: from Bio.PDB.StructureBuilder.StructureBuilder import init_structure [as 别名]
class PDBParser(object):
"""
Parse a PDB file and return a Structure object.
"""
def __init__(self, PERMISSIVE=True, get_header=False,
structure_builder=None, QUIET=False):
"""
The PDB parser call a number of standard methods in an aggregated
StructureBuilder object. Normally this object is instanciated by the
PDBParser object itself, but if the user provides his/her own
StructureBuilder object, the latter is used instead.
Arguments:
o PERMISSIVE - Evaluated as a Boolean. If false, exceptions in
constructing the SMCRA data structure are fatal. If true (DEFAULT),
the exceptions are caught, but some residues or atoms will be missing.
THESE EXCEPTIONS ARE DUE TO PROBLEMS IN THE PDB FILE!.
o structure_builder - an optional user implemented StructureBuilder class.
o QUIET - Evaluated as a Boolean. If true, warnings issued in constructing
the SMCRA data will be suppressed. If false (DEFAULT), they will be shown.
These warnings might be indicative of problems in the PDB file!
"""
if structure_builder is not None:
self.structure_builder = structure_builder
else:
self.structure_builder = StructureBuilder()
self.header = None
self.trailer = None
self.line_counter = 0
self.PERMISSIVE = bool(PERMISSIVE)
self.QUIET = bool(QUIET)
# Public methods
def get_structure(self, id, file):
"""Return the structure.
Arguments:
o id - string, the id that will be used for the structure
o file - name of the PDB file OR an open filehandle
"""
if self.QUIET:
warning_list = warnings.filters[:]
warnings.filterwarnings("ignore", category=PDBConstructionWarning)
self.header = None
self.trailer = None
# Make a StructureBuilder instance (pass id of structure as parameter)
self.structure_builder.init_structure(id)
with as_handle(file) as handle:
self._parse(handle.readlines())
self.structure_builder.set_header(self.header)
# Return the Structure instance
structure = self.structure_builder.get_structure()
if self.QUIET:
warnings.filters = warning_list
return structure
def get_header(self):
"Return the header."
return self.header
def get_trailer(self):
"Return the trailer."
return self.trailer
# Private methods
def _parse(self, header_coords_trailer):
"Parse the PDB file."
# Extract the header; return the rest of the file
self.header, coords_trailer = self._get_header(header_coords_trailer)
# Parse the atomic data; return the PDB file trailer
self.trailer = self._parse_coordinates(coords_trailer)
def _get_header(self, header_coords_trailer):
"Get the header of the PDB file, return the rest."
structure_builder = self.structure_builder
i = 0
for i in range(0, len(header_coords_trailer)):
structure_builder.set_line_counter(i + 1)
line = header_coords_trailer[i]
record_type = line[0:6]
if record_type == "ATOM " or record_type == "HETATM" or record_type == "MODEL ":
break
header = header_coords_trailer[0:i]
# Return the rest of the coords+trailer for further processing
self.line_counter = i
coords_trailer = header_coords_trailer[i:]
header_dict = _parse_pdb_header_list(header)
return header_dict, coords_trailer
#.........这里部分代码省略.........